mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-07 18:44:08 +00:00
store all makeFetch, with isLoaded check
This commit is contained in:
parent
e4629ed599
commit
2144b247b3
@ -78,7 +78,7 @@ import MyEvaluations from './MyEvaluations';
|
|||||||
import MyTasks from './MyTasks';
|
import MyTasks from './MyTasks';
|
||||||
import MyAccompanyingCourses from './MyAccompanyingCourses';
|
import MyAccompanyingCourses from './MyAccompanyingCourses';
|
||||||
import MyNotifications from './MyNotifications';
|
import MyNotifications from './MyNotifications';
|
||||||
import { mapState, mapGetters } from "vuex";
|
import { mapState } from "vuex";
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: "App",
|
name: "App",
|
||||||
@ -99,8 +99,10 @@ export default {
|
|||||||
...mapState([
|
...mapState([
|
||||||
'loading',
|
'loading',
|
||||||
]),
|
]),
|
||||||
...mapGetters([
|
// just to see all in devtool :
|
||||||
])
|
...mapState({
|
||||||
|
state: (state) => state,
|
||||||
|
}),
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
selectTab(tab) {
|
selectTab(tab) {
|
||||||
|
@ -3,8 +3,18 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
|
import { mapState, mapGetters } from "vuex";
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: "MyEvaluations"
|
name: "MyEvaluations",
|
||||||
|
computed: {
|
||||||
|
...mapState([
|
||||||
|
'evaluations',
|
||||||
|
]),
|
||||||
|
...mapGetters([
|
||||||
|
'isEvaluationsLoaded',
|
||||||
|
])
|
||||||
|
},
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
@ -3,8 +3,18 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
|
import { mapState, mapGetters } from "vuex";
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: "MyNotifications"
|
name: "MyNotifications",
|
||||||
|
computed: {
|
||||||
|
...mapState([
|
||||||
|
'notifications',
|
||||||
|
]),
|
||||||
|
...mapGetters([
|
||||||
|
'isNotificationsLoaded',
|
||||||
|
])
|
||||||
|
},
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
@ -3,8 +3,19 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
|
import { mapState, mapGetters } from "vuex";
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: "MyTasks"
|
name: "MyTasks",
|
||||||
|
computed: {
|
||||||
|
...mapState([
|
||||||
|
'tasks',
|
||||||
|
]),
|
||||||
|
...mapGetters([
|
||||||
|
'isTasksWarningLoaded',
|
||||||
|
'isTasksAlertLoaded',
|
||||||
|
])
|
||||||
|
},
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
@ -3,8 +3,18 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
|
import { mapState, mapGetters } from "vuex";
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: "MyWorks"
|
name: "MyWorks",
|
||||||
|
computed: {
|
||||||
|
...mapState([
|
||||||
|
'works',
|
||||||
|
]),
|
||||||
|
...mapGetters([
|
||||||
|
'isWorksLoaded',
|
||||||
|
])
|
||||||
|
},
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
@ -1,6 +1,12 @@
|
|||||||
import 'es6-promise/auto';
|
import 'es6-promise/auto';
|
||||||
import { createStore } from 'vuex';
|
import { createStore } from 'vuex';
|
||||||
import { makeFetch } from "ChillMainAssets/lib/api/apiMethods";
|
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';
|
const debug = process.env.NODE_ENV !== 'production';
|
||||||
|
|
||||||
@ -13,20 +19,62 @@ const isEmpty = (obj) => {
|
|||||||
const store = createStore({
|
const store = createStore({
|
||||||
strict: debug,
|
strict: debug,
|
||||||
state: {
|
state: {
|
||||||
|
works: {},
|
||||||
|
evaluations: {},
|
||||||
|
tasks: {
|
||||||
|
warning: {},
|
||||||
|
alert: {}
|
||||||
|
},
|
||||||
accompanyingCourses: {},
|
accompanyingCourses: {},
|
||||||
|
notifications: {},
|
||||||
errorMsg: [],
|
errorMsg: [],
|
||||||
loading: false
|
loading: false
|
||||||
},
|
},
|
||||||
getters: {
|
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) {
|
isAccompanyingCoursesLoaded(state) {
|
||||||
return !isEmpty(state.accompanyingCourses);
|
return !isEmpty(state.accompanyingCourses);
|
||||||
},
|
},
|
||||||
|
isNotificationsLoaded(state) {
|
||||||
|
return !isEmpty(state.notifications);
|
||||||
|
},
|
||||||
},
|
},
|
||||||
mutations: {
|
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) {
|
addCourses(state, courses) {
|
||||||
console.log('addCourses', courses);
|
console.log('addCourses', courses);
|
||||||
state.accompanyingCourses = courses;
|
state.accompanyingCourses = courses;
|
||||||
},
|
},
|
||||||
|
addNotifications(state, notifications) {
|
||||||
|
console.log('addNotifications', notifications);
|
||||||
|
state.notifications = notifications;
|
||||||
|
},
|
||||||
setLoading(state, bool) {
|
setLoading(state, bool) {
|
||||||
state.loading = bool;
|
state.loading = bool;
|
||||||
},
|
},
|
||||||
@ -37,10 +85,73 @@ const store = createStore({
|
|||||||
actions: {
|
actions: {
|
||||||
getByTab({ commit, getters }, tab) {
|
getByTab({ commit, getters }, tab) {
|
||||||
switch (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':
|
case 'MyAccompanyingCourses':
|
||||||
if (!getters.isAccompanyingCoursesLoaded) {
|
if (!getters.isAccompanyingCoursesLoaded) {
|
||||||
commit('setLoading', true);
|
commit('setLoading', true);
|
||||||
const url = `/api/1.0/person/accompanying-period/work/my-near-end`;
|
const url = `/api/1.0/`;
|
||||||
makeFetch('GET', url)
|
makeFetch('GET', url)
|
||||||
.then((response) => {
|
.then((response) => {
|
||||||
commit('addCourses', response);
|
commit('addCourses', response);
|
||||||
@ -50,13 +161,27 @@ const store = createStore({
|
|||||||
commit('catchError', error);
|
commit('catchError', error);
|
||||||
throw error;
|
throw error;
|
||||||
})
|
})
|
||||||
|
;
|
||||||
}
|
}
|
||||||
break;
|
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;
|
break;
|
||||||
default:
|
default:
|
||||||
throw 'tab '+ tab;
|
throw 'tab '+ tab;
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
Loading…
x
Reference in New Issue
Block a user