[Calendar] Fixed non working hours, added blockers to teams

This commit is contained in:
Matej Glasnák committed 2023-03-24 02:26:59 +01:00
1 parent f3f86261f4
commit 11c73b2b37
8 files changed
+281 -212

No files matched your search

@@ -0,0 +1,162 @@
import { setHours, setMinutes } from 'date-fns'
import moment from 'moment'
import timelineUtils from '@/plugins/tm@dashboard/tasks/_utils/timeline.utils'
export default {
computed: {
calendarData() {
if (!this.subtasks || !this.blockers)
return
return {
unscheduledTime: 333,
tasks: [...this._generateNonWorking(), ...this._generateTasks(), ...this._generateBlockers()]
}
},
splitDays() {
const days = []
this.filter.team.employees.forEach((employee, index) => {
let workingHours = 0
this.calendarData.tasks.forEach(task => {
if (task?.subtask?.employee_id == employee.id)
workingHours += timelineUtils._getDifferenceInHours(task.end, task.start)
})
days.push({
id: index + 1,
name: employee.name,
fullname: `${employee.name} ${employee.surname}`,
initials: employee.name.charAt(0).toUpperCase() + employee.surname.charAt(0).toUpperCase(),
unscheduledTime: workingHours
})
})
return days
},
},
methods: {
_generateNonWorking() {
const nonWorkingHours = []
const date = new Date(this.filter.start)
let earliestStartHour = null
this.calendarConfig.date = date
const { start: dayStart, end: dayEnd } = this._getDayStartEnd()
this.filter.team.employees.forEach((employee, index) => {
if (!earliestStartHour || employee.work_start < earliestStartHour)
earliestStartHour = employee.work_start
nonWorkingHours.push({
title: "Non working hours",
start: dayStart,
end: this._setMinutesToDate(employee.work_start),
split: index + 1,
type: 'non-working-hours',
draggable: false
})
nonWorkingHours.push({
title: "Non working hours",
start: this._setMinutesToDate(employee.work_end),
end: dayEnd,
split: index + 1,
type: 'non-working-hours',
draggable: false
})
})
this.calendarConfig.scrollHour = earliestStartHour - 1
return nonWorkingHours
},
_generateTasks() {
const tasks = []
const calendarDate = moment(this.filter.start).format('DD-MM-YYYY')
this.subtasks.forEach(subtask => {
let split = null
let employee = null
this.filter.team.employees.forEach((e, index) => {
if (e.id == subtask.employee_id) {
split = index + 1
employee = e
}
})
subtask.timeblocks.forEach(timeblock => {
const formattedDate = moment(timeblock.start).format('DD-MM-YYYY')
if (formattedDate == calendarDate) {
tasks.push({
id: subtask.id,
start: new Date(timeblock.start),
end: new Date(timeblock.end),
master_task: subtask.master_task,
name: employee?.name,
surname: employee?.surname,
// date: new Date(timeblock.start),
isWeekend: moment(timeblock.start).day() % 6 == 0,
initials: employee?.name?.charAt(0)?.toUpperCase() + employee?.surname?.charAt(0)?.toUpperCase(),
split: split,
project_code: subtask.project_code,
subtask: subtask,
_timeblock_id: timeblock.id
})
}
})
})
return tasks
},
_generateBlockers() {
const blockers = []
this.blockers.forEach(blocker => {
let split = null
let employee = null
this.filter.team.employees.forEach((e, index) => {
if (e.id == blocker.employee?.id) {
split = index + 1
employee = e
}
})
blockers.push({
blocker,
split,
start: new Date(blocker.start),
end: new Date(blocker.end),
type: 'blocker',
initials: `${employee?.name[0]}${employee?.surname[0]}`,
color: '#B00020',
draggable: false,
isWeekend: moment(blocker.start).day() % 6 == 0,
})
})
return blockers
},
_getDayStartEnd() {
return {
start: this._setMinutesToDate(0),
end: this._setMinutesToDate(1439)
}
},
_setMinutesToDate(minutes, date = new Date(this.filter.start)) {
date.setHours(Math.floor(minutes / 60), minutes % 60, 0, 0)
return date
}
}
}