[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

+7 -7
View File
@@ -18,7 +18,7 @@
"@vuelidate/core": "^2.0.0", "@vuelidate/core": "^2.0.0",
"@vuelidate/validators": "^2.0.0", "@vuelidate/validators": "^2.0.0",
"@vuepic/vue-datepicker": "^3.6.0", "@vuepic/vue-datepicker": "^3.6.0",
"@vueup/vue-quill": "^1.0.1", "@vueup/vue-quill": "^1.0.0-beta.11",
"axios": "^1.1.3", "axios": "^1.1.3",
"axios-auth-refresh": "^3.3.4", "axios-auth-refresh": "^3.3.4",
"core-js": "^3.8.3", "core-js": "^3.8.3",
@@ -3481,9 +3481,9 @@
} }
}, },
"node_modules/@vueup/vue-quill": { "node_modules/@vueup/vue-quill": {
"version": "1.0.1", "version": "1.0.0-beta.11",
"resolved": "https://registry.npmjs.org/@vueup/vue-quill/-/vue-quill-1.0.1.tgz", "resolved": "https://registry.npmjs.org/@vueup/vue-quill/-/vue-quill-1.0.0-beta.11.tgz",
"integrity": "sha512-/VJHwUxH2BAms7gwIlNhHb0KfCqn/58onOK1H0ZZX9juEha4nrb32yZbv2xLsqLxf+JKsNbJgQ8Ne6VF8ACNGw==", "integrity": "sha512-TeCgXPyVbN5muBPKm3EZjmIg/s8R8O0YmTp0RRG4J48skJVe035scLjeWZTDVrt/TEagmzcRUcB+9nPIyvF9fQ==",
"dependencies": { "dependencies": {
"quill": "^1.3.7", "quill": "^1.3.7",
"quill-delta": "^4.2.2" "quill-delta": "^4.2.2"
@@ -16417,9 +16417,9 @@
} }
}, },
"@vueup/vue-quill": { "@vueup/vue-quill": {
"version": "1.0.1", "version": "1.0.0-beta.11",
"resolved": "https://registry.npmjs.org/@vueup/vue-quill/-/vue-quill-1.0.1.tgz", "resolved": "https://registry.npmjs.org/@vueup/vue-quill/-/vue-quill-1.0.0-beta.11.tgz",
"integrity": "sha512-/VJHwUxH2BAms7gwIlNhHb0KfCqn/58onOK1H0ZZX9juEha4nrb32yZbv2xLsqLxf+JKsNbJgQ8Ne6VF8ACNGw==", "integrity": "sha512-TeCgXPyVbN5muBPKm3EZjmIg/s8R8O0YmTp0RRG4J48skJVe035scLjeWZTDVrt/TEagmzcRUcB+9nPIyvF9fQ==",
"requires": { "requires": {
"quill": "^1.3.7", "quill": "^1.3.7",
"quill-delta": "^4.2.2" "quill-delta": "^4.2.2"
+1 -1
View File
@@ -18,7 +18,7 @@
"@vuelidate/core": "^2.0.0", "@vuelidate/core": "^2.0.0",
"@vuelidate/validators": "^2.0.0", "@vuelidate/validators": "^2.0.0",
"@vuepic/vue-datepicker": "^3.6.0", "@vuepic/vue-datepicker": "^3.6.0",
"@vueup/vue-quill": "^1.0.1", "@vueup/vue-quill": "^1.0.0-beta.11",
"axios": "^1.1.3", "axios": "^1.1.3",
"axios-auth-refresh": "^3.3.4", "axios-auth-refresh": "^3.3.4",
"core-js": "^3.8.3", "core-js": "^3.8.3",
+8 -5
View File
@@ -10,12 +10,12 @@
<Z-task-modal ref="z-task-modal" @on-task-edited="onTaskEdited" /> <Z-task-modal ref="z-task-modal" @on-task-edited="onTaskEdited" />
<Z-delete-task-modal ref="z-delete-task-modal" @on-task-deleted="onTaskDeleted" /> <Z-delete-task-modal ref="z-delete-task-modal" @on-task-deleted="onTaskDeleted" />
<Z-delete-master-task-modal ref="z-delete-master-task-modal" /> <Z-delete-master-task-modal ref="z-delete-master-task-modal" @on-master-task-deleted="onMasterTaskDeleted" />
<Z-complete-task-modal ref="z-complete-task-modal" @task-completed="onTaskCompleted" /> <Z-complete-task-modal ref="z-complete-task-modal" @task-completed="onTaskCompleted" />
<Z-task-add-time-modal ref="z-task-add-time-modal" /> <Z-task-add-time-modal ref="z-task-add-time-modal" />
<Z-blocker-modal ref="z-blocker-modal" /> <Z-blocker-modal ref="z-blocker-modal" />
<Z-master-task-modal ref="z-master-task-modal" /> <Z-master-task-modal ref="z-master-task-modal" @master-task-edited="onMasterTaskEdited" />
</template> </template>
<script> <script>
@@ -59,8 +59,8 @@ export default {
this.$refs['z-delete-master-task-modal'].showModal(masterTask) this.$refs['z-delete-master-task-modal'].showModal(masterTask)
}) })
this.$events.on('show-task-modal', ({task, editMode}) => { this.$events.on('show-task-modal', ({task, editMode, masterTask}) => {
this.$refs['z-task-modal'].showModal(task, editMode) this.$refs['z-task-modal'].showModal(task, editMode, masterTask)
}) })
this.$events.on('show-master-task-modal', ({masterTask, editMode}) => { this.$events.on('show-master-task-modal', ({masterTask, editMode}) => {
@@ -78,7 +78,6 @@ export default {
this.$events.on('show-task-add-time-modal', ({task}) => { this.$events.on('show-task-add-time-modal', ({task}) => {
this.$refs['z-task-add-time-modal'].showModal(task) this.$refs['z-task-add-time-modal'].showModal(task)
}) })
}, },
methods: { methods: {
@@ -100,6 +99,10 @@ export default {
onMasterTaskDeleted(masterTask){ onMasterTaskDeleted(masterTask){
this.$events.emit('on-master-task-deleted', masterTask) this.$events.emit('on-master-task-deleted', masterTask)
},
onMasterTaskEdited(masterTask){
this.$events.emit('on-master-task-edited', masterTask)
} }
} }
} }
+5 -1
View File
@@ -77,4 +77,8 @@ input[type="time"]::-webkit-calendar-picker-indicator
.rich-text-editor .rich-text-editor
.ql-tooltip .ql-tooltip
left: 0 !important left: 0 !important
.v-toast,
.v-toast__item
z-index: 10000 !important
@@ -22,8 +22,8 @@
.v-field .v-field
border-bottom: 1px solid rgba(0, 0, 0, 0) border-bottom: 1px solid rgba(0, 0, 0, 0)
.error .v-field // .error .v-field
border-bottom: 1px solid red // border-bottom: 1px solid red
@media screen and (max-width: 904px) @media screen and (max-width: 904px)
.auth-card .auth-card
@@ -48,15 +48,6 @@
box-shadow: none !important box-shadow: none !important
border: 1px solid rgba(0, 0, 0, .1) !important border: 1px solid rgba(0, 0, 0, .1) !important
.auth-card .error .v-field
border: .5px solid red !important
.error .v-field
border: .5px solid red !important
.error .dp__input
border: .5px solid red !important
.v-input__append .v-input__append
margin: 0 !important margin: 0 !important
@@ -65,11 +56,11 @@
right: 45px right: 45px
input::-webkit-outer-spin-button, input::-webkit-outer-spin-button,
input::-webkit-inner-spin-button input::-webkit-inner-spin-button
-webkit-appearance: none -webkit-appearance: none
.error-message .error-message
position: absolute position: absolute
top: 50% top: 50%
left: 30px left: 30px
color: red color: red
@@ -78,5 +69,10 @@ input::-webkit-inner-spin-button
.v-select .v-field--variant-solo .v-select .v-field--variant-solo
border: none !important border: none !important
.error .dp__input,
.v-input.error .v-input__control,
.rich-text-editor.error
border: 1px solid red !important
.v-messages__message .v-messages__message
color: red !important color: red !important
@@ -86,7 +86,8 @@ export default {
background: unset background: unset
&:deep(.fc-day-today) &:deep(.fc-day-today)
background: white background: white
a
.fc-daygrid-day-top a
background: #3700B3 background: #3700B3
width: 28px width: 28px
color: white color: white
@@ -76,6 +76,16 @@ export default {
this._getData() this._getData()
}, },
mounted() {
this.$events.on('on-master-task-deleted', (masterTask) => {
this.masterTasks = this.masterTasks.filter(mt => mt.id != masterTask.id)
})
this.$events.on('on-master-task-edited', (masterTask) => {
this._getData()
})
},
methods: { methods: {
async _getData() { async _getData() {
try { try {
@@ -13,7 +13,7 @@
<v-card-actions class="d-flex flex-column modal-content"> <v-card-actions class="d-flex flex-column modal-content">
<v-select <v-select
v-model="masterTask.project_id" v-model="projectCodeSelect"
@focus="onInputFocus" @focus="onInputFocus"
class="modal-input border-select" class="modal-input border-select"
label="Kód projektu" label="Kód projektu"
@@ -61,15 +61,15 @@
class="modal-input mt-5" class="modal-input mt-5"
variant="solo" variant="solo"
type="number" type="number"
:value="totalHours"
disabled disabled
:label="totalHours + ' h'" :label="`${masterTask.duration} h`"
></v-text-field> ></v-text-field>
<v-select <v-select
v-model="teamSelect" v-model="teamSelect"
@focus="onInputFocus" @focus="onInputFocus"
class="modal-input border-select" class="modal-input border-select"
:class="{ error: v$.masterTask.team.$errors.length }"
label="Tím" label="Tím"
variant="solo" variant="solo"
:items="teams" :items="teams"
@@ -81,14 +81,15 @@
v-for="(employee, index) in masterTask.employees" v-for="(employee, index) in masterTask.employees"
:key="employee.id" :key="employee.id"
@focus="onInputFocus" @focus="onInputFocus"
:class="{ error: masterTask.employees[index].hours < 0 }" :class="{ error: !masterTask.employees[index].duration }"
class="modal-input" class="modal-input"
:label="`${employee.name} ${employee.surname}`" :label="`${employee.name} ${employee.surname}`"
variant="solo" variant="solo"
placeholder="h" placeholder="h"
v-model="masterTask.employees[index].hours" v-model="masterTask.employees[index].duration"
type="number" type="number"
min="1" min="1"
@input="onEmployeeDurationChanged"
> >
<p class="employee-select-avatar d-flex justify-center align-center"> <p class="employee-select-avatar d-flex justify-center align-center">
{{ employee.name.charAt(0) + employee.surname.charAt(0) }} {{ employee.name.charAt(0) + employee.surname.charAt(0) }}
@@ -110,17 +111,20 @@
<div class="w-100 modal-input"> <div class="w-100 modal-input">
<QuillEditor <QuillEditor
ref="description"
v-model="masterTask.description" v-model="masterTask.description"
placeholder="Popis" placeholder="Popis"
theme="snow" theme="snow"
class="rich-text-editor" class="rich-text-editor"
:class="{ error: v$.masterTask.deadline.$errors.length }"
@input="masterTask.description = $event.srcElement.innerHTML"
/> />
</div> </div>
<Z-files-upload class="mt-15 files" @files-uploaded="filesUploaded"/> <Z-files-upload class="mt-15 files" @files-uploaded="filesUploaded"/>
</v-card-actions> </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-card v-else height="100%" class="d-flex flex-column scrolling"> <v-card v-else height="100%" class="d-flex flex-column scrolling">
@@ -137,7 +141,7 @@
<h1>{{ masterTask.name }}</h1> <h1>{{ masterTask.name }}</h1>
<div class="d-flex justify-start"> <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" :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>
</div> </div>
@@ -194,7 +198,7 @@
</v-col> </v-col>
<v-col cols="7"> <v-col cols="7">
<v-sheet class="d-flex flex-wrap flex-column"> <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"> <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"> <p class="employee-selected-avatar d-flex justify-center align-center">
{{ employee.name.charAt(0) + employee.surname.charAt(0) }} {{ employee.name.charAt(0) + employee.surname.charAt(0) }}
@@ -287,7 +291,7 @@
<td class="task-action"> <td class="task-action">
<div class="d-flex justify-start"> <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" :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)"> <img class="trash-icon" :src="require('@/plugins/tm@overview/_img/trash-icon.svg')" alt="trash-icon" @click.stop="openDeleteTaskModal(task)">
</div> </div>
</td> </td>
@@ -311,7 +315,7 @@ import useVuelidate from '@vuelidate/core'
import { required } from '@vuelidate/validators' import { required } from '@vuelidate/validators'
import errorUtils from '@/plugins/lib@auth/_utils/error.utils' import errorUtils from '@/plugins/lib@auth/_utils/error.utils'
import ZAutocomplete from '@/plugins/tm@_components/z-autocomplete.vue' 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 moment from 'moment'
import { QuillEditor } from '@vueup/vue-quill' import { QuillEditor } from '@vueup/vue-quill'
import tmUtils from '@/plugins/tm@_utils/tm.utils' 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 const atLeastOne = (value) => value.length
export default { export default {
emits: ['close'], emits: ['master-task-edited', 'close'],
mixins: [VuetifyFixFocusMixin], mixins: [VuetifyFixFocusMixin],
components: { components: {
@@ -342,6 +346,7 @@ export default {
projects: null, projects: null,
employees: null, employees: null,
employeeSelect: null, employeeSelect: null,
projectCodeSelect: null,
teamSelect: '', teamSelect: '',
masterTask: null, masterTask: null,
@@ -367,6 +372,10 @@ export default {
this.$events.on('on-master-task-deleted', (masterTask) => { this.$events.on('on-master-task-deleted', (masterTask) => {
if (masterTask?.id == this.masterTask?.id) this.closeModal() 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: { methods: {
@@ -383,15 +392,17 @@ export default {
fullName, fullName,
initials initials
} }
}, },
async showModal(masterTask, editMode = false) { async showModal(masterTask, editMode = false) {
this.visible = true this.v$.$reset()
this.masterTask = null this.visible = true
this.teamSelect = null this.masterTask = null
this.employeeSelect = null this.teamSelect = null
this.employeeSelect = null
this.projectCodeSelect = null
try { try {
this.teams = await this.$axios.get_auth_data('v1/teams') this.teams = await this.$axios.get_auth_data('v1/teams')
@@ -401,28 +412,27 @@ export default {
if (masterTask?.id) { if (masterTask?.id) {
this.masterTask = await this.$axios.get_auth_data(`v1/mastertasks/${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 { } else {
this.masterTask = {team: {}, employees: []} this.masterTask = {team: {}, employees: [], duration: 0}
} }
this.editMode = (editMode || !this.masterTask.id) this.editMode = (editMode || !this.masterTask.id)
} catch (error) { } catch (error) {
this.$toast.error(error) this.$toast.error(error)
} }
}, },
async save() { async save() {
if (!(await this.v$.$validate())) if (!(await this.v$.$validate()))
return return console.log(this.v$)
try { 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") this.masterTask.deadline = moment(this.masterTask.deadline).format("YYYY-MM-DD HH:MM:SS")
if (this.masterTask.id) if (this.masterTask.id)
@@ -431,6 +441,7 @@ export default {
else else
await this.$axios.post_auth_data('v1/mastertasks', this.masterTask) await this.$axios.post_auth_data('v1/mastertasks', this.masterTask)
this.$emit('master-task-edited', this.masterTask)
this.closeModal() this.closeModal()
} catch (error) { } catch (error) {
this.$toast.error(error) this.$toast.error(error)
@@ -448,7 +459,11 @@ export default {
openDeleteTaskModal(task) { openDeleteTaskModal(task) {
this.$events.emit('show-delete-task-modal', { task }) this.$events.emit('show-delete-task-modal', { task })
}, },
openEditTaskModal(task) {
this.$events.emit('show-task-modal', { task, editMode: false })
},
employeeSelected(selectedOption) { employeeSelected(selectedOption) {
const employee = this.employees.find((empl) => empl.id == selectedOption.key) const employee = this.employees.find((empl) => empl.id == selectedOption.key)
@@ -461,8 +476,26 @@ export default {
}, },
addTask() { 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: { computed: {
@@ -498,7 +531,9 @@ export default {
if (!value || !this.masterTask) return if (!value || !this.masterTask) return
this.masterTask.team = this.teams.find(team => team.id == value) 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.masterTask.employees = this.masterTask.team.employees
this.$nextTick(() => this.v$.$reset())
}, },
employeeSelect(value) { employeeSelect(value) {
@@ -510,9 +545,17 @@ export default {
this.$nextTick(() => { this.$nextTick(() => {
this.employeeSelect = null this.employeeSelect = null
this.$el.activeElement.blur() 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 || '')
}) })
} }
} }
+31 -21
View File
@@ -34,6 +34,7 @@
@focus="onInputFocus" @focus="onInputFocus"
class="modal-input border-select" class="modal-input border-select"
label="Priradený" label="Priradený"
:class="{ error: v$.task.employee_id.$errors.length }"
variant="solo" variant="solo"
:items="employees" :items="employees"
item-value="id" item-value="id"
@@ -181,9 +182,9 @@
<v-sheet class="ma-2"> <v-sheet class="ma-2">
<div v-for="(date, index) in task.timeblocks" :key="date.id"> <div v-for="(date, index) in task.timeblocks" :key="date.id">
<div class="d-flex align-center m-5"> <div class="d-flex align-center m-5">
<v-icon <v-icon
@click.stop="removeDate(index)" @click.stop="removeDate(index)"
class="remove-date cursor-pointer mr-2" icon="mdi-minus" size="medium" class="remove-date cursor-pointer mr-2" icon="mdi-minus" size="medium"
/> />
<p <p
class="task-badge px-4 py-2 rounded-pill mt-2" class="task-badge px-4 py-2 rounded-pill mt-2"
@@ -193,9 +194,9 @@
/> />
</div> </div>
</div> </div>
<v-icon <v-icon
@click="showDatePicker = true" @click="showDatePicker = true"
class="add-date cursor-pointer mt-5" icon="mdi-plus" size="medium" class="add-date cursor-pointer mt-5" icon="mdi-plus" size="medium"
/> />
<v-dialog max-width="650" v-model="showDatePicker"> <v-dialog max-width="650" v-model="showDatePicker">
<v-card> <v-card>
@@ -413,9 +414,9 @@ export default {
return { return {
task: { task: {
date: { required }, date: { required },
// team: { required }, // team_id: { required },
duration: { required }, duration: { required },
employee: { required }, employee_id: { required },
} }
} }
}, },
@@ -427,21 +428,28 @@ export default {
}, },
methods: { methods: {
async showModal(task, editMode = false) { async showModal(task, editMode = false, masterTask = null) {
this.visible = true this.v$.$reset()
this.task = null this.visible = true
this.task = null
this.employeeIdSelect = null
this.masterTaskIdSelect = null
try { try {
this.masterTasks = await this.$axios.get_auth_data('v1/mastertasks') 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}`)
this.employeeIdSelect = t.employee.id if (task?.id) {
this.masterTaskIdSelect = t.master_task.id const t = await this.$axios.get_auth_data(`v1/subtasks/${task.id}`)
this.task = t t.master_task = this.masterTasks.find(mt => mt.id == t.master_task_id)
this.task.spent_time = ((t.spent_time) / 3600000).toFixed(2) 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 { } else {
this.task = {master_task: {}} this.task = {master_task: masterTask}
this.masterTaskIdSelect = masterTask ? masterTask.id : null
} }
this.editMode = (editMode || !this.task.id) this.editMode = (editMode || !this.task.id)
@@ -455,14 +463,15 @@ export default {
}, },
async save() { async save() {
if (!(await this.v$.$validate())) return console.log(this.v$) if (!(await this.v$.$validate()))
return
try { try {
if (this.task.id) { if (this.task?.id) {
await this.$axios.put_auth(`v1/mastertasks/${this.task.id}`, this.task) await this.$axios.put_auth(`v1/mastertasks/subtasks/${this.task.id}`, this.task)
this.$events.emit('on-task-edited', this.task) this.$events.emit('on-task-edited', this.task)
} else { } else {
await this.$axios.post_auth('v1/subtasks', this.task) await this.$axios.post_auth(`v1/mastertasks/${this.task.master_task.id}/subtasks`, this.task)
} }
this.closeModal() this.closeModal()
@@ -509,7 +518,8 @@ export default {
employeeIdSelect(value) { employeeIdSelect(value) {
if (!value || !this.task) return if (!value || !this.task) return
this.task.employee = this.task.master_task.employees.find(employee => employee.id == value) this.task.employee = this.task.master_task.employees.find(employee => employee.id == value)
this.task.employee_id = value
}, },
}, },
} }
+21 -12
View File
@@ -1,34 +1,43 @@
import { $t } from '@/plugins/app/_config/main'
export default { export default {
parseAndTranslate(data) { parseAndTranslate(data) {
const errorsArray = this._parseToArrayOfStrings(data) const errorsArray = this._parseToArrayOfStrings(data)
return errorsArray.map(error => this._translate(error))
// console.log(errorsArray.map(error => $t(error)))
return errorsArray.join(', ')
// return errorsArray.map(error => $t(error))
}, },
_parseToArrayOfStrings(data) { _parseToArrayOfStrings(data) {
if (typeof data == 'string') { if (typeof data == 'string') {
return [this._translate(data)] return [$t(data)]
} }
if (data?.response?.data)
return Object.values(data?.response?.data)
if (data && data.error && typeof data.error == 'string') { if (data && data.error && typeof data.error == 'string') {
return [this._translate(data.error)] return [$t(data.error)]
} }
if (data && data.error && typeof data.error == 'object') { if (data && data.error && typeof data.error == 'object') {
return Object.values(this._translate(data.error)) return Object.values($t(data.error))
} }
if (data.data && data.data.error && typeof data.data.error == 'string') { if (data.data && data.data.error && typeof data.data.error == 'string') {
return [this._translate(data.data.error)] return [$t(data.data.error)]
} }
if (data && data.data && data.data.error && typeof data.data.error == 'object') { if (data && data.data && data.data.error && typeof data.data.error == 'object') {
return Object.values(data.data.error).map(error => this._translate(error[0]) + ' ') return Object.values(data.data.error).map(error => $t(error[0]) + ' ')
} }
if (data.statusText) { if (data.statusText) {
return [this._translate(data.statusText)] return [$t(data.statusText)]
} }
return [data] return [data]
+21 -20
View File
@@ -1,5 +1,6 @@
import axios from 'axios' import axios from 'axios'
import store from '@/store' import store from '@/store'
import toastUtils from '@/plugins/w/toast/utils/toast.utils'
axios.defaults.baseURL = process.env.VUE_APP_WAXIOS_URL axios.defaults.baseURL = process.env.VUE_APP_WAXIOS_URL
@@ -7,7 +8,7 @@ export default {
async get(url: string, config?: any) { async get(url: string, config?: any) {
return axios.get(url, config) return axios.get(url, config)
.then(response => response.data) .then(response => response.data)
.catch(error => Promise.reject(error)) .catch(error => Promise.reject(toastUtils.parseAndTranslate(error)))
}, },
async get_auth(url: string, config?: any) { async get_auth(url: string, config?: any) {
@@ -15,13 +16,13 @@ export default {
return axios.get(url, config) return axios.get(url, config)
.then(response => response.data) .then(response => response.data)
.catch(error => Promise.reject(error)) .catch(error => Promise.reject(toastUtils.parseAndTranslate(error)))
}, },
async get_data(url: string, config?: any) { async get_data(url: string, config?: any) {
return axios.get(url, config) return axios.get(url, config)
.then(response => response.data.data) .then(response => response.data.data)
.catch(error => Promise.reject(error.response || error)) .catch(error => Promise.reject(toastUtils.parseAndTranslate(error.response || error)))
}, },
async get_auth_data(url: string, config?: any) { async get_auth_data(url: string, config?: any) {
@@ -29,14 +30,14 @@ export default {
return axios.get(url, config) return axios.get(url, config)
.then(response => Promise.resolve(response.data.data)) .then(response => Promise.resolve(response.data.data))
.catch(error => Promise.reject(error.response || error)) .catch(error => Promise.reject(toastUtils.parseAndTranslate(error.response || error)))
}, },
async post(url: string, params = null, config?: any) { async post(url: string, params = null, config?: any) {
return axios.post(url, this._objectToFormData(params), config) return axios.post(url, this._objectToFormData(params), config)
.then(response => response.data) .then(response => response.data)
.catch(error => Promise.reject(error)) .catch(error => Promise.reject(toastUtils.parseAndTranslate(error)))
}, },
async post_auth(url: string, params = null, config?: any) { async post_auth(url: string, params = null, config?: any) {
@@ -44,14 +45,14 @@ export default {
return axios.post(url, this._objectToFormData(params), config) return axios.post(url, this._objectToFormData(params), config)
.then(response => response.data) .then(response => response.data)
.catch(error => Promise.reject(error)) .catch(error => Promise.reject(toastUtils.parseAndTranslate(error)))
}, },
async post_data(url: string, params = null, config?: any) { async post_data(url: string, params = null, config?: any) {
return axios.post(url, this._objectToFormData(params), config) return axios.post(url, this._objectToFormData(params), config)
.then(response => response.data.data) .then(response => response.data.data)
.catch(error => Promise.reject(error.response || error)) .catch(error => Promise.reject(toastUtils.parseAndTranslate(error.response || error)))
}, },
async post_auth_data(url: string, params = null, config?: any) { async post_auth_data(url: string, params = null, config?: any) {
@@ -59,13 +60,13 @@ export default {
return axios.post(url, this._objectToFormData(params), config) return axios.post(url, this._objectToFormData(params), config)
.then(response => response.data.data) .then(response => response.data.data)
.catch(error => Promise.reject(error.response || error)) .catch(error => Promise.reject(toastUtils.parseAndTranslate(error.response || error)))
}, },
async delete(url: string, config?: any) { async delete(url: string, config?: any) {
return axios.delete(url, config) return axios.delete(url, config)
.then(response => response.data) .then(response => response.data)
.catch(error => Promise.reject(error)) .catch(error => Promise.reject(toastUtils.parseAndTranslate(error)))
}, },
async delete_auth(url: string, config?: any) { async delete_auth(url: string, config?: any) {
@@ -73,13 +74,13 @@ export default {
return axios.delete(url, config) return axios.delete(url, config)
.then(response => response.data) .then(response => response.data)
.catch(error => Promise.reject(error)) .catch(error => Promise.reject(toastUtils.parseAndTranslate(error)))
}, },
async delete_data(url: string, config?: any) { async delete_data(url: string, config?: any) {
return axios.delete(url, config) return axios.delete(url, config)
.then(response => response.data.data) .then(response => response.data.data)
.catch(error => Promise.reject(error.response || error)) .catch(error => Promise.reject(toastUtils.parseAndTranslate(error.response || error)))
}, },
async delete_auth_data(url: string, config?: any) { async delete_auth_data(url: string, config?: any) {
@@ -87,13 +88,13 @@ export default {
return axios.delete(url, config) return axios.delete(url, config)
.then(response => response.data.data) .then(response => response.data.data)
.catch(error => Promise.reject(error.response || error)) .catch(error => Promise.reject(toastUtils.parseAndTranslate(error.response || error)))
}, },
async patch(url: string, params = null, config?: any) { async patch(url: string, params = null, config?: any) {
return axios.patch(url, this._objectToFormData(params), config) return axios.patch(url, this._objectToFormData(params), config)
.then(response => response.data) .then(response => response.data)
.catch(error => Promise.reject(error)) .catch(error => Promise.reject(toastUtils.parseAndTranslate(error)))
}, },
async patch_auth(url: string, params = null, config?: any) { async patch_auth(url: string, params = null, config?: any) {
@@ -101,13 +102,13 @@ export default {
return axios.patch(url, this._objectToFormData(params), config) return axios.patch(url, this._objectToFormData(params), config)
.then(response => response.data) .then(response => response.data)
.catch(error => Promise.reject(error)) .catch(error => Promise.reject(toastUtils.parseAndTranslate(error)))
}, },
async patch_data(url: string, params = null, config?: any) { async patch_data(url: string, params = null, config?: any) {
return axios.patch(url, this._objectToFormData(params), config) return axios.patch(url, this._objectToFormData(params), config)
.then(response => response.data.data) .then(response => response.data.data)
.catch(error => Promise.reject(error.response || error)) .catch(error => Promise.reject(toastUtils.parseAndTranslate(error.response || error)))
}, },
async patch_auth_data(url: string, params = null, config?: any) { async patch_auth_data(url: string, params = null, config?: any) {
@@ -115,13 +116,13 @@ export default {
return axios.patch(url, this._objectToFormData(params), config) return axios.patch(url, this._objectToFormData(params), config)
.then(response => response.data.data) .then(response => response.data.data)
.catch(error => Promise.reject(error.response || error)) .catch(error => Promise.reject(toastUtils.parseAndTranslate(error.response || error)))
}, },
async put(url: string, params = null, config?: any) { async put(url: string, params = null, config?: any) {
return axios.put(url, this._objectToFormData(params), config) return axios.put(url, this._objectToFormData(params), config)
.then(response => response.data) .then(response => response.data)
.catch(error => Promise.reject(error)) .catch(error => Promise.reject(toastUtils.parseAndTranslate(error)))
}, },
async put_auth(url: string, params = null, config?: any) { async put_auth(url: string, params = null, config?: any) {
@@ -129,13 +130,13 @@ export default {
return axios.put(url, this._objectToFormData(params), config) return axios.put(url, this._objectToFormData(params), config)
.then(response => response.data) .then(response => response.data)
.catch(error => Promise.reject(error)) .catch(error => Promise.reject(toastUtils.parseAndTranslate(error)))
}, },
async put_data(url: string, params = null, config?: any) { async put_data(url: string, params = null, config?: any) {
return axios.put(url, this._objectToFormData(params), config) return axios.put(url, this._objectToFormData(params), config)
.then(response => response.data.data) .then(response => response.data.data)
.catch(error => Promise.reject(error.response || error)) .catch(error => Promise.reject(toastUtils.parseAndTranslate(error.response || error)))
}, },
async put_auth_data(url: string, params = null, config?: any) { async put_auth_data(url: string, params = null, config?: any) {
@@ -143,7 +144,7 @@ export default {
return axios.put(url, this._objectToFormData(params), config) return axios.put(url, this._objectToFormData(params), config)
.then(response => response.data.data) .then(response => response.data.data)
.catch(error => Promise.reject(error.response || error)) .catch(error => Promise.reject(toastUtils.parseAndTranslate(error.response || error)))
}, },
_config(config: any) { _config(config: any) {