[Subtask] Possible to add multiple employees

This commit is contained in:
Matej Glasnák committed 2023-05-20 14:05:49 +02:00
1 parent 2aec357f76
commit e3373ef513
1 file changed
+23 -3
+23 -3
View File
@@ -12,7 +12,15 @@
<v-autocomplete v-model="subtask.master_task_id" label="Master task" :class="{error: v$.subtask.master_task_id.$errors.length}" :items="mastertasks" item-title="name" item-value="id" variant="solo" class="modal-input" clearable /> <v-autocomplete v-model="subtask.master_task_id" label="Master task" :class="{error: v$.subtask.master_task_id.$errors.length}" :items="mastertasks" item-title="name" item-value="id" variant="solo" class="modal-input" clearable />
<v-autocomplete v-model="subtask.employee_id" label="Priradený" :class="{error: v$.subtask.employee_id.$errors.length}" :items="enrichedEmployees" item-title="_fullName" item-value="id" variant="solo" class="modal-input" clearable /> <v-text-field v-model="subtask.name" @focus="onInputFocus" class="modal-input" label="Názov subtasku" variant="solo" :class="{ error: v$.subtask.name.$errors.length }" :hint="v$.subtask.name.$errors ? errorUtils.parseErrors(v$.subtask.name.$errors) : null"></v-text-field>
<template v-if="subtask.id">
<v-autocomplete v-model="subtask.employee_id" :class="{error: employeeError}" label="Priradený" :items="enrichedEmployees" item-title="_fullName" item-value="id" variant="solo" class="modal-input" clearable />
</template>
<template v-else>
<v-autocomplete v-for="(employee, index) in [...subtask.employees, null]" v-model="subtask.employees[index]" :key="`employee-${index}`" :class="{error: employeeError}" label="Priradený" :items="enrichedEmployees" item-title="_fullName" item-value="id" variant="solo" class="modal-input" clearable />
</template>
<v-text-field v-model="subtask.duration" @focus="onInputFocus" class="modal-input" variant="solo" type="number" label="Časový odhad" :class="{ error: v$.subtask.duration.$errors.length }" :hint="v$.subtask.duration.$errors ? errorUtils.parseErrors(v$.subtask.duration.$errors) : null" append-inner-icon="mdi-clock-outline"></v-text-field> <v-text-field v-model="subtask.duration" @focus="onInputFocus" class="modal-input" variant="solo" type="number" label="Časový odhad" :class="{ error: v$.subtask.duration.$errors.length }" :hint="v$.subtask.duration.$errors ? errorUtils.parseErrors(v$.subtask.duration.$errors) : null" append-inner-icon="mdi-clock-outline"></v-text-field>
@@ -97,6 +105,7 @@ export default {
v$: useVuelidate(), v$: useVuelidate(),
preventInputFocus: false, preventInputFocus: false,
showDatePicker: false, showDatePicker: false,
employeeError: false,
selectedNewDate: [] selectedNewDate: []
} }
}, },
@@ -113,7 +122,7 @@ export default {
subtask: { subtask: {
master_task_id: { required }, master_task_id: { required },
duration: { required }, duration: { required },
employee_id: { required } name: { required }
} }
} }
}, },
@@ -143,7 +152,7 @@ export default {
const data = await this.$axios.get_auth_data(`v1/subtasks/${subtask.id}`) const data = await this.$axios.get_auth_data(`v1/subtasks/${subtask.id}`)
this.subtask = this._enrichTask(data) this.subtask = this._enrichTask(data)
} else { } else {
this.subtask = { master_task: mastertask, timeblocks: [{start: tmUtils.formatDateTimeForBackend(moment()), end: tmUtils.formatDateTimeForBackend(moment())}] } this.subtask = { master_task: mastertask, employees: [], timeblocks: [] }
} }
this.editMode = editMode || !this.subtask.id this.editMode = editMode || !this.subtask.id
@@ -158,9 +167,15 @@ export default {
}, },
async save() { async save() {
if (!this.subtask.employee_id && !this.subtask.employees.length)
this.employeeError = true
if (!(await this.v$.$validate())) if (!(await this.v$.$validate()))
return return
if (!this.subtask.employee_id && !this.subtask.employees.length)
return
this.subtask.description = this.$refs['description'].getHTML() this.subtask.description = this.$refs['description'].getHTML()
try { try {
@@ -213,12 +228,17 @@ export default {
watch: { watch: {
'subtask.employee_id'(value, oldValue) { 'subtask.employee_id'(value, oldValue) {
this.employeeError = false
if (!value || !oldValue) return if (!value || !oldValue) return
this.subtask.timeblocks = [] this.subtask.timeblocks = []
this.subtask._employee = this.enrichedEmployees.find((employee) => employee.id == this.subtask.employee_id) this.subtask._employee = this.enrichedEmployees.find((employee) => employee.id == this.subtask.employee_id)
}, },
'subtask.employees'() {
this.employeeError = false
},
'subtask.master_task_id'(value) { 'subtask.master_task_id'(value) {
if (!value) return if (!value) return
this.subtask._master_task = this.mastertasks.find((mastertask) => mastertask.id == this.subtask.master_task_id) this.subtask._master_task = this.mastertasks.find((mastertask) => mastertask.id == this.subtask.master_task_id)