synced day selector + implemented current time difference in analytics
This commit is contained in:
@@ -19,7 +19,7 @@
|
||||
|
||||
<ion-modal [keepContentsMounted]="true">
|
||||
<ng-template>
|
||||
<ion-datetime id="current-datetime-analysis" presentation="date" [(ngModel)]="currentDate" (ngModelChange)="updateCurrentData()"></ion-datetime>
|
||||
<ion-datetime id="current-datetime-analysis" presentation="date" [(ngModel)]="currentDate" (ngModelChange)="updateCurrentDate()"></ion-datetime>
|
||||
</ng-template>
|
||||
</ion-modal>
|
||||
</ion-item>
|
||||
|
||||
@@ -24,6 +24,7 @@ import {briefcase, card, pizza} from "ionicons/icons";
|
||||
import {NgIf} from "@angular/common";
|
||||
import {SettingsService} from "../../services/settings.service";
|
||||
import {Settings} from "../../models/settings";
|
||||
import {AppComponent} from "../app.component";
|
||||
|
||||
@Component({
|
||||
selector: 'app-tab2',
|
||||
@@ -54,6 +55,12 @@ export class AnalysisPage {
|
||||
}
|
||||
|
||||
ionViewDidEnter() {
|
||||
this.currentDate = AppComponent.currentDate;
|
||||
this.updateCurrentData();
|
||||
}
|
||||
|
||||
public updateCurrentDate() {
|
||||
AppComponent.currentDate = this.currentDate;
|
||||
this.updateCurrentData();
|
||||
}
|
||||
|
||||
@@ -65,26 +72,50 @@ export class AnalysisPage {
|
||||
this.driveTime = 0;
|
||||
this.combinedWorkTime = 0;
|
||||
|
||||
if (this.timeData.length < 2) {
|
||||
if (this.timeData.length == 0) {
|
||||
this.showEmptyChart();
|
||||
return;
|
||||
}
|
||||
|
||||
for (let i = 1; i < this.timeData.length; i++) {
|
||||
const start = this.timeData[i - 1];
|
||||
const end = this.timeData[i];
|
||||
const diff = this.time.calculateTimespanInMinutes(start, end);
|
||||
if (this.timeData.length >= 1 && this.time.isToday(this.currentDate)) {
|
||||
const lastEntry = this.timeData[this.timeData.length - 1];
|
||||
const diff = this.time.calculateTimespanInMinutes(lastEntry, {
|
||||
type: undefined,
|
||||
registeredAt: new Date(Date.now())
|
||||
});
|
||||
|
||||
if (start.type == 'start-drive' && end.type == 'end-drive') {
|
||||
this.driveTime += diff;
|
||||
}
|
||||
else if (start.type === 'login') {
|
||||
if (lastEntry.type == "login") {
|
||||
this.workTime += diff;
|
||||
}
|
||||
else {
|
||||
this.pauseTime += diff;
|
||||
else if (lastEntry.type == "start-drive") {
|
||||
this.driveTime += diff;
|
||||
}
|
||||
|
||||
if (lastEntry.registeredAt.getHours() < this.settings.dontTrackPauseAfter) {
|
||||
if (lastEntry.type == "logout" || lastEntry.type == "end-drive") {
|
||||
this.pauseTime += diff;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (this.timeData.length > 2) {
|
||||
for (let i = 1; i < this.timeData.length; i++) {
|
||||
const start = this.timeData[i - 1];
|
||||
const end = this.timeData[i];
|
||||
const diff = this.time.calculateTimespanInMinutes(start, end);
|
||||
|
||||
if (start.type == 'start-drive' && end.type == 'end-drive') {
|
||||
this.driveTime += diff;
|
||||
}
|
||||
else if (start.type === 'login') {
|
||||
this.workTime += diff;
|
||||
}
|
||||
else {
|
||||
this.pauseTime += diff;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
this.combinedWorkTime = this.workTime + this.driveTime;
|
||||
|
||||
if (this.combinedWorkTime < 360) {
|
||||
|
||||
@@ -8,5 +8,6 @@ import { IonApp, IonRouterOutlet } from '@ionic/angular/standalone';
|
||||
imports: [IonApp, IonRouterOutlet],
|
||||
})
|
||||
export class AppComponent {
|
||||
public static currentDate: any;
|
||||
constructor() {}
|
||||
}
|
||||
|
||||
@@ -45,6 +45,11 @@
|
||||
<ion-input type="number" fill="solid" [placeholder]="settings.pauseAfter9" [(ngModel)]="input.pauseAfter9" />
|
||||
<ion-label slot="end">Minuten</ion-label>
|
||||
</ion-item>
|
||||
<ion-item>
|
||||
<ion-label slot="start">Nicht tracken nach</ion-label>
|
||||
<ion-input type="number" fill="solid" [placeholder]="settings.dontTrackPauseAfter" [(ngModel)]="input.dontTrackPauseAfter" />
|
||||
<ion-label slot="end">Uhr</ion-label>
|
||||
</ion-item>
|
||||
<ion-item-divider/>
|
||||
<ion-item>
|
||||
<ion-label><h1>Überstunden</h1></ion-label>
|
||||
|
||||
@@ -6,3 +6,7 @@ ion-item-divider {
|
||||
ion-item {
|
||||
--border-style: none;
|
||||
}
|
||||
|
||||
ion-label {
|
||||
min-width: 60px;
|
||||
}
|
||||
|
||||
@@ -43,6 +43,7 @@ export class SettingsPage {
|
||||
this.input.pauseAfter9 ??= this.settings.pauseAfter9;
|
||||
this.input.maxOverTime ??= this.settings.maxOverTime;
|
||||
this.input.desiredOverTime ??= this.settings.desiredOverTime;
|
||||
this.input.dontTrackPauseAfter ??= this.settings.dontTrackPauseAfter;
|
||||
|
||||
this.settingsProvider.saveSettings(this.input);
|
||||
|
||||
|
||||
@@ -19,7 +19,7 @@
|
||||
|
||||
<ion-modal [keepContentsMounted]="true">
|
||||
<ng-template>
|
||||
<ion-datetime id="current-datetime" presentation="date" [(ngModel)]="currentDate"></ion-datetime>
|
||||
<ion-datetime id="current-datetime" presentation="date" [(ngModel)]="currentDate" (ngModelChange)="updateCurrentDate()"></ion-datetime>
|
||||
</ng-template>
|
||||
</ion-modal>
|
||||
</ion-item>
|
||||
|
||||
@@ -15,6 +15,7 @@ import {addIcons} from "ionicons";
|
||||
import {add} from "ionicons/icons";
|
||||
import {FormsModule} from "@angular/forms";
|
||||
import {TimeService} from "../../services/time.service";
|
||||
import {AppComponent} from "../app.component";
|
||||
|
||||
@Component({
|
||||
selector: 'app-tab1',
|
||||
@@ -45,6 +46,14 @@ export class TimePage {
|
||||
addIcons({add});
|
||||
}
|
||||
|
||||
ionViewDidEnter() {
|
||||
this.currentDate = AppComponent.currentDate;
|
||||
}
|
||||
|
||||
public updateCurrentDate() {
|
||||
AppComponent.currentDate = this.currentDate;
|
||||
}
|
||||
|
||||
public getEntriesOfToday(): TimeEntry[] {
|
||||
const today = new Date(this.currentDate || Date.now()).toLocaleDateString();
|
||||
this.today = this.data.filter(entry => entry.registeredAt.toLocaleDateString() === today);
|
||||
@@ -186,7 +195,7 @@ export class TimePage {
|
||||
}
|
||||
|
||||
public isToday(): boolean {
|
||||
return new Date(this.currentDate || Date.now()).toLocaleDateString() === new Date(Date.now()).toLocaleDateString();
|
||||
return this.timeService.isToday(this.currentDate);
|
||||
}
|
||||
|
||||
protected readonly open = open;
|
||||
|
||||
Reference in New Issue
Block a user