Skip to content
Prev Previous commit
Next Next commit
Implementing time sum feature
  • Loading branch information
sbateca committed Apr 5, 2022
commit e2a27619c89fcfc8af6cb1e0662e978beb480741
Original file line number Diff line number Diff line change
@@ -1,62 +1,58 @@
<div class="row scroll-table mt-5 ml-0">
<table
class="table table-striped mb-0"
datatable
[dtTrigger]="dtTrigger"
[dtOptions]="dtOptions"
*ngIf="(reportDataSource$ | async) as dataSource">
<thead class="thead-blue">
<tr class="d-flex">
<th class="hidden-col">ID</th>
<th class="col md-col">User email</th>
<th class="col sm-col">Date</th>
<th class="col sm-col" title="Duration (hours)">Duration</th>
<th class="col x-sm-col" title="Time in">Time in</th>
<th class="col x-sm-col" title="Time out">Time out</th>
<th class="col md-col">Project</th>
<th class="hidden-col">Project ID</th>
<th class="col md-col">Customer</th>
<th class="hidden-col">Customer ID</th>
<th class="col md-col">Activity</th>
<th class="col lg-col">Ticket</th>
<th class="col lg-col">Description</th>
<th class="col lg-col">Technologies</th>
</tr>
</thead>
<app-loading-bar *ngIf="dataSource.isLoading"></app-loading-bar>
<tbody *ngIf="!dataSource.isLoading">
<tr class="d-flex" *ngFor="let entry of dataSource.data">
<td class="hidden-col">{{ entry.id }}</td>
<td class="col md-col">{{ entry.owner_email }}</td>
<td class="col sm-col">
{{ entry.start_date | date: 'MM/dd/yyyy' }}
</td>
<td class="col sm-col">
{{ entry.end_date | substractDate: entry.start_date }}
</td>
<td class="col x-sm-col">{{ entry.start_date | date: 'HH:mm' }}</td>
<td class="col x-sm-col">{{ entry.end_date | date: 'HH:mm' }}</td>
<td class="col md-col">{{ entry.project_name }}</td>
<td class="hidden-col">{{ entry.project_id }}</td>
<td class="col md-col">{{ entry.customer_name }}</td>
<td class="hidden-col">{{ entry.customer_id }}</td>
<td class="col md-col">{{ entry.activity_name }}</td>
<td class="col lg-col">
<ng-container *ngIf="entry.uri !== null">
<a [class.is-url]="isURL(entry.uri)" (click)="openURLInNewTab(entry.uri)">
<div class="row scroll-table mt-5 ml-0 mb-3">
<table class="table table-striped mb-0" datatable [dtTrigger]="dtTrigger" [dtOptions]="dtOptions" *ngIf="(reportDataSource$ | async) as dataSource">
<thead class="thead-blue">
<tr class="d-flex">
<th class="hidden-col">ID</th>
<th class="col md-col">User email</th>
<th class="col sm-col">Date</th>
<th class="col sm-col" title="Duration (hours)">Duration</th>
<th class="col x-sm-col" title="Time in">Time in</th>
<th class="col x-sm-col" title="Time out">Time out</th>
<th class="col md-col">Project</th>
<th class="hidden-col">Project ID</th>
<th class="col md-col">Customer</th>
<th class="hidden-col">Customer ID</th>
<th class="col md-col">Activity</th>
<th class="col lg-col">Ticket</th>
<th class="col lg-col">Description</th>
<th class="col lg-col">Technologies</th>
</tr>
</thead>
<app-loading-bar *ngIf="dataSource.isLoading"></app-loading-bar>
<tbody *ngIf="!dataSource.isLoading">
<tr class="d-flex" *ngFor="let entry of dataSource.data">
<td class="hidden-col">{{ entry.id }}</td>
<td class="col md-col">{{ entry.owner_email }}</td>
<td class="col sm-col">
{{ entry.start_date | date: 'MM/dd/yyyy' }}
</td>
<td class="col sm-col">
{{ entry.end_date | substractDate: entry.start_date }}
</td>
<td class="col x-sm-col">{{ entry.start_date | date: 'HH:mm' }}</td>
<td class="col x-sm-col">{{ entry.end_date | date: 'HH:mm' }}</td>
<td class="col md-col">{{ entry.project_name }}</td>
<td class="hidden-col">{{ entry.project_id }}</td>
<td class="col md-col">{{ entry.customer_name }}</td>
<td class="hidden-col">{{ entry.customer_id }}</td>
<td class="col md-col">{{ entry.activity_name }}</td>
<td class="col lg-col">
<ng-container *ngIf="entry.uri !== null">
<a [class.is-url]="isURL(entry.uri)" (click)="openURLInNewTab(entry.uri)">
{{ entry.uri }}
</a>
</ng-container>
</td>
<td class="col lg-col">{{ entry.description }}</td>
<td class="col lg-col">
<ng-container *ngIf="entry.technologies.length > 0">
<div *ngFor="let technology of entry.technologies" class="badge bg-secondary text-wrap">
{{ technology }}
</div>
</ng-container>
</td>
</tr>
</tbody>
</table>
</ng-container>
</td>
<td class="col lg-col">{{ entry.description }}</td>
<td class="col lg-col">
<ng-container *ngIf="entry.technologies.length > 0">
<div *ngFor="let technology of entry.technologies" class="badge bg-secondary text-wrap">
{{ technology }}
</div>
</ng-container>
</td>
</tr>
</tbody>
</table>
</div>
<div class="alert alert-dark">Total: {{this.resultSum.hours}} hours, {{this.resultSum.minutes}} minutes, {{this.resultSum.seconds}} seconds</div>
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ export class TimeEntriesTableComponent implements OnInit, OnDestroy, AfterViewIn
isLoading$: Observable<boolean>;
reportDataSource$: Observable<DataSource<Entry>>;
rerenderTableSubscription: Subscription;
resultSum: TotalHours;

