#45-Registro Semanal de Horas Trabajadas corregir duplicados #70

Closed
melina.gutierrez wants to merge 12 commits from hoursworked into main
11 changed files with 159 additions and 183 deletions
Showing only changes of commit c67cdf868e - Show all commits

View File

@ -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 }}."

View File

@ -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 }}."

View File

@ -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();
}
}

Binary file not shown.

View File

@ -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

View File

@ -1,7 +1,9 @@
package com.primefactorsolutions.service; package com.primefactorsolutions.service;
import com.primefactorsolutions.model.Employee;
import com.primefactorsolutions.model.HoursWorked; import com.primefactorsolutions.model.HoursWorked;
import com.primefactorsolutions.repositories.HoursWorkedRepository; import com.primefactorsolutions.repositories.HoursWorkedRepository;
import org.apache.commons.beanutils.BeanComparator;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
@ -24,7 +26,8 @@ public class HoursWorkedService {
public HoursWorked findHoursWorked(final UUID id) { public HoursWorked findHoursWorked(final UUID id) {
Optional<HoursWorked> hoursWorked = hoursWorkedRepository.findById(id); Optional<HoursWorked> hoursWorked = hoursWorkedRepository.findById(id);
return hoursWorked.orElse(null); HoursWorked hw = hoursWorked.get();
return hw;
} }
public HoursWorked saveHoursWorked(final HoursWorked hoursWorked) { public HoursWorked saveHoursWorked(final HoursWorked hoursWorked) {
@ -47,5 +50,35 @@ public class HoursWorkedService {
return hoursWorkedRepository.findByDate(date); return hoursWorkedRepository.findByDate(date);
} }
} public List<HoursWorked> findHoursWorkeds(
final int start, final int pageSize, final String sortProperty, final boolean asc) {
List<HoursWorked> 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<HoursWorked> findHoursWorkeds(final int start, final int pageSize) {
List<HoursWorked> hoursWorkeds = hoursWorkedRepository.findAll();
int end = Math.min(start + pageSize, hoursWorkeds.size());
return hoursWorkeds.subList(start, end);
}
public HoursWorked getHoursWorked(final UUID id) {
Optional<HoursWorked> 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;
}
}

View File

@ -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<HoursWorked> 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<HoursWorked> 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<HoursWorked> fetchSortedHoursWorkeds(final int start, final int pageSize) {
GridSortOrder<HoursWorked> sortOrder = table.getSortOrder().getFirst();
return hoursWorkedService.findHoursWorkeds(start, pageSize,
sortOrder.getSorted().getKey(),
sortOrder.getDirection() == SortDirection.ASCENDING);
}
@FunctionalInterface
private interface ButtonClickHandler {
void handle(HoursWorked hoursWorked);
}
}

View File

