export default { computed: { employeesOptions() { const selectedEmployees = [...this.mastertask.employees].map(employee => employee.id) return this.enrichedEmployees.filter( (employee) => !selectedEmployees.includes(employee.id) ) || [] }, projectsOptions() { // Added to "paginate" projects, because v-autocomplete was unable to handle so many projects at once const projects = this.projects.filter(project => project.code.includes(this.projectCodeSearch)) let filteredProjects = projects?.length ? projects.slice(0, 10) : this.projects.slice(0, 10) if (!this.mastertask?.project_id) return filteredProjects const selectedProject = this.projects.find(project => project.id == this.mastertask?.project_id) filteredProjects = filteredProjects.filter(project => project.id != selectedProject.id) return [...filteredProjects, selectedProject] } }, methods: { // onProjectSelected(id) { // const project = this.projects.find(project => project.id == id) // this.mastertask.project_code = project.code // this.mastertask.project_id = project.id // }, onEmployeeSelected(id) { const employee = this.enrichedEmployees.find(employee => employee.id == id) console.log('add employee', employee) 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) { if (!value) return this.mastertask.team = this.teams.find(team => team.id == value) this.mastertask.employees = this.mastertask.team.employees }, } }