[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

@@ -42,7 +42,7 @@ export default {
methods: {
openMastertask() {
this.$emit('close-modal')
this.$events.emit('show-master-task-modal', {mastertask: {id: this.id}, editMode: false})
this.$events.emit('show-mastertask-modal', {mastertask: {id: this.id}, editMode: false})
}
}
}
@@ -20,8 +20,8 @@
<p class="task-badge rounded-pill">Pridať záznam</p>
</div>
<template v-if="task.timesheets.length">
<div v-for="timesheet in task.timesheets" :key="timesheet.id" class="d-flex align-center mb-3">
<template v-if="subtask.timesheets.length">
<div v-for="timesheet in subtask.timesheets" :key="timesheet.id" class="d-flex align-center mb-3">
<v-icon @click.stop="deleteTimesheet(timesheet)" class="remove-date cursor-pointer mr-2" icon="mdi-minus" size="medium" />
<div class="d-flex align-center flex-start width-100">
@@ -61,7 +61,7 @@ export default {
required: true
},
task: {
subtask: {
type: Object,
required: true
}
@@ -91,22 +91,22 @@ export default {
if (!await this.v$.$validate())
return
const task = JSON.parse(JSON.stringify(this.task))
const subtask = JSON.parse(JSON.stringify(this.subtask))
task.timesheets.push({
subtask.timesheets.push({
id: null,
employee_id: task.employee_id,
employee_id: subtask.employee_id,
time: typeof this.form.hours == 'string' ? parseInt(this.form.hours) : this.form.hours
})
this._update(task)
this._update(subtask)
},
async deleteTimesheet({ id }) {
const task = JSON.parse(JSON.stringify(this.task))
task.timesheets = task.timesheets.filter(timesheet => timesheet.id != id)
const subtask = JSON.parse(JSON.stringify(this.subtask))
subtask.timesheets = subtask.timesheets.filter(timesheet => timesheet.id != id)
this._update(task)
this._update(subtask)
},
closeModal() {
@@ -118,9 +118,9 @@ export default {
this.$nextTick(() => this.v$.$reset())
},
async _update(task) {
async _update(data) {
try {
const { subtask } = await this.$axios.put_auth(`v1/subtasks/${task.id}`, task)
const { subtask } = await this.$axios.put_auth(`v1/subtasks/${data.id}`, data)
this.closeModal()
this.$events.emit('on-subtask-edited', subtask)
@@ -62,7 +62,7 @@ export default {
required: true
},
task: {
subtask: {
type: Object,
required: true
}
@@ -97,32 +97,32 @@ export default {
if (!await this.v$.$validate())
return
const task = JSON.parse(JSON.stringify(this.task))
const subtask = JSON.parse(JSON.stringify(this.subtask))
const splittedStartsAtTime = this.form.starts_at_time.split(':')
const splittedEndsAtTime = this.form.ends_at_time.split(':')
const start = moment(this.form.date).hours(parseInt(splittedStartsAtTime[0])).minutes(parseInt(splittedStartsAtTime[1])).toISOString()
const end = moment(this.form.date).hours(parseInt(splittedEndsAtTime[0])).minutes(parseInt(splittedEndsAtTime[1])).toISOString()
task.timeblocks.push({
subtask.timeblocks.push({
id: null,
start: tmUtils.formatDateTimeForBackend(start),
end: tmUtils.formatDateTimeForBackend(end)
})
this._update(task)
this._update(subtask)
},
async deleteTimeblock({ id }) {
const task = JSON.parse(JSON.stringify(this.task))
task.timeblocks = task.timeblocks.filter(timeblock => timeblock.id != id)
const subtask = JSON.parse(JSON.stringify(this.subtask))
subtask.timeblocks = subtask.timeblocks.filter(timeblock => timeblock.id != id)
this._update(task)
this._update(subtask)
},
async _update(task) {
async _update(data) {
try {
const { subtask } = await this.$axios.put_auth(`v1/subtasks/${task.id}`, task)
const { subtask } = await this.$axios.put_auth(`v1/subtasks/${data.id}`, data)
this.closeModal()
this.$events.emit('on-subtask-edited', subtask)
@@ -1,14 +1,14 @@
<template>
<A-mastertask-name :name="task.master_task?.name || task.master_task" :id="task.master_task.id" :color="task.master_task.color" @close-modal="$emit('close-modal')" />
<A-mastertask-status :status="task.is_finished" />
<A-task-timeblocks :timeblocks="task.timeblocks" :task="task" />
<Z-created-by :employee-id="task.created_by" />
<A-task-assigned-employee :employee="task.employee" />
<A-task-planned-time :hours="task.duration" />
<A-task-remaining-time :hours="task.duration - task.spent_time" />
<A-task-spent-time :hours="task.spent_time" :task="task" />
<A-task-description :description="task.description" :mastertask-description="task.master_task_description" />
<Z-files :files="task.files" />
<A-mastertask-name :name="subtask.master_task?.name || task.master_task" :id="subtask.master_task.id" :color="subtask.master_task.color" @close-modal="$emit('close-modal')" />
<A-mastertask-status :status="subtask.is_finished" />
<A-task-timeblocks :timeblocks="subtask.timeblocks" :subtask="subtask" />
<Z-created-by :employee-id="subtask.created_by" />
<A-task-assigned-employee :employee="subtask.employee" />
<A-task-planned-time :hours="subtask.duration" />
<A-task-remaining-time :hours="subtask.duration - subtask.spent_time" />
<A-task-spent-time :hours="subtask.spent_time" :subtask="subtask" />
<A-task-description :description="subtask.description" :mastertask-description="subtask.master_task_description" />
<Z-files :files="subtask.files" />
</template>
<script>
@@ -40,7 +40,7 @@ export default {
},
props: {
task: {
subtask: {
type: Object,
required: true
}
@@ -2,7 +2,7 @@
<v-dialog v-model="visible" max-width="750">
<v-card>
<div class="d-flex justify-space-between align-center">
<h1>Ste si istý, že chcete zmazať task z mastertasku <b>{{ task.project_code }}</b>?</h1>
<h1>Ste si istý, že chcete zmazať task z mastertasku <b>{{ subtask.project_code }}</b>?</h1>
<v-icon
@click.stop="closeModal()"
@@ -21,18 +21,18 @@
<script>
export default {
emits: ['on-task-deleted'],
emits: ['on-subtask-deleted'],
data() {
return {
visible: false,
task: null
subtask: null
}
},
methods: {
async showModal(task) {
this.task = task
async showModal({ subtask }) {
this.subtask = subtask
this.visible = true
},
@@ -42,10 +42,10 @@ export default {
async deleteTask() {
try {
await this.$axios.delete_auth(`v1/subtasks/${this.task.id}`)
await this.$axios.delete_auth(`v1/subtasks/${this.subtask.id}`)
this.$store.commit('tm/delete_subtask', this.task)
this.$emit('on-task-deleted', this.task)
this.$store.commit('tm/delete_subtask', this.subtask)
this.$emit('on-subtask-deleted', this.subtask)
this.closeModal()
} catch (error) {
this.$toast.error(error)
@@ -46,6 +46,7 @@ export default {
async showModal({ subtask }) {
this.subtask = subtask
this.visible = true
this.$nextTick(() => this.v$.$reset())
},
async submit() {
+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 || ''
})
}
}