Files
jandl-taskmanager-app/app/src/plugins/tm@modal/task/z-task-modal.vue
T

555 lines
15 KiB
Vue

<template>
<v-dialog v-model="visible" max-width="650" max-height="90%" height="700px">
<W-loadable :content="task" 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>
<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"
@focus="onInputFocus"
class="modal-input"
label="Kód projektu"
variant="solo"
disabled
></v-text-field>
<!-- Toto treba fixnut -->
<v-select
v-model="masterTaskIdSelect"
@focus="onInputFocus"
class="modal-input border-select"
label="MasterTask"
variant="solo"
:items="masterTasks"
item-value="id"
item-title="name"
></v-select>
<v-select
v-model="employeeIdSelect"
@focus="onInputFocus"
class="modal-input border-select"
label="Priradený"
:class="{ error: v$.task.employee_id.$errors.length }"
variant="solo"
:items="employees"
item-value="id"
item-title="_fullName"
></v-select>
<Datepicker
class="modal-input mb-5"
v-model="task.date"
format="dd.MM.yyyy, HH:mm"
locale="sk"
:class="{ error: v$.task.date.$errors.length }"
@focus="onDateFocus"
:validations="v$.task.date"
select-text="Vybrať"
cancel-text="Zrušiť"
placeholder="Trvanie od - do"
range
/>
<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>
<div class="w-100 modal-input">
<QuillEditor
v-model="task.description"
placeholder="Popis"
theme="snow"
class="rich-text-editor"
/>
</div>
<Z-files-upload class="mt-15 files" @files-uploaded="filesUploaded" />
</v-card-actions>
<v-btn class="button primary" @click="save()">{{
task.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>
<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>
<div class="d-flex justify-start">
<img
class="icon"
:src="require('@/plugins/tm@overview/_img/pencil-icon.svg')"
alt="pencil-icon"
@click.stop="editMode = !editMode"
/>
<img
class="icon trash"
:src="require('@/plugins/tm@overview/_img/trash-icon.svg')"
alt="trash-icon"
@click.stop="openDeleteTaskModal(task)"
/>
</div>
</div>
<v-card-actions class="d-flex flex-column modal-content">
<div class="w-100">
<v-row no-gutters class="align-center">
<v-col cols="5">
<v-sheet class="pa-2 ma-2">
<div class="d-flex align-center">
<v-icon icon="mdi-link" size="large"></v-icon>
<p class="mx-3">Mastertask</p>
</div>
</v-sheet>
</v-col>
<v-col cols="7">
<v-sheet class="ma-2">
<p class="task-badge px-4 py-2 rounded-pill">
{{ task.master_task.name }}
</p>
</v-sheet>
</v-col>
</v-row>
<v-row no-gutters class="align-center">
<v-col cols="5">
<v-sheet class="pa-2 ma-2">
<div class="d-flex align-center">
<v-icon
icon="mdi-drag-vertical"
size="large"
></v-icon>
<p class="mx-3">Status</p>
</div>
</v-sheet>
</v-col>
<v-col cols="7">
<v-sheet class="ma-2">
<p
v-if="task.is_finished"
class="status-badge px-4 py-2 rounded-pill"
>
Ukončený
</p>
<p
v-if="!task.is_finished"
class="status-badge px-4 py-2 rounded-pill"
>
Neukončený
</p>
</v-sheet>
</v-col>
</v-row>
<v-row no-gutters>
<v-col cols="5">
<v-sheet class="pa-2 ma-2 pt-5">
<div class="d-flex align-center">
<v-icon
icon="mdi-calendar-week"
size="large"
></v-icon>
<p class="mx-3">Trvanie</p>
</div>
</v-sheet>
</v-col>
<v-col cols="7">
<v-sheet class="ma-2">
<div v-for="(date, index) in task.timeblocks" :key="date.id">
<div class="d-flex align-center m-5">
<v-icon
@click.stop="removeDate(index)"
class="remove-date cursor-pointer mr-2" icon="mdi-minus" size="medium"
/>
<p
class="task-badge px-4 py-2 rounded-pill mt-2"
v-html="
`${tmUtils.formatDateTime(date.start)} - ${tmUtils.formatDateTime(date.end)}`
"
/>
</div>
</div>
<v-icon
@click="showDatePicker = true"
class="add-date cursor-pointer mt-5" icon="mdi-plus" size="medium"
/>
<v-dialog max-width="650" v-model="showDatePicker">
<v-card>
<div class="d-flex justify-space-between align-center">
<h1>Pridať dátum</h1>
<v-icon
@click.stop="showDatePicker = false"
icon="mdi-close"
size="large"
></v-icon>
</div>
<v-card-actions class="mt-10 d-flex justify-start align-center">
<Datepicker
v-model="selectedNewDate"
class="modal-input"
format="dd.MM.yyyy, HH:mm"
locale="sk"
select-text="Vybrať"
cancel-text="Zrušiť"
placeholder="Trvanie od - do"
range
/>
</v-card-actions>
<v-btn @click="addNewDate()" class="button primary mt-5">Potvrdiť</v-btn>
</v-card>
</v-dialog>
</v-sheet>
</v-col>
</v-row>
<v-row no-gutters class="align-center">
<v-col cols="5">
<v-sheet class="pa-2 ma-2">
<div class="d-flex align-center">
<v-icon
icon="mdi-account-outline"
size="large"
></v-icon>
<p class="mx-3">Priradený</p>
</div>
</v-sheet>
</v-col>
<v-col cols="7">
<v-sheet class="ma-2 d-flex align-center">
<p
class="employee-selected-avatar d-flex justify-center align-center"
>
{{
task.employee.name.charAt(0) +
task.employee.surname.charAt(0)
}}
</p>
<p
class="ml-2"
v-html="
`${task.employee.name} ${task.employee.surname}`
"
/>
</v-sheet>
</v-col>
</v-row>
<v-row no-gutters class="align-center">
<v-col cols="5">
<v-sheet class="pa-2 ma-2">
<div class="d-flex align-center">
<v-icon
icon="mdi-clock-time-three-outline"
size="large"
></v-icon>
<p class="mx-3">Naplánovaný čas</p>
</div>
</v-sheet>
</v-col>
<v-col cols="7">
<v-sheet class="ma-2">
<p>{{ (task.duration / 3600000).toFixed(2) }} h</p>
</v-sheet>
</v-col>
</v-row>
<v-row no-gutters class="align-center">
<v-col cols="5">
<v-sheet class="pa-2 ma-2">
<div class="d-flex align-center">
<v-icon
icon="mdi-timer-outline"
size="large"
></v-icon>
<p class="mx-3">Odpracovaný čas</p>
</div>
</v-sheet>
</v-col>
<v-col cols="7">
<v-sheet class="ma-2">
<v-text-field
v-model="task.spent_time"
class="modal-input"
variant="solo"
type="number"
placeholder="h"
></v-text-field>
</v-sheet>
</v-col>
</v-row>
<v-row no-gutters class="align-center border-bottom">
<v-col cols="5">
<v-sheet class="pa-2 ma-2">
<div class="d-flex align-center">
<v-icon
icon="mdi-clock-time-three-outline"
size="large"
></v-icon>
<p class="mx-3">Zostávajúci čas</p>
</div>
</v-sheet>
</v-col>
<v-col cols="7">
<v-sheet class="ma-2">
<p>
{{ ((task.duration / 3600000) - (task.spent_time)).toFixed(2) }} h
</p>
</v-sheet>
</v-col>
</v-row>
<div class="px-5 py-5 border-bottom">
<p>Popis zadania</p>
<section
v-html="task.description"
class="description-detail px-2 py-2 w-100 rounded mt-2"
/>
<p class="mt-5">Prílohy</p>
<div class="w-100 d-flex align-center">
<div
v-for="(file, index) in task.files"
:key="file.id"
class="d-flex align-center flex-wrap"
:class="[index === 0 ? 'ml-0' : 'ml-2']"
>
<v-chip class="mt-2">
<p @click="downloadFile(index)" class="cursor-pointer">
{{ file.name }}
</p>
<v-icon
class="mx-1"
icon="mdi-paperclip"
></v-icon>
</v-chip>
</div>
</div>
</div>
<div class="d-flex justify-start align-center mt-8">
<v-btn class="done-btn" @click.stop="task.is_finished = 1; save()"
>Dokončené</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 Datepicker from '@vuepic/vue-datepicker'
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 moment from 'moment'
import { QuillEditor } from '@vueup/vue-quill'
import VuetifyFixFocusMixin from '@/plugins/tm@modal/_mixins/vuetify-fix-focus'
import * as FileSaver from 'file-saver'
import tmUtils from '@/plugins/tm@_utils/tm.utils'
import '@vueup/vue-quill/dist/vue-quill.snow.css'
export default {
emits: ['close', 'refresh'],
mixins: [VuetifyFixFocusMixin],
components: {
Datepicker,
ZFilesUpload,
QuillEditor,
},
data() {
return {
tmUtils,
editMode: false,
visible: false,
task: null,
errorUtils,
v$: useVuelidate(),
preventInputFocus: false,
masterTasks: [],
masterTaskIdSelect: null,
employeeIdSelect: null,
showDatePicker: false,
selectedNewDate: []
}
},
computed: {
employees() {
if (!this.task?.master_task?.employees)
return []
return tmUtils.enrichEmployeesByFullName(this.task.master_task.employees)
}
},
validations() {
return {
task: {
date: { required },
// team_id: { required },
duration: { required },
employee_id: { required },
}
}
},
mounted() {
this.$events.on('on-task-deleted', (task) => {
if (task?.id == this.task?.id) this.closeModal()
})
},
methods: {
async showModal(task, editMode = false, masterTask = null) {
this.v$.$reset()
this.visible = true
this.task = null
this.employeeIdSelect = null
this.masterTaskIdSelect = null
try {
this.masterTasks = await this.$axios.get_auth_data('v1/mastertasks')
if (task?.id) {
const t = await this.$axios.get_auth_data(`v1/subtasks/${task.id}`)
t.master_task = this.masterTasks.find(mt => mt.id == t.master_task_id)
t.employee = t.master_task.employees.find(e => t.employee_id == e.id)
this.employeeIdSelect = t.employee.id
this.masterTaskIdSelect = t.master_task.id
this.task = t
this.task.spent_time = ((t.spent_time) / 3600000).toFixed(2)
} else {
this.task = {master_task: masterTask}
this.masterTaskIdSelect = masterTask ? masterTask.id : null
}
this.editMode = (editMode || !this.task.id)
} catch (error) {
this.$toast.error(error)
}
},
closeModal() {
this.visible = false
},
async save() {
if (!(await this.v$.$validate()))
return
try {
if (this.task?.id) {
await this.$axios.put_auth(`v1/mastertasks/subtasks/${this.task.id}`, this.task)
this.$events.emit('on-task-edited', this.task)
} else {
await this.$axios.post_auth(`v1/mastertasks/${this.task.master_task.id}/subtasks`, this.task)
}
this.closeModal()
} catch (error) {
this.$toast.error(error)
}
},
async addNewDate() {
if (this.selectedNewDate) {
this.task.timeblocks.push({
start: this.selectedNewDate[0],
end: this.selectedNewDate[1]
})
this.showDatePicker = false
this.selectedNewDate = []
}
},
async downloadFile(id) {
try {
const file = await this.$axios.get_auth_data(`v1/subtasks/${this.task.id}`, { responseType: 'arraybuffer' })
FileSaver.saveAs(file.files[id].path, file.files[id].name)
} catch(error) {
this.$toast.error(error)
}
},
removeDate(index) {
this.task.timeblocks.splice(index, 1)
},
openDeleteTaskModal(task) {
this.$events.emit('show-delete-task-modal', { task })
},
filesUploaded(files) {
this.task.files = files
},
},
watch: {
masterTaskIdSelect(value) {
if (!value || !this.task) return
this.task.master_task = this.masterTasks.find(masterTask => masterTask.id == value)
const selectedMasterTask = this.masterTasks.find(masterTask => masterTask.id === value)
if (selectedMasterTask) {
this.task.project_code = selectedMasterTask.project_code
}
},
employeeIdSelect(value) {
if (!value || !this.task) return
this.task.employee = this.task.master_task.employees.find(employee => employee.id == value)
this.task.employee_id = value
},
},
}
</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>