[tm@store] Added store

This commit is contained in:
Matej Glasnák committed 2023-02-15 15:56:24 +01:00
1 parent a1a410c54d
commit 774ca7b607
44 files changed
+989 -720

No files matched your search

@@ -1,13 +1,12 @@
<template>
<div>
<W-loadable :content="masterTasks" empty-message="Nepodarilo sa nacitat data!">
<A-project-filter :projects="projects" :teams="teams" :employees="employees" @filterChanged="onFilterChanged" />
<A-project-calendar :events="filteredEvents" :month="filter.selectedMonth" @open-detail="openMasterTaskModal" />
</W-loadable>
</div>
<W-loadable :content="filteredEvents" empty-message="Nepodarilo sa nacitat data!">
<A-project-filter :projects="projects" :teams="teams" :employees="employees" @filterChanged="onFilterChanged" />
<A-project-calendar :events="filteredEvents" :month="filter.selectedMonth" @open-detail="openMasterTaskModal" />
</W-loadable>
</template>
<script>
import { mapGetters } from 'vuex'
import AProjectCalendar from './_components/a-project-calendar.vue'
import AProjectFilter from './_components/a-project-filter.vue'
@@ -18,10 +17,6 @@ export default {
},
data() {
return {
projects: null,
masterTasks: null,
teams: null,
employees: null,
selectedProject: null,
filter: {
selectedMonth: new Date().getMonth()
@@ -30,12 +25,25 @@ export default {
},
computed: {
...mapGetters('tm', [
'employees',
'mastertasks',
'teams',
'projects'
]),
filteredEvents() {
if (!this.masterTasks || this.masterTasks.error)
if (!this.mastertasks)
return null
if (this.mastertasks.error)
return this.mastertasks
if (!this.mastertasks.length)
return []
// duplicate all tasks
let events = this.masterTasks
let events = this.mastertasks
// show/hide finished tasks
if (!this.filter.showFinishedTasks)
@@ -55,8 +63,6 @@ export default {
// format masterTasks to event format for calendar
events = events.map(event => {
const color = this._stringToHexColor(event.color)
return {
id: event.id,
title: `${event.project_code} - ${event.name}`,
@@ -65,8 +71,8 @@ export default {
end: new Date(event.deadline),
is_finished: event.is_finished,
project_code: event.project_code,
backgroundColor: `${color}CC`,
borderColor: color
backgroundColor: `${event.color}`,
borderColor: event.color
}
})
@@ -74,56 +80,25 @@ export default {
}
},
created() {
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-deleted', (masterTask) => {
// this.mastertasks = this.mastertasks.filter(mt => mt.id != masterTask.id)
// })
this.$events.on('on-master-task-edited', (masterTask) => {
this.masterTasks = this.masterTasks.map(mTask => mTask.id == masterTask.id ? masterTask : mTask)
this._getData()
})
// this.$events.on('on-master-task-edited', (masterTask) => {
// this.mastertasks = this.mastertasks.map(mTask => mTask.id == masterTask.id ? masterTask : mTask)
// this._getData()
// })
},
methods: {
async _getData() {
try {
this.teams = await this.$axios.get_auth_data('v1/teams')
this.projects = await this.$axios.get_auth_data('v1/projects')
this.employees = await this.$axios.get_auth_data('v1/employees')
this.masterTasks = await this.$axios.get_auth_data('v1/mastertasks')
} catch (error) {
this.masterTasks = {error}
}
},
onFilterChanged(filterValues) {
this.filter = filterValues
},
openMasterTaskModal(masterTaskId) {
const masterTask = this.masterTasks.find(masterTask => masterTask.id == masterTaskId)
console.log(masterTask)
const masterTask = this.mastertasks.find(masterTask => masterTask.id == masterTaskId)
this.$events.emit('show-master-task-modal', {masterTask, editMode: false})
},
_stringToHexColor(string) {
let hash = 0
for (let i = 0; i < string.length; i++) {
hash = string.charCodeAt(i) + ((hash << 5) - hash)
}
let color = '#'
for (let i = 0; i < 3; i++) {
let value = (hash >> (i * 8)) & 0xFF
color += ('00' + value.toString(16)).substr(-2)
}
return color
}
}
}