[65] #IMPLEMENT 'Time capping function'
LocationBasedServices/maptology/angular-time-sheet-feature This commit looks good
LocationBasedServices/maptology/angular-time-sheet-feature This commit looks good
{- Finished the time capping functionality which subtracts the break time from the working time if there has been no time gaps.
- Documented and cleaned up the code.}
This commit is contained in:
@@ -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',
|
||||
|
||||
@@ -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<number>;
|
||||
devicesSet?: Set<number>;
|
||||
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<number>; /* A set of Places. Null if placeId is set. */
|
||||
devicesSet?: Set<number>; /* 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<Date>, begin?: number, end?: number };
|
||||
@@ -40,6 +42,10 @@ type DateRange = { range?: SatDatepickerRangeValue<Date>, 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<TimeSheetData> {
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* 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<TimeSheetData> {
|
||||
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<TimeSheetData> {
|
||||
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<TimeSheetData> {
|
||||
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<TimeSheetData> {
|
||||
});
|
||||
|
||||
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<TimeSheetData> {
|
||||
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<TimeSheetData> {
|
||||
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<TimeSheetData> {
|
||||
|
||||
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;
|
||||
}, [])
|
||||
}
|
||||
})
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,170 +1,165 @@
|
||||
<ng-container>
|
||||
<div >
|
||||
<mat-toolbar style="display: flex; background:transparent;">
|
||||
<mat-icon style="margin-left: 5px;">access_time_icon</mat-icon>
|
||||
<span style="margin-left: 10px">{{ res.strings('time_sheet_title') }}</span>
|
||||
<mat-toolbar style="display: flex; background:transparent;">
|
||||
<mat-icon style="margin-left: 5px;">access_time_icon</mat-icon>
|
||||
<span style="margin-left: 10px">{{ res.strings('time_sheet_title') }}</span>
|
||||
|
||||
<!-- TODO: Fix overflow bug caused by faulty mat icon fonts. -->
|
||||
<div flexLayout="row" fxLayoutAlign="end center" fxFlex="1 1 auto" fxLayoutGap="10px">
|
||||
<!-- <div style="display: flex; flex: 1 1 auto; justify-content: end;"> -->
|
||||
<button mat-icon-button
|
||||
[matTooltip]="res.strings('time_shet_update_btn_tooltip')"
|
||||
(click)="updateTimeSheetTable()">
|
||||
<mat-icon style="font-size: 18px;">update_icon</mat-icon>
|
||||
<!-- <mat-icon>update_icon</mat-icon> -->
|
||||
</button>
|
||||
<div flexLayout="row" fxLayoutAlign="end center" fxFlex="1 1 auto" fxLayoutGap="10px">
|
||||
<button mat-icon-button
|
||||
[matTooltip]="res.strings('time_sheet_update_btn_tooltip')"
|
||||
(click)="updateTimeSheetTable()">
|
||||
<mat-icon style="font-size: 18px;">update_icon</mat-icon>
|
||||
</button>
|
||||
|
||||
<mat-menu #exportMenu="matMenu" class="mat-elevation-z1">
|
||||
<ng-template matMenuContent>
|
||||
<button mat-menu-item
|
||||
(click)="exportTimeSheet('csv')"
|
||||
[disabled]="!timeSheetService.isTimeSheetReady">
|
||||
{{ res.strings('time_shet_export_as_csv_label') }}
|
||||
</button>
|
||||
<button mat-menu-item
|
||||
(click)="exportTimeSheet('json')"
|
||||
[disabled]="!timeSheetService.isTimeSheetReady">
|
||||
{{ res.strings('time_shet_export_as_json_label') }}
|
||||
</button>
|
||||
</ng-template>
|
||||
</mat-menu>
|
||||
<button mat-icon-button
|
||||
[matMenuTriggerFor]="exportMenu"
|
||||
[matTooltip]="res.strings('time_shet_export_btn_tooltip')">
|
||||
<mat-icon >import_export</mat-icon>
|
||||
</button>
|
||||
</div>
|
||||
</mat-toolbar>
|
||||
|
||||
<!-- Configuration Side Panel -->
|
||||
<div class="timesheet-container">
|
||||
<div class="timesheet-config">
|
||||
<mat-list class="config-col">
|
||||
<h3 mat-subheader class="flex-center">{{ res.strings('time_sheet_config_label') }}</h3>
|
||||
<mat-list-item class="flex-center toggle-btn">
|
||||
<mat-button-toggle-group
|
||||
[(value)]="timeSheetService.grouped"
|
||||
name="groupingChoice"
|
||||
aria-label="Grouping Choice">
|
||||
<mat-button-toggle [value]="1" [matTooltip]="res.strings('time_sheet_toggle_default_tooltip')">
|
||||
{{ res.strings('time_sheet_toggle_default_label') }}</mat-button-toggle>
|
||||
<mat-button-toggle [value]="2" [matTooltip]="res.strings('time_sheet_toggle_acc_tooltip')">
|
||||
{{ res.strings('time_sheet_toggle_acc_label') }}</mat-button-toggle>
|
||||
<mat-button-toggle [value]="3" [matTooltip]="res.strings('time_sheet_toggle_by_days_tooltip')">
|
||||
{{ res.strings('time_sheet_toggle_by_days_label') }}</mat-button-toggle>
|
||||
<mat-button-toggle [value]="4" [matTooltip]="res.strings('time_sheet_toggle_raw_tooltip')" hidden>
|
||||
{{ res.strings('time_sheet_toggle_raw_label') }}</mat-button-toggle>
|
||||
</mat-button-toggle-group>
|
||||
</mat-list-item>
|
||||
<mat-form-field class="config-item" [matTooltip]="res.strings('time_sheet_select_device_tooltip')">
|
||||
<mat-label>{{ res.strings('time_sheet_select_device_label') }}</mat-label>
|
||||
<mat-select
|
||||
[(value)]="timeSheetService.device">
|
||||
<mat-option [value]="null">{{ res.strings('time_sheet_no_device_selected') }}</mat-option>
|
||||
<ng-container *ngIf="devices">
|
||||
<mat-option *ngFor="let device of devices" [value]="device">
|
||||
{{ device.model }}
|
||||
</mat-option>
|
||||
</ng-container>
|
||||
</mat-select>
|
||||
</mat-form-field>
|
||||
<mat-form-field class="config-item" [matTooltip]="res.strings('time_sheet_break_time_tooltip')">
|
||||
<mat-label>{{ res.strings('time_sheet_break_time_label') }}</mat-label>
|
||||
<mat-select
|
||||
[(value)]="timeSheetService.breakTime"
|
||||
[disabled]="timeSheetService.grouped > 2">
|
||||
<mat-option [value]="null">{{ res.strings('time_sheet_no_break_time_selected') }}</mat-option>
|
||||
<mat-option *ngFor="let opt of breakTimeOptions" [value]="opt">
|
||||
{{ opt + ' ' + res.strings('time_sheet_break_time_minutes') }}
|
||||
</mat-option>
|
||||
</mat-select>
|
||||
</mat-form-field>
|
||||
<mat-form-field class="config-item" [matTooltip]="res.strings('time_sheet_time_period_tooltip')">
|
||||
<input matInput
|
||||
[placeholder]="res.strings('time_sheet_time_period_label')"
|
||||
[satDatepicker]="picker"
|
||||
[value]="timeSheetService.dateRange"
|
||||
(dateChange)="timeSheetService.dateRange = $event.target.value">
|
||||
<sat-datepicker #picker [rangeMode]="true" orderPeriodLabel="month"></sat-datepicker>
|
||||
<sat-datepicker-toggle matSuffix [for]="picker"></sat-datepicker-toggle>
|
||||
</mat-form-field>
|
||||
</mat-list>
|
||||
|
||||
<mat-divider class="divider"></mat-divider>
|
||||
|
||||
<mat-list class="config-col">
|
||||
<button mat-subheader mat-button class="config-item" (click)="openWorkPlacesDialog()">
|
||||
<mat-icon class="icon-button">list_icon</mat-icon>
|
||||
<span>{{ res.strings('time_sheet_workplace_button') }}</span>
|
||||
</button>
|
||||
<ng-container *ngIf="workPlaces.length > 0">
|
||||
<mat-divider class="divider"></mat-divider>
|
||||
|
||||
<div class="config-item" *ngFor="let workPlace of workPlaces">
|
||||
<button mat-icon-button (click)="deleteWorkPlaceEntry(workPlace)">
|
||||
<mat-icon class="icon-button">clear_icon</mat-icon>
|
||||
</button>
|
||||
<span fxLayoutAlign="center" fxFlex="1 1 auto">{{ getWorkplaceName(workPlace) }}</span>
|
||||
</div>
|
||||
|
||||
<mat-divider class="divider"></mat-divider>
|
||||
|
||||
<button mat-button style="margin-bottom: 10px;" (click)="clearWorkPlaceList()" color="primary">
|
||||
<mat-icon class="icon-button" style="margin-left: 12px">delete_icon</mat-icon>
|
||||
<span>{{ res.strings('time_sheet_workplace_clear_list') }}</span>
|
||||
<mat-menu #exportMenu="matMenu" class="mat-elevation-z1">
|
||||
<ng-template matMenuContent>
|
||||
<button mat-menu-item
|
||||
(click)="exportTimeSheet('csv')"
|
||||
[disabled]="!timeSheetService.isTimeSheetReady">
|
||||
{{ res.strings('time_sheet_export_as_csv_label') }}
|
||||
</button>
|
||||
</ng-container>
|
||||
</mat-list>
|
||||
<button mat-menu-item
|
||||
(click)="exportTimeSheet('json')"
|
||||
[disabled]="!timeSheetService.isTimeSheetReady">
|
||||
{{ res.strings('time_sheet_export_as_json_label') }}
|
||||
</button>
|
||||
</ng-template>
|
||||
</mat-menu>
|
||||
<button mat-icon-button
|
||||
[matMenuTriggerFor]="exportMenu"
|
||||
[matTooltip]="res.strings('time_sheet_export_btn_tooltip')">
|
||||
<mat-icon >import_export</mat-icon>
|
||||
</button>
|
||||
</div>
|
||||
</mat-toolbar>
|
||||
|
||||
<!-- Table Content -->
|
||||
<ng-container *ngIf="false">
|
||||
<mat-progress-bar mode="indeterminate" color="accent"></mat-progress-bar>
|
||||
</ng-container>
|
||||
<mat-card class="main-content mat-elevation-z2">
|
||||
<mat-card-content>
|
||||
<table mat-table #timeSheet class="main-table" [dataSource]="timeSheetDataSource" matSort>
|
||||
|
||||
<ng-container matColumnDef="date">
|
||||
<th mat-header-cell *matHeaderCellDef mat-sort-header="date">{{ res.strings('time_sheet_table_date') }}</th>
|
||||
<td mat-cell *matCellDef="let data">{{ getDate(data) }}</td>
|
||||
<!-- Configuration Side Panel -->
|
||||
<div class="timesheet-container">
|
||||
<div class="timesheet-config">
|
||||
<mat-list class="config-col">
|
||||
<h3 mat-subheader class="flex-center">{{ res.strings('time_sheet_config_label') }}</h3>
|
||||
<mat-list-item class="flex-center toggle-btn">
|
||||
<mat-button-toggle-group
|
||||
[(value)]="timeSheetService.grouped"
|
||||
name="groupingChoice"
|
||||
aria-label="Grouping Choice">
|
||||
<mat-button-toggle [value]="1" [matTooltip]="res.strings('time_sheet_toggle_default_tooltip')">
|
||||
{{ res.strings('time_sheet_toggle_default_label') }}</mat-button-toggle>
|
||||
<mat-button-toggle [value]="2" [matTooltip]="res.strings('time_sheet_toggle_acc_tooltip')">
|
||||
{{ res.strings('time_sheet_toggle_acc_label') }}</mat-button-toggle>
|
||||
<mat-button-toggle [value]="3" [matTooltip]="res.strings('time_sheet_toggle_by_days_tooltip')">
|
||||
{{ res.strings('time_sheet_toggle_by_days_label') }}</mat-button-toggle>
|
||||
<mat-button-toggle [value]="4" [matTooltip]="res.strings('time_sheet_toggle_raw_tooltip')" hidden>
|
||||
{{ res.strings('time_sheet_toggle_raw_label') }}</mat-button-toggle>
|
||||
</mat-button-toggle-group>
|
||||
</mat-list-item>
|
||||
<mat-form-field class="config-item" [matTooltip]="res.strings('time_sheet_select_device_tooltip')">
|
||||
<mat-label>{{ res.strings('time_sheet_select_device_label') }}</mat-label>
|
||||
<mat-select
|
||||
[(value)]="timeSheetService.device">
|
||||
<mat-option [value]="null">{{ res.strings('time_sheet_no_device_selected') }}</mat-option>
|
||||
<ng-container *ngIf="devices">
|
||||
<mat-option *ngFor="let device of devices" [value]="device">
|
||||
{{ device.model }}
|
||||
</mat-option>
|
||||
</ng-container>
|
||||
</mat-select>
|
||||
</mat-form-field>
|
||||
<mat-form-field class="config-item" [matTooltip]="res.strings('time_sheet_break_time_tooltip')">
|
||||
<mat-label>{{ res.strings('time_sheet_break_time_label') }}</mat-label>
|
||||
<mat-select
|
||||
[(value)]="timeSheetService.breakTime"
|
||||
[disabled]="timeSheetService.grouped > 2">
|
||||
<mat-option [value]="null">{{ res.strings('time_sheet_no_break_time_selected') }}</mat-option>
|
||||
<mat-option *ngFor="let opt of breakTimeOptions" [value]="opt">
|
||||
{{ opt + ' ' + res.strings('time_sheet_break_time_minutes') }}
|
||||
</mat-option>
|
||||
</mat-select>
|
||||
</mat-form-field>
|
||||
<mat-form-field class="config-item" [matTooltip]="res.strings('time_sheet_time_period_tooltip')">
|
||||
<input matInput
|
||||
[placeholder]="res.strings('time_sheet_time_period_label')"
|
||||
[satDatepicker]="picker"
|
||||
[value]="timeSheetService.dateRange"
|
||||
(dateChange)="timeSheetService.dateRange = $event.target.value">
|
||||
<sat-datepicker #picker [rangeMode]="true" orderPeriodLabel="month"></sat-datepicker>
|
||||
<sat-datepicker-toggle matSuffix [for]="picker"></sat-datepicker-toggle>
|
||||
</mat-form-field>
|
||||
</mat-list>
|
||||
|
||||
<ng-container matColumnDef="from-time">
|
||||
<th mat-header-cell *matHeaderCellDef>{{ res.strings('time_sheet_table_from') }}</th>
|
||||
<td mat-cell *matCellDef="let data">
|
||||
{{ data.beginDate | date:'H:mm' }}
|
||||
</td>
|
||||
</ng-container>
|
||||
<mat-divider class="divider"></mat-divider>
|
||||
|
||||
<ng-container matColumnDef="to-time">
|
||||
<th mat-header-cell *matHeaderCellDef>{{ res.strings('time_sheet_table_to') }}</th>
|
||||
<td mat-cell *matCellDef="let data">
|
||||
{{ data.endDate | date:'H:mm' }}
|
||||
</td>
|
||||
</ng-container>
|
||||
<mat-list class="config-col">
|
||||
<button mat-subheader mat-button class="config-item" (click)="openWorkPlacesDialog()">
|
||||
<mat-icon class="icon-button">list_icon</mat-icon>
|
||||
<span>{{ res.strings('time_sheet_workplace_button') }}</span>
|
||||
</button>
|
||||
<ng-container *ngIf="workPlaces.length > 0">
|
||||
<mat-divider class="divider"></mat-divider>
|
||||
|
||||
<ng-container matColumnDef="time">
|
||||
<th mat-header-cell *matHeaderCellDef mat-sort-header>{{ res.strings('time_sheet_table_working_time') }}</th>
|
||||
<td mat-cell *matCellDef="let data">{{ getWorkingTime(data.workingTime) }}</td>
|
||||
</ng-container>
|
||||
<div class="config-item" *ngFor="let workPlace of workPlaces">
|
||||
<button mat-icon-button (click)="deleteWorkPlaceEntry(workPlace)">
|
||||
<mat-icon class="icon-button">clear_icon</mat-icon>
|
||||
</button>
|
||||
<span fxLayoutAlign="center" fxFlex="1 1 auto">{{ getWorkplaceName(workPlace) }}</span>
|
||||
</div>
|
||||
|
||||
<ng-container matColumnDef="place">
|
||||
<th mat-header-cell *matHeaderCellDef mat-sort-header>{{ res.strings('time_sheet_table_place') }}</th>
|
||||
<td mat-cell *matCellDef="let data">{{ getWorkplaceString(data) }}</td>
|
||||
</ng-container>
|
||||
<mat-divider class="divider"></mat-divider>
|
||||
|
||||
<ng-container matColumnDef="device">
|
||||
<th mat-header-cell *matHeaderCellDef mat-sort-header>{{ res.strings('time_sheet_table_device') }}</th>
|
||||
<td mat-cell *matCellDef="let data">{{ getDeviceNameString(data) }}</td>
|
||||
</ng-container>
|
||||
|
||||
<tr mat-header-row *matHeaderRowDef="displayedColumns; sticky: true"></tr>
|
||||
<tr mat-row *matRowDef="let row; columns: displayedColumns;"></tr>
|
||||
</table>
|
||||
<mat-paginator #paginator [pageSizeOptions]="[10, 20, 50, 100]" showFirstLastButtons></mat-paginator>
|
||||
</mat-card-content>
|
||||
</mat-card>
|
||||
<button mat-button style="margin-bottom: 10px;" (click)="clearWorkPlaceList()" color="primary">
|
||||
<mat-icon class="icon-button" style="margin-left: 12px">delete_icon</mat-icon>
|
||||
<span>{{ res.strings('time_sheet_workplace_clear_list') }}</span>
|
||||
</button>
|
||||
</ng-container>
|
||||
</mat-list>
|
||||
</div>
|
||||
|
||||
<!-- Table Content -->
|
||||
<ng-container *ngIf="false">
|
||||
<mat-progress-bar mode="indeterminate" color="accent"></mat-progress-bar>
|
||||
</ng-container>
|
||||
<mat-card class="main-content mat-elevation-z2">
|
||||
<mat-card-content>
|
||||
<table mat-table #timeSheet class="main-table" [dataSource]="timeSheetDataSource">
|
||||
|
||||
<ng-container matColumnDef="date">
|
||||
<th mat-header-cell *matHeaderCellDef>{{ res.strings('time_sheet_table_date') }}</th>
|
||||
<td mat-cell *matCellDef="let data">{{ getDate(data) }}</td>
|
||||
</ng-container>
|
||||
|
||||
<ng-container matColumnDef="from-time">
|
||||
<th mat-header-cell *matHeaderCellDef>{{ res.strings('time_sheet_table_from') }}</th>
|
||||
<td mat-cell *matCellDef="let data">
|
||||
{{ data.beginDate | date:'H:mm' }}
|
||||
</td>
|
||||
</ng-container>
|
||||
|
||||
<ng-container matColumnDef="to-time">
|
||||
<th mat-header-cell *matHeaderCellDef>{{ res.strings('time_sheet_table_to') }}</th>
|
||||
<td mat-cell *matCellDef="let data">
|
||||
{{ data.endDate | date:'H:mm' }}
|
||||
</td>
|
||||
</ng-container>
|
||||
|
||||
<ng-container matColumnDef="time">
|
||||
<th mat-header-cell *matHeaderCellDef>{{ res.strings('time_sheet_table_working_time') }}</th>
|
||||
<td mat-cell *matCellDef="let data">{{ getWorkingTime(data.duration) }}</td>
|
||||
</ng-container>
|
||||
|
||||
<ng-container matColumnDef="place">
|
||||
<th mat-header-cell *matHeaderCellDef>{{ res.strings('time_sheet_table_place') }}</th>
|
||||
<td mat-cell *matCellDef="let data">{{ getWorkplaceString(data) }}</td>
|
||||
</ng-container>
|
||||
|
||||
<ng-container matColumnDef="device">
|
||||
<th mat-header-cell *matHeaderCellDef>{{ res.strings('time_sheet_table_device') }}</th>
|
||||
<td mat-cell *matCellDef="let data">{{ getDeviceNameString(data) }}</td>
|
||||
</ng-container>
|
||||
|
||||
<tr mat-header-row *matHeaderRowDef="displayedColumns; sticky: true"></tr>
|
||||
<tr mat-row *matRowDef="let row; columns: displayedColumns;" (click)="showTimeSheetRowInfo(row)"></tr>
|
||||
</table>
|
||||
<mat-paginator #paginator [pageSizeOptions]="[10, 20, 50, 100]" showFirstLastButtons></mat-paginator>
|
||||
</mat-card-content>
|
||||
</mat-card>
|
||||
</div>
|
||||
</ng-container>
|
||||
@@ -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;
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user