[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
+100 -89
+100 -89
View File
@@ -10,44 +10,48 @@
<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-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>
<div class="splitted-inputs">
<!-- 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"
:class="{ error: v$.subtask.deadline.$errors?.length }" :validations="v$.subtask.deadline" />
<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" />
<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" />
<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" />
</div>
<!-- TODO: Toto tu nema byt ci? -->
<!-- <div class="w-full">
<A-task-timeblocks
class="w-full"
:timeblocks="subtask.timeblocks"
:subtask="subtask"
<A-task-timeblocks
class="w-full"
:timeblocks="subtask.timeblocks"
:subtask="subtask"
@update-subtask="$emit('update-subtask')"
@update-unfinished-subtask="subtask = $event"
@delete-timeblock="deleteTimeblock($event)"
/>
</div> -->
<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 }"
@update:model-value="employeeValidations[0] ? employeeValidations[0].employee = false : null" />
<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" />
<div class="employee-wrapper" :class="{'hide-arrow': subtask.employee_id}">
<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"
@click.prevent="subtask.employee_id = null; subtask.employee = 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 v-else>
<!-- R: Subtask nemoze mat viacero employees ci? Vyhodit -->
<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 }"
@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-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" />
<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>
</template>
@@ -58,8 +62,8 @@
<Z-files-upload class="mt-15 files" :files="subtask.files" @files-uploaded="filesUploaded" :is-saving="isSaving" />
</v-card-actions>
<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" 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-card>
<v-card v-else height="100%" class="d-flex flex-column scrolling">
@@ -104,26 +108,26 @@
<script>
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 useVuelidate from "@vuelidate/core"
import { required } from "@vuelidate/validators"
import errorUtils from "@/plugins/lib@auth/_utils/error.utils"
import { QuillEditor } from "@vueup/vue-quill"
import VuetifyFixFocusMixin from "@/plugins/tm@modal/_mixins/vuetify-fix-focus"
import SelectsMixin from "../master-task/_mixins/selects.mixin"
import * as FileSaver from "file-saver"
import tmUtils from "@/plugins/tm@_utils/tm.utils"
import useVuelidate from '@vuelidate/core'
import { required } from '@vuelidate/validators'
import errorUtils from '@/plugins/lib@auth/_utils/error.utils'
import { QuillEditor } from '@vueup/vue-quill'
import VuetifyFixFocusMixin from '@/plugins/tm@modal/_mixins/vuetify-fix-focus'
import SelectsMixin from '../master-task/_mixins/selects.mixin'
import * as FileSaver from 'file-saver'
import tmUtils from '@/plugins/tm@_utils/tm.utils'
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 ZTaskReadonlyInfo from "./_components/z-task-readonly-info.vue"
import { mapGetters } from "vuex"
import ZTaskReadonlyInfo from './_components/z-task-readonly-info.vue'
import { mapGetters } from 'vuex'
import modalMixin from '@/plugins/tm@modal/_mixins/modal.mixin'
export default {
emits: ["close", "refresh"],
emits: ['close', 'refresh'],
mixins: [VuetifyFixFocusMixin, SelectsMixin, AutocompleteMixin, modalMixin],
components: {
@@ -151,10 +155,7 @@ export default {
},
computed: {
...mapGetters('tm', [
'mastertasks',
'enrichedEmployees'
])
...mapGetters('tm', ['mastertasks', 'enrichedEmployees'])
},
validations() {
@@ -169,19 +170,24 @@ export default {
},
mounted() {
this.$events.on("add-timeblock", (timeblock) => {
if (!this.subtask?.timeblocks) { this.subtask.timeblocks = [] }
if (!this.subtask?.timesheets) { this.subtask.timesheets = [] }
if (!this.subtask?.is_finished) { this.subtask.is_finished = 0 }
this.$events.on('add-timeblock', (timeblock) => {
if (!this.subtask?.timeblocks) {
this.subtask.timeblocks = []
}
if (!this.subtask?.timesheets) {
this.subtask.timesheets = []
}
if (!this.subtask?.is_finished) {
this.subtask.is_finished = 0
}
this.subtask.timeblocks.push(timeblock)
})
this.$events.on("on-subtask-edited", (subtask) => {
if (subtask?.id == this.subtask?.id)
this.subtask = this._enrichTask(subtask)
this.$events.on('on-subtask-edited', (subtask) => {
if (subtask?.id == this.subtask?.id) this.subtask = this._enrichTask(subtask)
// TODO: Remove? riesil som neodstranovanie jedineho zanamu v trvani a odpracovanom case
this.$forceUpdate()
// TODO: Remove? riesil som neodstranovanie jedineho zanamu v trvani a odpracovanom case
this.$forceUpdate()
})
this.$events.on('on-subtask-deleted', (subtask) => {
@@ -190,18 +196,17 @@ export default {
},
methods: {
async showModal({subtask, editMode = false, mastertask = {}}) {
this.isSaving = false
this.subtask = null
this.visible = true
async showModal({ subtask, editMode = false, mastertask = {} }) {
this.isSaving = false
this.subtask = null
this.visible = true
this.$nextTick(() => this.v$.$reset())
try {
if (subtask?.id) {
const data = await this.$axios.get_auth_data(`v1/subtasks/${subtask.id}`)
if (!data.deadline)
return this.subtask = this._enrichTask(data)
if (!data.deadline) return (this.subtask = this._enrichTask(data))
const splittedDeadline = data.deadline.split(' ')
data.deadline = moment(splittedDeadline[0])
@@ -229,7 +234,7 @@ export default {
closeModal() {
this.visible = false
this.$router.replace({name: this.$route.name})
this.$router.replace({ name: this.$route.name })
},
async save() {
@@ -251,19 +256,19 @@ export default {
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.$events.emit("on-subtask-edited", this.subtask)
this.$events.emit('on-subtask-edited', this.subtask)
} else {
const { subtasks } = await this.$axios.post_auth(`v1/mastertasks/${this.subtask.master_task_id}/subtasks`, this.subtask)
this.subtask.id = subtasks[0].id
subtasks.forEach(subtask => {
subtasks.forEach((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()
@@ -275,12 +280,12 @@ export default {
},
openDeleteTaskModal(subtask) {
this.$events.emit("show-delete-task-modal", { subtask })
this.$events.emit('show-delete-task-modal', { subtask })
},
showCompleteTaskModal() {
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) {
@@ -307,36 +312,28 @@ export default {
this.employeeValidations = []
if (this.subtask.id) {
if (this.subtask.employee && this.subtask.duration)
return
if (this.subtask.employee && this.subtask.duration) return
this.employeeValidations[0] = {}
if (!this.subtask.employee_id)
this.employeeValidations[0].employee = true
if (!this.subtask.employee_id) this.employeeValidations[0].employee = true
if (!this.subtask.duration)
this.employeeValidations[0].duration = true
if (!this.subtask.duration) this.employeeValidations[0].duration = true
} else {
this.subtask.employees.forEach((employee, index) => {
if (index == this.subtask.employees.length - 1 && index > 0)
return // Skip the last which is allways empty
if (employee.id && employee.duration)
return
if (index == this.subtask.employees.length - 1 && index > 0) return // Skip the last which is allways empty
if (employee.id && employee.duration) return
this.employeeValidations[index] = {}
if (!employee.id)
this.employeeValidations[index].employee = true
if (!employee.duration)
this.employeeValidations[index].duration = true
if (!employee.id) this.employeeValidations[index].employee = true
if (!employee.duration) 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)
})
},
@@ -356,17 +353,15 @@ export default {
if (!value || !oldValue) return
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': {
handler() {
if (!this.subtask?.employees)
return
if (!this.subtask?.employees) return
const lastEmployee = this.subtask.employees[this.subtask.employees.length - 1]
if (lastEmployee.id || lastEmployee.duration)
this.subtask.employees.push({})
if (lastEmployee.id || lastEmployee.duration) this.subtask.employees.push({})
},
deep: true
},
@@ -379,7 +374,7 @@ export default {
editMode() {
this.$nextTick(() => {
this.$refs["description"]?.setHTML(this.subtask.description || "")
this.$refs['description']?.setHTML(this.subtask.description || '')
})
}
}
@@ -413,6 +408,22 @@ export default {
height: 50px
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)
.files
margin-top: 104px !important