fix(): fixed master task not editable because of invalid employee duration

This commit is contained in:
Matej Glasnák committed 2025-10-08 20:36:52 +02:00
1 parent f38d45160c
commit 80d0e57351
2 files changed
+450 -176

No files matched your search

@@ -1,78 +1,277 @@
<template> <template>
<v-dialog v-model="visible" max-width="750" max-height="90%" height="700px" persistent> <v-dialog
v-model="visible"
max-width="750"
max-height="90%"
height="700px"
persistent
>
<W-loadable :content="mastertask" class="h-100"> <W-loadable :content="mastertask" class="h-100">
<v-card v-if="editMode" height="100%" class="d-flex flex-column scrolling"> <v-card
v-if="editMode"
height="100%"
class="d-flex flex-column scrolling"
>
<div class="d-flex justify-space-between align-center modal-header"> <div class="d-flex justify-space-between align-center modal-header">
<h1>{{ mastertask?.id ? 'Upraviť master task' : 'Vytvoriť master task' }}</h1> <h1>
<v-icon @click.stop="closeModal()" icon="mdi-close" size="large"></v-icon> {{
mastertask?.id ? 'Upraviť master task' : 'Vytvoriť master task'
}}
</h1>
<v-icon
@click.stop="closeModal()"
icon="mdi-close"
size="large"
></v-icon>
</div> </div>
<v-card-actions class="d-flex flex-column modal-content"> <v-card-actions class="d-flex flex-column modal-content">
<v-autocomplete :custom-filter="customFilter" :match-any="true" v-model="mastertask.project_id" :label="$t('Project code')" :class="{ error: v$.mastertask.project_id.$errors.length }" :items="projectsOptions" item-title="code" item-value="id" variant="solo" class="modal-input" clearable @update:search="projectCodeSearch = $event" /> <v-autocomplete
:custom-filter="customFilter"
:match-any="true"
v-model="mastertask.project_id"
:label="$t('Project code')"
:class="{ error: v$.mastertask.project_id.$errors.length }"
:items="projectsOptions"
item-title="code"
item-value="id"
variant="solo"
class="modal-input"
clearable
@update:search="projectCodeSearch = $event"
/>
<v-text-field v-model="mastertask.name" @focus="onInputFocus" class="modal-input" label="Názov mastertasku" variant="solo" :class="{ error: v$.mastertask.name.$errors.length }" :hint="v$.mastertask.name.$errors ? errorUtils.parseErrors(v$.mastertask.name.$errors) : null"></v-text-field> <v-text-field
v-model="mastertask.name"
@focus="onInputFocus"
class="modal-input"
label="Názov mastertasku"
variant="solo"
:class="{ error: v$.mastertask.name.$errors.length }"
:hint="
v$.mastertask.name.$errors
? errorUtils.parseErrors(v$.mastertask.name.$errors)
: null
"
></v-text-field>
<div class="splitted-inputs"> <div class="splitted-inputs">
<!-- TODO: Bialko validacie --> <!-- TODO: Bialko validacie -->
<Datepicker v-model="mastertask.deadline" :auto-apply="true" @focus="onDateFocus" :min-date="new Date()" class="modal-input left" format="dd.MM.yyyy" locale="sk" select-text="Vybrať" cancel-text="Zrušiť" placeholder="Dátum" :class="{ error: v$.mastertask.deadline.$errors?.length }" :validations="v$.mastertask.deadline" /> <Datepicker
v-model="mastertask.deadline"
:auto-apply="true"
@focus="onDateFocus"
:min-date="new Date()"
class="modal-input left"
format="dd.MM.yyyy"
locale="sk"
select-text="Vybrať"
cancel-text="Zrušiť"
placeholder="Dátum"
:class="{ error: v$.mastertask.deadline.$errors?.length }"
:validations="v$.mastertask.deadline"
/>
<v-text-field class="modal-input right" variant="solo" v-model="mastertask._deadline_time" label="Čas" append-inner-icon="mdi-clock-outline" type="time" @focus="onInputFocus" :class="{ error: v$.mastertask._deadline_time.$errors.length }" :hint="v$.mastertask._deadline_time.$errors ? errorUtils.parseErrors(v$.mastertask._deadline_time.$errors) : null" /> <v-text-field
class="modal-input right"
variant="solo"
v-model="mastertask._deadline_time"
label="Čas"
append-inner-icon="mdi-clock-outline"
type="time"
@focus="onInputFocus"
:class="{ error: v$.mastertask._deadline_time.$errors.length }"
:hint="
v$.mastertask._deadline_time.$errors
? errorUtils.parseErrors(v$.mastertask._deadline_time.$errors)
: null
"
/>
</div> </div>
<v-text-field v-model="mastertask.estimated_duration" @focus="onInputFocus" class="modal-input" variant="solo" type="number" label="Nacenené hodiny" :class="{ error: v$.mastertask.estimated_duration.$errors.length }" :hint="v$.mastertask.estimated_duration.$errors ? errorUtils.parseErrors(v$.mastertask.estimated_duration.$errors) : null"></v-text-field> <v-text-field
v-model="mastertask.estimated_duration"
@focus="onInputFocus"
class="modal-input"
variant="solo"
type="number"
label="Nacenené hodiny"
:class="{ error: v$.mastertask.estimated_duration.$errors.length }"
:hint="
v$.mastertask.estimated_duration.$errors
? errorUtils.parseErrors(
v$.mastertask.estimated_duration.$errors,
)
: null
"
></v-text-field>
<v-text-field v-model="mastertask.duration" @focus="onInputFocus" class="modal-input" variant="solo" type="number" :label="`${mastertask.duration} h`" :disabled="true"></v-text-field> <v-text-field
v-model="mastertask.duration"
@focus="onInputFocus"
class="modal-input"
variant="solo"
type="number"
:label="`${mastertask.duration} h`"
:disabled="true"
></v-text-field>
<v-select v-model="mastertask.team_id" @focus="onInputFocus" class="modal-input border-select" :class="{ error: v$.mastertask.employees.$errors.length }" label="Tím" variant="solo" :items="teams" item-value="id" item-title="name" :disabled="!!mastertask.id" :clearable="true" /> <v-select
v-model="mastertask.team_id"
@focus="onInputFocus"
class="modal-input border-select"
:class="{ error: v$.mastertask.employees.$errors.length }"
label="Tím"
variant="solo"
:items="teams"
item-value="id"
item-title="name"
:disabled="!!mastertask.id"
:clearable="true"
/>
<template v-if="!mastertask.id"> <template v-if="!mastertask.id">
<v-text-field v-for="(employee, index) in mastertask.employees" :key="employee.id" @focus="onInputFocus" class="modal-input" :class="{ error: employee.invalid }" :label="`${employee.name} ${employee.surname}`" variant="solo" placeholder="h" v-model="mastertask.employees[index].duration" type="number" min="1" @input="onEmployeeDurationChanged"> <v-text-field
<p class="employee-select-avatar d-flex justify-center align-center"> v-for="(employee, index) in mastertask.employees"
:key="employee.id"
@focus="onInputFocus"
class="modal-input"
:class="{ error: employee.invalid }"
:label="`${employee.name} ${employee.surname}`"
variant="solo"
placeholder="h"
v-model="mastertask.employees[index].duration"
type="number"
min="1"
@input="onEmployeeDurationChanged"
>
<p
class="employee-select-avatar d-flex justify-center align-center"
>
{{ employee?.name.charAt(0) + employee?.surname.charAt(0) }} {{ employee?.name.charAt(0) + employee?.surname.charAt(0) }}
</p> </p>
<v-icon @click.stop="removeEmployee(employee)" class="remove-input" icon="mdi-close-circle" size="default"></v-icon> <v-icon
@click.stop="removeEmployee(employee)"
class="remove-input"
icon="mdi-close-circle"
size="default"
></v-icon>
</v-text-field> </v-text-field>
</template> </template>
<!-- mastertask._allEmployees is used in edit to combine team employees with extra employees and subtask durations --> <!-- mastertask._allEmployees is used in edit to combine team employees with extra employees and subtask durations -->
<template v-else> <template v-else>
<v-text-field v-for="employee in mastertask._allEmployees" :key="employee.id" class="modal-input" :label="`${employee.name} ${employee.surname}`" variant="solo" placeholder="h" v-model="employee.duration" type="number" :disabled="true"> <v-text-field
<p class="employee-select-avatar d-flex justify-center align-center"> v-for="employee in mastertask._allEmployees"
:key="employee.id"
class="modal-input"
:label="`${employee.name} ${employee.surname}`"
variant="solo"
placeholder="h"
v-model="employee.duration"
type="number"
:disabled="true"
>
<p
class="employee-select-avatar d-flex justify-center align-center"
>
{{ employee?.name.charAt(0) + employee?.surname.charAt(0) }} {{ employee?.name.charAt(0) + employee?.surname.charAt(0) }}
</p> </p>
<v-icon @click.stop="removeEmployee(employee)" class="remove-input" icon="mdi-close-circle" size="default"></v-icon> <v-icon
@click.stop="removeEmployee(employee)"
class="remove-input"
icon="mdi-close-circle"
size="default"
></v-icon>
</v-text-field> </v-text-field>
</template> </template>
<v-autocomplete :custom-filter="customFilter" :match-any="true" v-if="showAddEmployeeInput" :label="$t('Search for employee')" :class="{ error: v$.mastertask.project_id.$errors.length }" :items="employeesOptions" item-title="_fullName" item-value="id" variant="solo" class="modal-input" clearable @update:model-value="onEmployeeSelected" /> <v-autocomplete
:custom-filter="customFilter"
:match-any="true"
v-if="showAddEmployeeInput"
:label="$t('Search for employee')"
:class="{ error: v$.mastertask.project_id.$errors.length }"
:items="employeesOptions"
item-title="_fullName"
item-value="id"
variant="solo"
class="modal-input"
clearable
@update:model-value="onEmployeeSelected"
/>
<!-- <Z-autocomplete label="Vyhľadať zamestnanca" :options="employeesOptions" class="modal-input" @option-selected="onEmployeeSelected" /> --> <!-- <Z-autocomplete label="Vyhľadať zamestnanca" :options="employeesOptions" class="modal-input" @option-selected="onEmployeeSelected" /> -->
<v-btn :disabled="!!mastertask.id" class="w-100 mb-5 button secondary" :class="{ error: v$.mastertask.project_id.$errors.length }" @click="showAddEmployeeInput = true"> <v-icon class="mx-1" icon="mdi-plus" />Pridať zamestnanca </v-btn> <v-btn
:disabled="!!mastertask.id"
class="w-100 mb-5 button secondary"
:class="{ error: v$.mastertask.project_id.$errors.length }"
@click="showAddEmployeeInput = true"
>
<v-icon class="mx-1" icon="mdi-plus" />Pridať zamestnanca
</v-btn>
<div class="w-100 modal-input" :class="{ error: v$.mastertask.description.$errors.length }"> <div
<QuillEditor ref="description" v-model="mastertask.description" placeholder="Popis" theme="snow" class="rich-text-editor" @keyup="onQuillEditorInput" /> class="w-100 modal-input"
:class="{ error: v$.mastertask.description.$errors.length }"
>
<QuillEditor
ref="description"
v-model="mastertask.description"
placeholder="Popis"
theme="snow"
class="rich-text-editor"
@keyup="onQuillEditorInput"
/>
</div> </div>
<Z-files-upload class="mt-15 files" :files="mastertask.files" @files-uploaded="filesUploaded" :is-saving="isSaving" /> <Z-files-upload
class="mt-15 files"
:files="mastertask.files"
@files-uploaded="filesUploaded"
:is-saving="isSaving"
/>
</v-card-actions> </v-card-actions>
<v-btn class="button primary" v-if="!isSaving" @click="save()">{{ mastertask.id ? 'ULOŽIŤ' : 'VYTVORIŤ' }}</v-btn> <v-btn class="button primary" v-if="!isSaving" @click="save()">{{
<v-btn class="button primary disabled" v-else disabled>{{ $t('Ukladám...') }}</v-btn> mastertask.id ? 'ULOŽIŤ' : 'VYTVORIŤ'
}}</v-btn>
<v-btn class="button primary disabled" v-else disabled>{{
$t('Ukladám...')
}}</v-btn>
</v-card> </v-card>
<v-card v-else height="100%" class="d-flex flex-column scrolling"> <v-card v-else height="100%" class="d-flex flex-column scrolling">
<div class="d-flex justify-space-between align-center"> <div class="d-flex justify-space-between align-center">
<p>{{ mastertask.project_code }}</p> <p>{{ mastertask.project_code }}</p>
<v-icon @click.stop="closeModal()" icon="mdi-close" size="large" class="pb-5"></v-icon> <v-icon
@click.stop="closeModal()"
icon="mdi-close"
size="large"
class="pb-5"
></v-icon>
</div> </div>
<div class="d-flex justify-space-between align-center modal-header border-bottom pb-4"> <div
class="d-flex justify-space-between align-center modal-header border-bottom pb-4"
>
<h1>{{ mastertask.name }}</h1> <h1>{{ mastertask.name }}</h1>
<div class="d-flex justify-start"> <div class="d-flex justify-start">
<img v-if="!mastertask.is_finished" class="icon" :src="require('@/plugins/app/_img/icons/pencil.svg')" alt="pencil-icon" @click.stop="editMode = !editMode" /> <img
<img class="icon trash" :src="require('@/plugins/app/_img/icons/bin.svg')" alt="trash-icon" @click.stop="openDeleteMasterTaskModal(mastertask)" /> v-if="!mastertask.is_finished"
class="icon"
:src="require('@/plugins/app/_img/icons/pencil.svg')"
alt="pencil-icon"
@click.stop="editMode = !editMode"
/>
<img
class="icon trash"
:src="require('@/plugins/app/_img/icons/bin.svg')"
alt="trash-icon"
@click.stop="openDeleteMasterTaskModal(mastertask)"
/>
</div> </div>
</div> </div>
@@ -81,13 +280,23 @@
<A-mastertask-description :mastertask="mastertask" /> <A-mastertask-description :mastertask="mastertask" />
<div class="d-flex justify-start align-center mt-8"> <div class="d-flex justify-start align-center mt-8">
<v-btn class="button primary" @click="toggleIsFinished(mastertask)">{{ mastertask.is_finished ? 'Otvoriť mastertask' : 'Ukončiť mastertask' }}</v-btn> <v-btn
class="button primary"
@click="toggleIsFinished(mastertask)"
>{{
mastertask.is_finished
? 'Otvoriť mastertask'
: 'Ukončiť mastertask'
}}</v-btn
>
</div> </div>
<A-tasks-table :subtasks="mastertask.subtasks" /> <A-tasks-table :subtasks="mastertask.subtasks" />
<div class="d-flex align-center"> <div class="d-flex align-center">
<v-btn class="subtask-btn w-100" @click="addTask()"><v-icon class="mx-1" icon="mdi-plus" />Pridať sub task</v-btn> <v-btn class="subtask-btn w-100" @click="addTask()"
><v-icon class="mx-1" icon="mdi-plus" />Pridať sub task</v-btn
>
</div> </div>
</div> </div>
</v-card-actions> </v-card-actions>
@@ -97,25 +306,25 @@
</template> </template>
<script> <script>
import Datepicker from '@vuepic/vue-datepicker' import Datepicker from '@vuepic/vue-datepicker';
import ZFilesUpload from '@/plugins/tm@_components/z-files-upload.vue' import ZFilesUpload from '@/plugins/tm@_components/z-files-upload.vue';
import useVuelidate from '@vuelidate/core' import useVuelidate from '@vuelidate/core';
import { required, minLength } from '@vuelidate/validators' import { required, minLength } from '@vuelidate/validators';
import errorUtils from '@/plugins/lib@auth/_utils/error.utils' import errorUtils from '@/plugins/lib@auth/_utils/error.utils';
// import ZAutocomplete from '@/plugins/tm@_components/z-autocomplete.vue' // import ZAutocomplete from '@/plugins/tm@_components/z-autocomplete.vue'
import VuetifyFixFocusMixin from '@/plugins/tm@modal/_mixins/vuetify-fix-focus' import VuetifyFixFocusMixin from '@/plugins/tm@modal/_mixins/vuetify-fix-focus';
import moment from 'moment' import moment from 'moment';
import { QuillEditor } from '@vueup/vue-quill' import { QuillEditor } from '@vueup/vue-quill';
// import tmUtils from '@/plugins/tm@_utils/tm.utils' // import tmUtils from '@/plugins/tm@_utils/tm.utils'
import modalMixin from '@/plugins/tm@modal/_mixins/modal.mixin' import modalMixin from '@/plugins/tm@modal/_mixins/modal.mixin';
import '@vueup/vue-quill/dist/vue-quill.snow.css' import '@vueup/vue-quill/dist/vue-quill.snow.css';
import SelectsMixin from './_mixins/selects.mixin' import SelectsMixin from './_mixins/selects.mixin';
import ATasksTable from './_components/a-tasks-table.vue' import ATasksTable from './_components/a-tasks-table.vue';
import AMastertaskDescription from './_components/a-mastertask-description.vue' import AMastertaskDescription from './_components/a-mastertask-description.vue';
import { mapGetters } from 'vuex' import { mapGetters } from 'vuex';
import AutocompleteMixin from '@/plugins/tm@_mixins/autocomplete.mixin' import AutocompleteMixin from '@/plugins/tm@_mixins/autocomplete.mixin';
export default { export default {
// MIXINS // MIXINS
@@ -132,7 +341,7 @@ export default {
Datepicker, Datepicker,
ZFilesUpload, ZFilesUpload,
// ZAutocomplete, // ZAutocomplete,
QuillEditor QuillEditor,
}, },
data() { data() {
@@ -146,90 +355,108 @@ export default {
isSaving: false, isSaving: false,
showAddEmployeeInput: false, showAddEmployeeInput: false,
date: null, date: null,
projectCodeSearch: null projectCodeSearch: null,
} };
}, },
computed: { computed: {
...mapGetters('tm', ['teams', 'projects', 'enrichedEmployees']), ...mapGetters('tm', ['teams', 'projects', 'enrichedEmployees']),
enrichedSubtasks() { enrichedSubtasks() {
if (!this.mastertask?.subtasks) return null if (!this.mastertask?.subtasks) return null;
return this.mastertask.subtasks return this.mastertask.subtasks
.map((subtask) => { .map((subtask) => {
const employee = this.enrichedEmployees.find((employee) => employee.id == subtask.employee_id) const employee = this.enrichedEmployees.find(
(employee) => employee.id == subtask.employee_id,
);
return { return {
...subtask, ...subtask,
_initials: employee ? employee.name.charAt(0) + employee.surname.charAt(0) : '?', _initials: employee
_fullName: employee ? `${employee.name} ${employee.surname}` : '' ? employee.name.charAt(0) + employee.surname.charAt(0)
} : '?',
_fullName: employee ? `${employee.name} ${employee.surname}` : '',
};
}) })
.filter((subtask) => subtask !== null) .filter((subtask) => subtask !== null);
} },
}, },
validations() { validations() {
const quillEditorRequired = (value) => { const quillEditorRequired = (value) => {
if (!value || !value.length || !value.replace(/<[^>]*>/g, '').length) return false if (!value || !value.length || !value.replace(/<[^>]*>/g, '').length)
return false;
return true return true;
} };
return { return {
mastertask: { mastertask: {
employees: { required, minLength: minLength(1), $each: { duration: { required } } }, employees: {
required,
minLength: minLength(1),
$each: { duration: { required } },
},
project_id: { required }, project_id: { required },
name: { required }, name: { required },
description: { quillEditorRequired }, description: { quillEditorRequired },
deadline: { required }, deadline: { required },
estimated_duration: { required }, estimated_duration: { required },
_deadline_time: { required } _deadline_time: { required },
} },
} };
}, },
mounted() { mounted() {
this.$events.on('close-both-modals', this.closeBothModals) this.$events.on('close-both-modals', this.closeBothModals);
this.$events.on('master-task:team-member-deleted', ({ teamId, memberId }) => { this.$events.on(
if (this.mastertask.team_id != teamId) return 'master-task:team-member-deleted',
({ teamId, memberId }) => {
if (this.mastertask.team_id != teamId) return;
this.mastertask.employees = this.mastertask.employees.filter((employee) => employee.id != memberId) this.mastertask.employees = this.mastertask.employees.filter(
}), (employee) => employee.id != memberId,
);
},
),
this.$events.on('on-mastertask-deleted', (mastertask) => { this.$events.on('on-mastertask-deleted', (mastertask) => {
if (mastertask?.id == this.mastertask?.id) this.closeModal() if (mastertask?.id == this.mastertask?.id) this.closeModal();
}) });
this.$events.on('on-subtask-deleted', (task) => { this.$events.on('on-subtask-deleted', (task) => {
if (!this.mastertask) return if (!this.mastertask) return;
this.mastertask.subtasks = this.mastertask.subtasks.filter((subtask) => subtask.id != task.id) this.mastertask.subtasks = this.mastertask.subtasks.filter(
}) (subtask) => subtask.id != task.id,
);
});
this.$events.on('on-subtask-edited', (task) => { this.$events.on('on-subtask-edited', (task) => {
if (!this.mastertask?.subtasks) return if (!this.mastertask?.subtasks) return;
if (this.mastertask.subtasks.find((subtask) => subtask.id == task.id)) { if (this.mastertask.subtasks.find((subtask) => subtask.id == task.id)) {
this.mastertask.subtasks = this.mastertask.subtasks.map((t) => (t.id == task.id ? task : t)) this.mastertask.subtasks = this.mastertask.subtasks.map((t) =>
t.id == task.id ? task : t,
);
} else { } else {
this.mastertask.subtasks.push(task) this.mastertask.subtasks.push(task);
} }
}) });
}, },
beforeUnmount() { beforeUnmount() {
this.$events.off('on-mastertask-deleted') this.$events.off('on-mastertask-deleted');
this.$events.off('on-subtask-deleted') this.$events.off('on-subtask-deleted');
this.$events.off('on-subtask-edited') this.$events.off('on-subtask-edited');
this.$events.off('master-task:team-member-deleted') this.$events.off('master-task:team-member-deleted');
this.$events.off('close-both-modals', this.closeBothModals) this.$events.off('close-both-modals', this.closeBothModals);
}, },
methods: { methods: {
closeBothModals() { closeBothModals() {
this.$emit('close') this.$emit('close');
this.visible = false this.visible = false;
}, },
removeEmployee({ id }) { removeEmployee({ id }) {
@@ -240,210 +467,251 @@ export default {
// this.mastertask.team = null // this.mastertask.team = null
// } // }
this.mastertask.employees = this.mastertask.employees.filter((employee) => employee.id != id) this.mastertask.employees = this.mastertask.employees.filter(
(employee) => employee.id != id,
);
}, },
removeMemberAlert(member) { removeMemberAlert(member) {
const team = this.mastertask.team const team = this.mastertask.team;
this.$events.emit('show-delete-team-member-modal', { member, team }) this.$events.emit('show-delete-team-member-modal', { member, team });
}, },
async loadMastertask(id) { async loadMastertask(id) {
try { try {
this.mastertask = await this.$axios.get_auth_data(`v1/mastertasks/${id}`) this.mastertask = await this.$axios.get_auth_data(
`v1/mastertasks/${id}`,
);
// TODO zmazat ked zacne prichadzat project_id a team_id // TODO zmazat ked zacne prichadzat project_id a team_id
const project = this.projects.find((project) => project.code == this.mastertask.project_code) const project = this.projects.find(
this.mastertask.project_id = project?.id || null (project) => project.code == this.mastertask.project_code,
this.mastertask.team_id = this.mastertask.team?.id || null );
this.mastertask.project_id = project?.id || null;
this.mastertask.team_id = this.mastertask.team?.id || null;
this.mastertask._allEmployees = this.mastertask.subtasks this.mastertask._allEmployees = this.mastertask.subtasks
.map(({ employee_id, duration }) => { .map(({ employee_id, duration }) => {
const employee = this.enrichedEmployees.find(({ id }) => id == employee_id) const employee = this.enrichedEmployees.find(
({ id }) => id == employee_id,
);
if (!employee) { if (!employee) {
return null return null;
} }
employee.duration = duration employee.duration = duration;
return employee return employee;
}) })
.filter((employee) => employee !== null) .filter((employee) => employee !== null);
} catch (error) { } catch (error) {
this.$toast.error(error.message || error) this.$toast.error(error.message || error);
} }
}, },
async showModal({ mastertask, editMode = false }) { async showModal({ mastertask, editMode = false }) {
this.isSaving = false this.isSaving = false;
this.editMode = null this.editMode = null;
this.visible = true this.visible = true;
this.mastertask = null this.mastertask = null;
this.$nextTick(() => { this.$nextTick(() => {
this.setFocusEvent() this.setFocusEvent();
this.v$.$reset() this.v$.$reset();
}) });
try { try {
if (mastertask?.id) { if (mastertask?.id) {
await this.loadMastertask(mastertask.id) await this.loadMastertask(mastertask.id);
// this.mastertask.project_code = project.code // this.mastertask.project_code = project.code
} else { } else {
const savedMastertask = localStorage.getItem('mastertaskData') const savedMastertask = localStorage.getItem('mastertaskData');
try { try {
if (savedMastertask) { if (savedMastertask) {
const parsedMastertask = JSON.parse(savedMastertask) const parsedMastertask = JSON.parse(savedMastertask);
this.mastertask = parsedMastertask this.mastertask = parsedMastertask;
// If the parsed result is not an object, reset to default // If the parsed result is not an object, reset to default
if (typeof this.mastertask !== 'object' || this.mastertask === null) { if (
throw new Error('Parsed mastertask is not an object') typeof this.mastertask !== 'object' ||
this.mastertask === null
) {
throw new Error('Parsed mastertask is not an object');
} }
this.$nextTick(() => { this.$nextTick(() => {
this.$refs['description']?.setHTML(this.mastertask.description || '') this.$refs['description']?.setHTML(
}) this.mastertask.description || '',
);
});
} else { } else {
throw new Error('mastertaskData is null or undefined') throw new Error('mastertaskData is null or undefined');
} }
} catch (error) { } catch (error) {
console.error('Error parsing mastertaskData:', error) console.error('Error parsing mastertaskData:', error);
this.mastertask = { employees: [], duration: 0, _deadline_time: '17:00' } this.mastertask = {
employees: [],
duration: 0,
_deadline_time: '17:00',
};
} }
} }
this.editMode = editMode || !this.mastertask.id this.editMode = editMode || !this.mastertask.id;
} catch (error) { } catch (error) {
this.$toast.error(error.message || error) this.$toast.error(error.message || error);
if (process.env.NODE_ENV === 'development') console.log('[z-master-task-modal.vue] Error: ', error) if (process.env.NODE_ENV === 'development')
console.log('[z-master-task-modal.vue] Error: ', error);
} }
}, },
toggleIsFinished() { toggleIsFinished() {
this.$events.emit('show-complete-master-task-modal', { mastertask: this.mastertask }) this.$events.emit('show-complete-master-task-modal', {
mastertask: this.mastertask,
});
}, },
async save() { async save() {
if (this.mastertask.id) { if (this.mastertask.id) {
this.mastertask.employees = this.mastertask.employees.map((employee) => { this.mastertask.employees = this.mastertask.employees.map(
const { duration } = this.mastertask.subtasks.find(({ employee_id }) => employee_id == employee.id) || {} (employee) => {
employee.duration = duration const { duration } =
return employee this.mastertask.subtasks.find(
}) ({ employee_id }) => employee_id == employee.id,
) || {};
employee.duration = duration || 0;
return employee;
},
);
} }
const vuelidateValid = await this.v$.$validate() const vuelidateValid = await this.v$.$validate();
const employeesValid = await this._validateEmployees() const employeesValid = await this._validateEmployees();
if (!vuelidateValid || !employeesValid) return if (!vuelidateValid || !employeesValid) return;
if (this.$refs['description']) this.mastertask.description = this.$refs['description'].getHTML() if (this.$refs['description'])
this.mastertask.description = this.$refs['description'].getHTML();
this._mergeDeadlineTimeDate() this._mergeDeadlineTimeDate();
try { try {
this.isSaving = true this.isSaving = true;
this.mastertask.deadline = moment(this.mastertask.deadline).format('YYYY-MM-DD HH:MM:SS') this.mastertask.deadline = moment(this.mastertask.deadline).format(
if (this.mastertask.id) await this.$axios.patch_auth_form(`v1/mastertasks/${this.mastertask.id}`, this.mastertask) 'YYYY-MM-DD HH:MM:SS',
else await this.$axios.post_auth_data('v1/mastertasks', this.mastertask) );
localStorage.removeItem('mastertaskData') if (this.mastertask.id)
await this.$axios.patch_auth_form(
`v1/mastertasks/${this.mastertask.id}`,
this.mastertask,
);
else
await this.$axios.post_auth_data('v1/mastertasks', this.mastertask);
localStorage.removeItem('mastertaskData');
this.$emit('master-task-edited', this.mastertask) this.$emit('master-task-edited', this.mastertask);
this.closeModal() this.closeModal();
} catch (error) { } catch (error) {
this.$toast.error(this.$parseError(error)) this.$toast.error(this.$parseError(error));
if (process.env.NODE_ENV === 'development') console.log('[z-master-task-modal.vue] Error: ', error) if (process.env.NODE_ENV === 'development')
console.log('[z-master-task-modal.vue] Error: ', error);
} finally { } finally {
this.isSaving = false this.isSaving = false;
} }
}, },
filesUploaded(files) { filesUploaded(files) {
this.mastertask.files = files this.mastertask.files = files;
}, },
closeModal() { closeModal() {
this.visible = false this.visible = false;
}, },
openDeleteMasterTaskModal(mastertask) { openDeleteMasterTaskModal(mastertask) {
this.$events.emit('show-delete-master-task-modal', { mastertask }) this.$events.emit('show-delete-master-task-modal', { mastertask });
}, },
addTask() { addTask() {
this.$events.emit('show-subtask-modal', { this.$events.emit('show-subtask-modal', {
subtask: { subtask: {
master_task_id: this.mastertask.id, master_task_id: this.mastertask.id,
project_code: this.mastertask.project_code project_code: this.mastertask.project_code,
} },
}) });
}, },
onQuillEditorInput() { onQuillEditorInput() {
this.mastertask.description = this.$refs['description'].getHTML() this.mastertask.description = this.$refs['description'].getHTML();
}, },
_mergeDeadlineTimeDate() { _mergeDeadlineTimeDate() {
const date = new Date(this.mastertask.deadline) const date = new Date(this.mastertask.deadline);
console.log('z-master-task-modal', this.subtask) console.log('z-master-task-modal', this.subtask);
const timeParts = this.mastertask._deadline_time.split(':') const timeParts = this.mastertask._deadline_time.split(':');
date.setHours(parseInt(timeParts[0])) date.setHours(parseInt(timeParts[0]));
date.setMinutes(parseInt(timeParts[1])) date.setMinutes(parseInt(timeParts[1]));
this.mastertask.deadline = date this.mastertask.deadline = date;
}, },
_validateEmployees() { _validateEmployees() {
let isValid = true let isValid = true;
this.mastertask.employees = this.mastertask.employees.map((employee) => { this.mastertask.employees = this.mastertask.employees.map((employee) => {
if (!employee.duration) { if (employee.duration === null || employee.duration === undefined) {
employee.invalid = true employee.invalid = true;
isValid = false isValid = false;
} }
return employee return employee;
}) });
return isValid return isValid;
} },
}, },
watch: { watch: {
editMode() { editMode() {
this.$nextTick(() => { this.$nextTick(() => {
this.$refs['description']?.setHTML(this.mastertask.description || '') this.$refs['description']?.setHTML(this.mastertask.description || '');
if (!this.mastertask?.id) return if (!this.mastertask?.id) return;
const date = new Date(this.mastertask.deadline) const date = new Date(this.mastertask.deadline);
const hours = date.getHours() const hours = date.getHours();
const minutes = date.getMinutes() const minutes = date.getMinutes();
this.mastertask._deadline_time = `${hours.toString().padStart(2, '0')}:${minutes.toString().padStart(2, '0')}` this.mastertask._deadline_time = `${hours
}) .toString()
.padStart(2, '0')}:${minutes.toString().padStart(2, '0')}`;
});
}, },
mastertask: { mastertask: {
handler(val) { handler(val) {
if (this.editMode && !this.mastertask?.id) { if (this.editMode && !this.mastertask?.id) {
localStorage.setItem('mastertaskData', JSON.stringify(val)) localStorage.setItem('mastertaskData', JSON.stringify(val));
} }
}, },
deep: true deep: true,
}, },
'mastertask.team_id': { 'mastertask.team_id': {
handler(value, oldValue) { handler(value, oldValue) {
if (this.editMode && !value && oldValue) { if (this.editMode && !value && oldValue) {
// Removes only employees from the old team when team_id is removed // Removes only employees from the old team when team_id is removed
const oldTeamEmployeesIds = this.teams.find((team) => team.id == oldValue)?.employees.map((employee) => employee?.id) || [] const oldTeamEmployeesIds =
const employeesNotInOldTeam = this.mastertask.employees.filter((employee) => !oldTeamEmployeesIds.includes(employee?.id)) this.teams
this.mastertask.employees = employeesNotInOldTeam .find((team) => team.id == oldValue)
?.employees.map((employee) => employee?.id) || [];
const employeesNotInOldTeam = this.mastertask.employees.filter(
(employee) => !oldTeamEmployeesIds.includes(employee?.id),
);
this.mastertask.employees = employeesNotInOldTeam;
} }
}, },
deep: true deep: true,
}, },
'$route.query': { '$route.query': {
handler(_, oldValue) { handler(_, oldValue) {
@@ -453,8 +721,8 @@ export default {
}, },
deep: true, deep: true,
}, },
} },
} };
</script> </script>
<style lang="sass" scoped> <style lang="sass" scoped>
@@ -38,8 +38,8 @@
v-model="subtask.master_task_id" v-model="subtask.master_task_id"
label="Master task" label="Master task"
:class="{ error: v$.subtask.master_task_id.$errors.length }" :class="{ error: v$.subtask.master_task_id.$errors.length }"
:items="mastertasks" :items="enrichedMastertasks"
:item-title="(item) => item.name + ' [' + item.project_code + ']'" :item-title="(item) => item._fullName || item.name"
item-value="id" item-value="id"
variant="solo" variant="solo"
class="modal-input" class="modal-input"
@@ -453,6 +453,12 @@ export default {
computed: { computed: {
...mapGetters('tm', ['mastertasks', 'enrichedEmployees']), ...mapGetters('tm', ['mastertasks', 'enrichedEmployees']),
enrichedMastertasks() {
return this.mastertasks.map((mastertask) => ({
...mastertask,
_fullName: `${mastertask.name} [${mastertask.project_code}]`,
}));
},
}, },
validations() { validations() {