Compare commits

..

41 Commits

Author SHA1 Message Date
Melina Gutierrez
067941e540 #46 Perfil de Empleado - Registro Semanal de Horas trabajadas
Some checks failed
PR Builder / Build-PR (pull_request) Failing after 20s
2024-10-08 12:16:19 -04:00
Melina Gutierrez
2c18455581 Merge branch 'main' into #10-Registro-Informacion-Profesional 2024-10-08 11:57:41 -04:00
2782fcfb86 Merge pull request 'En-desarrollo' (#27) from En-desarrollo into main
All checks were successful
Builder / Build-Project (push) Successful in 2m31s
Reviewed-on: #27
Reviewed-by: alex <alex@primefactorsolutions.com>
2024-10-07 18:23:33 +00:00
d2357a2adf Merge branch 'main' into En-desarrollo
All checks were successful
PR Builder / Build-PR (pull_request) Successful in 2m29s
2024-10-04 15:18:21 -04:00
2d4dbbd023 Coreccion cambios ver documento
All checks were successful
PR Builder / Build-PR (pull_request) Successful in 2m8s
2024-10-02 16:06:59 -04:00
78f41d59e0 Coreccion del enlace a documentos
All checks were successful
PR Builder / Build-PR (pull_request) Successful in 2m4s
2024-10-01 18:35:52 -04:00
e77e63491a Resuelve construccion fallido
All checks were successful
PR Builder / Build-PR (pull_request) Successful in 2m13s
2024-10-01 17:57:26 -04:00
9c94b703ca Merge branch 'En-desarrollo' of https://git.primefactorsolutions.com/PFS/pfs-intra into En-desarrollo
Some checks failed
PR Builder / Build-PR (pull_request) Failing after 13s
2024-10-01 17:39:26 -04:00
88342555a0 Resuelve conflictos en Employee.java y MainLayout.java 2024-10-01 15:40:46 -04:00
2e544519da Merge pull request 'Perfil-Empleado-Administrativo-Documentacion' (#40) from Perfil-Empleado-Administrativo-Documentacion into En-desarrollo
Reviewed-on: #40
2024-10-01 19:35:51 +00:00
85e0e44f4f Merge branch 'Perfil-Empleado-Administrativo-Documentacion' of https://git.primefactorsolutions.com/PFS/pfs-intra into Perfil-Empleado-Administrativo-Documentacion 2024-10-01 15:32:29 -04:00
dccc3ea09d #31 Perfil de Usuario Administrativo - EDITAR Documentos (Correccion validacion para editar) 2024-10-01 13:27:49 -04:00
9b67ee3902 Perfil de Personal Administrativo - VER, EDITAR, AÑADIR Documento (Correccion en el el boton view document) 2024-09-30 19:28:44 -04:00
b6a27c435e Merge pull request 'Perfil-Empleado-Administrativo-Documentacion' (#39) from Perfil-Empleado-Administrativo-Documentacion into En-desarrollo
Reviewed-on: #39
2024-09-27 07:31:14 +00:00
26af5f63c7 Merge branch 'En-desarrollo' into Perfil-Empleado-Administrativo-Documentacion 2024-09-27 07:30:59 +00:00
6d9a2f65e5 #32 Perfil de Personal Administrativo - VER Documento (agregar boton ver documento) 2024-09-27 03:29:26 -04:00
1519d82993 #29 Perfil de Empleado Administrativo - LISTAR Documentos (filtar por tipo de documento y empleado) 2024-09-27 00:07:27 -04:00
4241e7b52b #29 Perfil de Empleado Administrativo - LISTAR Documentos (correccion download, view, edit) 2024-09-25 18:50:59 -04:00
f0b41743c7 #30 Perfil de Usuario Administrativo - Añadir NUEVO Documento (agregar creador del registro del doc) 2024-09-24 20:44:16 -04:00
af3f13773b #29 Perfil de Empleado Administrativo - LISTAR Documentos (implementacion de download) 2024-09-24 19:26:18 -04:00
f3bda474d0 #32 Perfil de Personal Administrativo - VER Documento 2024-09-24 19:07:58 -04:00
45987ccad9 #29 Perfil de Empleado Administrativo - LISTAR Documentos (correccionse) 2024-09-24 17:25:43 -04:00
514e4eaf49 #29 Perfil de Empleado Administrativo - LISTAR Documentos 2024-09-24 17:07:53 -04:00
2caa878c07 #30 Perfil de Usuario Administrativo - Añadir NUEVO Documento 2024-09-24 12:30:03 -04:00
6df1d45c81 Merge pull request 'Change menu' (#33) from Perfil-Personal-Administrativo-Documentacion into En-desarrollo
Reviewed-on: #33
2024-09-23 17:53:00 +00:00
e349503fb4 Change menu 2024-09-23 13:50:27 -04:00
c997e3c282 Merge pull request 'Perfil-Personal-Administrativo-Documentacion' (#28) from Perfil-Personal-Administrativo-Documentacion into En-desarrollo
Reviewed-on: #28
2024-09-19 04:59:31 +00:00
613221dfb6 Refactorizacion del modulo de documentos 2024-09-19 00:56:44 -04:00
13c81de48c Correcciones 2024-09-16 20:09:16 -04:00
2208450692 Merge pull request 'Perfil-Personal-Administrativo-Documentacion' (#26) from Perfil-Personal-Administrativo-Documentacion into En-desarrollo
Reviewed-on: #26
2024-09-15 22:14:02 +00:00
f2a1d53e4a #19 Perfil de Personal Administrativo - Cargar Documentación de Gobierno (Ver, cargar y guardar) 2024-09-15 18:13:11 -04:00
109ddde243 #18 Perfil de Personal Administrativo - Carga de Documentación Corporativa (Ver, cargar y guardar) 2024-09-15 17:52:43 -04:00
0744e16dea #21 Perfil de Personal Administrativo - Carga de Documentación Profesional (Ver, cargar y guardar) 2024-09-15 03:22:18 -04:00
ca307e2c0b #20 Perfil de Personal Administrativo - Carga de Documentación Personal (Ver, cargar y guardar) 2024-09-15 03:09:38 -04:00
4d12dfdd18 Merge pull request '#17 Perfil de Personal Administrativo - Carga de Documentación Laboral (Revisiòn)' (#25) from #17-Perfil-Personal-Administrativo into En-desarrollo
Reviewed-on: #25
2024-09-15 06:50:44 +00:00
443299453b #17 Perfil de Personal Administrativo - Carga de Documentación Laboral (Revisiòn) 2024-09-15 02:47:52 -04:00
50a7809e6d Merge pull request '#17-Perfil-Personal-Administrativo' (#24) from #17-Perfil-Personal-Administrativo into En-desarrollo
Reviewed-on: #24
2024-09-15 06:27:56 +00:00
97c07a4558 #17 Perfil de Personal Administrativo - Carga de Documentación Laboral (Ver documento) 2024-09-15 02:25:38 -04:00
64d62a06db #17 Perfil de Personal Administrativo - Carga de Documentación Laboral (Funcionalidades save y upload v2) 2024-09-14 15:33:33 -04:00
5bbdb5f2ee #17 Perfil de Personal Administrativo - Carga de Documentación Laboral (Funcionalidades save y upload) 2024-09-14 15:30:51 -04:00
1887214ed2 #17 Perfil de Personal Administrativo - Carga de Documentación Laboral (VISTA) 2024-09-11 15:27:09 -04:00
17 changed files with 735 additions and 137 deletions

View File

@ -1,10 +1,6 @@
package com.primefactorsolutions.model; package com.primefactorsolutions.model;
import jakarta.persistence.GeneratedValue; import jakarta.persistence.*;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.MappedSuperclass;
import jakarta.persistence.Version;
import java.util.UUID; import java.util.UUID;

View File

@ -1,23 +1,23 @@
package com.primefactorsolutions.model; package com.primefactorsolutions.model;
import jakarta.annotation.Nullable; import jakarta.persistence.*;
import jakarta.persistence.Entity;
import jakarta.persistence.ManyToOne; import lombok.*;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
@Entity
@Data @Data
@Entity
@AllArgsConstructor @AllArgsConstructor
@NoArgsConstructor @NoArgsConstructor
@EqualsAndHashCode(callSuper = true) @EqualsAndHashCode(callSuper = true)
public class Document extends BaseEntity { public class Document extends BaseEntity {
@Nullable private String fileName;
private String description; @Enumerated(EnumType.STRING)
private String location;
private DocumentType documentType; private DocumentType documentType;
@ManyToOne @ManyToOne
@JoinColumn(name = "employee_id", nullable = false)
private Employee employee; private Employee employee;
@Lob
@Column(columnDefinition = "BLOB")
private byte[] fileData;
private String creator;
} }

View File

@ -1,7 +1,36 @@
package com.primefactorsolutions.model; package com.primefactorsolutions.model;
public enum DocumentType { public enum DocumentType {
All,
ID_CARD, ID_CARD,
PAY_STUB, PAY_STUB,
PAY_SLIPS,
EMPLOYMENT_CONTRACT,
WORK_CERTIFICATES,
NDA,
MEMORANDUMS,
CONTRACT_APPROVAL_MTEPS,
BACKGROUND_CHECK_CERTIFICATE,
PRE_EMPLOYMENT_EVALUATION,
INSURANCE_REGISTRATION_FORM,
INSURANCE_CANCELLATION_FORM,
PROFESSIONAL_DEGREE_1,
PROFESSIONAL_CERTIFICATE_1,
PROFESSIONAL_DEGREE_2,
PROFESSIONAL_CERTIFICATE_2,
PROFESSIONAL_DEGREE_3,
PROFESSIONAL_CERTIFICATE_3,
GENERAL_LABOR_REGULATIONS,
REMOTE_WORK_GUIDELINES,
SAFETY_REGULATIONS,
HUMAN_RESOURCES_GUIDELINES,
ADMINISTRATION_FUNCTIONS_MANUAL,
ENGINEERING_FUNCTIONS_MANUAL,
GENERAL_LABOR_LAW,
SUPREME_DECREE,
REGULATORY_RESOLUTION,
COMPLEMENTARY_REGULATION,
HEALTH_SAFETY_LAW,
INTERNSHIP_RULES,
OTHER OTHER
} }

View File

@ -0,0 +1,9 @@
package com.primefactorsolutions.repositories;
import com.primefactorsolutions.model.Document;
import org.springframework.data.jpa.repository.JpaRepository;
import java.util.UUID;
public interface DocumentRepository extends JpaRepository<Document, UUID> {
}

View File

@ -0,0 +1,78 @@
package com.primefactorsolutions.service;
import com.primefactorsolutions.model.Document;
import com.primefactorsolutions.model.DocumentType;
import com.primefactorsolutions.model.Employee;
import com.primefactorsolutions.repositories.DocumentRepository;
import lombok.AllArgsConstructor;
import org.apache.commons.beanutils.BeanComparator;
import org.springframework.stereotype.Service;
import java.util.Collections;
import java.util.List;
import java.util.UUID;
import java.util.Optional;
import java.util.stream.Collectors;
@Service
@AllArgsConstructor
public class DocumentService {
private final DocumentRepository documentRepository;
public void saveDocument(final Document newDocument) {
documentRepository.save(newDocument);
}
public void deleteDocument(final UUID id) {
documentRepository.deleteById(id);
}
public List<Document> getAllDocuments() {
return documentRepository.findAll();
}
public Document getDocument(final UUID id) {
Optional<Document> employee = documentRepository.findById(id);
return employee.orElse(null);
}
public List<Document> findDocuments(
final int start, final int pageSize, final String sortProperty, final boolean asc) {
List<Document> documents = documentRepository.findAll();
int end = Math.min(start + pageSize, documents.size());
documents.sort(new BeanComparator<>(sortProperty));
if (!asc) {
Collections.reverse(documents);
}
return documents.subList(start, end);
}
public List<Document> findDocuments(final int start, final int pageSize) {
List<Document> employees = documentRepository.findAll();
int end = Math.min(start + pageSize, employees.size());
return employees.subList(start, end);
}
public List<Document> findDocumentBy(final DocumentType documentType,
final Employee employee,
final int start,
final int pageSize) {
List<Document> documents = documentRepository.findAll();
if (documentType != null) {
documents = documents.stream()
.filter(doc -> doc.getDocumentType().equals(documentType))
.collect(Collectors.toList());
}
if (employee != null) {
documents = documents.stream()
.filter(doc -> doc.getEmployee().equals(employee))
.collect(Collectors.toList());
}
int end = Math.min(start + pageSize, documents.size());
return documents.subList(start, end);
}
}

View File

@ -100,4 +100,8 @@ public class EmployeeService {
ldapTemplate.modifyAttributes(buildDn(employee), new ModificationItem[] {item}); ldapTemplate.modifyAttributes(buildDn(employee), new ModificationItem[] {item});
} }
public List<Employee> findAllEmployees() {
return employeeRepository.findAll();
}
} }

View File

@ -1,16 +0,0 @@
package com.primefactorsolutions.views;
import com.vaadin.flow.component.html.Main;
import com.vaadin.flow.router.PageTitle;
import com.vaadin.flow.router.Route;
import com.vaadin.flow.spring.annotation.SpringComponent;
import jakarta.annotation.security.PermitAll;
import org.springframework.context.annotation.Scope;
@SpringComponent
@PermitAll
@Scope("prototype")
@PageTitle("CorporateDocuments")
@Route(value = "/corporate-documents/me", layout = MainLayout.class)
public class CorporateDocumentsView extends Main {
}

View File

@ -0,0 +1,273 @@
package com.primefactorsolutions.views;
import com.primefactorsolutions.model.Document;
import com.primefactorsolutions.model.DocumentType;
import com.primefactorsolutions.model.Employee;
import com.primefactorsolutions.service.DocumentService;
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.notification.Notification;
import com.vaadin.flow.component.orderedlayout.HorizontalLayout;
import com.vaadin.flow.component.textfield.TextField;
import com.vaadin.flow.component.upload.Upload;
import com.vaadin.flow.component.upload.receivers.MemoryBuffer;
import com.vaadin.flow.router.*;
import com.vaadin.flow.server.StreamRegistration;
import com.vaadin.flow.server.StreamResource;
import com.vaadin.flow.spring.annotation.SpringComponent;
import elemental.json.Json;
import elemental.json.JsonArray;
import elemental.json.JsonObject;
import jakarta.annotation.security.PermitAll;
import org.springframework.context.annotation.Scope;
import org.springframework.security.core.userdetails.UserDetails;
import org.vaadin.firitin.form.BeanValidationForm;
import com.vaadin.flow.spring.security.AuthenticationContext;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.util.Base64;
import java.util.List;
import java.util.UUID;
import java.io.InputStream;
@SpringComponent
@PermitAll
@Scope("prototype")
@PageTitle("Document")
@Route(value = "/documents/:documentId?/:action?", layout = MainLayout.class)
public class DocumentView extends BeanValidationForm<Document> implements HasUrlParameter<String> {
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");
private final MemoryBuffer buffer = new MemoryBuffer();
private final Upload uploadButton = new Upload(buffer);
private final DocumentService documentService;
private final EmployeeService employeeService;
private final AuthenticationContext authContext;
private boolean fileUploaded = false;
private Button saveButton;
private Button viewDocumentButton;
public DocumentView(final DocumentService documentService,
final EmployeeService employeeService,
final AuthenticationContext authContext) {
super(Document.class);
this.documentService = documentService;
this.employeeService = employeeService;
this.authContext = authContext;
initializeView();
}
private void initializeView() {
configureComponents();
configureUploadButton();
}
protected Button createSaveButton() {
saveButton = new Button("Save");
saveButton.addClickListener(event -> saveDocument());
return saveButton;
}
protected Button createCloseButton() {
Button closeButton = new Button("Close");
closeButton.addClickListener(event -> closeForm());
return closeButton;
}
protected Button createViewDocumentButton() {
viewDocumentButton = new Button("View Document");
viewDocumentButton.setEnabled(false);
viewDocumentButton.addClickListener(event -> viewDocument());
return viewDocumentButton;
}
private void setFileNameProperties() {
fileName.setWidthFull();
}
private void setDocumentTypeProperties() {
documentType.setItems(DocumentType.values());
documentType.setWidthFull();
}
private void setEmployeeComboBoxProperties() {
List<Employee> employees = employeeService.findAllEmployees();
employeeComboBox.setItems(employees);
employeeComboBox.setItemLabelGenerator(employee -> employee.getFirstName() + " " + employee.getLastName());
employeeComboBox.setWidthFull();
}
private void setDocumentCreator(final Document document) {
authContext.getAuthenticatedUser(UserDetails.class).ifPresent(user -> {
document.setCreator(user.getUsername());
});
}
private void setFieldsReadOnly(final boolean option) {
fileName.setReadOnly(option);
documentType.setReadOnly(option);
employeeComboBox.setReadOnly(option);
}
private void viewDocument() {
StreamResource resource;
try {
InputStream inputStream = buffer.getInputStream();
if (inputStream != null && inputStream.available() > 0) {
resource = new StreamResource(fileName.getValue(), () -> new ByteArrayInputStream(readFileData()));
} else {
byte[] fileData = getEntity().getFileData();
resource = new StreamResource(fileName.getValue(), () -> new ByteArrayInputStream(fileData));
}
resource.setContentType("application/pdf");
getUI().ifPresent(ui -> {
StreamRegistration registration = ui.getSession().getResourceRegistry().registerResource(resource);
ui.getPage().open(registration.getResourceUri().toString());
});
} catch (IOException e) {
Notification.show("Error reading file.");
}
}
private void navigateToDocumentsListView() {
getUI().ifPresent(ui -> ui.navigate(DocumentsListView.class));
}
private void saveDocument() {
if (isFormValid()) {
Document document = getEntity();
document.setFileName(fileName.getValue());
document.setDocumentType(documentType.getValue());
document.setEmployee(employeeComboBox.getValue());
document.setFileData(readFileData());
setDocumentCreator(document);
documentService.saveDocument(document);
Notification.show("File saved successfully.");
clearForm();
} else {
Notification.show("Save failed: Please complete all fields and upload a file.");
}
}
private void closeForm() {
navigateToDocumentsListView();
}
private boolean isFormValid() {
return !fileName.isEmpty()
&& documentType.getValue() != null
&& employeeComboBox.getValue() != null
&& fileUploaded;
}
private void clearForm() {
fileName.clear();
documentType.clear();
employeeComboBox.clear();
fileUploaded = false;
uploadButton.getElement().setPropertyJson("files", Json.createArray());
viewDocumentButton.setEnabled(false);
}
private byte[] readFileData() {
try {
return buffer.getInputStream().readAllBytes();
} catch (IOException e) {
Notification.show("Error reading file data.");
return new byte[0];
}
}
private void preLoadFile(final Document document) {
JsonArray jsonArray = Json.createArray();
JsonObject jsonObject = Json.createObject();
jsonObject.put("name", document.getFileName());
jsonObject.put("progress", 100);
jsonObject.put("complete", true);
jsonObject.put("fileData", Base64.getEncoder().encodeToString(document.getFileData()));
jsonArray.set(0, jsonObject);
uploadButton.getElement().setPropertyJson("files", jsonArray);
fileUploaded = true;
}
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 -> {
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) {
if ("edit".equals(action) && !documentIdString.isEmpty()) {
setFieldsReadOnly(false);
preLoadFile(getEntity());
viewDocumentButton.setEnabled(true);
} else if ("view".equals(action) && !documentIdString.isEmpty()) {
setFieldsReadOnly(true);
preLoadFile(getEntity());
saveButton.setEnabled(false);
viewDocumentButton.setEnabled(true);
}
}
@Override
public void setParameter(final BeforeEvent beforeEvent, final String action) {
final RouteParameters params = beforeEvent.getRouteParameters();
final String documentIdString = params.get("documentId").orElse(null);
if ("new".equals(action)) {
setEntityWithEnabledSave(new Document());
} else {
assert documentIdString != null;
UUID documentId = UUID.fromString(documentIdString);
Document document = documentService.getDocument(documentId);
setEntity(document);
employeeComboBox.setValue(document.getEmployee());
preLoadFile(document);
configureViewOrEditAction(action, documentIdString);
}
}
@Override
protected List<Component> getFormComponents() {
HorizontalLayout buttonLayout = new HorizontalLayout();
buttonLayout.add(uploadButton, createViewDocumentButton());
buttonLayout.setSpacing(true);
return List.of(fileName, documentType, employeeComboBox, buttonLayout, createCloseButton());
}
}

View File

@ -0,0 +1,205 @@
package com.primefactorsolutions.views;
import com.primefactorsolutions.model.Document;
import com.primefactorsolutions.model.DocumentType;
import com.primefactorsolutions.model.Employee;
import com.primefactorsolutions.service.DocumentService;
import com.primefactorsolutions.service.EmployeeService;
import com.vaadin.flow.component.UI;
import com.vaadin.flow.component.button.Button;
import com.vaadin.flow.component.combobox.ComboBox;
import com.vaadin.flow.component.grid.GridSortOrder;
import com.vaadin.flow.component.html.Main;
import com.vaadin.flow.component.html.Span;
import com.vaadin.flow.data.provider.SortDirection;
import com.vaadin.flow.router.PageTitle;
import com.vaadin.flow.router.Route;
import com.vaadin.flow.server.StreamRegistration;
import com.vaadin.flow.server.StreamResource;
import com.vaadin.flow.spring.annotation.SpringComponent;
import jakarta.annotation.security.PermitAll;
import org.springframework.context.annotation.Scope;
import org.vaadin.firitin.components.grid.PagingGrid;
import java.io.ByteArrayInputStream;
import java.util.List;
@SpringComponent
@Scope("prototype")
@PageTitle("Documents")
@Route(value = "/documents", layout = MainLayout.class)
@PermitAll
public class DocumentsListView extends Main {
private final DocumentService documentService;
private final EmployeeService employeeService;
private final PagingGrid<Document> documentGrid = new PagingGrid<>(Document.class);
private ComboBox<Employee> employeeFilter;
private ComboBox<DocumentType> documentTypeFilter;
public DocumentsListView(final DocumentService documentService, final EmployeeService employeeService) {
this.documentService = documentService;
this.employeeService = employeeService;
initializeView();
updateDocumentGrid(null, null);
}
private void initializeView() {
configureDocumentGrid();
add(createActionButton("Add Document", this::navigateToAddDocumentView));
add(createDocumentTypeFilter());
add(createEmployeeFilter());
add(documentGrid);
}
private void configureDocumentGrid() {
documentGrid.setColumns("fileName", "documentType", "creator");
documentGrid.addComponentColumn(this::createEmployeeSpan).setHeader("Employee");
addActionColumns();
configurePagination();
}
private Span createEmployeeSpan(final Document document) {
Employee employee = document.getEmployee();
String employeeName = employee.getFirstName() + " " + employee.getLastName();
return new Span(employeeName);
}
private void addActionColumns() {
addDocumentActionColumn("View", this::navigateToDocumentView);
addDocumentActionColumn("Edit", this::navigateToEditDocumentView);
addDocumentActionColumn("Download", this::downloadDocument);
}
private void addDocumentActionColumn(final String label, final DocumentActionHandler handler) {
documentGrid.addComponentColumn(document -> createActionButton(label, () -> handler.handle(document)));
}
private Button createActionButton(final String label, final Runnable onClickAction) {
Button actionButton = new Button(label);
actionButton.addClickListener(event -> onClickAction.run());
return actionButton;
}
private ComboBox<DocumentType> createDocumentTypeFilter() {
documentTypeFilter = new ComboBox<>("Document Type");
documentTypeFilter.setItems(DocumentType.values());
documentTypeFilter.setValue(DocumentType.values()[0]);
documentTypeFilter.addValueChangeListener(event -> {
updateDocumentGrid(event.getValue(), employeeFilter.getValue());
});
return documentTypeFilter;
}
private ComboBox<Employee> createEmployeeFilter() {
employeeFilter = new ComboBox<>("Employee");
List<Employee> employees = employeeService.findAllEmployees();
employees.addFirst(createAllEmployeesOption());
employeeFilter.setItems(employees);
employeeFilter.setItemLabelGenerator(this::getEmployeeLabel);
employeeFilter.setValue(employees.getFirst());
employeeFilter.addValueChangeListener(event -> {
updateDocumentGrid(documentTypeFilter.getValue(), event.getValue());
});
return employeeFilter;
}
private Employee createAllEmployeesOption() {
Employee allEmployeesOption = new Employee();
allEmployeesOption.setFirstName("All");
return allEmployeesOption;
}
private String getEmployeeLabel(final Employee employee) {
return employee.getFirstName().equals("All") ? "All" : employee.getFirstName() + " " + employee.getLastName();
}
private void navigateToEditDocumentView(final Document document) {
navigateToDocumentView(document, "edit");
}
private void navigateToDocumentView(final Document document) {
navigateToDocumentView(document, "view");
}
private void navigateToDocumentView(final Document document, final String action) {
getUI().ifPresent(ui -> ui.navigate(DocumentView.class, document.getId().toString() + "/" + action));
}
private void navigateToAddDocumentView() {
getUI().ifPresent(ui -> ui.navigate(DocumentView.class, "new"));
}
private void configurePagination() {
documentGrid.setPaginationBarMode(PagingGrid.PaginationBarMode.BOTTOM);
documentGrid.setPageSize(5);
}
private void updateDocumentGrid(final DocumentType documentType, final Employee employee) {
DocumentType finalDocumentType = isValidDocumentType(documentType) ? documentType : null;
Employee finalEmployee = isValidEmployee(employee) ? employee : null;
documentGrid.setPagingDataProvider((page, pageSize) ->
(finalDocumentType == null && finalEmployee == null)
? fetchDocuments((int) page, pageSize)
: fetchFilteredDocuments((int) page, pageSize, finalDocumentType, finalEmployee)
);
documentGrid.getDataProvider().refreshAll();
}
private boolean isValidDocumentType(final DocumentType documentType) {
return documentType != null && !"All".equals(documentType.name());
}
private boolean isValidEmployee(final Employee employee) {
return employee != null && !"All".equals(employee.getFirstName());
}
private List<Document> fetchFilteredDocuments(final int page,
final int pageSize,
final DocumentType documentType,
final Employee employee) {
return documentService.findDocumentBy(documentType, employee, page, pageSize);
}
private List<Document> fetchDocuments(final int page, final int size) {
int startIndex = page * size;
return isSortOrderPresent()
? fetchSortedDocuments(startIndex, size)
: documentService.findDocuments(startIndex, size);
}
private boolean isSortOrderPresent() {
return !documentGrid.getSortOrder().isEmpty();
}
private List<Document> fetchSortedDocuments(final int start, final int pageSize) {
GridSortOrder<Document> sortOrder = documentGrid.getSortOrder().getFirst();
return documentService.findDocuments(start, pageSize,
sortOrder.getSorted().getKey(),
sortOrder.getDirection() == SortDirection.ASCENDING);
}
private void downloadDocument(final Document document) {
StreamResource resource = createDocumentStreamResource(document);
getUI().ifPresent(ui -> openDocumentStream(resource, ui));
}
private StreamResource createDocumentStreamResource(final Document document) {
StreamResource resource = new StreamResource(document.getFileName(),
() -> new ByteArrayInputStream(document.getFileData()));
resource.setContentType("application/pdf");
resource.setHeader("Content-Disposition", "attachment; filename=\"" + document.getFileName() + ".pdf\"");
return resource;
}
private void openDocumentStream(final StreamResource resource, final UI ui) {
StreamRegistration registration = ui.getSession().getResourceRegistry().registerResource(resource);
ui.getPage().open(registration.getResourceUri().toString());
}
@FunctionalInterface
private interface DocumentActionHandler {
void handle(Document document);
}
}

View File

@ -1,17 +0,0 @@
package com.primefactorsolutions.views;
import com.vaadin.flow.component.html.Main;
import com.vaadin.flow.router.PageTitle;
import com.vaadin.flow.router.Route;
import com.vaadin.flow.spring.annotation.SpringComponent;
import jakarta.annotation.security.PermitAll;
import org.springframework.context.annotation.Scope;
@SpringComponent
@PermitAll
@Scope("prototype")
@PageTitle("Documents")
@Route(value = "/documents/me", layout = MainLayout.class)
public class DocumentsView extends Main {
}

View File

@ -47,12 +47,6 @@ public class EmployeesListView extends Main {
setupPagingGrid(); setupPagingGrid();
} }
private void updateEmployeeStatus(final Employee employee, final boolean isActive) {
employee.setStatus(isActive ? Employee.Status.ACTIVE : Employee.Status.INACTIVE);
employeeService.createOrUpdate(employee);
refreshGrid();
}
private void addEditButtonColumn(final String label, final ButtonClickHandler handler) { private void addEditButtonColumn(final String label, final ButtonClickHandler handler) {
table.addComponentColumn(employee -> createButton(label, () -> handler.handle(employee))); table.addComponentColumn(employee -> createButton(label, () -> handler.handle(employee)));
} }

View File

@ -1,16 +0,0 @@
package com.primefactorsolutions.views;
import com.vaadin.flow.component.html.Main;
import com.vaadin.flow.router.PageTitle;
import com.vaadin.flow.router.Route;
import com.vaadin.flow.spring.annotation.SpringComponent;
import jakarta.annotation.security.PermitAll;
import org.springframework.context.annotation.Scope;
@SpringComponent
@PermitAll
@Scope("prototype")
@PageTitle("GovernmentDocumentsView")
@Route(value = "/government-documents/me", layout = MainLayout.class)
public class GovernmentDocumentsView extends Main {
}

View File

@ -0,0 +1,120 @@
package com.primefactorsolutions.views;
import com.vaadin.flow.component.datepicker.DatePicker;
import com.vaadin.flow.component.orderedlayout.HorizontalLayout;
import com.vaadin.flow.component.textfield.TextField;
import com.vaadin.flow.component.button.Button;
import com.vaadin.flow.component.combobox.ComboBox;
import com.vaadin.flow.component.grid.Grid;
import com.vaadin.flow.component.orderedlayout.VerticalLayout;
import com.vaadin.flow.component.html.H2;
import com.vaadin.flow.router.PageTitle;
import com.vaadin.flow.router.Route;
import com.vaadin.flow.spring.annotation.SpringComponent;
import jakarta.annotation.security.PermitAll;
import org.springframework.context.annotation.Scope;
import java.time.LocalDate;
@SpringComponent
@PermitAll
@Scope("prototype")
@PageTitle("Hours Worked")
@Route(value = "/hours-worked/me", layout = MainLayout.class)
public class HoursWorkedView extends VerticalLayout {
public HoursWorkedView() {
H2 title = new H2("Registro de Horas Trabajadas");
DatePicker datePicker = new DatePicker("Selecciona una fecha");
datePicker.setValue(LocalDate.now());
ComboBox<String> equipoDropdown = new ComboBox<>("Equipo");
equipoDropdown.setItems("Equipo 1", "Equipo 2", "Equipo 3"); // Ejemplo de datos
TextField empleadoSearch = new TextField("Empleado (Search)");
HorizontalLayout filtersLayout = new HorizontalLayout(equipoDropdown, empleadoSearch);
Grid<Actividad> grid = new Grid<>(Actividad.class, false);
grid.addColumn(Actividad::getNombre).setHeader("Actividad");
grid.addColumn(Actividad::getLunes).setHeader("Lunes");
grid.addColumn(Actividad::getMartes).setHeader("Martes");
grid.addColumn(Actividad::getMiercoles).setHeader("Miércoles");
grid.addColumn(Actividad::getJueves).setHeader("Jueves");
grid.addColumn(Actividad::getViernes).setHeader("Viernes");
grid.addColumn(Actividad::getSabado).setHeader("Sábado");
grid.addColumn(Actividad::getDomingo).setHeader("Domingo");
grid.setItems(
new Actividad("Actividad 1", 3, 3, 3, 3, 3, 1, 2),
new Actividad("Actividad 2", 2, 2, 2, 2, 2, 0, 1),
new Actividad("Meeting 1", 0, 0.5, 0.5, 0, 0, 0.5, 0)
);
Button actualizarButton = new Button("Actualizar");
Button guardarButton = new Button("Guardar");
Button cerrarButton = new Button("Cerrar");
HorizontalLayout buttonsLayout = new HorizontalLayout(actualizarButton, guardarButton, cerrarButton);
add(title, datePicker, filtersLayout, grid, buttonsLayout);
}
public static class Actividad {
final private String nombre;
final private double lunes;
final private double martes;
final private double miercoles;
final private double jueves;
final private double viernes;
final private double sabado;
final private double domingo;
public Actividad(
final String nombre, final double lunes,
final double martes, final double miercoles,
final double jueves, final double viernes,
final double sabado, final double domingo)
{
this.nombre = nombre;
this.lunes = lunes;
this.martes = martes;
this.miercoles = miercoles;
this.jueves = jueves;
this.viernes = viernes;
this.sabado = sabado;
this.domingo = domingo;
}
public String getNombre() {
return nombre;
}
public double getLunes() {
return lunes;
}
public double getMartes() {
return martes;
}
public double getMiercoles() {
return miercoles;
}
public double getJueves() {
return jueves;
}
public double getViernes() {
return viernes;
}
public double getSabado() {
return sabado;
}
public double getDomingo() {
return domingo;
}
}
}

View File

@ -100,36 +100,23 @@ 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,
SideNavItem documents = new SideNavItem("Documents", MainView.class, LineAwesomeIcon.FILE_ALT_SOLID.create()));
LineAwesomeIcon.FILE_ALT_SOLID.create());
documents.addItem(new SideNavItem("Personal Documents", PersonalDocumentsView.class,
LineAwesomeIcon.ID_CARD_SOLID.create()));
documents.addItem(new SideNavItem("Professional Documents", ProfessionalDocumentsView.class,
LineAwesomeIcon.BRIEFCASE_SOLID.create()));
documents.addItem(new SideNavItem("Work Documents", WorkDocumentsView.class,
LineAwesomeIcon.FOLDER_OPEN_SOLID.create()));
documents.addItem(new SideNavItem("Corporate Documents", CorporateDocumentsView.class,
LineAwesomeIcon.BUILDING_SOLID.create()));
documents.addItem(new SideNavItem("Government Documents", GovernmentDocumentsView.class,
LineAwesomeIcon.BALANCE_SCALE_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());
SideNavItem timesheet = new SideNavItem("My Timesheet", TimesheetView.class, SideNavItem timesheet = new SideNavItem("My Timesheet", TimesheetView.class,
LineAwesomeIcon.HOURGLASS_START_SOLID.create()); LineAwesomeIcon.HOURGLASS_START_SOLID.create());
timesheet.addItem(new SideNavItem("Hours Worked", HoursWorkedView.class,
LineAwesomeIcon.ID_CARD_SOLID.create()));
SideNavItem profile = new SideNavItem("My Profile", ProfileView.class, SideNavItem profile = new SideNavItem("My Profile", ProfileView.class,
LineAwesomeIcon.USER_EDIT_SOLID.create()); LineAwesomeIcon.USER_EDIT_SOLID.create());
nav.addItem(new SideNavItem("Home", MainView.class, LineAwesomeIcon.HOME_SOLID.create())); nav.addItem(new SideNavItem("Home", MainView.class, LineAwesomeIcon.HOME_SOLID.create()));
nav.addItem(admin); nav.addItem(admin);
nav.addItem(documents);
nav.addItem(recruiting); nav.addItem(recruiting);
nav.addItem(profile); nav.addItem(profile);
nav.addItem(timesheet); nav.addItem(timesheet);

View File

@ -1,16 +0,0 @@
package com.primefactorsolutions.views;
import com.vaadin.flow.component.html.Main;
import com.vaadin.flow.router.PageTitle;
import com.vaadin.flow.router.Route;
import com.vaadin.flow.spring.annotation.SpringComponent;
import jakarta.annotation.security.PermitAll;
import org.springframework.context.annotation.Scope;
@SpringComponent
@PermitAll
@Scope("prototype")
@PageTitle("PersonalDocuments")
@Route(value = "/personal-documents/me", layout = MainLayout.class)
public class PersonalDocumentsView extends Main {
}

View File

@ -1,16 +0,0 @@
package com.primefactorsolutions.views;
import com.vaadin.flow.component.html.Main;
import com.vaadin.flow.router.PageTitle;
import com.vaadin.flow.router.Route;
import com.vaadin.flow.spring.annotation.SpringComponent;
import jakarta.annotation.security.PermitAll;
import org.springframework.context.annotation.Scope;
@SpringComponent
@PermitAll
@Scope("prototype")
@PageTitle("ProfessionalDocuments")
@Route(value = "/professional-documents/me", layout = MainLayout.class)
public class ProfessionalDocumentsView extends Main {
}

View File

@ -1,16 +0,0 @@
package com.primefactorsolutions.views;
import com.vaadin.flow.component.html.Main;
import com.vaadin.flow.router.PageTitle;
import com.vaadin.flow.router.Route;
import com.vaadin.flow.spring.annotation.SpringComponent;
import jakarta.annotation.security.PermitAll;
import org.springframework.context.annotation.Scope;
@SpringComponent
@PermitAll
@Scope("prototype")
@PageTitle("WorkDocuments")
@Route(value = "/work-documents/me", layout = MainLayout.class)
public class WorkDocumentsView extends Main {
}