synced day selector + implemented current time difference in analytics

This commit is contained in:
2024-11-08 16:00:38 +01:00
parent d957ce6a1d
commit 6271cdd99d
12 changed files with 72 additions and 15 deletions

View File

@@ -1,6 +1,6 @@
{
"name": "WorkTime",
"version": "0.3.0",
"version": "0.3.1",
"author": "Ionic Framework",
"homepage": "https://ionicframework.com/",
"scripts": {

View File

@@ -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>

View File

@@ -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) {

View File

@@ -8,5 +8,6 @@ import { IonApp, IonRouterOutlet } from '@ionic/angular/standalone';
imports: [IonApp, IonRouterOutlet],
})
export class AppComponent {
public static currentDate: any;
constructor() {}
}

View File

@@ -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>

View File

@@ -6,3 +6,7 @@ ion-item-divider {
ion-item {
--border-style: none;
}
ion-label {
min-width: 60px;
}

View File

@@ -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);

View File

@@ -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>

View File

@@ -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;

View File

@@ -4,6 +4,7 @@
defaultPauseTime?: number;
pauseAfter6?: number;
pauseAfter9?: number;
dontTrackPauseAfter?: number;
maxOverTime?: number;
desiredOverTime?: number;
}

View File

@@ -27,6 +27,7 @@ export class SettingsService {
defaultPauseTime: 0,
pauseAfter6: 30,
pauseAfter9: 45,
dontTrackPauseAfter: 14,
maxOverTime: 60,
desiredOverTime: 30
};

View File

@@ -43,4 +43,8 @@ export class TimeService {
public saveEntries(entries: TimeEntry[]): void {
localStorage.setItem("time-data", JSON.stringify(entries));
}
public isToday(currentDate: any): boolean {
return new Date(currentDate || Date.now()).toLocaleDateString() === new Date(Date.now()).toLocaleDateString();
}
}