-
Notifications
You must be signed in to change notification settings - Fork 1
fix: TTA-29 Selecting multiple time entries and show total of hours o… #896
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
wilc0519
merged 5 commits into
master
from
TTA-29-On-Reports-page-allow-selecting-multiple-time-entries-and-show-total-of-hours-of-selected-entries
Jul 18, 2022
Merged
Changes from 2 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
835d03c
fix: TTA-29 Selecting multiple time entries and show total of hours o…
wilc0519 d6c4865
refactor test TimeEntriesTableComponent
wilc0519 a46002d
Refactor sumHoursEntriesSelected
wilc0519 e49cc43
resolved conflicts
wilc0519 68cdc69
resolved conflicts
wilc0519 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Binary file not shown.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,7 +8,7 @@ import { filter } from 'rxjs/operators'; | |
| import { Entry } from 'src/app/modules/shared/models'; | ||
| import { DataSource } from 'src/app/modules/shared/models/data-source.model'; | ||
| import { EntryState } from '../../../time-clock/store/entry.reducer'; | ||
| import { getReportDataSource } from '../../../time-clock/store/entry.selectors'; | ||
| import { getReportDataSource, getResultSumEntriesSelected } from '../../../time-clock/store/entry.selectors'; | ||
| import { TotalHours } from '../../models/total-hours-report'; | ||
| import { User } from 'src/app/modules/users/models/users'; | ||
| import { LoadUsers, UserActionTypes } from 'src/app/modules/users/store/user.actions'; | ||
|
|
@@ -24,7 +24,9 @@ export class TimeEntriesTableComponent implements OnInit, OnDestroy, AfterViewIn | |
|
|
||
| selectOptionValues = [15, 30, 50, 100, -1]; | ||
| selectOptionNames = [15, 30, 50, 100, 'All']; | ||
| totalTimeSelected: moment.Duration; | ||
| users: User[] = []; | ||
|
|
||
| dtOptions: any = { | ||
| scrollY: '590px', | ||
| dom: '<"d-flex justify-content-between"B<"d-flex"<"mr-5"l>f>>rtip', | ||
|
|
@@ -60,7 +62,7 @@ export class TimeEntriesTableComponent implements OnInit, OnDestroy, AfterViewIn | |
| filename: `time-entries-${formatDate(new Date(), 'MM_dd_yyyy-HH_mm', 'en')}` | ||
| }, | ||
| ], | ||
| columnDefs: [{ type: 'date', targets: 2}], | ||
| columnDefs: [{ type: 'date', targets: 2}, {orderable: false, targets: [0]}], | ||
| order: [[1,'asc'],[2,'desc'],[4,'desc']] | ||
| }; | ||
| dtTrigger: Subject<any> = new Subject(); | ||
|
|
@@ -70,11 +72,17 @@ export class TimeEntriesTableComponent implements OnInit, OnDestroy, AfterViewIn | |
| reportDataSource$: Observable<DataSource<Entry>>; | ||
| rerenderTableSubscription: Subscription; | ||
| resultSum: TotalHours; | ||
| resultSumEntriesSelected: TotalHours; | ||
| resultSumEntriesSelected$:Observable<TotalHours>; | ||
| totalHoursSubscription: Subscription; | ||
| dateTimeOffset: ParseDateTimeOffset; | ||
|
|
||
|
|
||
| constructor(private store: Store<EntryState>, private actionsSubject$: ActionsSubject, private storeUser: Store<User> ) { | ||
| this.reportDataSource$ = this.store.pipe(select(getReportDataSource)); | ||
| this.dateTimeOffset = new ParseDateTimeOffset(); | ||
| this.reportDataSource$ = this.store.pipe(select(getReportDataSource)); | ||
| this.resultSumEntriesSelected$ = this.store.pipe(select(getResultSumEntriesSelected)); | ||
| this.dateTimeOffset = new ParseDateTimeOffset(); | ||
| this.resultSumEntriesSelected = new TotalHours(); | ||
| } | ||
|
|
||
| uploadUsers(): void { | ||
|
|
@@ -88,6 +96,10 @@ export class TimeEntriesTableComponent implements OnInit, OnDestroy, AfterViewIn | |
|
|
||
| ngOnInit(): void { | ||
| this.rerenderTableSubscription = this.reportDataSource$.subscribe((ds) => { | ||
| this.totalHoursSubscription = this.resultSumEntriesSelected$.subscribe((actTotalHours) => { | ||
| this.resultSumEntriesSelected = actTotalHours ; | ||
| this.totalTimeSelected = moment.duration(0); | ||
| }); | ||
| this.sumDates(ds.data); | ||
| this.rerenderDataTable(); | ||
| }); | ||
|
|
@@ -128,15 +140,15 @@ export class TimeEntriesTableComponent implements OnInit, OnDestroy, AfterViewIn | |
| const durationColumnIndex = 3; | ||
| return column === durationColumnIndex ? moment.duration(dataFormated).asHours().toFixed(2) : dataFormated; | ||
| } | ||
|
|
||
| sumDates(arrayData: Entry[]): TotalHours{ | ||
| this.resultSum = new TotalHours(); | ||
| let arrayDurations= new Array(); | ||
| arrayData.forEach(entry =>{ | ||
| let start = moment(entry.end_date).diff(moment(entry.start_date)); | ||
| arrayDurations.push(moment.utc(start).format("HH:mm:ss")); | ||
| }); | ||
|
|
||
| let totalDurations = arrayDurations.slice(1) | ||
| .reduce((prev, cur) => { | ||
| return prev.add(cur); | ||
|
|
@@ -153,5 +165,20 @@ export class TimeEntriesTableComponent implements OnInit, OnDestroy, AfterViewIn | |
| this.selectedUserId.emit(userId); | ||
| } | ||
|
|
||
| sumHoursEntriesSelected(entry: Entry, checked: boolean){ | ||
| this.resultSumEntriesSelected = new TotalHours(); | ||
| const duration = moment.duration(moment(entry.end_date).diff(moment(entry.start_date))); | ||
| if(checked){ | ||
| this.totalTimeSelected = this.totalTimeSelected.add(duration); | ||
| } | ||
| else{ | ||
| this.totalTimeSelected = this.totalTimeSelected.subtract(duration); | ||
| } | ||
| let daysTotalInHours = this.totalTimeSelected.days() * 24; | ||
| this.resultSumEntriesSelected.hours = this.totalTimeSelected.hours() + daysTotalInHours; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. daysTotalInHours is never reassigned, use 'const' instead of 'let'. |
||
| this.resultSumEntriesSelected.minutes = this.totalTimeSelected.minutes(); | ||
| this.resultSumEntriesSelected.seconds = this.totalTimeSelected.seconds(); | ||
| return this.resultSumEntriesSelected; | ||
| } | ||
| } | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can change this code section? , for example:
this.totalTimeSelected = checked ? this.totalTimeSelected.add(duration) : this.totalTimeSelected.subtract(duration);