[Tasks] WIP

This commit is contained in:
Matej Glasnák committed 2023-02-17 16:19:11 +01:00
1 parent e34386b179
commit c69f022423
15 files changed
+335 -307

No files matched your search

@@ -0,0 +1,84 @@
import { setHours, setMinutes, addDays, differenceInCalendarDays } from 'date-fns'
import moment from 'moment'
export default {
generateTimelineTasks(subtasks, date, employee) {
return [
...this.generateTimelineEvents(subtasks, employee, date),
...this.generateTimelineNonWorkingHours(date, employee)
]
},
getUnscheduledTime(subtasks) {
let unscheduledTime = 0
subtasks.forEach(subtask => unscheduledTime += (subtask.duration - subtask.spent_time))
return unscheduledTime
},
isWeekend(date) {
return moment(date).day() % 6 == 0
},
generateTimelineEvents(subtasks, employee, date) {
const events = []
subtasks.forEach(subtask => {
subtask.timeblocks?.forEach((timeblock) => {
events.push(this._composeTimelineEvent(subtask, employee, date, timeblock))
})
})
return events
},
_composeTimelineEvent(subtask, employee, date, timeblock) {
const diffInDays = differenceInCalendarDays(date, new Date(timeblock.start))
return {
id: subtask.id,
start: addDays(new Date(timeblock.start), diffInDays),
end: addDays(new Date(timeblock.end), diffInDays),
master_task: subtask.master_task,
name: employee.name,
surname: employee.surname,
date: new Date(timeblock.start),
isWeekend: this.isWeekend(timeblock.start),
initials: employee.name.charAt(0).toUpperCase() + employee.surname.charAt(0).toUpperCase(),
split: this._getSplitFromDate(date, timeblock.start),
project_code: subtask.project_code,
subtask: subtask,
_timeblock_id: timeblock.id
}
},
generateTimelineNonWorkingHours(date, employee) {
const nonWorkingHours = []
for (let i = 0; i < 7; i++) {
nonWorkingHours.push({
title: "Non working hours",
start: setMinutes(setHours(date, 0), 59),
end: setMinutes(setHours(date, employee.work_start), 0),
nonWorking: true,
split: i + 1,
draggable: false
})
nonWorkingHours.push({
title: "Non working hours",
start: setMinutes(setHours(date, employee.work_end), 0),
end: setMinutes(setHours(date, 23), 59),
nonWorking: true,
split: i + 1,
draggable: false
})
}
return nonWorkingHours
},
_getSplitFromDate(date, start) {
return differenceInCalendarDays(new Date(date), new Date(start)) * (-1) + 1
}
}