En-desarrollo #27
@ -8,6 +8,7 @@ import com.primefactorsolutions.service.EmployeeService;
|
|||||||
import com.vaadin.flow.component.Component;
|
import com.vaadin.flow.component.Component;
|
||||||
import com.vaadin.flow.component.button.Button;
|
import com.vaadin.flow.component.button.Button;
|
||||||
import com.vaadin.flow.component.combobox.ComboBox;
|
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.notification.Notification;
|
||||||
import com.vaadin.flow.component.orderedlayout.HorizontalLayout;
|
import com.vaadin.flow.component.orderedlayout.HorizontalLayout;
|
||||||
import com.vaadin.flow.component.textfield.TextField;
|
import com.vaadin.flow.component.textfield.TextField;
|
||||||
@ -39,6 +40,7 @@ import java.io.InputStream;
|
|||||||
@PageTitle("Document")
|
@PageTitle("Document")
|
||||||
@Route(value = "/documents/:documentId?/:action?", layout = MainLayout.class)
|
@Route(value = "/documents/:documentId?/:action?", layout = MainLayout.class)
|
||||||
public class DocumentView extends BeanValidationForm<Document> implements HasUrlParameter<String> {
|
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 TextField fileName = new TextField("Document Name");
|
||||||
private final ComboBox<DocumentType> documentType = new ComboBox<>("Document Type");
|
private final ComboBox<DocumentType> documentType = new ComboBox<>("Document Type");
|
||||||
private final ComboBox<Employee> employeeComboBox = new ComboBox<>("Employee");
|
private final ComboBox<Employee> employeeComboBox = new ComboBox<>("Employee");
|
||||||
@ -51,7 +53,6 @@ public class DocumentView extends BeanValidationForm<Document> implements HasUrl
|
|||||||
private Button saveButton;
|
private Button saveButton;
|
||||||
private Button viewDocumentButton;
|
private Button viewDocumentButton;
|
||||||
|
|
||||||
|
|
||||||
public DocumentView(final DocumentService documentService,
|
public DocumentView(final DocumentService documentService,
|
||||||
final EmployeeService employeeService,
|
final EmployeeService employeeService,
|
||||||
final AuthenticationContext authContext) {
|
final AuthenticationContext authContext) {
|
||||||
@ -130,7 +131,8 @@ public class DocumentView extends BeanValidationForm<Document> implements HasUrl
|
|||||||
ui.getPage().open(registration.getResourceUri().toString());
|
ui.getPage().open(registration.getResourceUri().toString());
|
||||||
});
|
});
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
Notification.show("Error reading file.");
|
e.printStackTrace();
|
||||||
|
Notification.show("Error al leer el archivo.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -196,36 +198,30 @@ public class DocumentView extends BeanValidationForm<Document> implements HasUrl
|
|||||||
fileUploaded = true;
|
fileUploaded = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateSaveButtonState() {
|
private void handleUploadSuccess() {
|
||||||
boolean isModified = !fileName.getValue().equals(getEntity().getFileName())
|
fileUploaded = true;
|
||||||
|| documentType.getValue() != getEntity().getDocumentType()
|
Notification.show("File uploaded successfully.");
|
||||||
|| employeeComboBox.getValue() != getEntity().getEmployee()
|
viewDocumentButton.setEnabled(true);
|
||||||
|| fileUploaded;
|
}
|
||||||
saveButton.setEnabled(isModified);
|
|
||||||
|
private void handleFileRemoval() {
|
||||||
|
fileUploaded = false;
|
||||||
|
Notification.show("File removed.");
|
||||||
|
viewDocumentButton.setEnabled(false);
|
||||||
|
uploadButton.setReceiver(new MemoryBuffer());
|
||||||
}
|
}
|
||||||
|
|
||||||
private void configureComponents() {
|
private void configureComponents() {
|
||||||
setFileNameProperties();
|
setFileNameProperties();
|
||||||
setDocumentTypeProperties();
|
setDocumentTypeProperties();
|
||||||
setEmployeeComboBoxProperties();
|
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() {
|
private void configureUploadButton() {
|
||||||
uploadButton.setMaxFiles(1);
|
uploadButton.setMaxFiles(1);
|
||||||
uploadButton.setAcceptedFileTypes(".pdf");
|
uploadButton.setAcceptedFileTypes(".pdf");
|
||||||
uploadButton.addSucceededListener(event -> {
|
uploadButton.addSucceededListener(event -> handleUploadSuccess());
|
||||||
fileUploaded = true;
|
uploadButton.getElement().addEventListener("file-remove", event -> handleFileRemoval());
|
||||||
updateSaveButtonState();
|
|
||||||
});
|
|
||||||
uploadButton.getElement().addEventListener("file-remove", event -> {
|
|
||||||
fileUploaded = false;
|
|
||||||
updateSaveButtonState();
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void configureViewOrEditAction(final String action, final String documentIdString) {
|
private void configureViewOrEditAction(final String action, final String documentIdString) {
|
||||||
@ -249,7 +245,6 @@ public class DocumentView extends BeanValidationForm<Document> implements HasUrl
|
|||||||
if ("new".equals(action)) {
|
if ("new".equals(action)) {
|
||||||
setEntityWithEnabledSave(new Document());
|
setEntityWithEnabledSave(new Document());
|
||||||
} else {
|
} else {
|
||||||
assert documentIdString != null;
|
|
||||||
UUID documentId = UUID.fromString(documentIdString);
|
UUID documentId = UUID.fromString(documentIdString);
|
||||||
Document document = documentService.getDocument(documentId);
|
Document document = documentService.getDocument(documentId);
|
||||||
setEntity(document);
|
setEntity(document);
|
||||||
@ -264,6 +259,6 @@ public class DocumentView extends BeanValidationForm<Document> implements HasUrl
|
|||||||
HorizontalLayout buttonLayout = new HorizontalLayout();
|
HorizontalLayout buttonLayout = new HorizontalLayout();
|
||||||
buttonLayout.add(uploadButton, createViewDocumentButton());
|
buttonLayout.add(uploadButton, createViewDocumentButton());
|
||||||
buttonLayout.setSpacing(true);
|
buttonLayout.setSpacing(true);
|
||||||
return List.of(fileName, documentType, employeeComboBox, buttonLayout, createCloseButton());
|
return List.of(title, fileName, documentType, employeeComboBox, buttonLayout, createCloseButton());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -100,12 +100,10 @@ public class MainLayout extends AppLayout {
|
|||||||
|
|
||||||
SideNavItem admin = new SideNavItem("Admin", MainView.class,
|
SideNavItem admin = new SideNavItem("Admin", MainView.class,
|
||||||
LineAwesomeIcon.SUPERSCRIPT_SOLID.create());
|
LineAwesomeIcon.SUPERSCRIPT_SOLID.create());
|
||||||
admin.addItem(new SideNavItem("Requests", RequestsListView.class,
|
|
||||||
LineAwesomeIcon.TASKS_SOLID.create()));
|
|
||||||
admin.addItem(new SideNavItem("Timesheets", TimesheestReportView.class,
|
|
||||||
LineAwesomeIcon.HOURGLASS_END_SOLID.create()));
|
|
||||||
admin.addItem(new SideNavItem("Employees", EmployeesListView.class,
|
admin.addItem(new SideNavItem("Employees", EmployeesListView.class,
|
||||||
LineAwesomeIcon.USER_EDIT_SOLID.create()));
|
LineAwesomeIcon.USER_EDIT_SOLID.create()));
|
||||||
|
admin.addItem(new SideNavItem("Documents", DocumentsListView.class,
|
||||||
|
LineAwesomeIcon.FILE_ALT_SOLID.create()));
|
||||||
|
|
||||||
SideNavItem timeOff = new SideNavItem("My Time-off", TimeoffView.class,
|
SideNavItem timeOff = new SideNavItem("My Time-off", TimeoffView.class,
|
||||||
LineAwesomeIcon.PLANE_DEPARTURE_SOLID.create());
|
LineAwesomeIcon.PLANE_DEPARTURE_SOLID.create());
|
||||||
|
Loading…
Reference in New Issue
Block a user