[65] #IMPLEMENT 'Time capping function'
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:
Adriano Markovic
2020-02-14 16:37:16 +01:00
parent bf90db3620
commit cf74b4fdc8
5 changed files with 321 additions and 231 deletions
@@ -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>