export default { computed: { employeesOptions() { const selectedEmployees = [...this.masterTask.employees].map(employee => employee.id) const employees = this.employees.filter( (employee) => !selectedEmployees.includes(employee.id) ) || [] return employees.map((employee) => { return { key: employee.id, value: `${employee.name} ${employee.surname}`, } }) } }, methods: { onProjectSelected({ key }) { const project = this.projects.find(project => project.id == key) this.masterTask.project_code = project.code this.masterTask.project_id = project.id }, onMasterTaskSelected({ key }) { const masterTask = this.masterTasks.find(masterTask => masterTask.id == key) this.task.master_task.name = masterTask.name this.task.master_task.id = masterTask.id this.task.project_code = masterTask.project_code }, onEmployeeSelected({ key }) { const employee = this.employees.find(employee => employee.id == key) this.masterTask.employees.push(employee) this.showAddEmployeeInput = false }, onEmployeeDurationChanged() { let totalDuration = 0 this.masterTask.employees = this.masterTask.employees.map(employee => { if (typeof employee.duration == 'string') { totalDuration += parseInt(employee.duration) employee.duration = parseInt(employee.duration) } else if (typeof employee.duration == 'number') { totalDuration += employee.duration } return employee }) this.masterTask.duration = totalDuration } }, watch: { 'masterTask.team_id'(value, oldValue) { if (!value || !oldValue) return this.masterTask.team = this.teams.find(team => team.id == value) this.masterTask.employees = this.masterTask.team.employees } } }