[sub & master task] saved data in LS + build for stage

This commit is contained in:
romankko2 committed 2024-08-01 17:41:51 +02:00
1 parent 8b1b1a7fb4
commit 7dcd9eda4d
3 files changed
+60 -12

No files matched your search

@@ -282,7 +282,25 @@ export default {
// this.mastertask.project_code = project.code
} else {
this.mastertask = { employees: [], duration: 0, _deadline_time: '17:00' }
const savedMastertask = localStorage.getItem('mastertaskData')
try {
if (savedMastertask) {
const parsedMastertask = JSON.parse(savedMastertask)
this.mastertask = parsedMastertask
// If the parsed result is not an object, reset to default
if (typeof this.mastertask !== 'object' || this.mastertask === null) {
throw new Error('Parsed mastertask is not an object')
}
this.$nextTick(() => {
this.$refs['description']?.setHTML(this.mastertask.description || '');
})
} else {
throw new Error('mastertaskData is null or undefined')
}
} catch (error) {
console.error('Error parsing mastertaskData:', error);
this.mastertask = { employees: [], duration: 0, _deadline_time: '17:00' }
}
}
this.editMode = editMode || !this.mastertask.id
@@ -319,6 +337,7 @@ export default {
this.mastertask.deadline = moment(this.mastertask.deadline).format('YYYY-MM-DD HH:MM:SS')
if (this.mastertask.id) await this.$axios.patch_auth_form(`v1/mastertasks/${this.mastertask.id}`, this.mastertask)
else await this.$axios.post_auth_data('v1/mastertasks', this.mastertask)
localStorage.removeItem('mastertaskData')
this.$emit('master-task-edited', this.mastertask)
this.closeModal()
@@ -394,12 +413,14 @@ export default {
})
},
// mastertask: {
// handler(value) {
// console.log(value.description)
// },
// deep: true
// }
mastertask: {
handler(val) {
if (this.editMode && !this.mastertask?.id) {
localStorage.setItem('mastertaskData', JSON.stringify(val))
}
},
deep: true
}
}
}
</script>
+30 -3
View File
@@ -158,8 +158,6 @@ import ATimeblock from './_components/a-timeblock.vue'
import { mapGetters } from 'vuex'
import modalMixin from '@/plugins/tm@modal/_mixins/modal.mixin'
import axios from 'axios'
export default {
emits: ['close', 'refresh'],
mixins: [VuetifyFixFocusMixin, SelectsMixin, AutocompleteMixin, modalMixin],
@@ -275,7 +273,25 @@ export default {
this.subtask = this._enrichTask(data)
} else {
this.subtask = { master_task: mastertask, employees: [{}], _deadline_time: '17:00' }
const savedSubtask = localStorage.getItem('subtaskData')
try {
if (savedSubtask) {
const parsedSubtask = JSON.parse(savedSubtask)
this.subtask = parsedSubtask
// If the parsed result is not an object, reset to default
if (typeof this.subtask !== 'object' || this.subtask === null) {
throw new Error('Parsed subtask is not an object')
}
this.$nextTick(() => {
this.$refs['description']?.setHTML(this.subtask.description || '');
})
} else {
throw new Error('subtaskData is null or undefined')
}
} catch (error) {
console.error('Error parsing subtaskData:', error);
this.subtask = { master_task: mastertask, employees: [{}], _deadline_time: '17:00' }
}
if (subtask?.deadline && subtask._deadline_time && subtask.employee_id) {
const employee = this.enrichedEmployees.find(employee => employee.id == subtask.employee_id)
@@ -326,6 +342,7 @@ export default {
})
const { subtask } = await this.$axios.patch_auth_form(`v1/subtasks/${this.subtask.id}`, { ...this.subtask, timesheets })
localStorage.removeItem('subtaskData')
this.$store.commit('tm/update_subtask', subtask)
this.$events.emit('on-subtask-edited', this.subtask)
@@ -337,6 +354,7 @@ export default {
const subtaskCopy = this.subtask
delete subtaskCopy._master_task
const { subtasks } = await this.$axios.post_auth(`v1/mastertasks/${this.subtask.master_task_id}/subtasks`, subtaskCopy)
localStorage.removeItem('subtaskData')
this.subtask.id = subtasks[0].id
subtasks.forEach((subtask) => {
@@ -459,6 +477,15 @@ export default {
this.$nextTick(() => {
this.$refs['description']?.setHTML(this.subtask.description || '')
})
},
subtask: {
handler(val) {
if (this.editMode && !this.subtask?.id) {
localStorage.setItem('subtaskData', JSON.stringify(val))
}
},
deep: true
}
}
}