[napajanie modalov na BE]

This commit is contained in:
romankko2 committed 2023-01-26 21:11:53 +01:00
1 parent 26792a85a6
commit 4c8ee66cd6
34 files changed
+494 -396

No files matched your search

@@ -1,18 +1,18 @@
<template>
<v-dialog v-model="show" max-width="650">
<v-dialog v-model="visible" max-width="650">
<v-card>
<div class="d-flex justify-space-between align-center">
<h1>Ste si istý, že chcete ukončiť <b>{{ task.title }}</b>?</h1>
<v-icon
@click.stop="show = false"
@click.stop="visible = false"
icon="mdi-close"
size="large"
></v-icon>
</div>
<v-card-actions class="mt-10 d-flex justify-start align-center">
<v-btn class="z-btn" variant="flat" @click="complete()">ÁNO</v-btn>
<v-btn class="ml-7 cancel-btn" @click.stop="show = false">ZRUŠIŤ</v-btn>
<v-btn class="ml-7 cancel-btn" @click.stop="visible = false">ZRUŠIŤ</v-btn>
</v-card-actions>
</v-card>
</v-dialog>
@@ -22,31 +22,19 @@
export default {
emits: ['close'],
props: {
visible: {
type: Boolean,
required: true
},
task: {
type: Object,
required: true
data() {
return {
visible: false,
task: null
}
},
computed: {
show: {
get() {
return this.visible
},
set(value) {
if (!value) this.$emit('close')
}
},
},
methods: {
async showModal(task) {
this.task = task
this.visible = true
},
async complete() {
try {
const task = {
@@ -55,7 +43,7 @@ export default {
}
await this.$axios.post(`v1/tasks/${task.id}`, task)
this.show = false
this.visible = false
this.$emit('completeTask', task.id)
} catch (error) {
this.$toast.error(error)
@@ -30,7 +30,7 @@ export default {
},
methods: {
async delete(task) {
async showModal(task) {
this.task = task
this.visible = true
},
@@ -0,0 +1,73 @@
<template>
<v-dialog v-model="show" max-width="650">
<v-card>
<div class="d-flex justify-space-between align-center">
<h1>Prosím zadajte odpracovaný čas</h1>
<v-icon
@click.stop="close()"
icon="mdi-close"
size="large"
></v-icon>
</div>
<v-card-actions class="mt-10 d-flex justify-start align-center">
<v-text-field
class="modal-input"
label="Odpracovaný čas"
variant="solo"
type="number"
placeholder="h"
append-inner-icon="mdi-timer-outline"
></v-text-field>
</v-card-actions>
<v-btn class="z-btn mt-5">Potvrdiť</v-btn>
</v-card>
</v-dialog>
</template>
<script>
export default {
emits: ['close'],
data() {
return {
visible: false
}
},
computed: {
show: {
get() {
return this.visible
},
set(value) {
if (!value) this.$emit('close')
}
},
},
methods: {
showModal() {
// Kravarik: Dorobit logiku
// 1. Save na be
// 2. this.$events.emit('task-time-updated', task)
this.visible = true
},
close() {
this.visible = false
this.$emit('close', this.blocker)
this.blocker = null
},
}
}
</script>
<style lang="sass" scoped>
.z-btn
height: 48px !important
h1
font-size: 34px
</style>
@@ -0,0 +1,627 @@
<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="close()" 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="selectedMasterTaskId"
@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="selectedEmployeeId"
@focus="onInputFocus"
class="modal-input border-select"
label="Priradený"
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="z-btn" @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="close()"
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="pencil-icon"
:src="require('@/plugins/tm@overview/_img/pencil-icon.svg')"
alt="pencil-icon"
@click.stop="editMode = !editMode"
/>
<img
class="trash-icon"
:src="require('@/plugins/tm@overview/_img/trash-icon.svg')"
alt="trash-icon"
@click.stop="deleteTask(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 class="align-center">
<v-col cols="5">
<v-sheet class="pa-2 ma-2">
<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">
<p
v-html="
`${formattedStartDate} - ${formattedEndDate}`
"
/>
</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 / 3600 }} 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 - task.spent_time) / 3600 }} 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" 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="clickCompleteTask()"
>Dokončené</v-btn
>
<v-btn class="add-employee-btn" @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 * as FileSaver from 'file-saver'
import '@vueup/vue-quill/dist/vue-quill.snow.css'
export default {
emits: ['close', 'refresh'],
components: {
Datepicker,
ZFilesUpload,
QuillEditor,
},
data() {
return {
editMode: false,
visible: false,
task: null,
errorUtils,
v$: useVuelidate(),
preventInputFocus: false,
masterTasks: [],
selectedMasterTaskId: null,
selectedEmployeeId: null
}
},
validations() {
return {
task: {
project_code: { required },
date: { required },
team: { required },
duration: { required },
employee: { required },
},
}
},
mounted() {
this.$events.on('on-task-deleted', (task) => {
if (task?.id == this.task?.id) this.close()
})
},
methods: {
// async downloadFile() {
// try {
// const file = await this.$axios.get_auth(`v1/files/${this.file.basename}`, { responseType: 'arraybuffer' })
// const blob = new Blob([file], { type: this.file.mimetype })
// FileSaver.saveAs(blob, this.file.name)
// this.isLoading = false
// } catch(error) {
// this.$toast.error(error)
// }
// },
async showModal(task, editMode = false) {
this.visible = true
this.task = null
try {
this.masterTasks = await this.$axios.get_auth_data('v1/mastertasks')
} catch (error) {
this.$toast.error(error)
}
if (task?.id) {
await this._load(task.id)
this.editMode = editMode || !this.task?.id
} else {
const task = {
project_code: null,
date: null,
team: {},
employee: null,
duration: null,
description: null,
files: [],
}
setTimeout(() => {
this.task = task
this.editMode = editMode || !this.task.id
})
}
},
async clickCompleteTask() {
try {
await this.$axios.delete(`v1/tasks/${this.task.id}`)
this.close()
} catch (error) {
this.$toast.error(error)
}
this.close()
},
async save() {
if (!(await this.v$.$validate())) return
try {
if (this.task.id) {
await this._update()
this.close()
} else await this._create()
this.close()
this.$router.push({ name: 'Dashboard - Tasks' })
} catch (error) {
this.$toast.error(error)
}
},
close() {
this.visible = false
this.$emit('close', this.task)
},
async _load(taskId) {
try {
const task = await this.$axios.get_auth_data(`v1/tasks/${taskId}`)
// const employees = task.master_task.employees.map(employee => {
// employee._fullName = `${employee.name} ${employee.surname}`
// return employee
// })
// this.employees = employees
this.task = task
this.selectedEmployeeId = this.task.employee.id
this.selectedMasterTaskId = this.task.master_task.id
} catch (error) {
this.$toast.error(error)
}
},
async _create() {
try {
await this.$axios.post_auth('v1/mastertasks')
} catch (error) {
this.$toast.error(error)
}
},
async _update() {
try {
await this.$axios.post_auth(`v1/master-tasks/${this.task.id}`)
} catch (error) {
this.$toast.error(error)
}
},
deleteTask(task) {
this.$events.emit('show-delete-task-modal', { task })
},
onTaskDeleted() {
this.$emit('refresh')
},
employeeSelected(selectedOption) {
const employee = this.task.master_task.employees.find(employee => employee.id == selectedOption.key)
this.task.employee = employee
},
// Vuetify input was automatically focus after date input was clicked. This will prevent this unwanted behavior
onDateFocus($event) {
if ($event == undefined) {
this.preventInputFocus = true
}
},
onInputFocus($event) {
if (this.preventInputFocus) {
$event.target.blur()
this.preventInputFocus = false
}
},
filesUploaded(files) {
this.task.files = files
},
},
computed: {
employees() {
if (!this.task?.master_task?.employees)
return []
return this.task.master_task.employees.map(employee => {
employee._fullName = `${employee.name} ${employee.surname}`
return employee
})
},
formattedStartDate() {
let startDate = moment(this.task.starts_at)
let date = startDate.format('DD.MM.yyyy, HH:mm')
return date
},
formattedEndDate() {
let endDate = moment(this.task.ends_at)
let date = endDate.format('DD.MM.yyyy, HH:mm')
return date
},
},
watch: {
selectedMasterTaskId() {
this.task.master_task = this.masterTasks.find(
(masterTask) => masterTask.id == this.selectedMasterTaskId
)
// Kravarik: Tu bude treba vymsliet logiku resetovania, ale ked dam toto sa to trigeruje aj pri otvarani existujuceho tasku a hned to vymaze
// this.selectedEmployeeId = null
// this.task.employee = {}
},
selectedEmployeeId() {
this.task.employee = this.task.master_task.employees.find(
(employee) => employee.id == this.selectedEmployeeId
)
},
},
}
</script>
<style lang="sass" scoped>
.modal-input
width: 100% !important
flex: 0 0 auto
.modal-header
flex: 0 0 auto
.modal-content
flex: 1 1 100%
margin: 10px 0
overflow-y: scroll
.z-btn
height: 50px
width: 100%
flex: 0 0 auto
.employee-position
position: relative
.employee-select-avatar
background: #6200EE
color: #fff
border-radius: 50%
padding: 13px
font-size: 11.5px
height: 24px
width: 24px
position: absolute
top: 50%
right: 0
transform: translate(-50%, -50%)
.add-employee-btn
color: #6200EE
border: 1px solid #E0E0E0
border-radius: 4px
height: 50px
width: 203px
.scrolling
overflow: hidden !important
.trash-icon
padding: 10px
background: rgba(0, 0, 0, 0.04)
margin-left: 12px
border-radius: 50%
cursor: pointer
.pencil-icon
padding: 10px
background: rgba(0, 0, 0, 0.04)
border-radius: 50%
cursor: pointer
.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>