Fix toggling subgroups and pagination
This commit is contained in:
parent
6f85943044
commit
b425373541
|
@ -14,7 +14,7 @@ export default {
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
toggleSubGroups(e) {
|
toggleSubGroups(e) {
|
||||||
if (e.target.tagName === 'A' || !this.hasSubgroups ) {
|
if (e.target.tagName === 'A' || !this.hasSubgroups) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -34,12 +34,18 @@ $(() => {
|
||||||
fetchGroups(parentGroup) {
|
fetchGroups(parentGroup) {
|
||||||
let parentId = null;
|
let parentId = null;
|
||||||
let getGroups = null;
|
let getGroups = null;
|
||||||
|
let page = null;
|
||||||
|
let pageParam = null;
|
||||||
|
|
||||||
if (parentGroup) {
|
if (parentGroup) {
|
||||||
parentId = parentGroup.id;
|
parentId = parentGroup.id;
|
||||||
}
|
}
|
||||||
|
|
||||||
const page = gl.utils.getParameterByName('page');
|
pageParam = gl.utils.getParameterByName('page');
|
||||||
|
|
||||||
|
if (pageParam) {
|
||||||
|
page = pageParam;
|
||||||
|
}
|
||||||
|
|
||||||
getGroups = service.getGroups(parentId, page);
|
getGroups = service.getGroups(parentId, page);
|
||||||
getGroups.then((response) => {
|
getGroups.then((response) => {
|
||||||
|
@ -53,8 +59,10 @@ $(() => {
|
||||||
},
|
},
|
||||||
toggleSubGroups(parentGroup = null) {
|
toggleSubGroups(parentGroup = null) {
|
||||||
if (!parentGroup.isOpen) {
|
if (!parentGroup.isOpen) {
|
||||||
|
store.resetGroups(parentGroup);
|
||||||
this.fetchGroups(parentGroup);
|
this.fetchGroups(parentGroup);
|
||||||
}
|
}
|
||||||
|
|
||||||
GroupsStore.toggleSubGroups(parentGroup);
|
GroupsStore.toggleSubGroups(parentGroup);
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
|
@ -8,7 +8,7 @@ export default class GroupsService {
|
||||||
this.groups = Vue.resource(endpoint);
|
this.groups = Vue.resource(endpoint);
|
||||||
}
|
}
|
||||||
|
|
||||||
getGroups(parentId, page = 1) {
|
getGroups(parentId, page) {
|
||||||
const data = {};
|
const data = {};
|
||||||
|
|
||||||
if (parentId) {
|
if (parentId) {
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
/* eslint-disable class-methods-use-this */
|
||||||
export default class GroupsStore {
|
export default class GroupsStore {
|
||||||
constructor() {
|
constructor() {
|
||||||
this.state = {};
|
this.state = {};
|
||||||
|
@ -9,7 +10,7 @@ export default class GroupsStore {
|
||||||
|
|
||||||
setGroups(rawGroups, parent = null) {
|
setGroups(rawGroups, parent = null) {
|
||||||
const parentGroup = parent;
|
const parentGroup = parent;
|
||||||
const tree = this.buildTree(rawGroups);
|
const tree = this.buildTree(rawGroups, parentGroup);
|
||||||
|
|
||||||
if (parentGroup) {
|
if (parentGroup) {
|
||||||
parentGroup.subGroups = tree;
|
parentGroup.subGroups = tree;
|
||||||
|
@ -20,6 +21,11 @@ export default class GroupsStore {
|
||||||
return tree;
|
return tree;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
resetGroups(parent) {
|
||||||
|
const parentGroup = parent;
|
||||||
|
parentGroup.subGroups = {};
|
||||||
|
}
|
||||||
|
|
||||||
storePagination(pagination = {}) {
|
storePagination(pagination = {}) {
|
||||||
let paginationInfo;
|
let paginationInfo;
|
||||||
|
|
||||||
|
@ -33,7 +39,7 @@ export default class GroupsStore {
|
||||||
this.state.pageInfo = paginationInfo;
|
this.state.pageInfo = paginationInfo;
|
||||||
}
|
}
|
||||||
|
|
||||||
buildTree(rawGroups) {
|
buildTree(rawGroups, parentGroup) {
|
||||||
const groups = this.decorateGroups(rawGroups);
|
const groups = this.decorateGroups(rawGroups);
|
||||||
const tree = {};
|
const tree = {};
|
||||||
const mappedGroups = {};
|
const mappedGroups = {};
|
||||||
|
@ -49,11 +55,14 @@ export default class GroupsStore {
|
||||||
Object.keys(mappedGroups).map((key) => {
|
Object.keys(mappedGroups).map((key) => {
|
||||||
const currentGroup = mappedGroups[key];
|
const currentGroup = mappedGroups[key];
|
||||||
// If the group is not at the root level, add it to its parent array of subGroups.
|
// If the group is not at the root level, add it to its parent array of subGroups.
|
||||||
const parentGroup = mappedGroups[currentGroup.parentId];
|
const findParentGroup = mappedGroups[currentGroup.parentId];
|
||||||
|
|
||||||
if (currentGroup.parentId) {
|
if (currentGroup.parentId) {
|
||||||
if (parentGroup) {
|
if (findParentGroup) {
|
||||||
mappedGroups[currentGroup.parentId].subGroups[currentGroup.id] = currentGroup;
|
mappedGroups[currentGroup.parentId].subGroups[currentGroup.id] = currentGroup;
|
||||||
mappedGroups[currentGroup.parentId].isOpen = true; // Expand group if it has subgroups
|
mappedGroups[currentGroup.parentId].isOpen = true; // Expand group if it has subgroups
|
||||||
|
} else if (parentGroup && parentGroup.id === currentGroup.parentId) {
|
||||||
|
tree[currentGroup.id] = currentGroup;
|
||||||
} else {
|
} else {
|
||||||
// Means the groups hast no direct parent.
|
// Means the groups hast no direct parent.
|
||||||
// Save for later processing, we will add them to its corresponding base group
|
// Save for later processing, we will add them to its corresponding base group
|
||||||
|
|
Loading…
Reference in New Issue