diff --git a/.gitea/workflows/build-pr.yaml b/.gitea/workflows/build-pr.yaml deleted file mode 100644 index 90aad01..0000000 --- a/.gitea/workflows/build-pr.yaml +++ /dev/null @@ -1,14 +0,0 @@ -name: PR Builder -run-name: ${{ gitea.actor }} building PR -on: [pull_request] - -jobs: - Build-PR: - runs-on: ubuntu-22.04 - steps: - - run: echo "The job was automatically triggered by a ${{ gitea.event_name }} event on branch ${{ gitea.head_ref }} and ref is ${{ gitea.ref }} and your repository is ${{ gitea.repository }}." - - name: Build PR - if: gitea.base_ref == 'main' - run: | - git clone --single-branch --branch "${{ gitea.head_ref }}" https://git.primefactorsolutions.com/PFS/pfs-intra.git && cd pfs-intra && ./mvnw clean package -Pproduction - - run: echo "This job's status is ${{ job.status }}." diff --git a/.gitea/workflows/build.yaml b/.gitea/workflows/build.yaml deleted file mode 100644 index e64cc3a..0000000 --- a/.gitea/workflows/build.yaml +++ /dev/null @@ -1,16 +0,0 @@ -name: Builder -run-name: ${{ gitea.actor }} building -on: - push: - branches: - - main - -jobs: - Build-Project: - runs-on: ubuntu-22.04 - steps: - - run: echo "The job was automatically triggered by a ${{ gitea.event_name }} event on branch is ${{ gitea.ref }} and your repository is ${{ gitea.repository }}." - - name: Build package - run: | - git clone --single-branch --branch main https://git.primefactorsolutions.com/PFS/pfs-intra.git && cd pfs-intra && ./mvnw clean package -Pproduction && unlink /home/ubuntu/pfs-intra/app.jar && cp target/*.jar /home/ubuntu/pfs-intra/app.jar && sudo systemctl restart pfs-intra - - run: echo "This job's status is ${{ job.status }}." diff --git a/.mvn/wrapper/MavenWrapperDownloader.java b/.mvn/wrapper/MavenWrapperDownloader.java deleted file mode 100644 index 8895dd4..0000000 --- a/.mvn/wrapper/MavenWrapperDownloader.java +++ /dev/null @@ -1,118 +0,0 @@ -/* - * Copyright 2007-present the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -import java.io.*; -import java.net.*; -import java.nio.channels.*; -import java.util.Properties; - -public class MavenWrapperDownloader { - - private static final String WRAPPER_VERSION = "0.5.6"; - /** - * Default URL to download the maven-wrapper.jar from, if no 'downloadUrl' is - * provided. - */ - private static final String DEFAULT_DOWNLOAD_URL = "https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/" - + WRAPPER_VERSION + "/maven-wrapper-" + WRAPPER_VERSION + ".jar"; - - /** - * Path to the maven-wrapper.properties file, which might contain a downloadUrl - * property to use instead of the default one. - */ - private static final String MAVEN_WRAPPER_PROPERTIES_PATH = ".mvn/wrapper/maven-wrapper.properties"; - - /** - * Path where the maven-wrapper.jar will be saved to. - */ - private static final String MAVEN_WRAPPER_JAR_PATH = ".mvn/wrapper/maven-wrapper.jar"; - - /** - * Name of the property which should be used to override the default download - * url for the wrapper. - */ - private static final String PROPERTY_NAME_WRAPPER_URL = "wrapperUrl"; - - public static void main(String args[]) { - System.out.println("- Downloader started"); - File baseDirectory = new File(args[0]); - System.out.println("- Using base directory: " + baseDirectory.getAbsolutePath()); - - // If the maven-wrapper.properties exists, read it and check if it contains a - // custom - // wrapperUrl parameter. - File mavenWrapperPropertyFile = new File(baseDirectory, MAVEN_WRAPPER_PROPERTIES_PATH); - String url = DEFAULT_DOWNLOAD_URL; - if (mavenWrapperPropertyFile.exists()) { - FileInputStream mavenWrapperPropertyFileInputStream = null; - try { - mavenWrapperPropertyFileInputStream = new FileInputStream(mavenWrapperPropertyFile); - Properties mavenWrapperProperties = new Properties(); - mavenWrapperProperties.load(mavenWrapperPropertyFileInputStream); - url = mavenWrapperProperties.getProperty(PROPERTY_NAME_WRAPPER_URL, url); - } catch (IOException e) { - System.out.println("- ERROR loading '" + MAVEN_WRAPPER_PROPERTIES_PATH + "'"); - } finally { - try { - if (mavenWrapperPropertyFileInputStream != null) { - mavenWrapperPropertyFileInputStream.close(); - } - } catch (IOException e) { - // Ignore ... - } - } - } - System.out.println("- Downloading from: " + url); - - File outputFile = new File(baseDirectory.getAbsolutePath(), MAVEN_WRAPPER_JAR_PATH); - if (!outputFile.getParentFile().exists()) { - if (!outputFile.getParentFile().mkdirs()) { - System.out.println( - "- ERROR creating output directory '" + outputFile.getParentFile().getAbsolutePath() + "'"); - } - } - System.out.println("- Downloading to: " + outputFile.getAbsolutePath()); - try { - downloadFileFromURL(url, outputFile); - System.out.println("Done"); - System.exit(0); - } catch (Throwable e) { - System.out.println("- Error downloading"); - e.printStackTrace(); - System.exit(1); - } - } - - private static void downloadFileFromURL(String urlString, File destination) throws Exception { - if (System.getenv("MVNW_USERNAME") != null && System.getenv("MVNW_PASSWORD") != null) { - String username = System.getenv("MVNW_USERNAME"); - char[] password = System.getenv("MVNW_PASSWORD").toCharArray(); - Authenticator.setDefault(new Authenticator() { - @Override - protected PasswordAuthentication getPasswordAuthentication() { - return new PasswordAuthentication(username, password); - } - }); - } - URL website = new URL(urlString); - ReadableByteChannel rbc; - rbc = Channels.newChannel(website.openStream()); - FileOutputStream fos = new FileOutputStream(destination); - fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE); - fos.close(); - rbc.close(); - } - -} diff --git a/.mvn/wrapper/maven-wrapper.jar b/.mvn/wrapper/maven-wrapper.jar deleted file mode 100644 index c1dd12f..0000000 Binary files a/.mvn/wrapper/maven-wrapper.jar and /dev/null differ diff --git a/.mvn/wrapper/maven-wrapper.properties b/.mvn/wrapper/maven-wrapper.properties deleted file mode 100644 index 8c79a83..0000000 --- a/.mvn/wrapper/maven-wrapper.properties +++ /dev/null @@ -1,18 +0,0 @@ -# Licensed to the Apache Software Foundation (ASF) under one -# or more contributor license agreements. See the NOTICE file -# distributed with this work for additional information -# regarding copyright ownership. The ASF licenses this file -# to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance -# with the License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, -# software distributed under the License is distributed on an -# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -# KIND, either express or implied. See the License for the -# specific language governing permissions and limitations -# under the License. -distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.8.4/apache-maven-3.8.4-bin.zip -wrapperUrl=https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.1.0/maven-wrapper-3.1.0.jar diff --git a/src/main/java/com/primefactorsolutions/repositories/HoursWorkedRepository.java b/src/main/java/com/primefactorsolutions/repositories/HoursWorkedRepository.java index 87162d9..06d8552 100644 --- a/src/main/java/com/primefactorsolutions/repositories/HoursWorkedRepository.java +++ b/src/main/java/com/primefactorsolutions/repositories/HoursWorkedRepository.java @@ -11,4 +11,4 @@ import java.util.UUID; public interface HoursWorkedRepository extends JpaRepository { List findByWeekNumber(int weekNumber); List findByDate(LocalDate date); -} +} \ No newline at end of file diff --git a/src/main/java/com/primefactorsolutions/service/HoursWorkedService.java b/src/main/java/com/primefactorsolutions/service/HoursWorkedService.java index 605f6f6..25d7235 100644 --- a/src/main/java/com/primefactorsolutions/service/HoursWorkedService.java +++ b/src/main/java/com/primefactorsolutions/service/HoursWorkedService.java @@ -1,7 +1,9 @@ package com.primefactorsolutions.service; +import com.primefactorsolutions.model.Employee; import com.primefactorsolutions.model.HoursWorked; import com.primefactorsolutions.repositories.HoursWorkedRepository; +import org.apache.commons.beanutils.BeanComparator; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @@ -24,7 +26,8 @@ public class HoursWorkedService { public HoursWorked findHoursWorked(final UUID id) { Optional hoursWorked = hoursWorkedRepository.findById(id); - return hoursWorked.orElse(null); + HoursWorked hw = hoursWorked.get(); + return hw; } public HoursWorked saveHoursWorked(final HoursWorked hoursWorked) { @@ -47,5 +50,35 @@ public class HoursWorkedService { return hoursWorkedRepository.findByDate(date); } -} + public List findHoursWorkeds( + final int start, final int pageSize, final String sortProperty, final boolean asc) { + List hoursWorkeds = hoursWorkedRepository.findAll(); + int end = Math.min(start + pageSize, hoursWorkeds.size()); + hoursWorkeds.sort(new BeanComparator<>(sortProperty)); + + if(!asc) { + Collections.reverse(hoursWorkeds); + } + + return hoursWorkeds.subList(start, end); + } + + public List findHoursWorkeds(final int start, final int pageSize) { + List hoursWorkeds = hoursWorkedRepository.findAll(); + + int end = Math.min(start + pageSize, hoursWorkeds.size()); + return hoursWorkeds.subList(start, end); + } + + public HoursWorked getHoursWorked(final UUID id) { + Optional registro = hoursWorkedRepository.findById(id); + HoursWorked hw = registro.orElse(null); + if (hw == null) { + System.out.println("No se encontrĂ³ el registro de horas trabajadas"); + return null; + } + return hw; + } + +} \ No newline at end of file diff --git a/src/main/java/com/primefactorsolutions/views/HoursWorkedListView.java b/src/main/java/com/primefactorsolutions/views/HoursWorkedListView.java new file mode 100644 index 0000000..dd526c9 --- /dev/null +++ b/src/main/java/com/primefactorsolutions/views/HoursWorkedListView.java @@ -0,0 +1,101 @@ +package com.primefactorsolutions.views; + +import com.primefactorsolutions.model.HoursWorked; +import com.primefactorsolutions.service.HoursWorkedService; +import com.vaadin.flow.component.button.Button; +import com.vaadin.flow.component.grid.GridSortOrder; +import com.vaadin.flow.component.html.H2; +import com.vaadin.flow.component.html.Main; +import com.vaadin.flow.data.provider.SortDirection; +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 org.vaadin.firitin.components.grid.PagingGrid; + +import java.util.List; + +@SpringComponent +@PermitAll +@Scope("prototype") +@PageTitle("HoursWorkedList") +@Route(value = "/hours-worked-list", layout = MainLayout.class) + +public class HoursWorkedListView extends Main { + private final HoursWorkedService hoursWorkedService; + private final PagingGrid table = new PagingGrid<>(HoursWorked.class); + + public HoursWorkedListView (final HoursWorkedService hoursWorkedService) { + this.hoursWorkedService = hoursWorkedService; + setupView(); + refreshGrid(); + } + + private void setupView() { + add(new H2("Lista de Horas trabajadas")); + configureTable(); + add(createAddHoursWorkedButton()); + add(table); + } + + private void configureTable() { + table.setColumns("Actividad", "Lunes", "Martes", "Miercoles", "Jueves", "Viernes", "Sabado", "Domingo"); + addEditButtonColumn("View", this::navigateToHoursWorkedView); + addEditButtonColumn("Edit", this::navigateToEditView); + setupPagingGrid(); + } + + private void addEditButtonColumn( final String label, final ButtonClickHandler handler) { + table.addComponentColumn(hoursWorked -> createButton(label, () -> handler.handle(hoursWorked))); + } + + private Button createButton(final String label, final Runnable onClickAction) { + Button button = new Button(label); + button.addClickListener(event -> onClickAction.run()); + return button; + } + + private Button createAddHoursWorkedButton() { return createButton("Crear Actividad", this::navigateToAddHoursWorkedView);} + + private void navigateToEditView(final HoursWorked hoursWorked) { + getUI().ifPresent(ui -> ui.navigate(HoursWorkedView.class, hoursWorked.getId().toString() + "/edit")); + } + + private void navigateToHoursWorkedView(final HoursWorked hoursWorked) { + getUI().ifPresent(ui -> ui.navigate(HoursWorkedView.class, hoursWorked.getId().toString() + "/view")); + } + + private void navigateToAddHoursWorkedView() { getUI().ifPresent(ui -> ui.navigate(HoursWorkedView.class, "new"));} + + private void setupPagingGrid() { + table.setPaginationBarMode(PagingGrid.PaginationBarMode.BOTTOM); + table.setPageSize(5); + } + + private void refreshGrid() { + table.setPagingDataProvider((page, pageSize) -> fetchHoursWorkeds((int) page, pageSize)); + } + + private List fetchHoursWorkeds(final int page, final int pageSize) { + int start = page * pageSize; + if (hasSortOrder()) { + return fetchSortedHoursWorkeds(start, pageSize); + } + return hoursWorkedService.findHoursWorkeds(start, pageSize); + } + + private boolean hasSortOrder() { return !table.getSortOrder().isEmpty(); } + + private List fetchSortedHoursWorkeds(final int start, final int pageSize) { + GridSortOrder sortOrder = table.getSortOrder().getFirst(); + return hoursWorkedService.findHoursWorkeds(start, pageSize, + sortOrder.getSorted().getKey(), + sortOrder.getDirection() == SortDirection.ASCENDING); + } + + @FunctionalInterface + private interface ButtonClickHandler { + void handle(HoursWorked hoursWorked); + } +} diff --git a/src/main/java/com/primefactorsolutions/views/HoursWorkedView.java b/src/main/java/com/primefactorsolutions/views/HoursWorkedView.java index d0f9df8..2a3cbdb 100644 --- a/src/main/java/com/primefactorsolutions/views/HoursWorkedView.java +++ b/src/main/java/com/primefactorsolutions/views/HoursWorkedView.java @@ -19,6 +19,7 @@ import jakarta.annotation.security.PermitAll; import org.springframework.context.annotation.Scope; import org.vaadin.firitin.form.BeanValidationForm; +import java.awt.*; import java.util.List; import java.util.UUID; @@ -26,12 +27,13 @@ import java.util.UUID; @PermitAll @Scope("prototype") @PageTitle("Horas Trabajadas") -@Route(value = "/timesheets/:hours-worked?/:action?", layout = MainLayout.class) +@Route(value = "/timesheets/listhw/:hours-worked?/me", layout = MainLayout.class) public class HoursWorkedView extends BeanValidationForm implements HasUrlParameter { private final DatePicker dateField = new DatePicker("Fecha"); private final ComboBox teamField = new ComboBox<>("Equipo"); private final ComboBox employeeField = new ComboBox<>("Empleado"); private final TextField activityField = new TextField("Actividad"); + private final TextField hoursField = new TextField("Horas"); private final HoursWorkedService hoursWorkedService; private final EmployeeService employeeService; @@ -55,28 +57,34 @@ public class HoursWorkedView extends BeanValidationForm implements } @Override - public void setParameter(BeforeEvent beforeEvent, String action) { + public void setParameter(BeforeEvent beforeEvent, final String action) { final RouteParameters params = beforeEvent.getRouteParameters(); - final String hoursWorkedId = params.get("hoursworkedId").orElse(null); + final String s = params.get("hours-workedId").orElse(null); if ("new".equals(action)) { setEntityWithEnabledSave(new HoursWorked()); - } else if (hoursWorkedId != null) { - UUID id = UUID.fromString(hoursWorkedId); - request = hoursWorkedService.findHoursWorked(id); - setEntity(request); - configureViewOrEditAction(action); + } else { + UUID hoursWorkedId = UUID.fromString(s); + var hoursWorked = hoursWorkedService.getHoursWorked(hoursWorkedId); + setEntityWithEnabledSave(hoursWorked); + + if ("edit".equals(action) && !s.isEmpty()) { + saveButton.setVisible(true); + } else if ("view".equals(action) && !s.isEmpty()) { + + saveButton.setVisible(false); + } } } @Override protected List getFormComponents() { return List.of( - createEmployeeHeader(), dateField, teamField, employeeField, activityField, + hoursField, createCloseButton() ); } @@ -121,10 +129,11 @@ public class HoursWorkedView extends BeanValidationForm implements hoursWorked.setTeam(teamField.getValue()); hoursWorked.setEmployee(employeeField.getValue()); hoursWorked.setActividad(activityField.getValue()); + //hoursWorked.setHours(hoursField.; } private void closeForm() { - getUI().ifPresent(ui -> ui.navigate("hoursworked")); + getUI().ifPresent(ui -> ui.navigate("hours-workedId")); } private boolean isFormValid() { @@ -151,6 +160,5 @@ public class HoursWorkedView extends BeanValidationForm implements } private H3 createEmployeeHeader() { - return new H3("Empleado: " + (employee != null ? employee.getFirstName() + " " + employee.getLastName() : "")); - } + return new H3("Empleado: " + (employee != null ? employee.getFirstName() + " " + employee.getLastName() : ""));} } \ No newline at end of file diff --git a/src/main/java/com/primefactorsolutions/views/MainLayout.java b/src/main/java/com/primefactorsolutions/views/MainLayout.java index a6dfaa0..420a9e4 100644 --- a/src/main/java/com/primefactorsolutions/views/MainLayout.java +++ b/src/main/java/com/primefactorsolutions/views/MainLayout.java @@ -153,7 +153,7 @@ public class MainLayout extends AppLayout { LineAwesomeIcon.LIST_ALT.create())); SideNavItem timesheet = new SideNavItem("My Timesheet", TimesheetView.class, LineAwesomeIcon.HOURGLASS_START_SOLID.create()); - timesheet.addItem(new SideNavItem("Horas Trabajadas", HoursWorkedView.class, + timesheet.addItem(new SideNavItem("Hours Worked List View", HoursWorkedListView.class, LineAwesomeIcon.ID_CARD_SOLID.create())); timesheet.addItem(new SideNavItem("Reporte Horas Trabajadas", ReporteView.class, LineAwesomeIcon.ID_CARD_SOLID.create())); diff --git a/src/main/java/com/primefactorsolutions/views/TimesheestReportView.java b/src/main/java/com/primefactorsolutions/views/TimesheestReportView.java index a2e0ff8..f45be8d 100644 --- a/src/main/java/com/primefactorsolutions/views/TimesheestReportView.java +++ b/src/main/java/com/primefactorsolutions/views/TimesheestReportView.java @@ -10,7 +10,7 @@ import org.springframework.context.annotation.Scope; @SpringComponent @Scope("prototype") @PageTitle("Timesheets") -@Route(value = "/timesheets", layout = MainLayout.class) +@Route(value = "/timesheets-report", layout = MainLayout.class) @PermitAll public class TimesheestReportView extends Main { }