Compare commits

..

No commits in common. "88e80a7dcc5635775197291d7a8a2e1279028291" and "eb6183df19bd3b1339b855ca448d2e24db5cd490" have entirely different histories.

4 changed files with 61 additions and 73 deletions

View File

@ -1,10 +1,8 @@
package com.primefactorsolutions.views; package com.primefactorsolutions.views;
import com.primefactorsolutions.model.Employee; import com.primefactorsolutions.model.Employee;
import com.primefactorsolutions.model.Team;
import com.primefactorsolutions.service.EmployeeService; import com.primefactorsolutions.service.EmployeeService;
import com.primefactorsolutions.service.ReportService; import com.primefactorsolutions.service.ReportService;
import com.primefactorsolutions.service.TeamService;
import com.vaadin.componentfactory.pdfviewer.PdfViewer; import com.vaadin.componentfactory.pdfviewer.PdfViewer;
import com.vaadin.flow.component.ClickEvent; import com.vaadin.flow.component.ClickEvent;
import com.vaadin.flow.component.Component; import com.vaadin.flow.component.Component;
@ -29,7 +27,6 @@ import com.vaadin.flow.router.*;
import com.vaadin.flow.server.StreamResource; import com.vaadin.flow.server.StreamResource;
import com.vaadin.flow.spring.annotation.SpringComponent; import com.vaadin.flow.spring.annotation.SpringComponent;
import jakarta.annotation.security.PermitAll; import jakarta.annotation.security.PermitAll;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope; import org.springframework.context.annotation.Scope;
import org.vaadin.firitin.components.datepicker.VDatePicker; import org.vaadin.firitin.components.datepicker.VDatePicker;
import org.vaadin.firitin.form.BeanValidationForm; import org.vaadin.firitin.form.BeanValidationForm;
@ -50,7 +47,6 @@ public class EmployeeView extends BeanValidationForm<Employee> implements HasUrl
private final EmployeeService employeeService; private final EmployeeService employeeService;
private final ReportService reportService; private final ReportService reportService;
private final TeamService teamService;
// TODO: campo usado para registrar al empleado en LDAP. Este campo podria estar en otro form eventualmente. // TODO: campo usado para registrar al empleado en LDAP. Este campo podria estar en otro form eventualmente.
private final TextField username = createTextField("Username: ", 30, true); private final TextField username = createTextField("Username: ", 30, true);
@ -71,7 +67,7 @@ public class EmployeeView extends BeanValidationForm<Employee> implements HasUrl
private final EmailField personalEmail = createEmailField("E-mail"); private final EmailField personalEmail = createEmailField("E-mail");
private final TextField cod = createTextField("Codigo de Empleado", 30, false); private final TextField cod = createTextField("Codigo de Empleado", 30, false);
private final TextField position = createTextField("Cargo", 30, false); private final TextField position = createTextField("Cargo", 30, false);
private final ComboBox<Team> team = new ComboBox<>("Equipo"); private final TextField team = createTextField("Equipo", 30, false);
private final TextField leadManager = createTextField("Lead/Manager", 30, false); private final TextField leadManager = createTextField("Lead/Manager", 30, false);
private final TextField project = createTextField("Proyecto", 30, false); private final TextField project = createTextField("Proyecto", 30, false);
private final TextField emergencyCName = createTextField("Nombres y Apellidos de Contacto", 50, false); private final TextField emergencyCName = createTextField("Nombres y Apellidos de Contacto", 50, false);
@ -139,13 +135,10 @@ public class EmployeeView extends BeanValidationForm<Employee> implements HasUrl
private final H3 datBanc = new H3("Datos Bancados"); private final H3 datBanc = new H3("Datos Bancados");
private final H3 datGest = new H3("Datos Gestora Pública y Seguro Social"); private final H3 datGest = new H3("Datos Gestora Pública y Seguro Social");
public EmployeeView(final EmployeeService employeeService, public EmployeeView(final EmployeeService employeeService, final ReportService reportService) {
final ReportService reportService,
final TeamService teamService) {
super(Employee.class); super(Employee.class);
this.employeeService = employeeService; this.employeeService = employeeService;
this.reportService = reportService; this.reportService = reportService;
this.teamService = teamService;
saveButton.addThemeVariants(ButtonVariant.LUMO_PRIMARY); saveButton.addThemeVariants(ButtonVariant.LUMO_PRIMARY);
configureComponents(); configureComponents();
@ -162,7 +155,6 @@ public class EmployeeView extends BeanValidationForm<Employee> implements HasUrl
editButton.setVisible(true); editButton.setVisible(true);
reportButton.setVisible(true); reportButton.setVisible(true);
birthday.addValueChangeListener(event -> calculateAge()); birthday.addValueChangeListener(event -> calculateAge());
createTeamComboBox();
reportButton.addClickListener((ComponentEventListener<ClickEvent<Button>>) buttonClickEvent -> { reportButton.addClickListener((ComponentEventListener<ClickEvent<Button>>) buttonClickEvent -> {
var employee = getEntity(); var employee = getEntity();
@ -270,11 +262,12 @@ public class EmployeeView extends BeanValidationForm<Employee> implements HasUrl
return emailField; return emailField;
} }
private void createTeamComboBox() { private <T> ComboBox<T> createComboBox(final String label, final T[] items) {
List<Team> teams = teamService.findAllTeams(); ComboBox<T> comboBox = new ComboBox<>(label);
team.setItems(teams); comboBox.setItems(items);
team.setItemLabelGenerator(Team::getName); comboBox.setItemLabelGenerator(Object::toString);
team.setWidthFull(); comboBox.setWidthFull();
return comboBox;
} }
private ComboBox<Employee.Gender> createGenderComboBox() { private ComboBox<Employee.Gender> createGenderComboBox() {
@ -324,7 +317,6 @@ public class EmployeeView extends BeanValidationForm<Employee> implements HasUrl
UUID employeeId = UUID.fromString(s); UUID employeeId = UUID.fromString(s);
var employee = employeeService.getEmployee(employeeId); var employee = employeeService.getEmployee(employeeId);
setEntityWithEnabledSave(employee); setEntityWithEnabledSave(employee);
team.setValue(employee.getTeam());
if ("edit".equals(action) && !s.isEmpty()) { if ("edit".equals(action) && !s.isEmpty()) {
saveButton.setVisible(true); saveButton.setVisible(true);

View File

@ -6,6 +6,7 @@ import com.primefactorsolutions.service.TimeOffRequestService;
import com.primefactorsolutions.service.VacationService; import com.primefactorsolutions.service.VacationService;
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.grid.Grid;
import com.vaadin.flow.component.html.Div; import com.vaadin.flow.component.html.Div;
import com.vaadin.flow.component.html.H3; import com.vaadin.flow.component.html.H3;
import com.vaadin.flow.component.html.Span; import com.vaadin.flow.component.html.Span;
@ -19,7 +20,6 @@ import com.vaadin.flow.router.Route;
import com.vaadin.flow.spring.annotation.SpringComponent; import com.vaadin.flow.spring.annotation.SpringComponent;
import jakarta.annotation.security.PermitAll; import jakarta.annotation.security.PermitAll;
import org.springframework.context.annotation.Scope; import org.springframework.context.annotation.Scope;
import org.vaadin.firitin.components.grid.PagingGrid;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
@ -36,7 +36,7 @@ public class RequestEmployeeView extends Div implements HasUrlParameter<String>
private final TimeOffRequestService requestService; private final TimeOffRequestService requestService;
private final EmployeeService employeeService; private final EmployeeService employeeService;
private final VacationService vacationService; private final VacationService vacationService;
private final PagingGrid<TimeOffRequest> requestGrid = new PagingGrid<>(TimeOffRequest.class); private final Grid<TimeOffRequest> requestGrid = new Grid<>(TimeOffRequest.class);
private List<TimeOffRequest> requests = Collections.emptyList(); private List<TimeOffRequest> requests = Collections.emptyList();
private ComboBox<TimeOffRequestType> categoryFilter; private ComboBox<TimeOffRequestType> categoryFilter;
private ComboBox<TimeOffRequestStatus> stateFilter; private ComboBox<TimeOffRequestStatus> stateFilter;
@ -65,7 +65,7 @@ public class RequestEmployeeView extends Div implements HasUrlParameter<String>
} }
private ComboBox<TimeOffRequestType> createCategoryFilter() { private ComboBox<TimeOffRequestType> createCategoryFilter() {
categoryFilter = new ComboBox<>("Categoría"); categoryFilter = new ComboBox<>("Category");
categoryFilter.setItems(TimeOffRequestType.values()); categoryFilter.setItems(TimeOffRequestType.values());
categoryFilter.setValue(TimeOffRequestType.values()[0]); categoryFilter.setValue(TimeOffRequestType.values()[0]);
categoryFilter.addValueChangeListener(event -> refreshRequestGrid(event.getValue(), stateFilter.getValue())); categoryFilter.addValueChangeListener(event -> refreshRequestGrid(event.getValue(), stateFilter.getValue()));
@ -73,7 +73,7 @@ public class RequestEmployeeView extends Div implements HasUrlParameter<String>
} }
private ComboBox<TimeOffRequestStatus> createStateFilter() { private ComboBox<TimeOffRequestStatus> createStateFilter() {
stateFilter = new ComboBox<>("Estado de la solicitud"); stateFilter = new ComboBox<>("State");
stateFilter.setItems(TimeOffRequestStatus.values()); stateFilter.setItems(TimeOffRequestStatus.values());
stateFilter.setValue(TimeOffRequestStatus.values()[0]); stateFilter.setValue(TimeOffRequestStatus.values()[0]);
stateFilter.addValueChangeListener(event -> refreshRequestGrid(categoryFilter.getValue(), event.getValue())); stateFilter.addValueChangeListener(event -> refreshRequestGrid(categoryFilter.getValue(), event.getValue()));
@ -87,15 +87,7 @@ public class RequestEmployeeView extends Div implements HasUrlParameter<String>
"startDate", "startDate",
"endDate", "endDate",
"daysToBeTake"); "daysToBeTake");
requestGrid.setAllRowsVisible(true);
requestGrid.getColumnByKey("category").setHeader("Categoría");
requestGrid.getColumnByKey("state").setHeader("Estado");
requestGrid.getColumnByKey("startDate").setHeader("Fecha de Inicio");
requestGrid.getColumnByKey("endDate").setHeader("Fecha de Fin");
requestGrid.getColumnByKey("daysToBeTake").setHeader("Días a Tomar");
requestGrid.setPaginationBarMode(PagingGrid.PaginationBarMode.BOTTOM);
requestGrid.setPageSize(5);
requestGrid.asSingleSelect().addValueChangeListener(event -> { requestGrid.asSingleSelect().addValueChangeListener(event -> {
TimeOffRequest selectedRequest = event.getValue(); TimeOffRequest selectedRequest = event.getValue();
if (selectedRequest != null) { if (selectedRequest != null) {
@ -110,22 +102,22 @@ public class RequestEmployeeView extends Div implements HasUrlParameter<String>
.mapToDouble(TimeOffRequest::getAvailableDays) .mapToDouble(TimeOffRequest::getAvailableDays)
.sum(); .sum();
double totalVacations = requests.stream() double totalVacations = requests.stream()
.filter(req -> req.getCategory().toString().startsWith("VACACION")) .filter(req -> req.getCategory().toString().startsWith("VACATION"))
.mapToDouble(TimeOffRequest::getAvailableDays) .mapToDouble(TimeOffRequest::getAvailableDays)
.sum(); .sum();
double totalPersonalDays = requests.stream() double totalPersonalDays = requests.stream()
.filter(req -> !verificationIsHoliday(req)) .filter(req -> !verificationIsHoliday(req))
.filter(req -> !req.getCategory().name().startsWith("VACACION")) .filter(req -> !req.getCategory().name().startsWith("VACATION"))
.mapToDouble(TimeOffRequest::getAvailableDays) .mapToDouble(TimeOffRequest::getAvailableDays)
.sum(); .sum();
double totalAvailableDays = totalHoliday + totalVacations + totalPersonalDays; double totalAvailableDays = totalHoliday + totalVacations + totalPersonalDays;
return new VerticalLayout( return new VerticalLayout(
new Span("Total días libres: " + totalHoliday), new Span("TOTAL HOLIDAYS: " + totalHoliday),
new Span("Total vacaciones: " + totalVacations), new Span("TOTAL VACATIONS: " + totalVacations),
new Span("Total días personales: " + totalPersonalDays), new Span("TOTAL PERSONAL DAYS: " + totalPersonalDays),
new Span("Total general: " + totalAvailableDays) new Span("TOTAL GENERAL: " + totalAvailableDays)
); );
} }
@ -135,21 +127,22 @@ public class RequestEmployeeView extends Div implements HasUrlParameter<String>
} }
private HorizontalLayout createActionButtons() { private HorizontalLayout createActionButtons() {
Button viewButton = createButton("Ver", () -> navigateToViewRequest(request)); Button viewButton = new Button("View", event -> {
Button editButton = createButton("Editar", () -> navigateToEditRequest(request));
Button closeButton = new Button("Salir", event -> navigateToRequestsListView());
return new HorizontalLayout(viewButton, editButton, closeButton);
}
private Button createButton(String caption, Runnable action) {
return new Button(caption, event -> {
if (request != null) { if (request != null) {
action.run(); navigateToViewRequest(request);
} else { } else {
Notification.show("Seleccione una solicitud.", 3000, Notification.Position.MIDDLE); Notification.show("Please select a request to view.", 3000, Notification.Position.MIDDLE);
} }
}); });
Button editButton = new Button("Edit", event -> {
if (request != null) {
navigateToEditRequest(request);
} else {
Notification.show("Please select a request to view.", 3000, Notification.Position.MIDDLE);
}
});
Button closeButton = new Button("Close", event -> navigateToRequestsListView());
return new HorizontalLayout(viewButton, editButton, closeButton);
} }
private void navigateToRequestsListView() { private void navigateToRequestsListView() {
@ -169,30 +162,33 @@ public class RequestEmployeeView extends Div implements HasUrlParameter<String>
} }
private void refreshRequestGrid(final TimeOffRequestType category, final TimeOffRequestStatus state) { private void refreshRequestGrid(final TimeOffRequestType category, final TimeOffRequestStatus state) {
requestGrid.setPagingDataProvider((page, pageSize) -> { List<TimeOffRequest> filteredRequests = allFiltersAreNull(category, state)
int start = (int) (page * requestGrid.getPageSize()); ? requestService.findRequestsByEmployeeId(employeeId)
return fetchFilteredTimeOffRequests(start, pageSize, category, state); : fetchFilteredTimeOffRequests(category, state);
}); for (TimeOffRequest request : filteredRequests) {
requestGrid.getDataProvider().refreshAll(); requestService.saveTimeOffRequest(request);
}
requestGrid.setItems(filteredRequests);
} }
private List<TimeOffRequest> fetchFilteredTimeOffRequests(final int start, private boolean allFiltersAreNull(final TimeOffRequestType category, final TimeOffRequestStatus state) {
final int pageSize, return category == null && state == null;
final TimeOffRequestType category, }
private List<TimeOffRequest> fetchFilteredTimeOffRequests(final TimeOffRequestType category,
final TimeOffRequestStatus state) { final TimeOffRequestStatus state) {
requests = requestService.findRequestsByEmployeeId(employeeId); requests = requestService.findRequestsByEmployeeId(employeeId);
if (category != null && !"TODOS".equals(category.name())) { if (category != null && !"ALL".equals(category.name())) {
requests = requests.stream() requests = requests.stream()
.filter(req -> req.getCategory().equals(category)) .filter(req -> req.getCategory().equals(category))
.collect(Collectors.toList()); .collect(Collectors.toList());
} }
if (state != null && !"TODOS".equals(state.name())) { if (state != null && !"ALL".equals(state.name())) {
requests = requests.stream() requests = requests.stream()
.filter(req -> req.getState().equals(state)) .filter(req -> req.getState().equals(state))
.collect(Collectors.toList()); .collect(Collectors.toList());
} }
int end = Math.min(start + pageSize, requests.size()); return requests;
return requests.subList(start, end);
} }
@Override @Override
@ -206,7 +202,7 @@ public class RequestEmployeeView extends Div implements HasUrlParameter<String>
} }
private void setViewTitle(final String employeeName, final String employeeTeam) { private void setViewTitle(final String employeeName, final String employeeTeam) {
addComponentAsFirst(new H3("Nombre del empleado: " + employeeName)); addComponentAsFirst(new H3("Name: " + employeeName));
addComponentAtIndex(1, new H3("Equipo: " + employeeTeam)); addComponentAtIndex(1, new H3("Team: " + employeeTeam));
} }
} }

View File

@ -27,12 +27,12 @@ import java.util.UUID;
@Route(value = "/requests/:requestId?/:action?", layout = MainLayout.class) @Route(value = "/requests/:requestId?/:action?", layout = MainLayout.class)
public class RequestView extends BeanValidationForm<TimeOffRequest> implements HasUrlParameter<String> { public class RequestView extends BeanValidationForm<TimeOffRequest> implements HasUrlParameter<String> {
private final ComboBox<TimeOffRequestStatus> state = new ComboBox<>("Estado de la solicitud"); private final ComboBox<TimeOffRequestStatus> state = new ComboBox<>("State");
private final DatePicker expiration = new DatePicker("Vencimiento"); private final DatePicker expiration = new DatePicker("Expiration");
private final DatePicker startDate = new DatePicker("Fecha de inicio"); private final DatePicker startDate = new DatePicker("Start Date");
private final DatePicker endDate = new DatePicker("Fecha de fin"); private final DatePicker endDate = new DatePicker("End Date");
private final NumberField availableDays = new NumberField("Días disponibles"); private final NumberField availableDays = new NumberField("Available Days");
private final NumberField daysToBeTake = new NumberField("Días a tomar"); private final NumberField daysToBeTake = new NumberField("Days To Be Take");
private final TimeOffRequestService requestService; private final TimeOffRequestService requestService;
private final EmployeeService employeeService; private final EmployeeService employeeService;
@ -85,13 +85,13 @@ public class RequestView extends BeanValidationForm<TimeOffRequest> implements H
} }
protected Button createSaveButton() { protected Button createSaveButton() {
saveButton = new Button("Guardar"); saveButton = new Button("Save");
saveButton.addClickListener(event -> saveRequest()); saveButton.addClickListener(event -> saveRequest());
return saveButton; return saveButton;
} }
protected Button createCloseButton() { protected Button createCloseButton() {
Button closeButton = new Button("Salir"); Button closeButton = new Button("Close");
closeButton.addClickListener(event -> closeForm()); closeButton.addClickListener(event -> closeForm());
return closeButton; return closeButton;
} }
@ -110,7 +110,7 @@ public class RequestView extends BeanValidationForm<TimeOffRequest> implements H
TimeOffRequest request = getEntity(); TimeOffRequest request = getEntity();
setRequestFieldValues(request); setRequestFieldValues(request);
requestService.saveTimeOffRequest(request); requestService.saveTimeOffRequest(request);
Notification.show("Solicitud guardada correctamente."); Notification.show("Request saved successfully.");
closeForm(); closeForm();
} }
} }
@ -147,14 +147,14 @@ public class RequestView extends BeanValidationForm<TimeOffRequest> implements H
} }
private H3 createEmployeeHeader() { private H3 createEmployeeHeader() {
return new H3("Empleado: " + employee.getFirstName() + " " + employee.getLastName()); return new H3("Employee: " + employee.getFirstName() + " " + employee.getLastName());
} }
private H3 createTeamHeader() { private H3 createTeamHeader() {
return new H3("Equipo: " + employee.getTeam().getName()); return new H3("Team: " + employee.getTeam().getName());
} }
private H3 createCategoryHeader() { private H3 createCategoryHeader() {
return new H3("Categoría: " + request.getCategory()); return new H3("Category: " + request.getCategory());
} }
} }

View File

@ -90,7 +90,7 @@ public class RequestsListView extends Main {
if (selectedEmployeeId != null) { if (selectedEmployeeId != null) {
navigateToTimeOffRequestView(selectedEmployeeId); navigateToTimeOffRequestView(selectedEmployeeId);
} else { } else {
Notification.show("Seleccione una solicitud.", 3000, Notification.Position.MIDDLE); Notification.show("Seleccione una solicitud para verla.", 3000, Notification.Position.MIDDLE);
} }
}); });
Button closeButton = new Button("Salir", event -> navigateToMainView()); Button closeButton = new Button("Salir", event -> navigateToMainView());