[Subtask] Added X to remove assigned employee from subtask

This commit is contained in:
Matej Glasnák committed 2023-08-30 17:13:06 +02:00
1 parent 3b8250db8f
commit 622b6ea45b
1 file changed
+88 -77
+88 -77
View File
@@ -10,17 +10,15 @@
<v-card-actions class="d-flex flex-column modal-content"> <v-card-actions class="d-flex flex-column modal-content">
<v-text-field v-model="subtask.project_code" label="Kód projektu" :value="subtask.project_code" @focus="onInputFocus" class="modal-input" variant="solo" disabled></v-text-field> <v-text-field v-model="subtask.project_code" label="Kód projektu" :value="subtask.project_code" @focus="onInputFocus" class="modal-input" variant="solo" disabled></v-text-field>
<v-autocomplete :custom-filter="customFilter" :match-any="true" 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 :custom-filter="customFilter" :match-any="true" 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-text-field v-model="subtask.title" @focus="onInputFocus" class="modal-input" label="Názov subtasku" variant="solo"></v-text-field> <v-text-field v-model="subtask.title" @focus="onInputFocus" class="modal-input" label="Názov subtasku" variant="solo"></v-text-field>
<div class="splitted-inputs"> <div class="splitted-inputs">
<!-- TODO: Bialko validacie --> <!-- TODO: Bialko validacie -->
<Datepicker v-model="subtask.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" <Datepicker v-model="subtask.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$.subtask.deadline.$errors?.length }" :validations="v$.subtask.deadline" />
:class="{ error: v$.subtask.deadline.$errors?.length }" :validations="v$.subtask.deadline" />
<v-text-field class="modal-input right" variant="solo" v-model="subtask._deadline_time" label="Čas" append-inner-icon="mdi-clock-outline" type="time" @focus="onInputFocus" <v-text-field class="modal-input right" variant="solo" v-model="subtask._deadline_time" label="Čas" append-inner-icon="mdi-clock-outline" type="time" @focus="onInputFocus" :class="{ error: v$.subtask._deadline_time.$errors.length }" :hint="v$.subtask._deadline_time.$errors ? errorUtils.parseErrors(v$.subtask._deadline_time.$errors) : null" />
:class="{ error: v$.subtask._deadline_time.$errors.length }" :hint="v$.subtask._deadline_time.$errors ? errorUtils.parseErrors(v$.subtask._deadline_time.$errors) : null" />
</div> </div>
<!-- TODO: Toto tu nema byt ci? --> <!-- TODO: Toto tu nema byt ci? -->
@@ -36,18 +34,24 @@
</div> --> </div> -->
<template v-if="subtask.id"> <template v-if="subtask.id">
<v-autocomplete :custom-filter="customFilter" :match-any="true" v-model="subtask.employee_id" label="Priradený" :items="enrichedEmployees" item-title="_fullName" item-value="id" variant="solo" class="modal-input" :class="{ error: employeeValidations[0]?.employee }" <div class="employee-wrapper" :class="{'hide-arrow': subtask.employee_id}">
@update:model-value="employeeValidations[0] ? employeeValidations[0].employee = false : null" /> <svg v-if="subtask.employee_id" version="1.1" xmlns="http://www.w3.org/2000/svg" width="32" height="32" viewBox="0 0 32 32" class="dp__icon dp__clear_icon dp__input_icons" data-test="clear-icon"
<v-text-field v-model="subtask.duration" class="modal-input" variant="solo" type="number" label="Časový odhad" :class="{ error: employeeValidations[0]?.duration }" append-inner-icon="mdi-clock-outline" @focus="onInputFocus" @click.prevent="subtask.employee_id = null; subtask.employee = null">
@update:model-value="employeeValidations[0] ? employeeValidations[0].duration = false : null" /> <path d="M23.057 7.057l-16 16c-0.52 0.52-0.52 1.365 0 1.885s1.365 0.52 1.885 0l16-16c0.52-0.52 0.52-1.365 0-1.885s-1.365-0.52-1.885 0z"></path>
<path d="M7.057 8.943l16 16c0.52 0.52 1.365 0.52 1.885 0s0.52-1.365 0-1.885l-16-16c-0.52-0.52-1.365-0.52-1.885 0s-0.52 1.365 0 1.885z"></path>
</svg>
<v-autocomplete :custom-filter="customFilter" :match-any="true" v-model="subtask.employee_id" label="Priradený" :items="enrichedEmployees" item-title="_fullName" item-value="id" variant="solo" class="modal-input" :class="{ error: employeeValidations[0]?.employee }" @update:model-value="employeeValidations[0] ? (employeeValidations[0].employee = false) : null" />
</div>
<v-text-field v-model="subtask.duration" class="modal-input" variant="solo" type="number" label="Časový odhad" :class="{ error: employeeValidations[0]?.duration }" append-inner-icon="mdi-clock-outline" @focus="onInputFocus" @update:model-value="employeeValidations[0] ? (employeeValidations[0].duration = false) : null" />
</template> </template>
<template v-else> <template v-else>
<!-- R: Subtask nemoze mat viacero employees ci? Vyhodit -->
<div v-for="(employee, index) in subtask.employees" :key="`employee-${index}`" class="splitted-inputs"> <div v-for="(employee, index) in subtask.employees" :key="`employee-${index}`" class="splitted-inputs">
<v-autocomplete :custom-filter="customFilter" :match-any="true" v-model="employee.id" label="Priradený" :items="enrichedEmployees" item-title="_fullName" item-value="id" variant="solo" class="modal-input left" :class="{ error: employeeValidations[index]?.employee }" <v-autocomplete :custom-filter="customFilter" :match-any="true" v-model="employee.id" label="Priradený" :items="enrichedEmployees" item-title="_fullName" item-value="id" variant="solo" class="modal-input left" :class="{ error: employeeValidations[index]?.employee }" @update:model-value="employeeValidations[index] ? (employeeValidations[index].employee = false) : null" />
@update:model-value="employeeValidations[index] ? employeeValidations[index].employee = false : null" /> <v-text-field v-model="employee.duration" class="modal-input right" variant="solo" type="number" label="Časový odhad" append-inner-icon="mdi-clock-outline" :class="{ error: employeeValidations[index]?.duration }" @focus="onInputFocus" @update:model-value="employeeValidations[index] ? (employeeValidations[index].duration = false) : null" />
<v-text-field v-model="employee.duration" class="modal-input right" variant="solo" type="number" label="Časový odhad" append-inner-icon="mdi-clock-outline" :class="{ error: employeeValidations[index]?.duration }" @focus="onInputFocus"
@update:model-value="employeeValidations[index] ? employeeValidations[index].duration = false : null" />
</div> </div>
</template> </template>
@@ -58,8 +62,8 @@
<Z-files-upload class="mt-15 files" :files="subtask.files" @files-uploaded="filesUploaded" :is-saving="isSaving" /> <Z-files-upload class="mt-15 files" :files="subtask.files" @files-uploaded="filesUploaded" :is-saving="isSaving" />
</v-card-actions> </v-card-actions>
<v-btn class="button primary" v-if="!isSaving" @click="save()">{{ subtask.id ? "UPRAVIŤ" : "VYTVORIŤ" }}</v-btn> <v-btn class="button primary" v-if="!isSaving" @click="save()">{{ subtask.id ? 'UPRAVIŤ' : 'VYTVORIŤ' }}</v-btn>
<v-btn class="button primary disabled" v-else disabled>{{ $t('Ukladám...')}}</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">
@@ -104,26 +108,26 @@
<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 ATaskTimeblocks from '@/plugins/tm@modal/task/_components/_components/a-task-timeblocks.vue' import ATaskTimeblocks from '@/plugins/tm@modal/task/_components/_components/a-task-timeblocks.vue'
import useVuelidate from "@vuelidate/core" import useVuelidate from '@vuelidate/core'
import { required } from "@vuelidate/validators" import { required } from '@vuelidate/validators'
import errorUtils from "@/plugins/lib@auth/_utils/error.utils" import errorUtils from '@/plugins/lib@auth/_utils/error.utils'
import { QuillEditor } from "@vueup/vue-quill" import { QuillEditor } from '@vueup/vue-quill'
import VuetifyFixFocusMixin from "@/plugins/tm@modal/_mixins/vuetify-fix-focus" import VuetifyFixFocusMixin from '@/plugins/tm@modal/_mixins/vuetify-fix-focus'
import SelectsMixin from "../master-task/_mixins/selects.mixin" import SelectsMixin from '../master-task/_mixins/selects.mixin'
import * as FileSaver from "file-saver" import * as FileSaver from 'file-saver'
import tmUtils from "@/plugins/tm@_utils/tm.utils" import tmUtils from '@/plugins/tm@_utils/tm.utils'
import moment from 'moment' import moment from 'moment'
import "@vueup/vue-quill/dist/vue-quill.snow.css" import '@vueup/vue-quill/dist/vue-quill.snow.css'
import AutocompleteMixin from '@/plugins/tm@_mixins/autocomplete.mixin' import AutocompleteMixin from '@/plugins/tm@_mixins/autocomplete.mixin'
import ZTaskReadonlyInfo from "./_components/z-task-readonly-info.vue" import ZTaskReadonlyInfo from './_components/z-task-readonly-info.vue'
import { mapGetters } from "vuex" import { mapGetters } from 'vuex'
import modalMixin from '@/plugins/tm@modal/_mixins/modal.mixin' import modalMixin from '@/plugins/tm@modal/_mixins/modal.mixin'
export default { export default {
emits: ["close", "refresh"], emits: ['close', 'refresh'],
mixins: [VuetifyFixFocusMixin, SelectsMixin, AutocompleteMixin, modalMixin], mixins: [VuetifyFixFocusMixin, SelectsMixin, AutocompleteMixin, modalMixin],
components: { components: {
@@ -151,10 +155,7 @@ export default {
}, },
computed: { computed: {
...mapGetters('tm', [ ...mapGetters('tm', ['mastertasks', 'enrichedEmployees'])
'mastertasks',
'enrichedEmployees'
])
}, },
validations() { validations() {
@@ -169,19 +170,24 @@ export default {
}, },
mounted() { mounted() {
this.$events.on("add-timeblock", (timeblock) => { this.$events.on('add-timeblock', (timeblock) => {
if (!this.subtask?.timeblocks) { this.subtask.timeblocks = [] } if (!this.subtask?.timeblocks) {
if (!this.subtask?.timesheets) { this.subtask.timesheets = [] } this.subtask.timeblocks = []
if (!this.subtask?.is_finished) { this.subtask.is_finished = 0 } }
if (!this.subtask?.timesheets) {
this.subtask.timesheets = []
}
if (!this.subtask?.is_finished) {
this.subtask.is_finished = 0
}
this.subtask.timeblocks.push(timeblock) this.subtask.timeblocks.push(timeblock)
}) })
this.$events.on("on-subtask-edited", (subtask) => { this.$events.on('on-subtask-edited', (subtask) => {
if (subtask?.id == this.subtask?.id) if (subtask?.id == this.subtask?.id) this.subtask = this._enrichTask(subtask)
this.subtask = this._enrichTask(subtask)
// TODO: Remove? riesil som neodstranovanie jedineho zanamu v trvani a odpracovanom case // TODO: Remove? riesil som neodstranovanie jedineho zanamu v trvani a odpracovanom case
this.$forceUpdate() this.$forceUpdate()
}) })
this.$events.on('on-subtask-deleted', (subtask) => { this.$events.on('on-subtask-deleted', (subtask) => {
@@ -190,18 +196,17 @@ export default {
}, },
methods: { methods: {
async showModal({subtask, editMode = false, mastertask = {}}) { async showModal({ subtask, editMode = false, mastertask = {} }) {
this.isSaving = false this.isSaving = false
this.subtask = null this.subtask = null
this.visible = true this.visible = true
this.$nextTick(() => this.v$.$reset()) this.$nextTick(() => this.v$.$reset())
try { try {
if (subtask?.id) { if (subtask?.id) {
const data = await this.$axios.get_auth_data(`v1/subtasks/${subtask.id}`) const data = await this.$axios.get_auth_data(`v1/subtasks/${subtask.id}`)
if (!data.deadline) if (!data.deadline) return (this.subtask = this._enrichTask(data))
return this.subtask = this._enrichTask(data)
const splittedDeadline = data.deadline.split(' ') const splittedDeadline = data.deadline.split(' ')
data.deadline = moment(splittedDeadline[0]) data.deadline = moment(splittedDeadline[0])
@@ -229,7 +234,7 @@ export default {
closeModal() { closeModal() {
this.visible = false this.visible = false
this.$router.replace({name: this.$route.name}) this.$router.replace({ name: this.$route.name })
}, },
async save() { async save() {
@@ -251,19 +256,19 @@ export default {
return timesheet return timesheet
}) })
const { subtask } = await this.$axios.put_auth(`v1/subtasks/${this.subtask.id}`, {...this.subtask, timesheets}) const { subtask } = await this.$axios.put_auth(`v1/subtasks/${this.subtask.id}`, { ...this.subtask, timesheets })
this.$store.commit('tm/update_subtask', subtask) this.$store.commit('tm/update_subtask', subtask)
this.$events.emit("on-subtask-edited", this.subtask) this.$events.emit('on-subtask-edited', this.subtask)
} else { } else {
const { subtasks } = await this.$axios.post_auth(`v1/mastertasks/${this.subtask.master_task_id}/subtasks`, this.subtask) const { subtasks } = await this.$axios.post_auth(`v1/mastertasks/${this.subtask.master_task_id}/subtasks`, this.subtask)
this.subtask.id = subtasks[0].id this.subtask.id = subtasks[0].id
subtasks.forEach(subtask => { subtasks.forEach((subtask) => {
this.$store.commit('tm/update_subtask', subtask) this.$store.commit('tm/update_subtask', subtask)
this.$events.emit("on-subtask-edited", this.subtask) this.$events.emit('on-subtask-edited', this.subtask)
}) })
this.$events.emit("task-created") this.$events.emit('task-created')
} }
this.closeModal() this.closeModal()
@@ -275,12 +280,12 @@ export default {
}, },
openDeleteTaskModal(subtask) { openDeleteTaskModal(subtask) {
this.$events.emit("show-delete-task-modal", { subtask }) this.$events.emit('show-delete-task-modal', { subtask })
}, },
showCompleteTaskModal() { showCompleteTaskModal() {
this.$events.emit('show-complete-task-modal', { subtask: this.subtask }) this.$events.emit('show-complete-task-modal', { subtask: this.subtask })
if(this.subtask.deadline) this.subtask.deadline = tmUtils.formatDateTimeForBackend(this.subtask.deadline) if (this.subtask.deadline) this.subtask.deadline = tmUtils.formatDateTimeForBackend(this.subtask.deadline)
}, },
filesUploaded(files) { filesUploaded(files) {
@@ -307,36 +312,28 @@ export default {
this.employeeValidations = [] this.employeeValidations = []
if (this.subtask.id) { if (this.subtask.id) {
if (this.subtask.employee && this.subtask.duration) if (this.subtask.employee && this.subtask.duration) return
return
this.employeeValidations[0] = {} this.employeeValidations[0] = {}
if (!this.subtask.employee_id) if (!this.subtask.employee_id) this.employeeValidations[0].employee = true
this.employeeValidations[0].employee = true
if (!this.subtask.duration) if (!this.subtask.duration) this.employeeValidations[0].duration = true
this.employeeValidations[0].duration = true
} else { } else {
this.subtask.employees.forEach((employee, index) => { this.subtask.employees.forEach((employee, index) => {
if (index == this.subtask.employees.length - 1 && index > 0) if (index == this.subtask.employees.length - 1 && index > 0) return // Skip the last which is allways empty
return // Skip the last which is allways empty
if (employee.id && employee.duration) if (employee.id && employee.duration) return
return
this.employeeValidations[index] = {} this.employeeValidations[index] = {}
if (!employee.id) if (!employee.id) this.employeeValidations[index].employee = true
this.employeeValidations[index].employee = true
if (!employee.duration) if (!employee.duration) this.employeeValidations[index].duration = true
this.employeeValidations[index].duration = true
}) })
} }
const isError = this.employeeValidations.some((employee) => employee.duration || employee.employee)
const isError = this.employeeValidations.some(employee => employee.duration || employee.employee)
resolve(!isError) resolve(!isError)
}) })
}, },
@@ -356,17 +353,15 @@ export default {
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': { 'subtask.employees': {
handler() { handler() {
if (!this.subtask?.employees) if (!this.subtask?.employees) return
return
const lastEmployee = this.subtask.employees[this.subtask.employees.length - 1] const lastEmployee = this.subtask.employees[this.subtask.employees.length - 1]
if (lastEmployee.id || lastEmployee.duration) if (lastEmployee.id || lastEmployee.duration) this.subtask.employees.push({})
this.subtask.employees.push({})
}, },
deep: true deep: true
}, },
@@ -379,7 +374,7 @@ export default {
editMode() { editMode() {
this.$nextTick(() => { this.$nextTick(() => {
this.$refs["description"]?.setHTML(this.subtask.description || "") this.$refs['description']?.setHTML(this.subtask.description || '')
}) })
} }
} }
@@ -413,6 +408,22 @@ export default {
height: 50px height: 50px
width: 203px width: 203px
.employee-wrapper
position: relative
width: 100%
svg
position: absolute
right: 4px
top: 28px
z-index: 5
opacity: 0.5
&.hide-arrow ::v-deep
.mdi-menu-down,
.mdi-menu-up
display: none
@media screen and (max-width: 522px) @media screen and (max-width: 522px)
.files .files
margin-top: 104px !important margin-top: 104px !important