diff --git a/app/src/plugins/tm@dashboard/_components/z-timeline.vue b/app/src/plugins/tm@dashboard/_components/z-timeline.vue index 0d2646b..1c39d94 100644 --- a/app/src/plugins/tm@dashboard/_components/z-timeline.vue +++ b/app/src/plugins/tm@dashboard/_components/z-timeline.vue @@ -223,13 +223,38 @@ export default { this.$events.emit('show-complete-task-modal', { subtask }) }, + // async toggleTimeblockIsFinished(event) { + // if (!event.timeblock.is_finished) + // this.$events.emit('show-task-add-time-modal', { subtask: event.subtask }) + + // try { + // await this.$axios.put_auth(`v1/timeblocks/${event._timeblock_id}`, {is_finished: !event.timeblock.is_finished}) + // // TODO: Co mi to vrati? A updatenut + // } catch (error) { + // this.$toast.error(error.message || error) + // } + // }, + async toggleTimeblockIsFinished(event) { - if (!event.timeblock.is_finished) - this.$events.emit('show-task-add-time-modal', { subtask: event.subtask }) + const subtask = event.subtask + const timeblock = subtask.timeblocks.find(originalTimeblock => originalTimeblock.id == event._timeblock_id) + + timeblock.is_finished = timeblock.is_finished ? 0 : 1 try { - await this.$axios.put_auth(`v1/timeblocks/${event._timeblock_id}`, {is_finished: !event.timeblock.is_finished}) - // TODO: Co mi to vrati? A updatenut + const {data: newTimeblock} = await this.$axios.put_auth(`v1/timeblocks/${timeblock.id}`, timeblock) + + subtask.timeblocks = subtask.timeblocks.map(originalTimeblock => { + if (originalTimeblock.id == newTimeblock.id) + return newTimeblock + + return originalTimeblock + }) + + this.$events.emit('on-subtask-edited', subtask) + + if (timeblock.is_finished) + this.$events.emit('show-task-add-time-modal', { subtask }) } catch (error) { this.$toast.error(error.message || error) } diff --git a/app/src/plugins/tm@modal/task/_components/_components/a-task-timeblocks.vue b/app/src/plugins/tm@modal/task/_components/_components/a-task-timeblocks.vue index 31b0914..b1d707a 100644 --- a/app/src/plugins/tm@modal/task/_components/_components/a-task-timeblocks.vue +++ b/app/src/plugins/tm@modal/task/_components/_components/a-task-timeblocks.vue @@ -53,6 +53,8 @@ import Datepicker from '@vuepic/vue-datepicker' import moment from 'moment' export default { + emits: ['update-subtask'], + components: { Datepicker }, @@ -119,16 +121,23 @@ export default { const subtask = JSON.parse(JSON.stringify(this.subtask)) const timeblock = JSON.parse(JSON.stringify(originalTimeblock)) - console.log(subtask) - console.log(timeblock) - if (!timeblock.is_finished) - this.$events.emit('show-task-add-time-modal', { subtask }) - - timeblock.is_finished = !timeblock.is_finished + timeblock.is_finished = timeblock.is_finished == 1 ? 0 : 1 try { - await this.$axios.put_auth(`v1/timeblocks/${timeblock.id}`, timeblock) - // TODO: Co mi to vrati? A updatenut + const {data: newTimeblock} = await this.$axios.put_auth(`v1/timeblocks/${timeblock.id}`, timeblock) + + subtask.timeblocks = subtask.timeblocks.map(originalTimeblock => { + if (originalTimeblock.id == newTimeblock.id) + return newTimeblock + + return originalTimeblock + }) + + this.$events.emit('on-subtask-edited', subtask) + this.$emit('update-subtask', subtask) + + if (timeblock.is_finished) + this.$events.emit('show-task-add-time-modal', { subtask }) } catch (error) { this.$toast.error(error.message || error) } diff --git a/app/src/plugins/tm@modal/task/_components/z-task-readonly-info.vue b/app/src/plugins/tm@modal/task/_components/z-task-readonly-info.vue index ad24549..1887303 100644 --- a/app/src/plugins/tm@modal/task/_components/z-task-readonly-info.vue +++ b/app/src/plugins/tm@modal/task/_components/z-task-readonly-info.vue @@ -1,7 +1,7 @@