@ -19,6 +19,7 @@ import jakarta.annotation.security.PermitAll;
import org.springframework.context.annotation.Scope; import org.springframework.context.annotation.Scope;
import org.vaadin.firitin.form.BeanValidationForm; import org.vaadin.firitin.form.BeanValidationForm;
import java.awt.*;
import java.util.List; import java.util.List;
import java.util.UUID; import java.util.UUID;
@ -26,12 +27,13 @@ import java.util.UUID;
@PermitAll @PermitAll
@Scope("prototype") @Scope("prototype")
@PageTitle("Horas Trabajadas") @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<HoursWorked> implements HasUrlParameter<String> { public class HoursWorkedView extends BeanValidationForm<HoursWorked> implements HasUrlParameter<String> {
private final DatePicker dateField = new DatePicker("Fecha"); private final DatePicker dateField = new DatePicker("Fecha");
private final ComboBox<Team> teamField = new ComboBox<>("Equipo"); private final ComboBox<Team> teamField = new ComboBox<>("Equipo");
private final ComboBox<Employee> employeeField = new ComboBox<>("Empleado"); private final ComboBox<Employee> employeeField = new ComboBox<>("Empleado");
private final TextField activityField = new TextField("Actividad"); private final TextField activityField = new TextField("Actividad");
private final TextField hoursField = new TextField("Horas");
private final HoursWorkedService hoursWorkedService; private final HoursWorkedService hoursWorkedService;
private final EmployeeService employeeService; private final EmployeeService employeeService;
@ -55,28 +57,34 @@ public class HoursWorkedView extends BeanValidationForm<HoursWorked> implements
} }
@Override @Override
public void setParameter(BeforeEvent beforeEvent, String action) { public void setParameter(BeforeEvent beforeEvent, final String action) {
final RouteParameters params = beforeEvent.getRouteParameters(); 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)) { if ("new".equals(action)) {
setEntityWithEnabledSave(new HoursWorked()); setEntityWithEnabledSave(new HoursWorked());
} else if (hoursWorkedId != null) { } else {
UUID id = UUID.fromString(hoursWorkedId); UUID hoursWorkedId = UUID.fromString(s);
request = hoursWorkedService.findHoursWorked(id); var hoursWorked = hoursWorkedService.getHoursWorked(hoursWorkedId);
setEntity(request); setEntityWithEnabledSave(hoursWorked);
configureViewOrEditAction(action);
if ("edit".equals(action) && !s.isEmpty()) {
saveButton.setVisible(true);
} else if ("view".equals(action) && !s.isEmpty()) {
saveButton.setVisible(false);
}
} }
} }
@Override @Override
protected List<Component> getFormComponents() { protected List<Component> getFormComponents() {
return List.of( return List.of(
createEmployeeHeader(),
dateField, dateField,
teamField, teamField,
employeeField, employeeField,
activityField, activityField,
hoursField,
createCloseButton() createCloseButton()
); );
} }
@ -121,10 +129,11 @@ public class HoursWorkedView extends BeanValidationForm<HoursWorked> implements
hoursWorked.setTeam(teamField.getValue()); hoursWorked.setTeam(teamField.getValue());
hoursWorked.setEmployee(employeeField.getValue()); hoursWorked.setEmployee(employeeField.getValue());
hoursWorked.setActividad(activityField.getValue()); hoursWorked.setActividad(activityField.getValue());
//hoursWorked.setHours(hoursField.;
} }
private void closeForm() { private void closeForm() {
getUI().ifPresent(ui -> ui.navigate("hoursworked")); getUI().ifPresent(ui -> ui.navigate("hours-workedId"));
} }
private boolean isFormValid() { private boolean isFormValid() {
@ -151,6 +160,5 @@ public class HoursWorkedView extends BeanValidationForm<HoursWorked> implements
} }
private H3 createEmployeeHeader() { private H3 createEmployeeHeader() {
return new H3("Empleado: " + (employee != null ? employee.getFirstName() + " " + employee.getLastName() : "")); return new H3("Empleado: " + (employee != null ? employee.getFirstName() + " " + employee.getLastName() : ""));}
}
} }

View File

@ -150,7 +150,7 @@ public class MainLayout extends AppLayout {
LineAwesomeIcon.LIST_ALT.create())); LineAwesomeIcon.LIST_ALT.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("Horas Trabajadas", HoursWorkedView.class, timesheet.addItem(new SideNavItem("Hours Worked List View", HoursWorkedListView.class,
LineAwesomeIcon.ID_CARD_SOLID.create())); LineAwesomeIcon.ID_CARD_SOLID.create()));
timesheet.addItem(new SideNavItem("Reporte Horas Trabajadas", ReporteView.class, timesheet.addItem(new SideNavItem("Reporte Horas Trabajadas", ReporteView.class,
LineAwesomeIcon.ID_CARD_SOLID.create())); LineAwesomeIcon.ID_CARD_SOLID.create()));

View File

@ -10,7 +10,7 @@ import org.springframework.context.annotation.Scope;
@SpringComponent @SpringComponent
@Scope("prototype") @Scope("prototype")
@PageTitle("Timesheets") @PageTitle("Timesheets")
@Route(value = "/timesheets", layout = MainLayout.class) @Route(value = "/timesheets-report", layout = MainLayout.class)
@PermitAll @PermitAll
public class TimesheestReportView extends Main { public class TimesheestReportView extends Main {
} }