Newer
Older
/* Vuex store, for centralized state management */
import Vue from 'vue';
import Vuex from 'vuex';
Sonia Zorba
committed
import router from './router.js';
Vue.use(Vuex);
export default new Vuex.Store({
state: {
// values populated from API calls
Sonia Zorba
committed
model: {
breadcrumbs: [],
groupsPanel: null,
permissionsPanel: null,
membersPanel: null,
permission: null,
Sonia Zorba
committed
genericSearchResults: {},
Sonia Zorba
committed
user: null,
Sonia Zorba
committed
},
// values used to perform API calls
input: {
selectedGroupId: 'ROOT',
paginatorPageSize: 20,
paginatorPage: 1,
Sonia Zorba
committed
},
Sonia Zorba
committed
loading: false
},
mutations: {
Sonia Zorba
committed
updateHomePageModel(state, model) {
Sonia Zorba
committed
state.model.breadcrumbs = model.breadcrumbs;
state.model.groupsPanel = model.groupsPanel;
state.model.permission = model.permission;
state.model.user = model.user;
Sonia Zorba
committed
state.model.breadcrumbs = model.breadcrumbs;
state.model.groupsPanel = model.groupsPanel;
state.model.permission = model.permission;
state.model.leaf = model.leaf;
Sonia Zorba
committed
state.model.groupsPanel = groupsPanel;
state.input.paginatorPage = groupsPanel.currentPage;
updatePermissionsPanel(state, permissionsPanel) {
Sonia Zorba
committed
state.model.permissionsPanel = permissionsPanel;
for(let up of permissionsPanel.items) {
Vue.set(up, 'editable', false);
}
state.input.paginatorPage = permissionsPanel.currentPage;
},
togglePermissionEditable(state, index) {
let up = state.model.permissionsPanel.items[index];
up.editable = !up.editable;
},
updateMembersPanel(state, membersPanel) {
Sonia Zorba
committed
state.model.membersPanel = membersPanel;
state.input.paginatorPage = membersPanel.currentPage;
Sonia Zorba
committed
},
setTabIndex(state, tabIndex) {
// this will trigger the tabChanged() method in Main.vue
Sonia Zorba
committed
state.input.tabIndex = tabIndex;
Sonia Zorba
committed
},
setLoading(state, loading) {
Sonia Zorba
committed
state.loading = loading;
},
displaySearchResults(state, results) {
if (results) {
Sonia Zorba
committed
state.model.genericSearchResults = results;
Sonia Zorba
committed
state.model.genericSearchResults = results;
},
setUserSearchModel(state, model) {
state.model.userSearchResults.user = model.user;
state.model.userSearchResults.groups = model.groups;
state.model.userSearchResults.permissions = model.permissions;
Sonia Zorba
committed
setGenericSearchFilter(state, filter) {
state.input.genericSearch.filter = filter;
}
},
actions: {
Sonia Zorba
committed
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
loadHomePageModel({ commit, state }) {
client.fetchHomePageModel(state.input)
.then(model => commit('updateHomePageModel', model));
},
search({ commit, state }, filter) {
commit('setGenericSearchFilter', filter);
client.search(state.input)
.then(results => commit('displaySearchResults', results));
},
changeTab({ commit, state }, tabIndex) {
state.input.tabIndex = tabIndex;
// reset paginator
state.input.paginatorPage = 1;
switch (tabIndex) {
case 0:
client.fetchGroupsTab(state.input)
.then(model => commit('updateGroups', model));
break;
case 1:
client.fetchMembersPanel(state.input)
.then(panel => commit('updateMembersPanel', panel));
break;
case 2:
client.fetchPermissionsPanel(state.input)
.then(panel => commit('updatePermissionsPanel', panel));
break;
}
},
openGroup({ commit, dispatch, state }, groupId) {
let input = state.input;
input.selectedGroupId = groupId;
input.searchFilter = '';
client.fetchGroupsTab(input)
Sonia Zorba
committed
commit('updateGroups', model);
if (model.leaf) {
// If there are no subgroups show the members panel
dispatch('changeTab', 1);
} else {
dispatch('changeTab', 0);
}
router.push('/', () => {});
Sonia Zorba
committed
},
openUserPage({ commit }, userId) {
client.openUserSearchResult(userId)
.then(model => commit('setUserSearchModel', model));
}
},
getters: {
selectedGroupId: state => {
return state.model.breadcrumbs[state.model.breadcrumbs.length - 1].groupId;
}
}
});