Skip to content
This repository has been archived by the owner on Feb 5, 2023. It is now read-only.

Rework add hours component #181

Merged
merged 37 commits into from
Aug 23, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
7dac621
Copy time-input from ui-kit repo
tsinevik Jul 26, 2021
1b1d895
Add time constraints check
tsinevik Jul 26, 2021
040442d
Adjust font style
tsinevik Jul 26, 2021
35236b5
Add maxlength to inputs
tsinevik Jul 26, 2021
043f966
Set validators for form
tsinevik Jul 26, 2021
7220649
Update layout
tsinevik Jul 28, 2021
aacdb41
Add rangePicker methods
tsinevik Jul 28, 2021
0f6f8d0
Provide default value for category
tsinevik Jul 28, 2021
98007d8
Hide datepicker at heading
tsinevik Jul 28, 2021
98f4e21
Remove calendar from top of page
tsinevik Jul 28, 2021
504a54e
Polish code
tsinevik Jul 28, 2021
bdb6ebb
Fix alignment at heading
tsinevik Jul 29, 2021
7471e2a
Merge branch 'develop' into improvement/update-add-hours-layout
tsinevik Jul 29, 2021
60f4cf9
Add maxlength indicator and fix logic for task validation
tsinevik Jul 30, 2021
ba0f33f
Update TimeService with LeaveType
tsinevik Jul 30, 2021
e99cf39
Create LeaveTime model
tsinevik Jul 30, 2021
63eabd4
Refactor onSubmit method and limit calendar to current month
tsinevik Jul 30, 2021
2ef3f40
Merge branch 'develop' into improvement/update-add-hours-layout
tsinevik Jul 30, 2021
c312ece
Refactor form type logic
tsinevik Jul 30, 2021
428e26b
Polish code
tsinevik Aug 1, 2021
774b849
Add autocomplete
tsinevik Aug 1, 2021
c18a026
Fix hours alignment
tsinevik Aug 1, 2021
7348f14
Refactor countMaxHours method
tsinevik Aug 2, 2021
e3c5dc1
Merge branch 'develop' into improvement/update-add-hours-layout
tsinevik Aug 2, 2021
eac8230
Refactor add-hours
tsinevik Aug 3, 2021
2ada964
Disable time input for absence form type
tsinevik Aug 3, 2021
b0574a2
Merge branch 'develop' into feature/add-hours-form-field
tsinevik Aug 3, 2021
8e9a297
Update time-input
tsinevik Aug 4, 2021
1a74116
Merge branch 'feature/add-hours-form-field' into improvement/update-a…
tsinevik Aug 4, 2021
e5948bd
Fix form type display
tsinevik Aug 4, 2021
01bbe24
Configure setDisabled and required properties
tsinevik Aug 4, 2021
7c4f30e
Polish code
tsinevik Aug 4, 2021
67f3bca
Merge branch 'develop' into improvement/update-add-hours-layout
tsinevik Aug 15, 2021
506c56c
Rework add hours layout
tsinevik Aug 16, 2021
508d008
Merge branch 'develop' into improvement/update-add-hours-layout
tsinevik Aug 17, 2021
2022e51
Link add hours form with backend
tsinevik Aug 18, 2021
0e03044
Fix default workTimes$ values to current month
tsinevik Aug 22, 2021
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
38 changes: 35 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 23 additions & 0 deletions src/app/core/models/leave-time.model.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { LeaveType } from '@data/api/time-service/models/leave-type';

export interface ILeaveType {
leaveType: LeaveType;
leaveInRussian: string;
}

export class LeaveTimeModel {
private static _leaveTypes: ILeaveType[] = [
{ leaveType: LeaveType.SickLeave, leaveInRussian: 'Больничный' },
{ leaveType: LeaveType.Idle, leaveInRussian: 'Отгул' },
{ leaveType: LeaveType.Training, leaveInRussian: 'Обучение' },
{ leaveType: LeaveType.Vacation, leaveInRussian: 'Отпуск' },
];

public static getLeaveInfoByLeaveType(leaveType: LeaveType) {
return this._leaveTypes.find((leave: ILeaveType) => leave.leaveType === leaveType);
}

public static getAllLeaveTypes(): ILeaveType[] {
return this._leaveTypes.slice();
}
}
20 changes: 11 additions & 9 deletions src/app/core/services/attendance.service.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
//@ts-nocheck
import { Injectable } from '@angular/core';
import { BehaviorSubject } from 'rxjs';
import { Time } from '@angular/common';
Expand All @@ -8,11 +7,11 @@ import { DateService } from './date.service';

