diff --git a/web-angular/src/app/services/resource.service.ts b/web-angular/src/app/services/resource.service.ts index 2c2a623..7b829c3 100644 --- a/web-angular/src/app/services/resource.service.ts +++ b/web-angular/src/app/services/resource.service.ts @@ -446,11 +446,14 @@ export class ResourceService { + 'Adressleiste Deines Browsers kopiert hast, stell sicher, dass der Link vollständig ist.', 'activate_error_expiredlink': 'Der Aktivierungslink ist nicht mehr gültig. Entweder wurder er schon benutzt oder er ist abgelaufen.', // TODO: Time Sheet labels DE - 'time_shet_update_btn_tooltip': 'Aktualisieren', - 'time_shet_export_btn_tooltip': 'Exportieren', - 'time_shet_export_as_csv_label': 'als CSV', - 'time_shet_export_as_json_label': 'als JSON', + 'time_sheet_update_btn_tooltip': 'Aktualisieren', + 'time_sheet_export_btn_tooltip': 'Exportieren', + 'time_sheet_export_as_csv_label': 'als CSV', + 'time_sheet_export_as_json_label': 'als JSON', + 'time_sheet_export_error_msg_title': 'Fehler!', + 'time_sheet_export_error_msg': 'Es ist ein unerwarteter Fehler aufgetreten. Der Export ist fehlgeschlagen.', 'time_sheet_title': 'Stundenzettel', + 'time_sheet_table_row_dialog_title': 'Zeitinfo', 'time_sheet_table_date': 'Datum', 'time_sheet_table_from': 'von', 'time_sheet_table_to': 'bis', @@ -921,11 +924,14 @@ export class ResourceService { + 'make sure to copy it completely.', 'activate_error_expiredlink': 'The activation link is no longer valid. Did you already use it?', // TODO: Time Sheet labels EN - 'time_shet_update_btn_tooltip': 'Update', - 'time_shet_export_btn_tooltip': 'Export', - 'time_shet_export_as_csv_label': 'as CSV', - 'time_shet_export_as_json_label': 'as JSON', + 'time_sheet_update_btn_tooltip': 'Update', + 'time_sheet_export_btn_tooltip': 'Export', + 'time_sheet_export_as_csv_label': 'as CSV', + 'time_sheet_export_as_json_label': 'as JSON', + 'time_sheet_export_error_msg_title': 'Error!', + 'time_sheet_export_error_msg': 'An unexpected error has occurred. The export has failed.', 'time_sheet_title': 'Time Sheet', + 'time_sheet_table_row_dialog_title': 'Time Info', 'time_sheet_table_date': 'Date', 'time_sheet_table_from': 'from', 'time_sheet_table_to': 'to', diff --git a/web-angular/src/app/services/time-sheet.service.ts b/web-angular/src/app/services/time-sheet.service.ts index 8ca8bfb..c2ac859 100644 --- a/web-angular/src/app/services/time-sheet.service.ts +++ b/web-angular/src/app/services/time-sheet.service.ts @@ -12,27 +12,29 @@ import { VisitPage, Device, Place, Visit } from '../../api/models'; import { UserService } from './user.service'; +/** + * Data model for the TimeSheetService. + */ export interface TimeSheetData { - overlappingDays: boolean; - beginDate: Date; - endDate: Date; - workingTime: Time; - placeId?: number; - deviceId?: number; - placesSet?: Set; - devicesSet?: Set; + overlappingDays: boolean; /* True if contained data is overlapping two or more days. */ + beginDate: Date; /* Start date */ + endDate: Date; /* End date */ + duration: Time; /* Duration time */ + placeId?: number; /* The id of the place. Null if placesSet is set. */ + deviceId?: number; /* The id of the device. Null if devicesSet is set. */ + placesSet?: Set; /* A set of Places. Null if placeId is set. */ + devicesSet?: Set; /* A set of Devices. Null if deviceId is set. */ } +/** + * Determines how the TimeSheetData + * of the service is grouped. + */ export enum Grouping { - DEFAULT = 1, - BY_DAY_ACC = 2, - BY_DAY = 3, - RAW = 4 -} - -export enum ExportType { - CSV = '.csv', - JSON = '.json' + DEFAULT = 1, /* Capped & accumulated working time per day. */ + BY_DAY_ACC = 2, /* Uncapped & accumulated working time per day. */ + BY_DAY = 3, /* All time entries per day. */ + RAW = 4 /* Raw data which was extracted from the call to the '/users/current/visits' api */ } type DateRange = { range?: SatDatepickerRangeValue, begin?: number, end?: number }; @@ -40,6 +42,10 @@ type DateRange = { range?: SatDatepickerRangeValue, begin?: number, end?: const COLUMN_SEPARATOR = ';'; const LINE_SEPARATOR = '\r\n'; +/** + * A service which is fetching data from the '/users/current/visits' + * api and transforms it to TimeSheetData. + */ @Injectable({ providedIn: 'root' }) @@ -240,6 +246,10 @@ export class TimeSheetService extends MatTableDataSource { }; } + /** + * Updates the member data of the MatTableDataSource if some of the properties change. + * The data is only updated if the property "isTimeSheetReady" is true. + */ private updateTimeSheet(): void { let timeSheet: TimeSheetData[] = []; if (this.isTimeSheetReady) { @@ -293,7 +303,7 @@ export class TimeSheetService extends MatTableDataSource { overlappingDays: overlapping, beginDate: new Date(visit.beginTime), endDate: new Date(visit.endTime), - workingTime: workingTime, + duration: workingTime, placeId: visit.place, deviceId: visit.device }; @@ -341,7 +351,7 @@ export class TimeSheetService extends MatTableDataSource { overlappingDays: false, beginDate: new Date(begin), endDate: new Date(end), - workingTime: this.getWorkingTime(begin, end), + duration: this.getWorkingTime(begin, end), placeId: currTS.placeId, deviceId: currTS.deviceId }; @@ -352,7 +362,7 @@ export class TimeSheetService extends MatTableDataSource { overlappingDays: false, beginDate: new Date(endMidnight), endDate: currTS.endDate, - workingTime: this.getWorkingTime(endMidnight, currTS.endDate.getTime()), + duration: this.getWorkingTime(endMidnight, currTS.endDate.getTime()), placeId: currTS.placeId, deviceId: currTS.deviceId }; @@ -393,41 +403,37 @@ export class TimeSheetService extends MatTableDataSource { }); const btThreshold = (this.breakTime) ? this.breakTime * 60_000 : 0; - let accWorkingHours = tsList.reduce( - (prev: { sheet?: TimeSheetData, skip: boolean, acc: Time }, curr: TimeSheetData) => { - if (prev.sheet && btThreshold > 0) { - const breakDiff = curr.beginDate.getTime() - prev.sheet.endDate.getTime(); - if (breakDiff <= btThreshold) { - const time = this.getWorkingTime( - prev.sheet.endDate.getTime(), - curr.beginDate.getTime() - ); - prev.acc.hours += time.hours; - prev.acc.minutes += time.minutes; + const timeAccumulation = tsList + .reduce((prev: { sheet?: TimeSheetData, acc: Time, breakAcc: Time }, curr: TimeSheetData) => { + if (prev.sheet) { + let addToBreakAcc = true; + const time = this.getWorkingTime(prev.sheet.endDate.getTime(), curr.beginDate.getTime()); + if (btThreshold > 0) { + if (curr.beginDate.getTime() - prev.sheet.endDate.getTime() <= btThreshold) { + prev.acc.hours += time.hours; + prev.acc.minutes += time.minutes; + addToBreakAcc = false; + } + } + if (addToBreakAcc) { + prev.breakAcc.hours += time.hours; + prev.breakAcc.minutes += time.minutes; + } } - } - prev.acc.hours += curr.workingTime.hours; - prev.acc.minutes += curr.workingTime.minutes; - prev.sheet = curr; - return prev; - }, - { sheet: null, skip: false, acc: { hours: 0, minutes: 0 }} - ).acc; - accWorkingHours.hours += Math.floor(accWorkingHours.minutes / 60); - accWorkingHours.minutes = accWorkingHours.minutes % 60; - if (this.grouped === Grouping.DEFAULT){ - if (accWorkingHours.hours >= 10) - accWorkingHours = { hours: 10, minutes: 0 }; - else { - // TODO: Aufrunden von angebrochenen viertel Stunden. - } - } - + prev.acc.hours += curr.duration.hours; + prev.acc.minutes += curr.duration.minutes; + prev.sheet = curr; + return prev; + }, + { sheet: null, acc: { hours: 0, minutes: 0 }, breakAcc: { hours: 0, minutes: 0} } + ); + const accWorkingHours = this.processWorkingHours(timeAccumulation.acc, timeAccumulation.breakAcc); + timeSheet.push({ overlappingDays: false, beginDate: new Date(erliestBegin), endDate: new Date(latestEnd), - workingTime: accWorkingHours, + duration: accWorkingHours, placesSet: places, devicesSet: devices }); @@ -436,6 +442,50 @@ export class TimeSheetService extends MatTableDataSource { return timeSheet; } + /** + * Processes the work and break time. If Grouping is DEFAULT, the break time is evaluated + * and has to fit the legal requirements of having at least a 30 or 45 minutes break when + * working more than 6 or 9 hours respectively. + * + * @param working The time that is counting as work time. + * @param breaking The time between the single work time entries + * which can be seen as break time. + * @return The normalized and processed work time. + */ + private processWorkingHours(working: Time, breaking: Time): Time { + working = this.normalizeTime(working); + if (this.grouped === Grouping.DEFAULT) { + let subtrahend = 0; + breaking = this.normalizeTime(breaking); + if (working.hours >= 6 && breaking.hours === 0 && breaking.minutes < 30) + subtrahend = 30 - breaking.minutes; + else if (working.hours >= 9 && breaking.hours === 0 && breaking.minutes < 45) + subtrahend = 45 - breaking.minutes; + working.minutes -= subtrahend; + if (working.minutes < 0) { + --working.hours; + working.minutes = 60 - working.minutes; + } + + /* Rounds up the minutes to a multiple of 15. */ + if (working.minutes !== 0) + working.minutes += Math.floor(15 - working.minutes % 15); + if (working.minutes === 60) { + ++working.hours; + working.minutes = 0; + } + if (working.hours >= 10) + working = { hours: 10, minutes: 0 }; + } + return working; + } + + private normalizeTime(time: Time): Time { + time.hours += Math.floor(time.minutes / 60); + time.minutes = time.minutes % 60; + return time; + } + private getMidnightDate(tstp: number): Date { let midnight = new Date(tstp); midnight.setHours(0, 0, 0, 0); @@ -541,7 +591,7 @@ export class TimeSheetService extends MatTableDataSource { result += this.getDate(td) + COLUMN_SEPARATOR; result += formatDate(td.beginDate, 'H:mm', 'de') + COLUMN_SEPARATOR; result += formatDate(td.endDate, 'H:mm', 'de') + COLUMN_SEPARATOR; - result += `${td.workingTime.hours} h ${td.workingTime.minutes} m` + COLUMN_SEPARATOR; + result += `${td.duration.hours} h ${td.duration.minutes} m` + COLUMN_SEPARATOR; result += this.getWorkplaceString(td) + COLUMN_SEPARATOR; result += LINE_SEPARATOR; }); @@ -550,16 +600,15 @@ export class TimeSheetService extends MatTableDataSource { private createJSON(): string | null { return JSON.stringify( - this.data.reduce((prev: object[], td: TimeSheetData) => { - prev.push({ + this.data.map((td: TimeSheetData) => { + return { date: this.getDate(td), from: formatDate(td.beginDate, 'H:mm', 'de'), to: formatDate(td.endDate, 'H:mm', 'de'), - workingTime: `${td.workingTime.hours} h ${td.workingTime.minutes} m`, + workingTime: `${td.duration.hours} h ${td.duration.minutes} m`, workplaces: this.getWorkplaceString(td) - }); - return prev; - }, []) + } + }) ); } } diff --git a/web-angular/src/app/views/time-sheet.component.html b/web-angular/src/app/views/time-sheet.component.html index 497c918..84e29e1 100644 --- a/web-angular/src/app/views/time-sheet.component.html +++ b/web-angular/src/app/views/time-sheet.component.html @@ -1,170 +1,165 @@ -
- - access_time_icon - {{ res.strings('time_sheet_title') }} + + access_time_icon + {{ res.strings('time_sheet_title') }} - -
- - +
+ - - - - - - - -
- - - -
-
- -

{{ res.strings('time_sheet_config_label') }}

- - - - {{ res.strings('time_sheet_toggle_default_label') }} - - {{ res.strings('time_sheet_toggle_acc_label') }} - - {{ res.strings('time_sheet_toggle_by_days_label') }} - - - - - {{ res.strings('time_sheet_select_device_label') }} - - {{ res.strings('time_sheet_no_device_selected') }} - - - {{ device.model }} - - - - - - {{ res.strings('time_sheet_break_time_label') }} - - {{ res.strings('time_sheet_no_break_time_selected') }} - - {{ opt + ' ' + res.strings('time_sheet_break_time_minutes') }} - - - - - - - - -
- - - - - - - - -
- - {{ getWorkplaceName(workPlace) }} -
- - - - -
-
+ + + +
+ - - - - - - - - - - - + +
+
+ +

{{ res.strings('time_sheet_config_label') }}

+ + + + {{ res.strings('time_sheet_toggle_default_label') }} + + {{ res.strings('time_sheet_toggle_acc_label') }} + + {{ res.strings('time_sheet_toggle_by_days_label') }} + + + + + {{ res.strings('time_sheet_select_device_label') }} + + {{ res.strings('time_sheet_no_device_selected') }} + + + {{ device.model }} + + + + + {{ res.strings('time_sheet_break_time_label') }} + + {{ res.strings('time_sheet_no_break_time_selected') }} + + {{ opt + ' ' + res.strings('time_sheet_break_time_minutes') }} + + + + + + + + +
- -
- - + - - - - + + + + - - - - +
+ + {{ getWorkplaceName(workPlace) }} +
- - - - + - - - - - - - -
{{ res.strings('time_sheet_table_date') }}{{ getDate(data) }}{{ res.strings('time_sheet_table_from') }} - {{ data.beginDate | date:'H:mm' }} - {{ res.strings('time_sheet_table_to') }} - {{ data.endDate | date:'H:mm' }} - {{ res.strings('time_sheet_table_working_time') }}{{ getWorkingTime(data.workingTime) }}{{ res.strings('time_sheet_table_place') }}{{ getWorkplaceString(data) }}{{ res.strings('time_sheet_table_device') }}{{ getDeviceNameString(data) }}
- -
-
+ + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
{{ res.strings('time_sheet_table_date') }}{{ getDate(data) }}{{ res.strings('time_sheet_table_from') }} + {{ data.beginDate | date:'H:mm' }} + {{ res.strings('time_sheet_table_to') }} + {{ data.endDate | date:'H:mm' }} + {{ res.strings('time_sheet_table_working_time') }}{{ getWorkingTime(data.duration) }}{{ res.strings('time_sheet_table_place') }}{{ getWorkplaceString(data) }}{{ res.strings('time_sheet_table_device') }}{{ getDeviceNameString(data) }}
+ +
+
\ No newline at end of file diff --git a/web-angular/src/app/views/time-sheet.component.ts b/web-angular/src/app/views/time-sheet.component.ts index 1eede67..d06ea70 100644 --- a/web-angular/src/app/views/time-sheet.component.ts +++ b/web-angular/src/app/views/time-sheet.component.ts @@ -1,8 +1,7 @@ -import { Component, OnInit, HostListener, ViewChild, OnDestroy, ElementRef, AfterViewInit } from '@angular/core'; -import { Time } from '@angular/common'; +import { Component, OnInit, HostListener, ViewChild, OnDestroy, AfterViewInit } from '@angular/core'; +import { Time, formatDate } from '@angular/common'; import { MatSidenav, MatPaginator, MatTableDataSource, MatSort } from "@angular/material"; import { MatDialog } from "@angular/material/dialog"; -import { CdkTable } from '@angular/cdk/table'; import { Subscription } from "rxjs"; @@ -10,10 +9,20 @@ import { ResourceService } from "../services/resource.service"; import { DeviceService } from "../services/device.service"; import { TimeSheetService, TimeSheetData, Grouping } from '../services/time-sheet.service'; import { PlacesDialogComponent } from "../widgets/places-dialog.component"; -import { PaginationHandler, Page } from '../utils/pagination'; import { Device, Place } from '../../api/models'; +import { MessageDialogComponent } from '../widgets/message-dialog.component'; +/** + * A view that offers the functionality to generate a timesheet by filtering on the + * time period and the places a device has been. + * It offers three modes: + * 1. Default -> Shows the time entries per day processed in terms of legal working requirements. + * It also offers the functionality of defining a filter at which point the + * absence from a defined "working place" should be booked as a break. + * 2. Summed -> Shows the time entries per day without any processing at all. + * 3. By Day -> Shows every single time entry. Due to that a single day can occure frequently. + */ @Component({ selector: 'app-time-sheet', templateUrl: './time-sheet.component.html', @@ -44,8 +53,6 @@ export class TimeSheetComponent implements OnInit, OnDestroy, AfterViewInit { private static readonly LAYOUT_BREAKPOINT = 960; readonly breakTimeOptions = [5, 10, 15, 20, 30, 45, 60, 90, 120, 150, 180]; - @ViewChild(MatSidenav, { static: true }) sidenav: MatSidenav; - @ViewChild(MatSort, { static: true }) sort: MatSort; @ViewChild(MatPaginator, { static: true }) paginator: MatPaginator; compact = false; @@ -78,7 +85,7 @@ export class TimeSheetComponent implements OnInit, OnDestroy, AfterViewInit { } ngAfterViewInit(): void { - this.timeSheetService.setup(this.paginator, this.sort); + this.timeSheetService.setup(this.paginator); } ngOnDestroy(): void { @@ -98,10 +105,28 @@ export class TimeSheetComponent implements OnInit, OnDestroy, AfterViewInit { } exportTimeSheet(type: string): void { - if (!this.timeSheetService.exportTimeSheet(type)) { - // TODO: Implement Dialog - console.log('Did not export!'); - } + if (!this.timeSheetService.exportTimeSheet(type)) + this.openMessageDialog( + this.res.strings('time_sheet_export_error_msg_title'), + this.res.strings('time_sheet_export_error_msg') + ); + } + + showTimeSheetRowInfo(data: TimeSheetData): void { + if (!this.compact) return; + + const res_values = [ + 'time_sheet_table_date', 'time_sheet_table_from', 'time_sheet_table_to', + 'time_sheet_table_working_time', 'time_sheet_table_place', 'time_sheet_table_device' + ]; + const data_values = [ + `${this.getDate(data)}`, `${formatDate(data.beginDate, 'H:mm', 'de')}`, + `${formatDate(data.endDate, 'H:mm', 'de')}`, `${this.getWorkingTime(data.duration)}`, + `${this.getWorkplaceString(data)}`,`${this.getWorkplaceString(data)}` + ]; + let msg = ''; + res_values.forEach((val: string, idx: number, _) => msg += `${this.res.strings(val)}: ${data_values[idx]}; `) + this.openMessageDialog(this.res.strings('time_sheet_table_row_dialog_title'), msg.slice(0, msg.length - 2)); } openWorkPlacesDialog(): void { @@ -158,6 +183,11 @@ export class TimeSheetComponent implements OnInit, OnDestroy, AfterViewInit { return this.timeSheetService.getDate(data); } + private openMessageDialog(title: string, message: string): void { + const dialogSubscription = MessageDialogComponent.open(this.dialog, { title, message }) + .subscribe(() => dialogSubscription.unsubscribe()); + } + private updateDisplayedColumns(width: number): void { if (width < TimeSheetComponent.LAYOUT_BREAKPOINT && !this.compact) { this.compact = true; diff --git a/web-angular/src/theme.scss b/web-angular/src/theme.scss index c57dafa..8e6bbe8 100644 --- a/web-angular/src/theme.scss +++ b/web-angular/src/theme.scss @@ -1,4 +1,5 @@ @import '~@angular/material/theming'; +@import '~saturn-datepicker/theming'; // Plus imports for other components in your app. // Include the common styles for Angular Material. We include this here so that you only @@ -13,13 +14,22 @@ $app-primary: mat-palette($mat-light-blue, 900); $app-accent: mat-palette($mat-yellow, 800); $app-accent-dark: mat-palette($mat-yellow, 800); +// Colors for the dark theme. +$dark-primary: mat-palette($mat-blue-grey); +$dark-accent: mat-palette($mat-amber, A200, A100, A400); +$dark-warn: mat-palette($mat-deep-orange); + // The warn palette is optional (defaults to red). $app-warn: mat-palette($mat-red); // Create the theme object (a Sass map containing all of the palettes). +// light theme $app-theme: mat-light-theme($app-primary, $app-accent, $app-warn); +// dark theme +// $app-theme: mat-dark-theme($dark-primary, $dark-accent, $dark-warn); // Include theme styles for core and each component used in your app. // Alternatively, you can import and @include the theme mixins for each component // that you are using. @include angular-material-theme($app-theme); +@include sat-datepicker-theme($app-theme);