diff --git a/time-tracker-ui/src/app/time-card-aggregate-stats/time-card-aggregate-stats.component.html b/time-tracker-ui/src/app/time-card-aggregate-stats/time-card-aggregate-stats.component.html index 8840e78..d8aef47 100644 --- a/time-tracker-ui/src/app/time-card-aggregate-stats/time-card-aggregate-stats.component.html +++ b/time-tracker-ui/src/app/time-card-aggregate-stats/time-card-aggregate-stats.component.html @@ -1,4 +1,8 @@ -

Your aggregate time statistics for {{isoViewDate()}} (click on calendar to change)

-

Hours worked this week: {{weeklyH}}

-

Hours worked this and previous week: {{biWeeklyH}}

-

Hours worked this month: {{monthlyH}}

+

Your aggregate time statistics for {{isoDate(viewDate)}} (click on calendar to change)

+

Hours worked in 7 days: {{sevenDaysH}} ({{isoDate(sevenDaysDates[0])}} to {{isoDate(sevenDaysDates[1])}})

+

Hours worked in 14 days: {{fourteenDaysH}} ({{isoDate(fourteenDaysDates[0])}} to {{isoDate(fourteenDaysDates[1])}})

+

Hours worked in 30 days: {{thirtyDaysH}} ({{isoDate(thirtyDaysDates[0])}} to {{isoDate(thirtyDaysDates[1])}})

+
+

Hours worked this week: {{weeklyH}} ({{isoDate(weeklyDates[0])}} to {{isoDate(weeklyDates[1])}})

+

Hours worked this and previous week: {{biWeeklyH}} ({{isoDate(biWeeklyDates[0])}} to {{isoDate(biWeeklyDates[1])}})

+

Hours worked this month: {{monthlyH}} ({{isoDate(monthlyDates[0])}} to {{isoDate(monthlyDates[1])}})