@Injectable()
export class AttendanceService {
private readonly _datePeriod = new BehaviorSubject<DatePeriod>(this.dateService.getDefaultDatePeriod(6));
private readonly _datePeriod = new BehaviorSubject<DatePeriod>(this.dateService.getDefaultDatePeriod());

readonly datePeriod$ = this._datePeriod.asObservable();

private readonly _recommendedTime = new BehaviorSubject<Time>(this.getRecommendedTime(this.datePeriod));
private readonly _recommendedTime = new BehaviorSubject<number>(this.getRecommendedTime(this.datePeriod));

readonly recommendedTime$ = this._recommendedTime.asObservable();

Expand All @@ -35,22 +34,25 @@ export class AttendanceService {
return timeString.length === 1 ? '0' + timeString : timeString;
}

public getRecommendedTime(datePeriod: DatePeriod, hoursPerDay: number = 8, rate: number = 1): Time {
public getRecommendedTime(datePeriod: DatePeriod, hoursPerDay: number = 8, skipHolidays = false, rate: number = 1): number {
const daysArray: Date[] = [];

if (datePeriod.endDate && this.dateService.isSameDay(datePeriod.startDate, datePeriod.endDate)) {
return { hours: hoursPerDay * rate, minutes: 0 };
return hoursPerDay * rate;
} else {
const startDate = new Date(datePeriod.startDate);
const endDate = new Date(datePeriod.endDate);
const startDate = new Date(datePeriod.startDate as Date);
const endDate = new Date(datePeriod.endDate as Date);

while (startDate.getDate() !== endDate.getDate()) {
daysArray.push(new Date(startDate));
startDate.setDate(startDate.getDate() + 1);
}
const hours = (daysArray.filter((day: Date) => day.getDay() !== 6 && day.getDay() !== 0).length + 1) * hoursPerDay * rate;

return { hours: hours, minutes: 0 };
if (skipHolidays) {
return (daysArray.filter((day: Date) => day.getDay() !== 6 && day.getDay() !== 0).length + 1) * hoursPerDay * rate;
} else {
return (daysArray.length + 1) * hoursPerDay * rate;
}
}
}
}
17 changes: 10 additions & 7 deletions src/app/core/services/date.service.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
//@ts-nocheck
import { Injectable } from '@angular/core';
import { DatePeriod } from '@data/models/date-period';
import { DayOfWeek } from '@data/models/day-of-week';
Expand All @@ -9,8 +8,8 @@ import { DayOfWeek } from '@data/models/day-of-week';
export class DateService {
constructor() {}

isSameDay(fromDate: Date, toDate: Date): boolean {
return fromDate.getTime() === toDate.getTime();
isSameDay(fromDate: Date | null, toDate: Date | null): boolean {
return fromDate?.getTime() === toDate?.getTime();
}

isSameMonth(fromDate: Date, toDate: Date): boolean {
Expand All @@ -31,10 +30,14 @@ export class DateService {
}
}

getDefaultDatePeriod(daysFromToday: number): DatePeriod {
const today = new Date();
const inWeek = this.addDays(today, daysFromToday);
return { startDate: today, endDate: inWeek };
getDefaultDatePeriod(): DatePeriod {
// const today: Date = new Date();
const startDate: Date = new Date();
const endDate: Date = new Date(startDate.getFullYear(), startDate.getMonth(), startDate.getDate() + 7);

// const today = new Date();
// const inWeek = this.addDays(today, daysFromToday);
return { startDate, endDate };
}

getWeek(dateSelected: Date): DayOfWeek[] {
Expand Down
5 changes: 3 additions & 2 deletions src/app/core/services/time/time.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@ import { EditWorkTimeMonthLimitRequest } from '@data/api/time-service/models/edi
export interface IFindWorkTimesRequest {
userid?: string;
projectid?: string;
starttime?: string;
endtime?: string;
month?: number;
year?: number;
includedayjobs?: boolean;
takeCount?: number;
skipCount?: number;
}
Expand Down
1 change: 1 addition & 0 deletions src/app/core/services/user/user.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@ export class UserService {
includecommunications: true,
includerole: true,
includeimages: true,
includeprojects: true,
};

return this.getUser(params).pipe(tap(this._setUser.bind(this)));
Expand Down
Loading