[Master task, sub task] API

This commit is contained in:
Matej Glasnák committed 2023-02-09 03:43:32 +01:00
1 parent 4429e3e566
commit 6e8f57d06d
11 files changed
+188 -111

No files matched your search

@@ -13,7 +13,7 @@
<v-card-actions class="d-flex flex-column modal-content">
<v-select
v-model="masterTask.project_id"
v-model="projectCodeSelect"
@focus="onInputFocus"
class="modal-input border-select"
label="Kód projektu"
@@ -61,15 +61,15 @@
class="modal-input mt-5"
variant="solo"
type="number"
:value="totalHours"
disabled
:label="totalHours + ' h'"
:label="`${masterTask.duration} h`"
></v-text-field>
<v-select
v-model="teamSelect"
@focus="onInputFocus"
class="modal-input border-select"
:class="{ error: v$.masterTask.team.$errors.length }"
label="Tím"
variant="solo"
:items="teams"
@@ -81,14 +81,15 @@
v-for="(employee, index) in masterTask.employees"
:key="employee.id"
@focus="onInputFocus"
:class="{ error: masterTask.employees[index].hours < 0 }"
:class="{ error: !masterTask.employees[index].duration }"
class="modal-input"
:label="`${employee.name} ${employee.surname}`"
variant="solo"
placeholder="h"
v-model="masterTask.employees[index].hours"
v-model="masterTask.employees[index].duration"
type="number"
min="1"
@input="onEmployeeDurationChanged"
>
<p class="employee-select-avatar d-flex justify-center align-center">
{{ employee.name.charAt(0) + employee.surname.charAt(0) }}
@@ -110,17 +111,20 @@
<div class="w-100 modal-input">
<QuillEditor
ref="description"
v-model="masterTask.description"
placeholder="Popis"
theme="snow"
class="rich-text-editor"
:class="{ error: v$.masterTask.deadline.$errors.length }"
@input="masterTask.description = $event.srcElement.innerHTML"
/>
</div>
<Z-files-upload class="mt-15 files" @files-uploaded="filesUploaded"/>
</v-card-actions>
<v-btn class="button primary" @click="save()">VYTVORIŤ</v-btn>
<v-btn class="button primary" @click="save()">{{ masterTask.id ? 'ULOŽIŤ' : 'VYTVORIŤ'}}</v-btn>
</v-card>
<v-card v-else height="100%" class="d-flex flex-column scrolling">
@@ -137,7 +141,7 @@
<h1>{{ masterTask.name }}</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="openDeleteMasterTaskModal(masterTask)" />
<img class="icon trash" :src="require('@/plugins/tm@overview/_img/trash-icon.svg')" alt="trash-icon" @click.stop="openDeleteMasterTaskModal(masterTask)" />
</div>
</div>
@@ -194,7 +198,7 @@
</v-col>
<v-col cols="7">
<v-sheet class="d-flex flex-wrap flex-column">
<p class="task-badge px-4 py-2 rounded-pill flex-shrink-0">{{ masterTask.team.name }}</p>
<p class="task-badge px-4 py-2 rounded-pill flex-shrink-0">{{ masterTask.team?.name }}</p>
<div class="d-flex align-center flex-shrink-0 mt-2 task-badge px-4 py-2 rounded-pill" v-for="(employee, index) in masterTask.employees" :key="employee.id">
<p class="employee-selected-avatar d-flex justify-center align-center">
{{ employee.name.charAt(0) + employee.surname.charAt(0) }}
@@ -287,7 +291,7 @@
<td class="task-action">
<div class="d-flex justify-start">
<img class="pencil-icon" :src="require('@/plugins/tm@dashboard/_components/_img/checkmark.svg')" alt="checkmark-icon" :style="{opacity: 0.3}">
<img class="pencil-icon ml-2" :src="require('@/plugins/tm@overview/_img/pencil-icon.svg')" alt="pencil-icon" :style="{opacity: 0.3}">
<img class="pencil-icon ml-2" :src="require('@/plugins/tm@overview/_img/pencil-icon.svg')" alt="pencil-icon" @click.stop="openEditTaskModal(task)">
<img class="trash-icon" :src="require('@/plugins/tm@overview/_img/trash-icon.svg')" alt="trash-icon" @click.stop="openDeleteTaskModal(task)">
</div>
</td>
@@ -311,7 +315,7 @@ import useVuelidate from '@vuelidate/core'
import { required } from '@vuelidate/validators'
import errorUtils from '@/plugins/lib@auth/_utils/error.utils'
import ZAutocomplete from '@/plugins/tm@_components/z-autocomplete.vue'
import VuetifyFixFocusMixin from '@/plugins/tm@modal/_mixins/vuetify-fix-focus'
import VuetifyFixFocusMixin from '@/plugins/tm@modal/_mixins/vuetify-fix-focus'
import moment from 'moment'
import { QuillEditor } from '@vueup/vue-quill'
import tmUtils from '@/plugins/tm@_utils/tm.utils'
@@ -321,7 +325,7 @@ import '@vueup/vue-quill/dist/vue-quill.snow.css'
const atLeastOne = (value) => value.length
export default {
emits: ['close'],
emits: ['master-task-edited', 'close'],
mixins: [VuetifyFixFocusMixin],
components: {
@@ -342,6 +346,7 @@ export default {
projects: null,
employees: null,
employeeSelect: null,
projectCodeSelect: null,
teamSelect: '',
masterTask: null,
@@ -367,6 +372,10 @@ export default {
this.$events.on('on-master-task-deleted', (masterTask) => {
if (masterTask?.id == this.masterTask?.id) this.closeModal()
})
this.$events.on('on-task-deleted', (task) => {
this.masterTask.subtasks = this.masterTask.subtasks.filter(subtask => subtask.id != task.id)
})
},
methods: {
@@ -383,15 +392,17 @@ export default {
fullName,
initials
}
},
async showModal(masterTask, editMode = false) {
this.visible = true
this.masterTask = null
this.teamSelect = null
this.employeeSelect = null
this.v$.$reset()
this.visible = true
this.masterTask = null
this.teamSelect = null
this.employeeSelect = null
this.projectCodeSelect = null
try {
this.teams = await this.$axios.get_auth_data('v1/teams')
@@ -401,28 +412,27 @@ export default {
if (masterTask?.id) {
this.masterTask = await this.$axios.get_auth_data(`v1/mastertasks/${masterTask.id}`)
this.teamSelect = this.masterTask.team.id
const project = this.projects.find(project => project.code == this.masterTask?.project_code)
this.teamSelect = this.masterTask.team.id
this.projectCodeSelect = project.id
this.masterTask.project_id = project.id
} else {
this.masterTask = {team: {}, employees: []}
this.masterTask = {team: {}, employees: [], duration: 0}
}
this.editMode = (editMode || !this.masterTask.id)
} catch (error) {
this.$toast.error(error)
}
},
async save() {
if (!(await this.v$.$validate()))
return
return console.log(this.v$)
try {
this.masterTask.duration = 5
this.masterTask.description = 'popis'
this.masterTask.employees = this.masterTask.employees.map(employee => {
employee.duration = 5
return employee
})
this.masterTask.deadline = moment(this.masterTask.deadline).format("YYYY-MM-DD HH:MM:SS")
if (this.masterTask.id)
@@ -431,6 +441,7 @@ export default {
else
await this.$axios.post_auth_data('v1/mastertasks', this.masterTask)
this.$emit('master-task-edited', this.masterTask)
this.closeModal()
} catch (error) {
this.$toast.error(error)
@@ -448,7 +459,11 @@ export default {
openDeleteTaskModal(task) {
this.$events.emit('show-delete-task-modal', { task })
},
},
openEditTaskModal(task) {
this.$events.emit('show-task-modal', { task, editMode: false })
},
employeeSelected(selectedOption) {
const employee = this.employees.find((empl) => empl.id == selectedOption.key)
@@ -461,8 +476,26 @@ export default {
},
addTask() {
this.$events.emit('show-task-modal', {})
this.$events.emit('show-task-modal', {task: null, editMode: false, masterTask: this.masterTask})
},
onEmployeeDurationChanged() {
let totalDuration = 0
this.masterTask.employees = this.masterTask.employees.map(employee => {
if (typeof employee.duration == 'string') {
totalDuration += parseInt(employee.duration)
employee.duration = parseInt(employee.duration)
}
else if (typeof employee.duration == 'number') {
totalDuration += employee.duration
}
return employee
})
this.masterTask.duration = totalDuration
}
},
computed: {
@@ -498,7 +531,9 @@ export default {
if (!value || !this.masterTask) return
this.masterTask.team = this.teams.find(team => team.id == value)
this.masterTask.team_id = this.masterTask.team.id
this.masterTask.employees = this.masterTask.team.employees
this.$nextTick(() => this.v$.$reset())
},
employeeSelect(value) {
@@ -510,9 +545,17 @@ export default {
this.$nextTick(() => {
this.employeeSelect = null
this.$el.activeElement.blur()
// console.log(this.$refs['employee-select'])
// this.$refs['employee-select'].focused = false
// this.employeeSelect = ''
})
},
projectCodeSelect(value) {
if (!value || !this.masterTask) return
this.masterTask.project_id = value
},
editMode() {
this.$nextTick(() => {
this.$refs['description']?.setHTML(this.masterTask.description || '')
})
}
}