Refresh
This commit is contained in:
137
resources/js/store/modules/groups/actions.js
vendored
Executable file
137
resources/js/store/modules/groups/actions.js
vendored
Executable file
@@ -0,0 +1,137 @@
|
||||
/**
|
||||
* Actions on groups
|
||||
*/
|
||||
export default {
|
||||
/*
|
||||
* -------------------------------------------------------------------------
|
||||
* ----| CRUD |-------------------------------------------------------------
|
||||
* -------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
/**
|
||||
* Display a listing of the resource - Groups in which user is active
|
||||
*/
|
||||
async indexActive({ commit }) {
|
||||
const data = await api.get(route("group.index_active"));
|
||||
|
||||
commit("setGroups", data);
|
||||
},
|
||||
|
||||
/**
|
||||
* Display a listing of the resource - Groups associated with this user
|
||||
*/
|
||||
async indexMyGroups({ commit }) {
|
||||
const data = await api.get(route("group.my_groups"));
|
||||
|
||||
commit("setGroups", data);
|
||||
},
|
||||
|
||||
/**
|
||||
* Display the specified resource.
|
||||
*/
|
||||
show({ getters, dispatch, rootGetters }, { group, folder }) {
|
||||
const currentSelectedGroup = getters.selectedGroup;
|
||||
|
||||
if (!group) {
|
||||
group = currentSelectedGroup;
|
||||
} else if (Number.isInteger(group)) {
|
||||
group = getters.groups.find((g) => g.id === group);
|
||||
}
|
||||
|
||||
dispatch("selectGroup", group);
|
||||
|
||||
dispatch("documents/selectDocuments", [], { root: true });
|
||||
|
||||
api.get(route("group.show", group)).then(function (folders) {
|
||||
if (folder) {
|
||||
dispatch(
|
||||
"folders/index",
|
||||
{ folders: folders, show: folder },
|
||||
{ root: true }
|
||||
);
|
||||
} else {
|
||||
dispatch("folders/index", { folders: folders }, { root: true });
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
/**
|
||||
* Mark specified group as selected
|
||||
*/
|
||||
selectGroup({ commit, getters }, group) {
|
||||
if (Number.isInteger(group)) {
|
||||
group = getters.groups.find((g) => g.id === group);
|
||||
}
|
||||
|
||||
commit("setSelectedGroup", group);
|
||||
},
|
||||
|
||||
/**
|
||||
* Update a group
|
||||
*/
|
||||
updateGroup({ dispatch }, { group, newProperties }) {
|
||||
api.put(route("group.update", group), newProperties).then(function (
|
||||
response
|
||||
) {
|
||||
dispatch("updateProperties", {
|
||||
groupId: group.id,
|
||||
newProperties: response,
|
||||
});
|
||||
});
|
||||
},
|
||||
|
||||
/**
|
||||
* Delete group
|
||||
*/
|
||||
deleteGroup({ commit }, group) {
|
||||
api.delete(route("group.destroy", group)).then(function (response) {
|
||||
commit("setGroups", response);
|
||||
});
|
||||
},
|
||||
|
||||
/**
|
||||
* Update the specified resource in storage.
|
||||
*/
|
||||
updateProperties({ commit, getters }, { groupId, newProperties }) {
|
||||
const group = getters.groups.find((g) => g.id == groupId);
|
||||
|
||||
if (!group) {
|
||||
console.warn("Group #" + groupId + " not found");
|
||||
return;
|
||||
}
|
||||
|
||||
commit("update", { group: group, newProperties: newProperties });
|
||||
},
|
||||
|
||||
/**
|
||||
* Create a group
|
||||
*/
|
||||
createGroup({ commit }, properties) {
|
||||
api.post(route("group.store"), properties).then(function (response) {
|
||||
commit("setGroups", response);
|
||||
});
|
||||
},
|
||||
|
||||
/**
|
||||
* Update my groups positions
|
||||
*/
|
||||
updatePositions({ getters, commit }, { positions }) {
|
||||
for (var groupId in positions) {
|
||||
const group = getters.groups.find((g) => g.id == groupId);
|
||||
|
||||
if (!group) {
|
||||
console.warn("Group #" + groupId + " not found");
|
||||
return;
|
||||
}
|
||||
|
||||
commit("updatePosition", {
|
||||
group: group,
|
||||
position: positions[groupId],
|
||||
});
|
||||
}
|
||||
|
||||
api.post(route("group.update_positions"), {
|
||||
positions: positions,
|
||||
});
|
||||
},
|
||||
};
|
||||
19
resources/js/store/modules/groups/getters.js
vendored
Executable file
19
resources/js/store/modules/groups/getters.js
vendored
Executable file
@@ -0,0 +1,19 @@
|
||||
/**
|
||||
* Groups getters
|
||||
*/
|
||||
export default {
|
||||
/**
|
||||
* Return groups
|
||||
*/
|
||||
groups: state => {
|
||||
return state.groups;
|
||||
},
|
||||
/**
|
||||
* Return currently selected group
|
||||
*/
|
||||
selectedGroup: state => {
|
||||
var groups = state.groups ? state.groups : [];
|
||||
|
||||
return groups.find(group => group.is_selected);
|
||||
}
|
||||
}
|
||||
12
resources/js/store/modules/groups/index.js
vendored
Executable file
12
resources/js/store/modules/groups/index.js
vendored
Executable file
@@ -0,0 +1,12 @@
|
||||
import state from "./state";
|
||||
import getters from "./getters";
|
||||
import actions from "./actions";
|
||||
import mutations from "./mutations";
|
||||
|
||||
export default {
|
||||
'namespaced': true,
|
||||
state,
|
||||
getters,
|
||||
actions,
|
||||
mutations
|
||||
}
|
||||
39
resources/js/store/modules/groups/mutations.js
vendored
Executable file
39
resources/js/store/modules/groups/mutations.js
vendored
Executable file
@@ -0,0 +1,39 @@
|
||||
/**
|
||||
* Groups mutations
|
||||
*/
|
||||
export default {
|
||||
/**
|
||||
* Store groups list
|
||||
* @param {*} state
|
||||
* @param {*} groups
|
||||
*/
|
||||
setGroups(state, groups) {
|
||||
state.groups = groups;
|
||||
},
|
||||
|
||||
/**
|
||||
* Unselect all groups, and mark specified group as selected
|
||||
* @param {*} state
|
||||
* @param {*} group
|
||||
*/
|
||||
setSelectedGroup(state, group) {
|
||||
state.groups.find(g => (g.is_selected = false));
|
||||
|
||||
group.is_selected = true;
|
||||
},
|
||||
|
||||
/**
|
||||
* Update group's properties
|
||||
* @param {*} state
|
||||
* @param {*} param1
|
||||
*/
|
||||
update(state, { group, newProperties }) {
|
||||
for (var property in newProperties) {
|
||||
group[property] = newProperties[property];
|
||||
}
|
||||
},
|
||||
|
||||
updatePosition(state, { group, position }) {
|
||||
group.pivot.position = position;
|
||||
}
|
||||
};
|
||||
6
resources/js/store/modules/groups/state.js
vendored
Executable file
6
resources/js/store/modules/groups/state.js
vendored
Executable file
@@ -0,0 +1,6 @@
|
||||
export default {
|
||||
/**
|
||||
* Groups
|
||||
*/
|
||||
groups: []
|
||||
}
|
||||
Reference in New Issue
Block a user