constructor(private store: Store<EntryState>) {
this.reportDataSource$ = this.store.pipe(select(getReportDataSource));
Expand Down Expand Up @@ -109,28 +110,17 @@ export class TimeEntriesTableComponent implements OnInit, OnDestroy, AfterViewIn
return column === durationColumnIndex ? moment.duration(dataFormated).asHours().toFixed(2) : dataFormated;
}

sumDates(arrayData: Entry[]): TotalHours{

let totalDaysInHours: number = 0;
let totalHours: number = 0;
let totalMinutes: number = 0;
let totalSeconds: number = 0;
let resultSum: TotalHours;

sumDates(arrayData: Entry[]): TotalHours{
this.resultSum = new TotalHours();
arrayData.forEach(entry =>{
let duration = this.getTimeDifference(moment(entry.end_date),moment(entry.start_date));
totalDaysInHours += duration.days() >= 1 ? duration.days() * 24 : 0;
totalHours += duration.hours();
totalMinutes += duration.minutes();
totalSeconds += duration.seconds();

console.log(resultSum);


this.resultSum.hours = Math.abs( this.resultSum.hours + duration.days() >= 1 ? duration.days() * 24 : 0);
this.resultSum.hours = Math.abs(this.resultSum.hours + duration.hours());
this.resultSum.minutes = Math.abs(this.resultSum.minutes + duration.minutes());
this.resultSum.seconds = Math.abs(this.resultSum.seconds + duration.seconds());
});
return resultSum;
return this.resultSum;
}

getTimeDifference(substractDate: moment.Moment, fromDate: moment.Moment): moment.Duration {
return moment.duration(fromDate.diff(substractDate));
}
Expand Down
14 changes: 10 additions & 4 deletions src/app/modules/reports/models/total-hours-report.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
export interface TotalHours {
totalHours: number;
totalMinutes: number;
totalSeconds: number;
export class TotalHours {
hours?: number;
minutes?: number;
seconds?: number;

constructor() {
this.hours = 0;
this.minutes = 0;
this.seconds = 0;
}
}