mirror of
https://bitbucket.org/studiotem/jandl-taskmanager-app.git
synced 2026-10-21 14:29:34 +00:00
279 lines
9.3 KiB
Vue
279 lines
9.3 KiB
Vue
<template>
|
|
<v-dialog v-model="visible" max-width="750" max-height="90%" height="700px">
|
|
<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>{{ 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="subtask.project_code" label="Kód projektu" :value="subtask.project_code" @focus="onInputFocus" class="modal-input" variant="solo" disabled></v-text-field>
|
|
|
|
<v-autocomplete 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.name" @focus="onInputFocus" class="modal-input" label="Názov subtasku" variant="solo" :class="{ error: v$.subtask.name.$errors.length }" :hint="v$.subtask.name.$errors ? errorUtils.parseErrors(v$.subtask.name.$errors) : null"></v-text-field>
|
|
|
|
<template v-if="subtask.id">
|
|
<v-autocomplete v-model="subtask.employee_id" :class="{error: employeeError}" label="Priradený" :items="enrichedEmployees" item-title="_fullName" item-value="id" variant="solo" class="modal-input" clearable />
|
|
</template>
|
|
|
|
<template v-else>
|
|
<v-autocomplete v-for="(employee, index) in [...subtask.employees, null]" v-model="subtask.employees[index]" :key="`employee-${index}`" :class="{error: employeeError}" label="Priradený" :items="enrichedEmployees" item-title="_fullName" item-value="id" variant="solo" class="modal-input" clearable />
|
|
</template>
|
|
|
|
<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="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="subtask.files" @files-uploaded="filesUploaded" />
|
|
</v-card-actions>
|
|
|
|
<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">
|
|
<div>
|
|
<p>{{ subtask._master_task.project_code }}</p>
|
|
<h1>{{ subtask._master_task.name }}</h1>
|
|
</div>
|
|
|
|
<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>{{ 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(subtask)" />
|
|
</div>
|
|
</div>
|
|
|
|
<v-card-actions class="d-flex flex-column modal-content">
|
|
<div class="w-100">
|
|
<Z-task-readonly-info :subtask="subtask" @close-modal="closeModal" @update-subtask="updateSubtask" />
|
|
|
|
<div class="d-flex justify-start align-center mt-8">
|
|
<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>
|
|
</div>
|
|
</v-card-actions>
|
|
</v-card>
|
|
</W-loadable>
|
|
</v-dialog>
|
|
</template>
|
|
|
|
<script>
|
|
import ZFilesUpload from "@/plugins/tm@_components/z-files-upload.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 "@vueup/vue-quill/dist/vue-quill.snow.css"
|
|
import ZAutocomplete from "@/plugins/tm@_components/z-autocomplete.vue"
|
|
|
|
import ZTaskReadonlyInfo from "./_components/z-task-readonly-info.vue"
|
|
import { mapGetters } from "vuex"
|
|
import moment from "moment"
|
|
|
|
export default {
|
|
emits: ["close", "refresh"],
|
|
mixins: [VuetifyFixFocusMixin, SelectsMixin],
|
|
|
|
components: {
|
|
ZTaskReadonlyInfo,
|
|
ZFilesUpload,
|
|
QuillEditor,
|
|
// ZAutocomplete
|
|
},
|
|
|
|
data() {
|
|
return {
|
|
tmUtils,
|
|
editMode: false,
|
|
visible: false,
|
|
subtask: null,
|
|
errorUtils,
|
|
v$: useVuelidate(),
|
|
preventInputFocus: false,
|
|
showDatePicker: false,
|
|
employeeError: false,
|
|
selectedNewDate: []
|
|
}
|
|
},
|
|
|
|
computed: {
|
|
...mapGetters('tm', [
|
|
'mastertasks',
|
|
'enrichedEmployees'
|
|
])
|
|
},
|
|
|
|
validations() {
|
|
return {
|
|
subtask: {
|
|
master_task_id: { required },
|
|
duration: { required },
|
|
name: { required }
|
|
}
|
|
}
|
|
},
|
|
|
|
mounted() {
|
|
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-subtask-deleted', (subtask) => {
|
|
if (subtask?.id == this.subtask?.id) this.closeModal()
|
|
})
|
|
},
|
|
|
|
methods: {
|
|
async showModal({subtask, editMode = false, mastertask = {}}) {
|
|
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}`)
|
|
this.subtask = this._enrichTask(data)
|
|
} else {
|
|
this.subtask = { master_task: mastertask, employees: [], timeblocks: [] }
|
|
}
|
|
|
|
this.editMode = editMode || !this.subtask.id
|
|
} catch (error) {
|
|
this.$toast.error(error)
|
|
}
|
|
},
|
|
|
|
closeModal() {
|
|
this.visible = false
|
|
this.$router.replace({name: this.$route.name})
|
|
},
|
|
|
|
async save() {
|
|
if (!this.subtask.employee_id && !this.subtask.employees.length)
|
|
this.employeeError = true
|
|
|
|
if (!(await this.v$.$validate()))
|
|
return
|
|
|
|
if (!this.subtask.employee_id && !this.subtask.employees.length)
|
|
return
|
|
|
|
this.subtask.description = this.$refs['description'].getHTML()
|
|
|
|
try {
|
|
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.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.subtask)
|
|
this.closeModal()
|
|
} catch (error) {
|
|
this.$toast.error(error)
|
|
}
|
|
},
|
|
|
|
async downloadFile(id) {
|
|
try {
|
|
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)
|
|
}
|
|
},
|
|
|
|
openDeleteTaskModal(subtask) {
|
|
this.$events.emit("show-delete-task-modal", { subtask })
|
|
},
|
|
|
|
showCompleteTaskModal() {
|
|
this.$events.emit('show-complete-task-modal', { subtask: this.subtask })
|
|
},
|
|
|
|
filesUploaded(files) {
|
|
this.subtask.files = files
|
|
},
|
|
|
|
updateSubtask(subtask) {
|
|
console.log('UPDATE SUBTASK: ', subtask.timeblocks[0])
|
|
this.subtask = subtask
|
|
},
|
|
|
|
_enrichTask(subtask) {
|
|
return {
|
|
...subtask,
|
|
_created_by: this.enrichedEmployees.find((employee) => employee.id == subtask.created_by),
|
|
_employee: this.enrichedEmployees.find((employee) => employee.id == subtask.employee_id),
|
|
_master_task: this.mastertasks.find((mastertask) => mastertask.id == subtask.master_task_id)
|
|
}
|
|
}
|
|
},
|
|
|
|
watch: {
|
|
'subtask.employee_id'(value, oldValue) {
|
|
this.employeeError = false
|
|
if (!value || !oldValue) return
|
|
|
|
this.subtask.timeblocks = []
|
|
this.subtask._employee = this.enrichedEmployees.find((employee) => employee.id == this.subtask.employee_id)
|
|
},
|
|
|
|
'subtask.employees'() {
|
|
this.employeeError = false
|
|
},
|
|
|
|
'subtask.master_task_id'(value) {
|
|
if (!value) return
|
|
this.subtask._master_task = this.mastertasks.find((mastertask) => mastertask.id == this.subtask.master_task_id)
|
|
},
|
|
|
|
editMode() {
|
|
this.$nextTick(() => {
|
|
this.$refs["description"]?.setHTML(this.subtask.description || "")
|
|
})
|
|
}
|
|
}
|
|
}
|
|
</script>
|
|
|
|
<style lang="sass" scoped>
|
|
.scrolling
|
|
overflow: hidden !important
|
|
|
|
.border-bottom
|
|
border-bottom: 1px solid rgba(0,0,0,.1)
|
|
|
|
.done-btn
|
|
background: #7f39fb !important
|
|
border-radius: 4px !important
|
|
color: #fff !important
|
|
height: 50px
|
|
width: 203px
|
|
|
|
@media screen and (max-width: 522px)
|
|
.files
|
|
margin-top: 104px !important
|
|
</style>
|