synced day selector + implemented current time difference in analytics
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "WorkTime",
|
"name": "WorkTime",
|
||||||
"version": "0.3.0",
|
"version": "0.3.1",
|
||||||
"author": "Ionic Framework",
|
"author": "Ionic Framework",
|
||||||
"homepage": "https://ionicframework.com/",
|
"homepage": "https://ionicframework.com/",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
|||||||
@@ -19,7 +19,7 @@
|
|||||||
|
|
||||||
<ion-modal [keepContentsMounted]="true">
|
<ion-modal [keepContentsMounted]="true">
|
||||||
<ng-template>
|
<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>
|
</ng-template>
|
||||||
</ion-modal>
|
</ion-modal>
|
||||||
</ion-item>
|
</ion-item>
|
||||||
|
|||||||
@@ -24,6 +24,7 @@ import {briefcase, card, pizza} from "ionicons/icons";
|
|||||||
import {NgIf} from "@angular/common";
|
import {NgIf} from "@angular/common";
|
||||||
import {SettingsService} from "../../services/settings.service";
|
import {SettingsService} from "../../services/settings.service";
|
||||||
import {Settings} from "../../models/settings";
|
import {Settings} from "../../models/settings";
|
||||||
|
import {AppComponent} from "../app.component";
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'app-tab2',
|
selector: 'app-tab2',
|
||||||
@@ -54,6 +55,12 @@ export class AnalysisPage {
|
|||||||
}
|
}
|
||||||
|
|
||||||
ionViewDidEnter() {
|
ionViewDidEnter() {
|
||||||
|
this.currentDate = AppComponent.currentDate;
|
||||||
|
this.updateCurrentData();
|
||||||
|
}
|
||||||
|
|
||||||
|
public updateCurrentDate() {
|
||||||
|
AppComponent.currentDate = this.currentDate;
|
||||||
this.updateCurrentData();
|
this.updateCurrentData();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -65,11 +72,33 @@ export class AnalysisPage {
|
|||||||
this.driveTime = 0;
|
this.driveTime = 0;
|
||||||
this.combinedWorkTime = 0;
|
this.combinedWorkTime = 0;
|
||||||
|
|
||||||
if (this.timeData.length < 2) {
|
if (this.timeData.length == 0) {
|
||||||
this.showEmptyChart();
|
this.showEmptyChart();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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 (lastEntry.type == "login") {
|
||||||
|
this.workTime += 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++) {
|
for (let i = 1; i < this.timeData.length; i++) {
|
||||||
const start = this.timeData[i - 1];
|
const start = this.timeData[i - 1];
|
||||||
const end = this.timeData[i];
|
const end = this.timeData[i];
|
||||||
@@ -85,6 +114,8 @@ export class AnalysisPage {
|
|||||||
this.pauseTime += diff;
|
this.pauseTime += diff;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
this.combinedWorkTime = this.workTime + this.driveTime;
|
this.combinedWorkTime = this.workTime + this.driveTime;
|
||||||
|
|
||||||
if (this.combinedWorkTime < 360) {
|
if (this.combinedWorkTime < 360) {
|
||||||
|
|||||||
@@ -8,5 +8,6 @@ import { IonApp, IonRouterOutlet } from '@ionic/angular/standalone';
|
|||||||
imports: [IonApp, IonRouterOutlet],
|
imports: [IonApp, IonRouterOutlet],
|
||||||
})
|
})
|
||||||
export class AppComponent {
|
export class AppComponent {
|
||||||
|
public static currentDate: any;
|
||||||
constructor() {}
|
constructor() {}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -45,6 +45,11 @@
|
|||||||
<ion-input type="number" fill="solid" [placeholder]="settings.pauseAfter9" [(ngModel)]="input.pauseAfter9" />
|
<ion-input type="number" fill="solid" [placeholder]="settings.pauseAfter9" [(ngModel)]="input.pauseAfter9" />
|
||||||
<ion-label slot="end">Minuten</ion-label>
|
<ion-label slot="end">Minuten</ion-label>
|
||||||
</ion-item>
|
</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-divider/>
|
||||||
<ion-item>
|
<ion-item>
|
||||||
<ion-label><h1>Überstunden</h1></ion-label>
|
<ion-label><h1>Überstunden</h1></ion-label>
|
||||||
|
|||||||
@@ -6,3 +6,7 @@ ion-item-divider {
|
|||||||
ion-item {
|
ion-item {
|
||||||
--border-style: none;
|
--border-style: none;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ion-label {
|
||||||
|
min-width: 60px;
|
||||||
|
}
|
||||||
|
|||||||
@@ -43,6 +43,7 @@ export class SettingsPage {
|
|||||||
this.input.pauseAfter9 ??= this.settings.pauseAfter9;
|
this.input.pauseAfter9 ??= this.settings.pauseAfter9;
|
||||||
this.input.maxOverTime ??= this.settings.maxOverTime;
|
this.input.maxOverTime ??= this.settings.maxOverTime;
|
||||||
this.input.desiredOverTime ??= this.settings.desiredOverTime;
|
this.input.desiredOverTime ??= this.settings.desiredOverTime;
|
||||||
|
this.input.dontTrackPauseAfter ??= this.settings.dontTrackPauseAfter;
|
||||||
|
|
||||||
this.settingsProvider.saveSettings(this.input);
|
this.settingsProvider.saveSettings(this.input);
|
||||||
|
|
||||||
|
|||||||
@@ -19,7 +19,7 @@
|
|||||||
|
|
||||||
<ion-modal [keepContentsMounted]="true">
|
<ion-modal [keepContentsMounted]="true">
|
||||||
<ng-template>
|
<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>
|
</ng-template>
|
||||||
</ion-modal>
|
</ion-modal>
|
||||||
</ion-item>
|
</ion-item>
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ import {addIcons} from "ionicons";
|
|||||||
import {add} from "ionicons/icons";
|
import {add} from "ionicons/icons";
|
||||||
import {FormsModule} from "@angular/forms";
|
import {FormsModule} from "@angular/forms";
|
||||||
import {TimeService} from "../../services/time.service";
|
import {TimeService} from "../../services/time.service";
|
||||||
|
import {AppComponent} from "../app.component";
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'app-tab1',
|
selector: 'app-tab1',
|
||||||
@@ -45,6 +46,14 @@ export class TimePage {
|
|||||||
addIcons({add});
|
addIcons({add});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ionViewDidEnter() {
|
||||||
|
this.currentDate = AppComponent.currentDate;
|
||||||
|
}
|
||||||
|
|
||||||
|
public updateCurrentDate() {
|
||||||
|
AppComponent.currentDate = this.currentDate;
|
||||||
|
}
|
||||||
|
|
||||||
public getEntriesOfToday(): TimeEntry[] {
|
public getEntriesOfToday(): TimeEntry[] {
|
||||||
const today = new Date(this.currentDate || Date.now()).toLocaleDateString();
|
const today = new Date(this.currentDate || Date.now()).toLocaleDateString();
|
||||||
this.today = this.data.filter(entry => entry.registeredAt.toLocaleDateString() === today);
|
this.today = this.data.filter(entry => entry.registeredAt.toLocaleDateString() === today);
|
||||||
@@ -186,7 +195,7 @@ export class TimePage {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public isToday(): boolean {
|
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;
|
protected readonly open = open;
|
||||||
|
|||||||
@@ -4,6 +4,7 @@
|
|||||||
defaultPauseTime?: number;
|
defaultPauseTime?: number;
|
||||||
pauseAfter6?: number;
|
pauseAfter6?: number;
|
||||||
pauseAfter9?: number;
|
pauseAfter9?: number;
|
||||||
|
dontTrackPauseAfter?: number;
|
||||||
maxOverTime?: number;
|
maxOverTime?: number;
|
||||||
desiredOverTime?: number;
|
desiredOverTime?: number;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -27,6 +27,7 @@ export class SettingsService {
|
|||||||
defaultPauseTime: 0,
|
defaultPauseTime: 0,
|
||||||
pauseAfter6: 30,
|
pauseAfter6: 30,
|
||||||
pauseAfter9: 45,
|
pauseAfter9: 45,
|
||||||
|
dontTrackPauseAfter: 14,
|
||||||
maxOverTime: 60,
|
maxOverTime: 60,
|
||||||
desiredOverTime: 30
|
desiredOverTime: 30
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -43,4 +43,8 @@ export class TimeService {
|
|||||||
public saveEntries(entries: TimeEntry[]): void {
|
public saveEntries(entries: TimeEntry[]): void {
|
||||||
localStorage.setItem("time-data", JSON.stringify(entries));
|
localStorage.setItem("time-data", JSON.stringify(entries));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public isToday(currentDate: any): boolean {
|
||||||
|
return new Date(currentDate || Date.now()).toLocaleDateString() === new Date(Date.now()).toLocaleDateString();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user