Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
fix: TT-653 Add condition when someone is currently working on a task
  • Loading branch information
almeida-erick committed May 10, 2022
commit 047f7b87ac09fb62d037870b012d41ea894a8280
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ describe('Reports Page', () => {

it('Should populate the users with the payload from the action executed', () => {
const actionSubject = TestBed.inject(ActionsSubject) as ActionsSubject;
const usersArray = []
const usersArray = [];
const action = {
type: UserActionTypes.LOAD_USERS_SUCCESS,
payload: usersArray
Expand All @@ -201,10 +201,10 @@ describe('Reports Page', () => {

expect(component.users).toEqual(usersArray);
});

it('The sum of the data dates is equal to {"hours": 3, "minutes":20,"seconds":0}', () => {
let {hours,minutes,seconds}: TotalHours = component.sumDates(timeEntryList);
expect({hours, minutes, seconds}).toEqual({hours:3,minutes:20,seconds:0});
const {hours, minutes, seconds}: TotalHours = component.sumDates(timeEntryList);
expect({hours, minutes, seconds}).toEqual({hours: 3, minutes: 20, seconds: 0});
});

afterEach(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,22 +127,22 @@ 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"));
const arrayDurations = new Array();
arrayData.forEach(entry => {
const start = moment(entry.end_date).diff(moment(entry.start_date));
arrayDurations.push(moment.utc(start).format('HH:mm:ss'));
});
let totalDurations = arrayDurations.slice(1)

const totalDurations = arrayDurations.slice(1)
.reduce((prev, cur) => {
return prev.add(cur);
},
moment.duration(arrayDurations[0]));
let daysInHours = totalDurations.days() * 24;
this.resultSum.hours=totalDurations.hours() + daysInHours;
const daysInHours = totalDurations.days() * 24;
this.resultSum.hours = totalDurations.hours() + daysInHours;
this.resultSum.minutes = totalDurations.minutes();
this.resultSum.seconds = totalDurations.seconds();
return this.resultSum;
Expand Down
5 changes: 3 additions & 2 deletions src/app/modules/reports/models/total-hours-report.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export class TotalHours {

hours: number;
minutes: number;
seconds: number;
Expand All @@ -9,4 +9,5 @@ export class TotalHours {
this.minutes = 0;
this.seconds = 0;
}
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,7 @@ export class DetailsFieldsComponent implements OnChanges, OnInit {

const isStartDateInTheFuture = moment(startDateToSubmit).isAfter(moment());
const isEndDateInTheFuture = moment(endDateToSubmit).isAfter(moment());
const timeEntryIsInTheFuture = isStartDateInTheFuture || isEndDateInTheFuture;
const timeEntryIsInTheFuture = isStartDateInTheFuture || (isEndDateInTheFuture && !this.goingToWorkOnThis);

if (timeEntryIsInTheFuture) {
this.toastrService.error('You cannot start a time-entry in the future');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@ import * as moment from 'moment';

export class ParseDateTimeOffset {

parseDateTimeOffset(date:string, offset): string{
if(date == null || date == undefined || date == '') return 'In progress';
return moment.utc(date).utcOffset(-1*offset).format("HH:mm");
parseDateTimeOffset(date: string, offset): string {
if (date === null || date === undefined || date === '') {
Copy link
Collaborator

@FranLMSP FranLMSP May 10, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm just curious, why not if (!date) here?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I also noticed that offset doesn't have typing, I think it's a number offset: number

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well that code was already here, I just changed the format that was complaining when I tried to do a commit.
The change related to this task is on this file

src/app/modules/shared/components/details-fields/details-fields.component.ts

But what you are suggesting seems logical to me, do you think we need another task to "clean up" the code ?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

these would be small refactors so you can fit them here if you want yeah, if you are going to do so just make sure that it's well tested to not break anything :P

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just add here what the plugin used for checking the code was asking, which is adding blank spaces, or adding brackets in an "if", as you mentioned refactoring the code in this case is small, but could break something, and I feel comfortable doing them in another task IMO :p .

return 'In progress';
}
return moment.utc(date).utcOffset(-1 * offset).format('HH:mm');
}
}