diff --git a/time-tracker-ui/src/app/time-card-aggregate-stats/time-card-aggregate-stats.component.ts b/time-tracker-ui/src/app/time-card-aggregate-stats/time-card-aggregate-stats.component.ts index 8a68825..a819f56 100644 --- a/time-tracker-ui/src/app/time-card-aggregate-stats/time-card-aggregate-stats.component.ts +++ b/time-tracker-ui/src/app/time-card-aggregate-stats/time-card-aggregate-stats.component.ts @@ -1,6 +1,15 @@ import {Component, Input, OnInit} from '@angular/core'; import {TimeLogUpload} from "../service/timecard-api/time-card-api.service"; -import {endOfISOWeek, endOfMonth, formatISO, parseISO, startOfISOWeek, startOfMonth, subDays} from "date-fns"; +import { + endOfISOWeek, + endOfMonth, + formatISO, + parseISO, + startOfDay, + startOfISOWeek, + startOfMonth, + subDays +} from "date-fns"; import {ManagedTimeLog} from "../service/admin-api/admin-api-service"; @Component({ @@ -24,17 +33,31 @@ export class TimeCardAggregateStatsComponent implements OnInit { this.computeAggregateStats(this.logs, this.viewDate); } + sevenDaysH = 0; + fourteenDaysH = 0; + thirtyDaysH = 0; weeklyH = 0; biWeeklyH = 0; monthlyH = 0; + sevenDaysDates = []; + fourteenDaysDates = []; + thirtyDaysDates = []; + weeklyDates = []; + biWeeklyDates = []; + monthlyDates = []; + constructor() { } ngOnInit(): void { } - isoViewDate() { - return formatISO(this.viewDate, {representation: 'date'}); + isoDate(date: Date) { + if (!date) { + return ''; + } + + return formatISO(date, {representation: 'date'}); } private computeAggregateStats(updates: TimeLogUpload[], date: Date) { @@ -48,9 +71,27 @@ export class TimeCardAggregateStatsComponent implements OnInit { const monthStart = startOfMonth(date); const monthEnd = endOfMonth(date); const cardData = updates.map(it => new CardDuration(parseISO(it.timestamp), it.durationminutes)); - this.weeklyH = +this.round(cardData.filter(it => it.at >= weekStart && it.at <= weekEnd).map(it => it.durationminutes).reduce((a, b) => a + b, 0) / 60.0); - this.biWeeklyH = +this.round(cardData.filter(it => it.at >= biWeekStart && it.at <= weekEnd).map(it => it.durationminutes).reduce((a, b) => a + b, 0) / 60.0); - this.monthlyH = +this.round(cardData.filter(it => it.at >= monthStart && it.at <= monthEnd).map(it => it.durationminutes).reduce((a, b) => a + b, 0) / 60.0); + const sevenDaysStart = subDays(date, 6); + const fourteenDaysStart = subDays(date, 13); + const thirtyDaysStart = subDays(date, 29); + + this.sevenDaysDates = [sevenDaysStart, date]; + this.fourteenDaysDates = [fourteenDaysStart, date]; + this.thirtyDaysDates = [thirtyDaysStart, date]; + this.weeklyDates = [weekStart, weekEnd]; + this.biWeeklyDates = [biWeekStart, weekEnd]; + this.monthlyDates = [monthStart, monthEnd]; + + this.sevenDaysH = this.hoursBetweenDates(cardData, this.sevenDaysDates[0], this.sevenDaysDates[1]); + this.fourteenDaysH = this.hoursBetweenDates(cardData, this.fourteenDaysDates[0], this.fourteenDaysDates[1]); + this.thirtyDaysH = this.hoursBetweenDates(cardData, this.thirtyDaysDates[0], this.thirtyDaysDates[1]); + this.weeklyH = this.hoursBetweenDates(cardData, this.weeklyDates[0], this.weeklyDates[1]); + this.biWeeklyH = this.hoursBetweenDates(cardData, this.biWeeklyDates[0], this.biWeeklyDates[1]); + this.monthlyH = this.hoursBetweenDates(cardData, this.monthlyDates[0], this.monthlyDates[1]); + } + + private hoursBetweenDates(cardData: CardDuration[], start: Date, end: Date) { + return +this.round(cardData.filter(it => startOfDay(it.at) >= startOfDay(start) && startOfDay(it.at) <= startOfDay(end)).map(it => it.durationminutes).reduce((a, b) => a + b, 0) / 60.0); } private twoWeekStart(weekStart: Date) { diff --git a/time-tracker-ui/src/app/time-card-calendar/time-card-calendar.component.ts b/time-tracker-ui/src/app/time-card-calendar/time-card-calendar.component.ts index 177120c..9958370 100644 --- a/time-tracker-ui/src/app/time-card-calendar/time-card-calendar.component.ts +++ b/time-tracker-ui/src/app/time-card-calendar/time-card-calendar.component.ts @@ -128,7 +128,7 @@ export class TimeCardCalendarComponent implements OnInit { private doLoadTimecards() { this.loading = true; - return this.api.listTimeCards(subDays(startOfMonth(this.viewDate), 14), endOfMonth(this.viewDate)).pipe( + return this.api.listTimeCards(subDays(startOfMonth(this.viewDate), 30) /* Required for aggregate - time-card-aggregate-stats*/, endOfMonth(this.viewDate)).pipe( map(it => { this.loading = false; return it; diff --git a/time-tracker-ui/src/app/time-card-report/time-card-report.component.ts b/time-tracker-ui/src/app/time-card-report/time-card-report.component.ts index 70f067d..fa722b2 100644 --- a/time-tracker-ui/src/app/time-card-report/time-card-report.component.ts +++ b/time-tracker-ui/src/app/time-card-report/time-card-report.component.ts @@ -2,7 +2,7 @@ import {ChangeDetectionStrategy, Component, Input, OnInit, ViewEncapsulation} fr import {CalendarEvent, CalendarEventAction, CalendarMonthViewDay, CalendarView} from 'angular-calendar'; import {Subject} from 'rxjs'; -import {endOfMonth, isSameDay, isSameMonth, parseISO, startOfMonth} from 'date-fns'; +import {endOfMonth, isSameDay, isSameMonth, parseISO, startOfMonth, subDays} from 'date-fns'; import {MatDialog} from '@angular/material/dialog'; import {TimeCardEditComponent} from '../time-card-edit/time-card-edit.component'; import {TimeLogUpload} from '../service/timecard-api/time-card-api.service'; @@ -82,8 +82,8 @@ export class TimeCardReportComponent implements OnInit { private loadTimeLogs() { this.loading = true; const resp = this.ALL === this.selectedUserId.value ? - this.api.getManagedTimelogs([this.project.id], startOfMonth(this.viewDate), endOfMonth(this.viewDate)) - : this.api.getManagedTimelogsOfUsers([this.project.id], [+this.selectedUserId.value], startOfMonth(this.viewDate), endOfMonth(this.viewDate)); + this.api.getManagedTimelogs([this.project.id], subDays(startOfMonth(this.viewDate), 30) /* Required for aggregate - time-card-aggregate-stats*/, endOfMonth(this.viewDate)) + : this.api.getManagedTimelogsOfUsers([this.project.id], [+this.selectedUserId.value], subDays(startOfMonth(this.viewDate), 30) /* Required for aggregate - time-card-aggregate-stats*/, endOfMonth(this.viewDate)); resp .subscribe(res => {