tasks and teams overview subheader refactor

This commit is contained in:
Filip Kaluža committed 2023-01-12 18:22:48 +01:00
1 parent c542ea7760
commit a05d69eedc
4 files changed
+68 -32

No files matched your search

@@ -33,9 +33,9 @@ import { addDays, subDays } from 'date-fns'
export default { export default {
props: { props: {
unscheduledTime: { unscheduledTime: {
type: Number, type: String,
default() { default() {
return 0 return '0'
} }
} }
}, },
@@ -59,11 +59,17 @@ export default {
}, },
created() { created() {
this._getEmployees() this._getData()
this._getWeek()
}, },
methods: { methods: {
async _getData() {
await this._getEmployees()
this._getWeek()
this.$nextTick(() => {
this.$emit('dataChanged', {firstDay: this.firstDay, employeeId: this.selectedEmployee})
})
},
async _getEmployees() { async _getEmployees() {
this.employees = await this.$axios.get_auth_data('v1/employees') this.employees = await this.$axios.get_auth_data('v1/employees')
this.employees.forEach(employee => { this.employees.forEach(employee => {
@@ -71,12 +77,12 @@ export default {
}) })
}, },
_getWeek() { _getWeek(emitDataChanged = true) {
this.firstDay = subDays(this.date, 1) this.firstDay = subDays(this.date, 1)
this.lastDay = addDays(this.date, 5) this.lastDay = addDays(this.date, 5)
this.$emit('weekChange', {firstDay: this.firstDay, lastDay: this.lastDay})
this.selectedDate = String(this.firstDay.toLocaleDateString('sk-SK') + ' - ' + this.lastDay.toLocaleDateString('sk-SK')) this.selectedDate = String(this.firstDay.toLocaleDateString('sk-SK') + ' - ' + this.lastDay.toLocaleDateString('sk-SK'))
if (emitDataChanged) this.$emit('dataChanged', {firstDay: this.firstDay, employeeId: this.selectedEmployee})
}, },
prevWeek() { prevWeek() {
@@ -88,6 +94,12 @@ export default {
this.date = addDays(this.date, 7) this.date = addDays(this.date, 7)
this._getWeek() this._getWeek()
} }
},
watch: {
selectedTeam() {
this.$emit('dataChanged', {firstDay: this.firstDay, employeeId: this.selectedEmployee})
}
} }
} }
</script> </script>
+8 -7
View File
@@ -1,6 +1,6 @@
<template> <template>
<div> <div>
<A-task-filter :unscheduledTime="unscheduledTime" @weekChange="getWeekData" /> <A-task-filter :unscheduledTime="unscheduledTime" @dataChanged="getTimelineData" />
<W-loadable :content="timelineData" class="w-loadable" empty-message="Nepodarilo sa nacitat data!"> <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" @deleteTask="deleteTask" /> <Z-timeline :calData="timelineData" :calConfig="config" :splits="splitDays" @eventMoved="onEventMoved" @completeTask="completeTask" @deleteTask="deleteTask" />
@@ -33,13 +33,14 @@ export default {
}, },
methods: { methods: {
async getWeekData(week) { async getTimelineData(data) {
this.config.date = week.firstDay this.config.date = data.firstDay
const lastDay = addDays(data.firstDay, 6)
try { try {
this.timelineData = await this.$axios.get_auth_data('v1/overview/tasks') this.timelineData = await this.$axios.get_auth_data('v1/overview/tasks', {firstDay: data.firstDay, lastDay: lastDay, employeeId: data.employeeId})
this.formatTimelineDataToTimelineFormat(week.firstDay) this.formatTimelineDataToTimelineFormat(data.firstDay)
this.generateDays(week.firstDay) this.generateDays(data.firstDay)
this.generateNonWorkingHours(week.firstDay) this.generateNonWorkingHours(data.firstDay)
} catch (error) { } catch (error) {
this.timelineData = {error: error || 'Nepodarilo sa nacitat data!'} this.timelineData = {error: error || 'Nepodarilo sa nacitat data!'}
console.error(error) console.error(error)
@@ -1,9 +1,9 @@
<template> <template>
<v-row class="px-10 py-8 subheader"> <v-row class="px-10 py-8 subheader">
<v-select <v-select
v-model="selectedEmployee" v-model="selectedTeam"
class="subheader-input" class="subheader-input"
:items="teams" :items="teamsNames"
label="Tím" label="Tím"
variant="outlined" variant="outlined"
></v-select> ></v-select>
@@ -33,9 +33,9 @@ import { addDays, subDays } from 'date-fns'
export default { export default {
props: { props: {
unscheduledTime: { unscheduledTime: {
type: Number, type: String,
default() { default() {
return 0 return '0'
} }
} }
}, },
@@ -43,26 +43,43 @@ export default {
data() { data() {
return { return {
// Kaluza: Napojit funkcionalitu // Kaluza: Napojit funkcionalitu
teams: ['Foo', 'Bar', 'Fizz', 'Buzz'], teams: [],
teamsNames: [],
selectedTeam: '',
selectedDate: new Date(), selectedDate: new Date(),
day: new Date(), day: new Date(),
selectedEmployee: 'Bar',
date: new Date() date: new Date()
} }
}, },
created() {
this.getDay()
},
computed: { computed: {
time() { time() {
return this.unscheduledTime return this.unscheduledTime
} }
}, },
created() {
this._getData()
},
methods: { methods: {
getDay() { async _getData() {
await this._getTeams()
this._getDay(false)
this.$nextTick(() => {
this.$emit('dataChanged', {date: this.day, teamId: this.selectedTeam})
})
},
async _getTeams() {
this.teams = await this.$axios.get_auth_data('v1/teams')
this.teams.forEach(team => {
this.teamsNames.push(team.name)
})
},
_getDay(emitDataChanged = true) {
const today = new Date() const today = new Date()
const yesterday = new Date((new Date()).setDate(today.getDate() - 1)) const yesterday = new Date((new Date()).setDate(today.getDate() - 1))
const tomorrow = new Date((new Date()).setDate(today.getDate() + 1)) const tomorrow = new Date((new Date()).setDate(today.getDate() + 1))
@@ -72,17 +89,23 @@ export default {
else if (tomorrow.toLocaleDateString('sk-SK') === this.day.toLocaleDateString('sk-SK')) this.selectedDate = "Zajtra" else if (tomorrow.toLocaleDateString('sk-SK') === this.day.toLocaleDateString('sk-SK')) this.selectedDate = "Zajtra"
else this.selectedDate = String(this.day.toLocaleDateString('sk-SK')) else this.selectedDate = String(this.day.toLocaleDateString('sk-SK'))
this.$emit('dayChanged', this.day) if (emitDataChanged) this.$emit('dataChanged', {date: this.day, teamId: this.selectedTeam})
}, },
prevDay() { prevDay() {
this.day = subDays(this.day, 1) this.day = subDays(this.day, 1)
this.getDay() this._getDay()
}, },
nextDay() { nextDay() {
this.day = addDays(this.day, 1) this.day = addDays(this.day, 1)
this.getDay() this._getDay()
}
},
watch: {
selectedTeam() {
this.$emit('dataChanged', {date: this.day, teamId: this.selectedTeam})
} }
} }
} }
+5 -5
View File
@@ -1,6 +1,6 @@
<template> <template>
<div> <div>
<A-team-filter :unscheduledTime="unscheduledTime" @dayChanged="getDayData" /> <A-team-filter :unscheduledTime="unscheduledTime" @dataChanged="getTimelineData" />
<W-loadable :content="timelineData" class="w-loadable" empty-message="Nepodarilo sa nacitat data!"> <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" @deleteTask="deleteTask" /> <Z-timeline :calData="timelineData" :calConfig="config" :splits="splitDays" @eventMoved="onEventMoved" @completeTask="completeTask" @deleteTask="deleteTask" />
@@ -37,13 +37,13 @@ export default {
}, },
methods: { methods: {
async getDayData(date) { async getTimelineData(data) {
this.config.date = date this.config.date = data.date
try { try {
this.timelineData = await this.$axios.get_auth_data('v1/overview/teams') this.timelineData = await this.$axios.get_auth_data('v1/overview/teams', {date: data.date, team: data.teamId})
this.generateEmployees() this.generateEmployees()
this.formatTimelineDataToTimelineFormat() this.formatTimelineDataToTimelineFormat()
this.generateNonWorkingHours(date) this.generateNonWorkingHours(data.date)
} catch(error) { } catch(error) {
this.timelineData = {error: error || 'Nepodarilo sa nacitat data!'} this.timelineData = {error: error || 'Nepodarilo sa nacitat data!'}
console.error(error) console.error(error)