[65] #REFACTOR 'Layout and Service'
LocationBasedServices/maptology/angular-time-sheet-feature This commit looks good

{- Layout completely revised. Responsivness is now done through flex box.
 - TimeSheetService functions cleaned up.}
This commit is contained in:
Adriano Markovic
2020-02-14 02:04:39 +01:00
parent 6bd1076e75
commit bf90db3620
4 changed files with 248 additions and 474 deletions
@@ -446,6 +446,10 @@ 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_title': 'Stundenzettel',
'time_sheet_table_date': 'Datum',
'time_sheet_table_from': 'von',
@@ -454,17 +458,26 @@ export class ResourceService {
'time_sheet_table_place': 'Arbeitsplatz',
'time_sheet_table_device': 'Gerät',
'time_sheet_config_label': 'Konfiguration',
'time_sheet_toggle_default_label': 'Standard',
'time_sheet_toggle_acc_label': 'Akk.',
'time_sheet_toggle_default_label': 'Arbeit',
'time_sheet_toggle_default_tooltip': 'Gedeckelte & zusammengefasste Arbeitszeit je Tag.',
'time_sheet_toggle_acc_label': 'Normal',
'time_sheet_toggle_acc_tooltip': 'Ungedeckelte & zusammengefasste Zeiteinträge je Tag.',
'time_sheet_toggle_by_days_label': 'Nach Tagen',
'time_sheet_toggle_by_days_tooltip': 'Alle Zeiteinträge je Tag.',
'time_sheet_toggle_raw_label': 'Rohdaten',
'time_sheet_toggle_raw_tooltip': 'Rohdaten',
'time_sheet_select_device_label': 'Gerät',
'time_sheet_select_device_tooltip': 'Filtert die Zeiteinträge auf das ausgewählte Gerät.',
'time_sheet_no_device_selected': 'Keins',
'time_sheet_break_time_label': 'Pausendauer',
'time_sheet_break_time_tooltip': 'Gibt an, ab welcher Dauer die Abwesenheit vom Arbeitsplatz als Pausendauer '
+ 'zu werten ist und somit nicht zum Zeiteintrag hinzugerechnet wird.',
'time_sheet_break_time_minutes': 'Minuten',
'time_sheet_no_break_time_selected': 'Keine',
'time_sheet_time_period_label': 'Zeitraum',
'time_sheet_time_period_tooltip': 'Markiert den Zeitraum für die auszuwertendend Daten.',
'time_sheet_workplace_button': 'Arbeitsplatz auswählen',
'time_sheet_workplace_clear_list': 'List leeren',
'time_sheet_workplace_clear_list': 'Liste leeren',
// layouts
'drawer_navigation': 'Navigation',
'drawer_settings': 'Einstellungen',
@@ -908,6 +921,10 @@ 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_title': 'Time Sheet',
'time_sheet_table_date': 'Date',
'time_sheet_table_from': 'from',
@@ -916,15 +933,24 @@ export class ResourceService {
'time_sheet_table_place': 'Workplace',
'time_sheet_table_device': 'Device',
'time_sheet_config_label': 'Configuration',
'time_sheet_toggle_default_label': 'Default',
'time_sheet_toggle_acc_label': 'Acc.',
'time_sheet_toggle_default_label': 'Work',
'time_sheet_toggle_default_tooltip': 'Capped & accumulated working time per day.',
'time_sheet_toggle_acc_label': 'Normal',
'time_sheet_toggle_acc_tooltip': 'Uncapped & accumulated time entries per day.',
'time_sheet_toggle_by_days_label': 'By Days',
'time_sheet_toggle_by_days_tooltip': 'All time entries per day.',
'time_sheet_toggle_raw_label': 'Raw',
'time_sheet_toggle_raw_tooltip': 'Raw data.',
'time_sheet_select_device_label': 'Device',
'time_sheet_select_device_tooltip': 'Filters the time entries to the selected device.',
'time_sheet_no_device_selected': 'None',
'time_sheet_break_time_label': 'Break Time',
'time_sheet_break_time_tooltip': 'Specifies the duration from which the absence from the work '
+ 'place is to be valuated as a break duration and is therefore not added to the time entry.',
'time_sheet_break_time_minutes': 'Minutes',
'time_sheet_no_break_time_selected': 'None',
'time_sheet_time_period_label': 'Time Period',
'time_sheet_time_period_tooltip': 'Marks the period for the data to be evaluated.',
'time_sheet_workplace_button': 'Select Workplace',
'time_sheet_workplace_clear_list': 'Clear List',
// layouts
@@ -32,8 +32,7 @@ export enum Grouping {
export enum ExportType {
CSV = '.csv',
JSON = '.json',
XML = '.xml'
JSON = '.json'
}
type DateRange = { range?: SatDatepickerRangeValue<Date>, begin?: number, end?: number };
@@ -45,7 +44,6 @@ const LINE_SEPARATOR = '\r\n';
providedIn: 'root'
})
export class TimeSheetService extends MatTableDataSource<TimeSheetData> {
// export class TimeSheetService {
private static readonly BATCH_SIZE = 500;
@@ -69,7 +67,6 @@ export class TimeSheetService extends MatTableDataSource<TimeSheetData> {
* for a known bug in angular, where mat-selection is fireing
* a "selectionChange" event twice when the selected value is null. */
private _grouped: Grouping = Grouping.DEFAULT;
private _prevGrouped: Grouping = Grouping.DEFAULT;
private _device: Device = null;
private _prevDevice: Device = null;
private _breakTime: number = null;
@@ -77,9 +74,6 @@ export class TimeSheetService extends MatTableDataSource<TimeSheetData> {
private _dateRange: DateRange = {};
private _workPlaces: Place[] = [];
/* Final data which is shown to the user. */
// timeSheet: TimeSheetData[] = [];
/** Creates an empty page. */
private static emptyPage() {
return { elements: [], offset: 0, total: -1, size: 0 };
@@ -112,9 +106,8 @@ export class TimeSheetService extends MatTableDataSource<TimeSheetData> {
set grouped(grouped: Grouping) {
if (grouped != null) {
if (this._grouped !== grouped) {
if (this._grouped === Grouping.DEFAULT && this._breakTime)
if ((this._grouped === Grouping.DEFAULT || this.grouped === Grouping.BY_DAY_ACC) && this._breakTime)
this._breakTime = null;
this._prevGrouped = this._grouped;
this._grouped = grouped;
this.updateTimeSheet();
}
@@ -399,51 +392,36 @@ export class TimeSheetService extends MatTableDataSource<TimeSheetData> {
if (ts.deviceId) devices.add(ts.deviceId);
});
let accWorkingHours: Time;
if (Grouping.DEFAULT && this.breakTime !== null) {
const btThreshold = this.breakTime * 60_000;
accWorkingHours = tsList
.reduce(
(prev: { sheet?: TimeSheetData, skip: boolean, acc: Time }, curr: TimeSheetData) => {
// FIXME: The accumulation with the break time included is not working properly.
if (!prev.skip) {
if (prev) {
const breakDiff = curr.beginDate.getTime() - prev.sheet.endDate.getTime();
if (breakDiff <= btThreshold) {
const time = this.getWorkingTime(prev.sheet.beginDate.getTime(), curr.endDate.getTime());
prev.acc.hours += time.hours;
prev.acc.minutes += time.minutes;
prev.skip = true;
} else {
prev.acc.hours += curr.workingTime.hours;
prev.acc.minutes += curr.workingTime.minutes;
}
}
} else {
prev.skip = false;
}
// console.log('prev', prev);
// console.log('curr', curr);
prev.sheet = curr;
return prev;
},
{ sheet: null, skip: false, acc: { hours: 0, minutes: 0 }}
).acc;
} else {
accWorkingHours = tsList
.map((ts: TimeSheetData) => ts.workingTime)
.reduce((prev, curr) => {
prev.hours += curr.hours;
prev.minutes += curr.minutes;
return prev;
},
{ hours: 0, minutes: 0 }
);
}
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;
}
}
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 && accWorkingHours.hours > 10)
accWorkingHours = { hours: 10, minutes: 0 };
if (this.grouped === Grouping.DEFAULT){
if (accWorkingHours.hours >= 10)
accWorkingHours = { hours: 10, minutes: 0 };
else {
// TODO: Aufrunden von angebrochenen viertel Stunden.
}
}
timeSheet.push({
overlappingDays: false,
@@ -521,9 +499,6 @@ export class TimeSheetService extends MatTableDataSource<TimeSheetData> {
case 'json':
exportStr = this.createJSON();
break;
case 'xml':
exportStr = this.createXML();
break;
}
if (!exportStr) return false;
@@ -587,8 +562,4 @@ export class TimeSheetService extends MatTableDataSource<TimeSheetData> {
}, [])
);
}
private createXML(): string | null {
throw new Error('Not implemented yet');
}
}
@@ -1,380 +1,170 @@
<ng-container>
<style>
/* Styles for the work place table */
.workplaces{
margin-left: 16px;
margin-right: 16px;
}
.cdk-column-address {
width: 90%;
text-align: start;
}
.cdk-column-delete {
width: 10%;
text-align: right;
margin-right: 32px;
}
<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>
/* Styles for the main time sheet table */
.mat-column-date {
word-wrap: break-word !important;
white-space: unset !important;
flex: 0 0 16% !important;
width: 16% !important;
overflow-wrap: break-word;
word-wrap: break-word;
word-break: break-word;
-ms-hyphens: auto;
-moz-hyphens: auto;
-webkit-hyphens: auto;
hyphens: auto;
}
.mat-column-to-time, .mat-column-from-time {
word-wrap: break-word !important;
white-space: unset !important;
flex: 0 0 7% !important;
width: 7% !important;
overflow-wrap: break-word;
word-wrap: break-word;
word-break: break-word;
-ms-hyphens: auto;
-moz-hyphens: auto;
-webkit-hyphens: auto;
hyphens: auto;
}
.mat-column-time {
word-wrap: break-word !important;
white-space: unset !important;
flex: 0 0 10% !important;
width: 10% !important;
overflow-wrap: break-word;
word-wrap: break-word;
word-break: break-word;
-ms-hyphens: auto;
-moz-hyphens: auto;
-webkit-hyphens: auto;
hyphens: auto;
}
.mat-column-device {
word-wrap: break-word !important;
white-space: unset !important;
flex: 0 0 20% !important;
width: 20% !important;
overflow-wrap: break-word;
word-wrap: break-word;
word-break: break-word;
-ms-hyphens: auto;
-moz-hyphens: auto;
-webkit-hyphens: auto;
hyphens: auto;
}
.mat-column-place {
word-wrap: break-word !important;
white-space: unset !important;
flex: 0 0 40% !important;
width: 40% !important;
overflow-wrap: break-word;
word-wrap: break-word;
word-break: break-word;
-ms-hyphens: auto;
-moz-hyphens: auto;
-webkit-hyphens: auto;
hyphens: auto;
}
</style>
<div fxLayout="column" fxLayoutAlign="start stretch" fxFlexFill>
<mat-toolbar style="background:transparent;">
<mat-toolbar-row style="flex: 1 1 auto;">
<div>
<mat-icon style="margin-left: 5px;">access_time_icon</mat-icon>
<span style="margin-left: 10px">{{ res.strings('time_sheet_title') }}</span>
</div>
<!-- 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 class="flex-spacer"></div>
<div>
<button mat-icon-button style="padding-right: 10px;" (click)="updateTimeSheetTable()">
<mat-icon>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">as CSV</button>
<button mat-menu-item
(click)="exportTimeSheet('json')"
[disabled]="!timeSheetService.isTimeSheetReady">as JSON</button>
<!-- <button mat-menu-item
(click)="exportTimeSheet('xml')"
[disabled]="!timeSheetService.isTimeSheetReady">as XML</button> -->
</ng-template>
</mat-menu>
<button mat-icon-button style="margin-right: 10px;" [matMenuTriggerFor]="exportMenu">
<mat-icon>import_export</mat-icon>
</button>
</div>
</mat-toolbar-row>
</mat-toolbar>
<!-- Page Content -->
<mat-sidenav-container style="flex: 1; overflow: hidden;">
<mat-sidenav class="mat-elevation-z4" role="region" position="end" mode="side" disableClose
[opened]="isSidenavOpened"
style="border-radius: 10px;">
<mat-list fxLayout="column" fxLayoutAlign="center" fxLayoutGap="10px"
style="margin-bottom: 20px;">
<mat-list-item fxLayoutAlign="center">
<h3 mat-subheader>{{ res.strings('time_sheet_config_label') }}</h3>
</mat-list-item>
<mat-list-item fxLayoutAlign="center">
<mat-button-toggle-group
[(value)]="timeSheetService.grouped"
name="groupingChoice"
aria-label="Grouping Choice">
<mat-button-toggle [value]="1">{{ res.strings('time_sheet_toggle_default_label') }}</mat-button-toggle>
<mat-button-toggle [value]="2">{{ res.strings('time_sheet_toggle_acc_label') }}</mat-button-toggle>
<mat-button-toggle [value]="3">{{ res.strings('time_sheet_toggle_by_days_label') }}</mat-button-toggle>
<mat-button-toggle [value]="4" hidden>{{ res.strings('time_sheet_toggle_raw_label') }}</mat-button-toggle>
</mat-button-toggle-group>
</mat-list-item>
</mat-list>
<mat-list fxLayout="column" fxLayoutAlign="center" fxLayoutGap="10px">
<mat-list-item fxLayoutAlign="center">
<mat-form-field>
<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-list-item>
<mat-list-item fxLayoutAlign="center">
<mat-form-field>
<mat-label>{{ res.strings('time_sheet_break_time_label') }}</mat-label>
<mat-select
[(value)]="timeSheetService.breakTime"
[disabled]="timeSheetService.grouped > 1">
<mat-option [value]="null">{{ res.strings('time_sheet_no_break_time_selected') }}</mat-option>
<mat-option *ngFor="let opt of breakTimeOptions" [value]="opt">
{{ opt }}
</mat-option>
</mat-select>
</mat-form-field>
</mat-list-item>
<mat-list-item fxLayoutAlign="center">
<mat-form-field>
<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-item>
</mat-list>
<mat-divider role="seperator" style="margin: 16px;"></mat-divider>
<mat-list fxLayout="column" fxLayoutAlign="center">
<mat-list-item fxLayoutAlign="center">
<button mat-subheader mat-button (click)="openWorkPlacesDialog()">
<mat-icon class="icon-button">list_icon</mat-icon>
<span>{{ res.strings('time_sheet_workplace_button') }}</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_shet_export_as_csv_label') }}
</button>
</mat-list-item>
<ng-container *ngIf="workPlaces.length > 0">
<mat-divider role="seperator" style="margin: 16px;"></mat-divider>
<table #workPlacesTable cdk-table class="workplaces" [dataSource]="workPlaces">
<ng-container matColumnDef="address">
<th cdk-header-cell *cdkHeaderCellDef>Address</th>
<td cdk-cell *cdkCellDef="let workPlace">
{{ getWorkplaceName(workPlace) }}
</td>
</ng-container>
<ng-container matColumnDef="delete">
<th cdk-header-cell *cdkHeaderCellDef>Delete</th>
<td cdk-cell *cdkCellDef="let workPlace"
(click)="deleteWorkPlaceEntry(workPlace)">
<mat-icon class="icon-button">delete_icon</mat-icon>
</td>
</ng-container>
<tr cdk-row
*cdkRowDef="let workplaceRow; columns: ['address', 'delete']"
fxLayout="row"
fxLayoutAlign="center center"></tr>
</table>
<mat-divider role="seperator" style="margin: 16px;"></mat-divider>
<button mat-button (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 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>
</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" 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>
</ng-container>
</mat-list>
</mat-sidenav>
<mat-sidenav-content>
<!-- Responsive Sidenav for mobile devices. -->
<ng-container *ngIf="!isSidenavOpened">
<mat-card class="mat-elevation-z4" style="margin: 4px;">
<mat-card-content>
<mat-list fxLayout="column" fxLayoutAlign="center" fxLayoutGap="10px">
<mat-list-item fxLayoutAlign="center">
<h3 mat-subheader>{{ res.strings('time_sheet_config_label') }}</h3>
</mat-list-item>
<mat-list-item fxLayoutAlign="center">
<mat-button-toggle-group
[(value)]="timeSheetService.grouped"
name="groupingChoice"
aria-label="Grouping Choice">
<mat-button-toggle [value]="1">{{ res.strings('time_sheet_toggle_default_label') }}</mat-button-toggle>
<mat-button-toggle [value]="2">{{ res.strings('time_sheet_toggle_acc_label') }}</mat-button-toggle>
</mat-button-toggle-group>
</mat-list-item>
<mat-list-item fxLayoutAlign="center">
<mat-form-field>
<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-list-item>
<mat-list-item fxLayoutAlign="center">
<mat-form-field>
<mat-label>{{ res.strings('time_sheet_break_time_label') }}</mat-label>
<mat-select
[(value)]="timeSheetService.breakTime"
[disabled]="timeSheetService.grouped > 1">
<mat-option [value]="null">{{ res.strings('time_sheet_no_break_time_selected') }}</mat-option>
<mat-option *ngFor="let opt of breakTimeOptions" [value]="opt">
{{ opt }}
</mat-option>
</mat-select>
</mat-form-field>
</mat-list-item>
<mat-list-item fxLayoutAlign="center">
<mat-form-field>
<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-item>
</mat-list>
</mat-card-content>
</mat-card>
<mat-card class="mat-elevation-z4" style="margin: 4px;">
<mat-card-content>
<mat-list fxLayout="column" fxLayoutAlign="center" fxLayoutGap="10px">
<mat-list-item fxLayoutAlign="center">
<button mat-subheader mat-button (click)="openWorkPlacesDialog()">
<mat-icon class="icon-button" style="margin-left: 4px">list_icon</mat-icon>
<span>{{ res.strings('time_sheet_workplace_button') }}</span>
</button>
</mat-list-item>
</mat-list>
<ng-container *ngIf="workPlaces.length > 0">
<table #workPlacesTable cdk-table class="workplaces" [dataSource]="workPlaces">
<ng-container matColumnDef="address">
<td cdk-cell *cdkCellDef="let workPlace">
{{ getWorkplaceName(workPlace) }}
</td>
</ng-container>
<ng-container matColumnDef="delete">
<td cdk-cell *cdkCellDef="let workPlace"
(click)="deleteWorkPlaceEntry(workPlace)">
<mat-icon class="icon-button">delete_icon</mat-icon>
</td>
</ng-container>
<tr cdk-row
*cdkRowDef="let workplaceRow; columns: ['address', 'delete']"
fxLayout="row"
fxLayoutAlign="center center"></tr>
</table>
<mat-list fxLayout="column" fxLayoutAlign="center" fxLayoutGap="10px">
<mat-list-item fxLayoutAlign="center">
<button mat-button color="primary" (click)="clearWorkPlaceList()">
<mat-icon class="icon-button" style="margin-left: 4px">delete_icon</mat-icon>
<span>{{ res.strings('time_sheet_workplace_clear_list') }}</span>
</button>
</mat-list-item>
</mat-list>
</ng-container>
</mat-card-content>
</mat-card>
</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>
<!-- 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-z4">
<mat-card-content>
<table mat-table #timeSheet [dataSource]="timeSheetDataSource" matSort>
<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="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>
</ng-container>
<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>
<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="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>
<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="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>
<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>
<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>
<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>
</mat-sidenav-content>
</mat-sidenav-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>
</div>
</div>
</ng-container>
@@ -18,31 +18,37 @@ import { Device, Place } from '../../api/models';
selector: 'app-time-sheet',
templateUrl: './time-sheet.component.html',
styles: [
'table { width: 100%; }',
'mat-sidenav { width: 350px }',
'mat-button-toggle { font-size: 14px; }',
`.main-content {
margin: 4px;
padding-right: 16px;
padding-left: 16px;
padding-bottom: 8px;
padding-top: 8px;
}`
`.flex-center { display: flex; flex: 1 1 auto; justify-content: center; }`,
`.divider { margin: 16px; }`,
`.timesheet-container {
display: flex;
flex-flow: row-reverse wrap;
justify-content: center;
align-items: flex-start;
}`,
`.timesheet-config { width: 350px; max-width: 350px; }`,
`.config-col { display: flex; flex: 1 1 auto; flex-direction: column; justify-content: center; }`,
`.config-col .config-item { margin-left: 32px; margin-right: 32px; }`,
'.config-col .toggle-btn { font-size: 14px; margin: 20px 0px }',
`.main-content { flex: 1 1 auto; margin: 4px; padding: 8px 16px; }`,
`.main-content .main-table { width: 100%; }`,
`.main-content .mat-column-date { width: 16% !important; }`,
`.main-content .mat-column-to-time, .mat-column-from-time { width: 7% !important; }`,
`.main-content .mat-column-time { width: 10% !important; }`,
`.main-content .mat-column-device { width: 20% !important; }`,
`.main-content .mat-column-place { width: 40% !important; }`
],
})
export class TimeSheetComponent implements OnInit, OnDestroy, AfterViewInit {
private static readonly SIDENAV_BREAKPOINT = 960;
readonly breakTimeOptions = [5, 10, 15, 20, 30, 45, 60, 90, 120, 150];
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('workPlacesTable', { read: CdkTable, static: false }) workPlacesTable: CdkTable<Place>;
@ViewChild(MatSort, { static: true }) sort: MatSort;
@ViewChild(MatPaginator, { static: true }) paginator: MatPaginator;
compact = false;
isSidenavOpened = true;
// TODO: Implement TableHandler Logic.
static readonly normalDisplayCol = ['date', 'from-time', 'to-time', 'time', 'device', 'place'];
static readonly compactDisplayCol = ['date', 'time'];
displayedColumns = TimeSheetComponent.normalDisplayCol;
@@ -52,8 +58,6 @@ export class TimeSheetComponent implements OnInit, OnDestroy, AfterViewInit {
timeSheetDataSource: MatTableDataSource<TimeSheetData>;
private subscriptions: Subscription;
// TODO: Implement PaginationHandler Logic.
private pageHandler: PaginationHandler<TimeSheetData, Page<TimeSheetData>>;
constructor(
public res: ResourceService,
@@ -65,16 +69,10 @@ export class TimeSheetComponent implements OnInit, OnDestroy, AfterViewInit {
ngOnInit(): void {
this.workPlaces = this.timeSheetService.workPlaces;
this.timeSheetDataSource = this.timeSheetService;
this.updateDisplayedColumns(window.innerWidth);
this.updateSidenav(window.innerWidth);
this.isSidenavOpened = this.sidenav.opened;
this.subscriptions = this.sidenav.openedChange
.subscribe((state: boolean) => this.isSidenavOpened = state);
this.subscriptions.add(
this.deviceService.connect(null)
.subscribe((devices: Device[]) => this.devices = devices)
);
this.subscriptions = this.deviceService.connect(null)
.subscribe((devices: Device[]) => this.devices = devices);
this.deviceService.reload();
}
@@ -91,17 +89,17 @@ export class TimeSheetComponent implements OnInit, OnDestroy, AfterViewInit {
@HostListener('window:resize', ['$event'])
onResize(event: Event): void {
this.updateSidenav((event.target as Window).innerWidth);
this.updateDisplayedColumns((event.target as Window).innerWidth);
}
updateTimeSheetTable(): void {
// if (!this.timeSheetService.fetching$.getValue())
// this.timeSheetService.fetchData();
console.log(this.sort);
if (!this.timeSheetService.fetching$.getValue())
this.timeSheetService.fetchData();
}
exportTimeSheet(type: string): void {
if (!this.timeSheetService.exportTimeSheet(type)) {
// TODO: Implement Dialog
console.log('Did not export!');
}
}
@@ -149,7 +147,6 @@ export class TimeSheetComponent implements OnInit, OnDestroy, AfterViewInit {
deleteWorkPlaceEntry(workPlace: Place): void {
this.workPlaces = this.workPlaces.filter(place => workPlace !== place);
this.timeSheetService.workPlaces = this.workPlaces;
this.workPlacesTable.renderRows();
}
clearWorkPlaceList(): void {
@@ -161,24 +158,14 @@ export class TimeSheetComponent implements OnInit, OnDestroy, AfterViewInit {
return this.timeSheetService.getDate(data);
}
private updateSidenav(width: number): void {
if (width < TimeSheetComponent.SIDENAV_BREAKPOINT && !this.compact) {
this.sidenav.close();
private updateDisplayedColumns(width: number): void {
if (width < TimeSheetComponent.LAYOUT_BREAKPOINT && !this.compact) {
this.compact = true;
this.isSidenavOpened = false;
this.displayedColumns = TimeSheetComponent.compactDisplayCol;
this.timeSheetService.grouped = Grouping.BY_DAY_ACC;
} else if (width >= TimeSheetComponent.SIDENAV_BREAKPOINT && this.compact) {
} else if (width >= TimeSheetComponent.LAYOUT_BREAKPOINT && this.compact) {
this.compact = false;
this.sidenav.open();
this.isSidenavOpened = true;
this.displayedColumns = TimeSheetComponent.normalDisplayCol;
}
if (this.sidenav.opened !== this.isSidenavOpened) {
if (this.isSidenavOpened)
this.sidenav.open();
else
this.sidenav.close();
}
}
}