From 2d19a9d94ddb76ee496b72ba6885552371fc7c64 Mon Sep 17 00:00:00 2001 From: Benjamin Seber Date: Fri, 4 Oct 2024 16:18:50 +0200 Subject: [PATCH] add date-range-text to report week graph --- .../zeiterfassung/report/GraphWeekDto.java | 2 +- .../report/ReportControllerHelper.java | 10 ++-- .../zeiterfassung/user/DateFormatter.java | 2 - .../zeiterfassung/user/DateFormatterImpl.java | 6 --- .../user/DateRangeFormatter.java | 38 ++++++++++++++ src/main/resources/messages.properties | 4 +- src/main/resources/messages_en.properties | 3 ++ .../templates/reports/user-report-week.html | 49 +++++++++++++++++-- .../templates/reports/user-report.html | 4 +- 9 files changed, 100 insertions(+), 18 deletions(-) create mode 100644 src/main/java/de/focusshift/zeiterfassung/user/DateRangeFormatter.java diff --git a/src/main/java/de/focusshift/zeiterfassung/report/GraphWeekDto.java b/src/main/java/de/focusshift/zeiterfassung/report/GraphWeekDto.java index 6d22a8ea8..790c31a0b 100644 --- a/src/main/java/de/focusshift/zeiterfassung/report/GraphWeekDto.java +++ b/src/main/java/de/focusshift/zeiterfassung/report/GraphWeekDto.java @@ -2,7 +2,7 @@ import java.util.List; -record GraphWeekDto(String yearMonthWeek, List dayReports, Double maxHoursWorked) { +record GraphWeekDto(int calendarWeek, String dateRangeString, List dayReports, Double maxHoursWorked) { public Double graphLegendMaxHour() { diff --git a/src/main/java/de/focusshift/zeiterfassung/report/ReportControllerHelper.java b/src/main/java/de/focusshift/zeiterfassung/report/ReportControllerHelper.java index 711947451..8b0c06fbd 100644 --- a/src/main/java/de/focusshift/zeiterfassung/report/ReportControllerHelper.java +++ b/src/main/java/de/focusshift/zeiterfassung/report/ReportControllerHelper.java @@ -2,6 +2,7 @@ import de.focusshift.zeiterfassung.absence.Absence; import de.focusshift.zeiterfassung.user.DateFormatter; +import de.focusshift.zeiterfassung.user.DateRangeFormatter; import de.focusshift.zeiterfassung.user.UserId; import de.focusshift.zeiterfassung.usermanagement.User; import de.focusshift.zeiterfassung.usermanagement.UserLocalId; @@ -28,10 +29,12 @@ class ReportControllerHelper { private final ReportPermissionService reportPermissionService; private final DateFormatter dateFormatter; + private final DateRangeFormatter dateRangeFormatter; - ReportControllerHelper(ReportPermissionService reportPermissionService, DateFormatter dateFormatter) { + ReportControllerHelper(ReportPermissionService reportPermissionService, DateFormatter dateFormatter, DateRangeFormatter dateRangeFormatter) { this.reportPermissionService = reportPermissionService; this.dateFormatter = dateFormatter; + this.dateRangeFormatter = dateRangeFormatter; } UserId principalToUserId(OidcUser principal) { @@ -65,14 +68,15 @@ GraphWeekDto toGraphWeekDto(ReportWeek reportWeek, Month monthPivot) { .map(reportDay -> toUserReportDayReportDto(reportDay, !reportDay.date().getMonth().equals(monthPivot))) .toList(); - final String yearMonthWeek = dateFormatter.formatYearMonthWeek(reportWeek.firstDateOfWeek()); + final int calendarWeek = reportWeek.firstDateOfWeek().get(ChronoField.ALIGNED_WEEK_OF_YEAR); + final String dateRangeString = dateRangeFormatter.toDateRangeString(reportWeek.firstDateOfWeek(), reportWeek.lastDateOfWeek()); final double maxHoursWorked = dayReports.stream() .map(GraphDayDto::hoursWorked) .mapToDouble(value -> value) .max().orElse(0.0); - return new GraphWeekDto(yearMonthWeek, dayReports, maxHoursWorked); + return new GraphWeekDto(calendarWeek, dateRangeString, dayReports, maxHoursWorked); } private GraphDayDto toUserReportDayReportDto(ReportDay reportDay, boolean differentMonth) { diff --git a/src/main/java/de/focusshift/zeiterfassung/user/DateFormatter.java b/src/main/java/de/focusshift/zeiterfassung/user/DateFormatter.java index e41cad5c9..5ffff3543 100644 --- a/src/main/java/de/focusshift/zeiterfassung/user/DateFormatter.java +++ b/src/main/java/de/focusshift/zeiterfassung/user/DateFormatter.java @@ -19,6 +19,4 @@ public interface DateFormatter { String formatDate(LocalDate date); String formatDate(LocalDate date, MonthFormat monthFormat, YearFormat yearFormat); - - String formatYearMonthWeek(LocalDate date); } diff --git a/src/main/java/de/focusshift/zeiterfassung/user/DateFormatterImpl.java b/src/main/java/de/focusshift/zeiterfassung/user/DateFormatterImpl.java index 114358ee6..a29bbbfa6 100644 --- a/src/main/java/de/focusshift/zeiterfassung/user/DateFormatterImpl.java +++ b/src/main/java/de/focusshift/zeiterfassung/user/DateFormatterImpl.java @@ -8,7 +8,6 @@ import java.time.YearMonth; import java.time.format.DateTimeFormatter; import java.time.format.TextStyle; -import java.time.temporal.ChronoField; import java.util.Locale; @Service @@ -53,11 +52,6 @@ public String formatDate(LocalDate date, MonthFormat monthFormat, YearFormat yea return DateTimeFormatter.ofPattern(pattern, locale).format(date); } - public String formatYearMonthWeek(LocalDate date) { - final String yearMonth = formatYearMonth(YearMonth.from(date)); - return yearMonth + " KW " + date.get(ChronoField.ALIGNED_WEEK_OF_YEAR); - } - private Locale locale() { return LocaleContextHolder.getLocale(); } diff --git a/src/main/java/de/focusshift/zeiterfassung/user/DateRangeFormatter.java b/src/main/java/de/focusshift/zeiterfassung/user/DateRangeFormatter.java new file mode 100644 index 000000000..5793e2e96 --- /dev/null +++ b/src/main/java/de/focusshift/zeiterfassung/user/DateRangeFormatter.java @@ -0,0 +1,38 @@ +package de.focusshift.zeiterfassung.user; + +import org.springframework.context.MessageSource; +import org.springframework.context.i18n.LocaleContextHolder; +import org.springframework.stereotype.Component; + +import java.time.LocalDate; +import java.util.Locale; + +@Component +public class DateRangeFormatter { + + private final DateFormatter dateFormatter; + private final MessageSource messageSource; + + DateRangeFormatter(DateFormatter dateFormatter, MessageSource messageSource) { + this.dateFormatter = dateFormatter; + this.messageSource = messageSource; + } + + public String toDateRangeString(LocalDate from, LocalDate to) { + + final MonthFormat firstMonthFormat = + from.getMonthValue() == to.getMonthValue() ? MonthFormat.NONE : MonthFormat.STRING; + + final YearFormat firstYearFormat = + from.getYear() == to.getYear() ? YearFormat.NONE : YearFormat.FULL; + + final String firstDateString = dateFormatter.formatDate(from, firstMonthFormat, firstYearFormat); + final String lastDateString = dateFormatter.formatDate(to, MonthFormat.STRING, YearFormat.FULL); + + return messageSource.getMessage("date-range", new Object[]{firstDateString, lastDateString}, locale()); + } + + private Locale locale() { + return LocaleContextHolder.getLocale(); + } +} diff --git a/src/main/resources/messages.properties b/src/main/resources/messages.properties index 67f85a7a1..3c565c996 100644 --- a/src/main/resources/messages.properties +++ b/src/main/resources/messages.properties @@ -199,6 +199,9 @@ month.october.short=Okt month.november.short=Nov month.december.short=Dez +date-range={0} bis {1} +date-range.with-calendar-week=KW {0} | {1} + datepicker.today=Heute # duet-date-picker localization @@ -277,7 +280,6 @@ time-entry.form.delete.tooltip=Löschen time-entry.date.label=Datum time-entry.delete=Zeitslot wurde gelöscht. - report.page.meta.title=Zeiterfassung - Berichte report.view.select=Ansicht: diff --git a/src/main/resources/messages_en.properties b/src/main/resources/messages_en.properties index 027e3dcd0..737f901a8 100644 --- a/src/main/resources/messages_en.properties +++ b/src/main/resources/messages_en.properties @@ -199,6 +199,9 @@ month.october.short=Oct month.november.short=Nov month.december.short=Dec +date-range={0} to {1} +date-range.with-calendar-week=CW {0} | {1} + datepicker.today=Today # duet-date-picker localization diff --git a/src/main/resources/templates/reports/user-report-week.html b/src/main/resources/templates/reports/user-report-week.html index 8247251ca..7363307b4 100644 --- a/src/main/resources/templates/reports/user-report-week.html +++ b/src/main/resources/templates/reports/user-report-week.html @@ -65,16 +65,57 @@
Diese Woche - - Dezember 2021, KW 42 - +
+
+
+ + KW 40 | 30. September bis 06. Oktober 2024 + +

+ +01:58 + + + + + + + + + + + + +

+

+ Geleistet: + 41:58 + (Soll: 40:00) +

+
+
+
+
+
-
+