[Refactoring]

This commit is contained in:
Matej Glasnák committed 2023-03-03 10:36:11 +01:00
1 parent 26138f69b3
commit ca1cbd723a
25 files changed
+215 -206

No files matched your search

+59 -58
View File
@@ -1,50 +1,50 @@
<template>
<v-dialog v-model="visible" max-width="750" max-height="90%" height="700px">
<W-loadable :content="task" class="h-100">
<W-loadable :content="subtask" class="h-100">
<v-card v-if="editMode" height="100%" class="d-flex flex-column scrolling">
<div class="d-flex justify-space-between align-center modal-header">
<h1>{{ task.id ? "Upraviť task" : "Vytvoriť task" }}</h1>
<h1>{{ subtask.id ? "Upraviť task" : "Vytvoriť task" }}</h1>
<v-icon @click.stop="closeModal()" icon="mdi-close" size="large"></v-icon>
</div>
<v-card-actions class="d-flex flex-column modal-content">
<v-text-field v-model="task.project_code" label="Kód projektu" :value="task.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>
<Z-autocomplete label="Master task" :options="mastertasks.map((mastertask) => ({ key: mastertask.id, value: mastertask.name }))" :validations="v$.task.master_task.id" :clear-on-submit="false" :value="task?.master_task?.name" :class="{ error: v$.task.master_task.id.$errors.length }" class="modal-input" @option-selected="onMasterTaskSelected" />
<Z-autocomplete label="Master task" :options="mastertasks.map((mastertask) => ({ key: mastertask.id, value: mastertask.name }))" :validations="v$.subtask.master_task.id" :clear-on-submit="false" :value="subtask?.master_task?.name" :class="{ error: v$.subtask.master_task.id.$errors.length }" class="modal-input" @option-selected="onMasterTaskSelected" />
<v-select v-model="task.employee_id" ref="employee-select" @focus="onInputFocus" class="modal-input border-select" label="Priradený" :class="{ error: v$.task.employee_id.$errors.length }" variant="solo" :items="filteredEmployees" item-value="id" item-title="_fullName"></v-select>
<v-select v-model="subtask.employee_id" ref="employee-select" @focus="onInputFocus" class="modal-input border-select" label="Priradený" :class="{ error: v$.subtask.employee_id.$errors.length }" variant="solo" :items="filteredEmployees" item-value="id" item-title="_fullName"></v-select>
<v-text-field v-model="task.duration" @focus="onInputFocus" class="modal-input" variant="solo" type="number" label="Časový odhad" :class="{ error: v$.task.duration.$errors.length }" :hint="v$.task.duration.$errors ? errorUtils.parseErrors(v$.task.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>
<div class="w-100 modal-input">
<QuillEditor ref="description" v-model="task.description" placeholder="Popis" theme="snow" class="rich-text-editor" @input="task.description = $event.srcElement.innerHTML" />
<QuillEditor ref="description" v-model="subtask.description" placeholder="Popis" theme="snow" class="rich-text-editor" @input="subtask.description = $event.srcElement.innerHTML" />
</div>
<Z-files-upload class="mt-15 files" :files="task.files" @files-uploaded="filesUploaded" />
<Z-files-upload class="mt-15 files" :files="subtask.files" @files-uploaded="filesUploaded" />
</v-card-actions>
<v-btn class="button primary" @click="save()">{{ task.id ? "UPRAVIŤ" : "VYTVORIŤ" }}</v-btn>
<v-btn class="button primary" @click="save()">{{ subtask.id ? "UPRAVIŤ" : "VYTVORIŤ" }}</v-btn>
</v-card>
<v-card v-else height="100%" class="d-flex flex-column scrolling">
<div class="d-flex justify-space-between align-center">
<p>{{ task.project_code }}</p>
<p>{{ subtask.project_code }}</p>
<v-icon @click.stop="closeModal()" icon="mdi-close" size="large" class="pb-5"></v-icon>
</div>
<div class="d-flex justify-space-between align-center modal-header border-bottom pb-4">
<h1>{{ task.title }}</h1>
<h1>{{ subtask.title }}</h1>
<div class="d-flex justify-start">
<img 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="openDeleteTaskModal(task)" />
<img class="icon trash" :src="require('@/plugins/app/_img/icons/bin.svg')" alt="trash-icon" @click.stop="openDeleteTaskModal(subtask)" />
</div>
</div>
<v-card-actions class="d-flex flex-column modal-content">
<div class="w-100">
<Z-task-readonly-info :task="task" @close-modal="closeModal" />
<Z-task-readonly-info :subtask="subtask" @close-modal="closeModal" />
<div class="d-flex justify-start align-center mt-8">
<v-btn class="done-btn" v-if="!task.is_finished" @click.stop="showCompleteTaskModal()">Dokončiť</v-btn>
<v-btn class="done-btn" v-if="!subtask.is_finished" @click.stop="showCompleteTaskModal()">Dokončiť</v-btn>
<v-btn class="button secondary" v-else @click.stop="showCompleteTaskModal()">Znovu otvoriť</v-btn>
<v-btn class="button secondary" @click="save()">Uložiť zmeny</v-btn>
</div>
@@ -88,7 +88,7 @@ export default {
tmUtils,
editMode: false,
visible: false,
task: null,
subtask: null,
errorUtils,
v$: useVuelidate(),
preventInputFocus: false,
@@ -105,16 +105,16 @@ export default {
]),
filteredEmployees() {
if (!this.enrichedEmployees || !this.task?.master_task) return []
if (!this.enrichedEmployees || !this.subtask?.master_task) return []
const selectedEmployees = this.task.master_task.employees?.map((employee) => employee.id) || []
const selectedEmployees = this.subtask.master_task.employees?.map((employee) => employee.id) || []
return this.enrichedEmployees.filter((employee) => !selectedEmployees.includes(employee.id))
}
},
validations() {
return {
task: {
subtask: {
master_task: {
id: { required }
},
@@ -125,35 +125,35 @@ export default {
},
mounted() {
this.$events.on("on-subtask-edited", (task) => {
if (task?.id == this.task?.id)
this.task = this._enrichTask(task)
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()
})
this.$events.on('on-task-deleted', (task) => {
if (task?.id == this.task?.id) this.closeModal()
this.$events.on('on-subtask-deleted', (subtask) => {
if (subtask?.id == this.subtask?.id) this.closeModal()
})
},
methods: {
async showModal(task, editMode = false, mastertask = {}) {
this.task = null
async showModal({subtask, editMode = false, mastertask = {}}) {
this.subtask = null
this.visible = true
this.$nextTick(() => this.v$.$reset())
try {
if (task?.id) {
const subtask = await this.$axios.get_auth_data(`v1/subtasks/${task.id}`)
this.task = this._enrichTask(subtask)
if (subtask?.id) {
const data = await this.$axios.get_auth_data(`v1/subtasks/${subtask.id}`)
this.subtask = this._enrichTask(data)
} else {
this.task = { master_task: mastertask, timeblocks: [{start: tmUtils.formatDateTimeForBackend(moment()), end: tmUtils.formatDateTimeForBackend(moment())}] }
this.subtask = { master_task: mastertask, timeblocks: [{start: tmUtils.formatDateTimeForBackend(moment()), end: tmUtils.formatDateTimeForBackend(moment())}] }
this.mastertaskIdSelect = mastertask.id
}
this.editMode = editMode || !this.task.id
this.editMode = editMode || !this.subtask.id
} catch (error) {
this.$toast.error(error)
}
@@ -161,25 +161,26 @@ export default {
closeModal() {
this.visible = false
this.$router.replace({name: this.$route.name})
},
async save() {
if (!(await this.v$.$validate()))
return
this.task.description = this.$refs["description"].getHTML()
this.subtask.description = this.$refs["description"].getHTML()
try {
if (this.task?.id) {
const { subtask } = await this.$axios.put_auth(`v1/subtasks/${this.task.id}`, this.task)
if (this.subtask?.id) {
const { subtask } = await this.$axios.put_auth(`v1/subtasks/${this.subtask.id}`, this.subtask)
this.$store.commit('tm/update_subtask', subtask)
} else {
const { subtask } = await this.$axios.post_auth(`v1/mastertasks/${this.task.master_task.id}/subtasks`, this.task)
this.task.id = subtask.id
const { subtask } = await this.$axios.post_auth(`v1/mastertasks/${this.subtask.master_task.id}/subtasks`, this.subtask)
this.subtask.id = subtask.id
this.$store.commit('tm/update_subtask', subtask)
}
this.$events.emit("on-subtask-edited", this.task)
this.$events.emit("on-subtask-edited", this.subtask)
this.closeModal()
} catch (error) {
this.$toast.error(error)
@@ -188,7 +189,7 @@ export default {
async addNewDate() {
if (this.selectedNewDate) {
this.task.timeblocks.push({
this.subtask.timeblocks.push({
start: this.selectedNewDate[0],
end: this.selectedNewDate[1]
})
@@ -199,7 +200,7 @@ export default {
async downloadFile(id) {
try {
const file = await this.$axios.get_auth_data(`v1/subtasks/${this.task.id}`, { responseType: "arraybuffer" })
const file = await this.$axios.get_auth_data(`v1/subtasks/${this.subtask.id}`, { responseType: "arraybuffer" })
FileSaver.saveAs(file.files[id].path, file.files[id].name)
} catch (error) {
this.$toast.error(error)
@@ -207,55 +208,55 @@ export default {
},
removeDate(index) {
this.task.timeblocks.splice(index, 1)
this.subtask.timeblocks.splice(index, 1)
},
openDeleteTaskModal(task) {
this.$events.emit("show-delete-task-modal", { task })
openDeleteTaskModal(subtask) {
this.$events.emit("show-delete-task-modal", { subtask })
},
showCompleteTaskModal() {
this.$events.emit('show-complete-task-modal', { subtask: this.task })
this.$events.emit('show-complete-task-modal', { subtask: this.subtask })
},
filesUploaded(files) {
this.task.files = files
this.subtask.files = files
},
_enrichTask(task) {
task.master_task = this.mastertasks.find((mastertask) => mastertask.id == task.master_task_id)
task.employee = this.enrichedEmployees.find((employee) => employee.id == task.employee_id)
task._created_by = this.enrichedEmployees.find((employee) => employee.id == task.created_by)
this.mastertaskIdSelect = task.master_task?.id
_enrichTask(subtask) {
subtask.master_task = this.mastertasks.find((mastertask) => mastertask.id == subtask.master_task_id)
subtask.employee = this.enrichedEmployees.find((employee) => employee.id == subtask.employee_id)
subtask._created_by = this.enrichedEmployees.find((employee) => employee.id == subtask.created_by)
this.mastertaskIdSelect = subtask.master_task?.id
return task
return subtask
}
},
watch: {
mastertaskIdSelect(value) {
if (!value || !this.task) return
if (!value || !this.subtask) return
this.task.master_task = this.mastertasks.find((mastertask) => mastertask.id == value)
this.task.project_code = this.task.master_task.project_code
this.subtask.master_task = this.mastertasks.find((mastertask) => mastertask.id == value)
this.subtask.project_code = this.subtask.master_task.project_code
},
"task.employee_id"(value, oldValue) {
"subtask.employee_id"(value, oldValue) {
if (!value) return
if (value && oldValue)
this.task.timeblocks = []
this.subtask.timeblocks = []
this.task.employee = this.enrichedEmployees.find((employee) => employee.id == value)
this.subtask.employee = this.enrichedEmployees.find((employee) => employee.id == value)
},
editMode() {
this.$nextTick(() => {
this.$refs["description"]?.setHTML(this.task.description || "")
this.$refs["description"]?.setHTML(this.subtask.description || "")
const employeeSelect = this.$refs['employee-select']?.$el?.querySelector('.v-select__selection-text')
if (employeeSelect)
employeeSelect.innerHTML = this.task?.employee?._fullName || ''
employeeSelect.innerHTML = this.subtask?.employee?._fullName || ''
})
}
}