diff --git a/src/Bundle/ChillMainBundle/Resources/public/vuejs/HomepageWidget/App.vue b/src/Bundle/ChillMainBundle/Resources/public/vuejs/HomepageWidget/App.vue index 973dacad6..d357a2b00 100644 --- a/src/Bundle/ChillMainBundle/Resources/public/vuejs/HomepageWidget/App.vue +++ b/src/Bundle/ChillMainBundle/Resources/public/vuejs/HomepageWidget/App.vue @@ -78,7 +78,7 @@ import MyEvaluations from './MyEvaluations'; import MyTasks from './MyTasks'; import MyAccompanyingCourses from './MyAccompanyingCourses'; import MyNotifications from './MyNotifications'; -import { mapState, mapGetters } from "vuex"; +import { mapState } from "vuex"; export default { name: "App", @@ -99,8 +99,10 @@ export default { ...mapState([ 'loading', ]), - ...mapGetters([ - ]) + // just to see all in devtool : + ...mapState({ + state: (state) => state, + }), }, methods: { selectTab(tab) { diff --git a/src/Bundle/ChillMainBundle/Resources/public/vuejs/HomepageWidget/MyEvaluations.vue b/src/Bundle/ChillMainBundle/Resources/public/vuejs/HomepageWidget/MyEvaluations.vue index 019628a28..1998e2fac 100644 --- a/src/Bundle/ChillMainBundle/Resources/public/vuejs/HomepageWidget/MyEvaluations.vue +++ b/src/Bundle/ChillMainBundle/Resources/public/vuejs/HomepageWidget/MyEvaluations.vue @@ -3,8 +3,18 @@ diff --git a/src/Bundle/ChillMainBundle/Resources/public/vuejs/HomepageWidget/MyNotifications.vue b/src/Bundle/ChillMainBundle/Resources/public/vuejs/HomepageWidget/MyNotifications.vue index a8b811fbd..78e0fdb0f 100644 --- a/src/Bundle/ChillMainBundle/Resources/public/vuejs/HomepageWidget/MyNotifications.vue +++ b/src/Bundle/ChillMainBundle/Resources/public/vuejs/HomepageWidget/MyNotifications.vue @@ -3,8 +3,18 @@ diff --git a/src/Bundle/ChillMainBundle/Resources/public/vuejs/HomepageWidget/MyTasks.vue b/src/Bundle/ChillMainBundle/Resources/public/vuejs/HomepageWidget/MyTasks.vue index c61cf51b2..0378ea092 100644 --- a/src/Bundle/ChillMainBundle/Resources/public/vuejs/HomepageWidget/MyTasks.vue +++ b/src/Bundle/ChillMainBundle/Resources/public/vuejs/HomepageWidget/MyTasks.vue @@ -3,8 +3,19 @@ diff --git a/src/Bundle/ChillMainBundle/Resources/public/vuejs/HomepageWidget/MyWorks.vue b/src/Bundle/ChillMainBundle/Resources/public/vuejs/HomepageWidget/MyWorks.vue index 9f7f71bc4..b3bfdbbb7 100644 --- a/src/Bundle/ChillMainBundle/Resources/public/vuejs/HomepageWidget/MyWorks.vue +++ b/src/Bundle/ChillMainBundle/Resources/public/vuejs/HomepageWidget/MyWorks.vue @@ -3,8 +3,18 @@ diff --git a/src/Bundle/ChillMainBundle/Resources/public/vuejs/HomepageWidget/js/store.js b/src/Bundle/ChillMainBundle/Resources/public/vuejs/HomepageWidget/js/store.js index b9888da7b..991486dab 100644 --- a/src/Bundle/ChillMainBundle/Resources/public/vuejs/HomepageWidget/js/store.js +++ b/src/Bundle/ChillMainBundle/Resources/public/vuejs/HomepageWidget/js/store.js @@ -1,6 +1,12 @@ import 'es6-promise/auto'; import { createStore } from 'vuex'; import { makeFetch } from "ChillMainAssets/lib/api/apiMethods"; +import MyCustoms from "../MyCustoms"; +import MyWorks from "../MyWorks"; +import MyEvaluations from "../MyEvaluations"; +import MyTasks from "../MyTasks"; +import MyAccompanyingCourses from "../MyAccompanyingCourses"; +import MyNotifications from "../MyNotifications"; const debug = process.env.NODE_ENV !== 'production'; @@ -13,20 +19,62 @@ const isEmpty = (obj) => { const store = createStore({ strict: debug, state: { + works: {}, + evaluations: {}, + tasks: { + warning: {}, + alert: {} + }, accompanyingCourses: {}, + notifications: {}, errorMsg: [], loading: false }, getters: { + isWorksLoaded(state) { + return !isEmpty(state.works); + }, + isEvaluationsLoaded(state) { + return !isEmpty(state.evaluations); + }, + isTasksWarningLoaded(state) { + return !isEmpty(state.tasks.warning); + }, + isTasksAlertLoaded(state) { + return !isEmpty(state.tasks.alert); + }, isAccompanyingCoursesLoaded(state) { return !isEmpty(state.accompanyingCourses); }, + isNotificationsLoaded(state) { + return !isEmpty(state.notifications); + }, }, mutations: { + addWorks(state, works) { + console.log('addWorks', works); + state.works = works; + }, + addEvaluations(state, evaluations) { + console.log('addEvaluations', evaluations); + state.evaluations = evaluations; + }, + addTasksWarning(state, tasks) { + console.log('addTasksWarning', tasks); + state.tasks.warning = tasks; + }, + addTasksAlert(state, tasks) { + console.log('addTasksAlert', tasks); + state.tasks.alert = tasks; + }, addCourses(state, courses) { console.log('addCourses', courses); state.accompanyingCourses = courses; }, + addNotifications(state, notifications) { + console.log('addNotifications', notifications); + state.notifications = notifications; + }, setLoading(state, bool) { state.loading = bool; }, @@ -37,10 +85,73 @@ const store = createStore({ actions: { getByTab({ commit, getters }, tab) { switch (tab) { + case 'MyCustoms': + break; + case 'MyWorks': + if (!getters.isWorksLoaded) { + commit('setLoading', true); + const url = `/api/1.0/person/accompanying-period/work/my-near-end`; + makeFetch('GET', url) + .then((response) => { + commit('addWorks', response); + commit('setLoading', false); + }) + .catch((error) => { + commit('catchError', error); + throw error; + }) + ; + } + break; + case 'MyEvaluations': + if (!getters.isEvaluationsLoaded) { + commit('setLoading', true); + const url = `/api/1.0/person/accompanying-period/work/evaluation/my-near-end`; + makeFetch('GET', url) + .then((response) => { + commit('addEvaluations', response); + commit('setLoading', false); + }) + .catch((error) => { + commit('catchError', error); + throw error; + }) + ; + } + break; + case 'MyTasks': + if (!(getters.isTasksWarningLoaded && getters.isTasksAlertLoaded)) { + commit('setLoading', true); + const + urlWarning = `/api/1.0/task/single-task/list/my?f[q]=&f[checkboxes][status][]=warning&f[checkboxes][states][]=new&f[checkboxes][states][]=in_progress`, + urlAlert = `/api/1.0/task/single-task/list/my?f[q]=&f[checkboxes][status][]=alert&f[checkboxes][states][]=new&f[checkboxes][states][]=in_progress` //&f[f]= + ; + makeFetch('GET', urlWarning) + .then((response) => { + commit('addTasksWarning', response); + commit('setLoading', false); + }) + .catch((error) => { + commit('catchError', error); + throw error; + }) + ; + makeFetch('GET', urlAlert) + .then((response) => { + commit('addTasksAlert', response); + commit('setLoading', false); + }) + .catch((error) => { + commit('catchError', error); + throw error; + }) + ; + } + break; case 'MyAccompanyingCourses': if (!getters.isAccompanyingCoursesLoaded) { commit('setLoading', true); - const url = `/api/1.0/person/accompanying-period/work/my-near-end`; + const url = `/api/1.0/`; makeFetch('GET', url) .then((response) => { commit('addCourses', response); @@ -50,13 +161,27 @@ const store = createStore({ commit('catchError', error); throw error; }) + ; } break; - case 'MyCustoms': + case 'MyNotifications': + if (!getters.isNotificationsLoaded) { + commit('setLoading', true); + const url = `/api/1.0/main/notification/my/unread`; + makeFetch('GET', url) + .then((response) => { + commit('addNotifications', response); + commit('setLoading', false); + }) + .catch((error) => { + commit('catchError', error); + throw error; + }) + ; + } break; default: throw 'tab '+ tab; - } } },