Coreccion cambios ver documento
All checks were successful
PR Builder / Build-PR (pull_request) Successful in 2m8s
All checks were successful
PR Builder / Build-PR (pull_request) Successful in 2m8s
This commit is contained in:
parent
78f41d59e0
commit
2d4dbbd023
@ -8,7 +8,6 @@ import com.primefactorsolutions.service.EmployeeService;
|
||||
import com.vaadin.flow.component.Component;
|
||||
import com.vaadin.flow.component.button.Button;
|
||||
import com.vaadin.flow.component.combobox.ComboBox;
|
||||
import com.vaadin.flow.component.html.H2;
|
||||
import com.vaadin.flow.component.notification.Notification;
|
||||
import com.vaadin.flow.component.orderedlayout.HorizontalLayout;
|
||||
import com.vaadin.flow.component.textfield.TextField;
|
||||
@ -40,7 +39,6 @@ import java.io.InputStream;
|
||||
@PageTitle("Document")
|
||||
@Route(value = "/documents/:documentId?/:action?", layout = MainLayout.class)
|
||||
public class DocumentView extends BeanValidationForm<Document> implements HasUrlParameter<String> {
|
||||
private final H2 title = new H2("Edit Documents");
|
||||
private final TextField fileName = new TextField("Document Name");
|
||||
private final ComboBox<DocumentType> documentType = new ComboBox<>("Document Type");
|
||||
private final ComboBox<Employee> employeeComboBox = new ComboBox<>("Employee");
|
||||
@ -53,6 +51,7 @@ public class DocumentView extends BeanValidationForm<Document> implements HasUrl
|
||||
private Button saveButton;
|
||||
private Button viewDocumentButton;
|
||||
|
||||
|
||||
public DocumentView(final DocumentService documentService,
|
||||
final EmployeeService employeeService,
|
||||
final AuthenticationContext authContext) {
|
||||
@ -131,8 +130,7 @@ public class DocumentView extends BeanValidationForm<Document> implements HasUrl
|
||||
ui.getPage().open(registration.getResourceUri().toString());
|
||||
});
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
Notification.show("Error al leer el archivo.");
|
||||
Notification.show("Error reading file.");
|
||||
}
|
||||
}
|
||||
|
||||
@ -198,30 +196,40 @@ public class DocumentView extends BeanValidationForm<Document> implements HasUrl
|
||||
fileUploaded = true;
|
||||
}
|
||||
|
||||
private void handleUploadSuccess() {
|
||||
fileUploaded = true;
|
||||
Notification.show("File uploaded successfully.");
|
||||
viewDocumentButton.setEnabled(true);
|
||||
}
|
||||
|
||||
private void handleFileRemoval() {
|
||||
fileUploaded = false;
|
||||
Notification.show("File removed.");
|
||||
viewDocumentButton.setEnabled(false);
|
||||
uploadButton.setReceiver(new MemoryBuffer());
|
||||
private void updateSaveButtonState() {
|
||||
boolean isModified = !fileName.getValue().equals(getEntity().getFileName())
|
||||
|| documentType.getValue() != getEntity().getDocumentType()
|
||||
|| employeeComboBox.getValue() != getEntity().getEmployee()
|
||||
|| fileUploaded;
|
||||
saveButton.setEnabled(isModified);
|
||||
}
|
||||
|
||||
private void configureComponents() {
|
||||
setFileNameProperties();
|
||||
setDocumentTypeProperties();
|
||||
setEmployeeComboBoxProperties();
|
||||
fileName.addValueChangeListener(e -> updateSaveButtonState());
|
||||
documentType.addValueChangeListener(e -> updateSaveButtonState());
|
||||
employeeComboBox.addValueChangeListener(e -> updateSaveButtonState());
|
||||
uploadButton.addSucceededListener(e -> updateSaveButtonState());
|
||||
uploadButton.getElement().addEventListener("file-remove", event -> updateSaveButtonState());
|
||||
}
|
||||
|
||||
private void configureUploadButton() {
|
||||
uploadButton.setMaxFiles(1);
|
||||
uploadButton.setAcceptedFileTypes(".pdf");
|
||||
uploadButton.addSucceededListener(event -> handleUploadSuccess());
|
||||
uploadButton.getElement().addEventListener("file-remove", event -> handleFileRemoval());
|
||||
uploadButton.addSucceededListener(event -> {
|
||||
fileUploaded = true;
|
||||
Notification.show("File uploaded successfully.");
|
||||
viewDocumentButton.setEnabled(true);
|
||||
updateSaveButtonState();
|
||||
});
|
||||
uploadButton.getElement().addEventListener("file-remove", event -> {
|
||||
fileUploaded = false;
|
||||
Notification.show("File removed.");
|
||||
viewDocumentButton.setEnabled(false);
|
||||
updateSaveButtonState();
|
||||
});
|
||||
}
|
||||
|
||||
private void configureViewOrEditAction(final String action, final String documentIdString) {
|
||||
@ -245,6 +253,7 @@ public class DocumentView extends BeanValidationForm<Document> implements HasUrl
|
||||
if ("new".equals(action)) {
|
||||
setEntityWithEnabledSave(new Document());
|
||||
} else {
|
||||
assert documentIdString != null;
|
||||
UUID documentId = UUID.fromString(documentIdString);
|
||||
Document document = documentService.getDocument(documentId);
|
||||
setEntity(document);
|
||||
@ -259,6 +268,6 @@ public class DocumentView extends BeanValidationForm<Document> implements HasUrl
|
||||
HorizontalLayout buttonLayout = new HorizontalLayout();
|
||||
buttonLayout.add(uploadButton, createViewDocumentButton());
|
||||
buttonLayout.setSpacing(true);
|
||||
return List.of(title, fileName, documentType, employeeComboBox, buttonLayout, createCloseButton());
|
||||
return List.of(fileName, documentType, employeeComboBox, buttonLayout, createCloseButton());
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user