refactor podla review

This commit is contained in:
Filip Kaluža committed 2023-01-12 17:53:35 +01:00
1 parent d46a9151fc
commit c542ea7760
14 files changed
+89 -182

No files matched your search

+28 -70
View File
@@ -3,24 +3,14 @@
<A-task-filter :unscheduledTime="unscheduledTime" @weekChange="getWeekData" />
<W-loadable :content="timelineData" class="w-loadable" empty-message="Nepodarilo sa nacitat data!">
<Z-timeline :calData="timelineData" :calConfig="config" :splits="splitDays" @eventMoved="onEventMoved" @completeTask="completeTask" @reopenTask="reopenTask" @deleteTask="deleteTask" />
<Z-timeline :calData="timelineData" :calConfig="config" :splits="splitDays" @eventMoved="onEventMoved" @completeTask="completeTask" @deleteTask="deleteTask" />
</W-loadable>
<!-- Kaluza: Toto vyhodit a pouzit w toast -->
<v-snackbar
v-model="errorToast"
:timeout="2000"
color="red"
:rounded="true"
>
{{ errorToastMessage }}
</v-snackbar>
</div>
</template>
<script>
import ATaskFilter from './_components/a-tasks-filter.vue'
import ZTimeline from './_components/z-timeline.vue'
import ZTimeline from '@/plugins/tm@dashboard/_components/z-timeline.vue'
import { addDays, setHours, setMinutes, setSeconds, differenceInCalendarDays } from 'date-fns'
@@ -33,12 +23,6 @@ export default {
data() {
return {
timelineData: null,
// Kaluza: Vyhodit tieto toast veci
errorToast: false,
errorToastMessage: "Nepodarilo sa nacitat data!",
dataLoaded: false,
splitDays: [],
unscheduledTime: 0,
config: {
@@ -53,19 +37,17 @@ export default {
this.config.date = week.firstDay
try {
this.timelineData = await this.$axios.get_auth_data('v1/overview/tasks')
this.formatData(week.firstDay)
this.generateSplits(week.firstDay)
this.formatTimelineDataToTimelineFormat(week.firstDay)
this.generateDays(week.firstDay)
this.generateNonWorkingHours(week.firstDay)
} catch(error) {
// Kaluza: Ked to davas do w loadable tak nepouzi toast a iba daj this.timeineData = {error} a loadable ho parsne a zobrazi
this.timelineData = {}
} catch (error) {
this.timelineData = {error: error || 'Nepodarilo sa nacitat data!'}
console.error(error)
this.triggerToast("Nepodarilo sa nacitat data!")
// console.log(this.$store.getters['auth/user'])
}
},
// Kaluza: Toto prosimta premenuj lebo neviem vobec co znamena splits
generateSplits(date) {
generateDays(date) {
this.splitDays = []
for (let i = 0; i < 7; i++) {
this.splitDays.push({
@@ -78,8 +60,7 @@ export default {
}
},
// Kaluza: Toto nazvi nejako inak aby bolo viac jasne ze z coho to preformatovava na co
formatData(date) {
formatTimelineDataToTimelineFormat(date) {
// format events
this.timelineData.tasks.forEach(event => {
event.name = this.timelineData.name
@@ -137,56 +118,33 @@ export default {
this.timelineData.tasks.push(...nonWorkingHours)
},
// Kaluza: Vyhodit
triggerToast(message) {
this.errorToastMessage = message
this.errorToast = true
},
// Kaluza: Vyhodit ak sa nepouzije
async onEventMoved(event) {
console.log("drag", event)
// try {
// const newStartDate = addDays(event.event.start, differenceInCalendarDays(this.splitDays.filter((split) => {return split.id == event.newSplit})[0].date, event.event.start))
// const newEndDate = addDays(event.event.end, differenceInCalendarDays( newStartDate, event.event.start))
// await this.$axios.post_auth_data(`v1/overview/tasks/${event.event.id}`, {start: newStartDate, end: newEndDate})
// } catch(error) {
// this.triggerToast("Nepodarilo sa presunut ulohu!")
// this.timelineData.tasks.filter(e => {
// if (e.id == event.event.id) {
// e.start = new Date(event.originalEvent.start)
// e.end = new Date(event.originalEvent.end)
// }
// })
// }
const task = this.timelineData.tasks.find(task => task.id == event.event.id)
try {
const newStartDate = addDays(event.event.start, differenceInCalendarDays(this.splitDays.filter((split) => {return split.id == event.newSplit})[0].date, event.event.start))
const newEndDate = addDays(event.event.end, differenceInCalendarDays( newStartDate, event.event.start))
// await this.$axios.post_auth_data(`v1/overview/tasks/${event.event.id}`, {start: newStartDate, end: newEndDate})
task.start = newStartDate
task.end = newEndDate
task.split = event.newSplit
} catch(error) {
this.$toast.error(error)
task.start = new Date(event.originalEvent.start)
task.end = new Date(event.originalEvent.end)
task.split = event.oldSplit
}
},
completeTask(id) {
// Kaluza: Tu pridaj request na BE, nepouzi filter ale find a sprav to takto
// 1. const task = this.timelineData.tasks.find(task => task.id == id)
// 2. task.completed = true
// 3. V tryCatch zavolaj request na BE
// 4. Ak to spadne do catchu tak daj task.completed = false a pod tym daj this.$toast.error(error)
// A AKO NAD TYM ROZMYSLAM completeTask A reopenTask MOZES SPOJIT DO JEDNEJ A VZDY LEN DAS task.completed = !task.completed
this.timelineData.tasks.filter(task => {
if (task.id == id) {
task.completed = true
}
})
},
reopenTask(id) {
// Kaluza: Toto rovnakym sposobom ako complete task
this.timelineData.tasks.filter(task => {
if (task.id == id) {
task.completed = false
}
})
const task = this.timelineData.tasks.find(task => task.id == id)
task.completed = !task.completed
},
deleteTask(id) {
// Kaluza: Toto rovnako ako complete a reopen
this.timelineData.tasks.splice(this.timelineData.tasks.findIndex(item => item.id === id), 1)
}
}