Skip to content

Commit a9b8358

Browse files
author
Nolan Kingdon
committed
Removed reliance on hardcoded GroupsCompanyId values. Grabs the user's top level now instead. Fixes bug where lower levels of permissions can't generate list
1 parent 19d2011 commit a9b8358

File tree

2 files changed

+13
-10
lines changed

2 files changed

+13
-10
lines changed

generators/app/templates/src/.dev/groups/Groups.js

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ class Groups {
1313
constructor(api, state, target){
1414
this.api = api;
1515
this.state = state;
16+
this.baseNode;
1617
this.groupsDictionary;
1718
this.root = document.getElementById(target);
1819
this.activeLabel = document.getElementById('active-group');
@@ -27,7 +28,7 @@ class Groups {
2728
* collected groups and use this method to just re-generate the base html.
2829
*/
2930
generateRootHtml(){
30-
let html = _GroupHelper.generateNodeHtml(groupsFilter.groupsDictionary, 'GroupCompanyId');
31+
let html = _GroupHelper.generateNodeHtml(groupsFilter.groupsDictionary, this.baseNode);
3132
groupsFilter.root.innerHTML = html;
3233
}
3334

@@ -53,7 +54,7 @@ class Groups {
5354

5455
/**
5556
* Removes all group names from the 'Active Groups' header.
56-
* Removes all groups except for the root group 'GroupCompanyId' from the state.
57+
* Removes all groups from the state.
5758
* Unselects any previously selected groups in the groupsDictionary.
5859
* Resets the HTML to remove any checked attributes.
5960
*/
@@ -66,7 +67,7 @@ class Groups {
6667

6768
this.writeActiveGroups();
6869

69-
let html = _GroupHelper.generateNodeHtml(this.groupsDictionary, 'GroupCompanyId');
70+
let html = _GroupHelper.generateNodeHtml(this.groupsDictionary, this.baseNode);
7071
this.root.innerHTML = html;
7172

7273
geotab.addin.<%= root%>.focus(this.api, this.state);
@@ -145,7 +146,7 @@ class Groups {
145146
*/
146147
changeFocus(previous, current){
147148
this.previousGroupStack.push(previous);
148-
let html = _GroupHelper.generateNodeHtml(this.groupsDictionary, current);
149+
let html = _GroupHelper.generateNodeHtml(this.groupsDictionary, current, this.baseNode);
149150
this.root.innerHTML = html;
150151
}
151152

@@ -155,7 +156,7 @@ class Groups {
155156
*/
156157
goToPreviousFolder(){
157158
let previousFolder = this.previousGroupStack.pop();
158-
let html = _GroupHelper.generateNodeHtml(this.groupsDictionary, previousFolder);
159+
let html = _GroupHelper.generateNodeHtml(this.groupsDictionary, previousFolder, this.baseNode);
159160
this.root.innerHTML = html;
160161
}
161162

@@ -166,8 +167,9 @@ class Groups {
166167
*/
167168
_groupSuccessCallback(result, resolve){
168169
let groupInput = document.getElementById('group-input');
170+
this.baseNode = result[0].id;
169171
this.groupsDictionary = _GroupHelper.convertGroupsListToDictionary(result);
170-
let html = _GroupHelper.generateNodeHtml(this.groupsDictionary, 'GroupCompanyId');
172+
let html = _GroupHelper.generateNodeHtml(this.groupsDictionary, this.baseNode);
171173
this.root.innerHTML = html;
172174

173175
// If we had any errors, we want to reset the placeholder text.
@@ -188,7 +190,7 @@ class Groups {
188190

189191
setTimeout(() => {
190192
groupInput.placeholder = "Retrying...";
191-
this.groupsFilter.getAllGroupsInDatabase();
193+
groupsFilter.getAllGroupsInDatabase();
192194
}, 60000);
193195
}
194196
}

generators/app/templates/src/.dev/groups/_GroupHelper.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ class _GroupHelper {
8585
let resultCount = 0;
8686

8787
// When we iterate over all the keys in the groupsDictionary, we get all the groups instead of top level children
88-
// of GroupsCompanyId (Root).
88+
// of user's Root group.
8989
Object.keys(groupsDictionary).forEach(key => {
9090
let node = groupsDictionary[key];
9191
if(regex.test(node.name.toLowerCase())){
@@ -113,13 +113,14 @@ class _GroupHelper {
113113
*
114114
* @param {object} groupsDictionary the dictionary used to generate the folder.
115115
* @param {string} root the dictionary key we start the folder on.
116+
* @param {string} baseNode the user's highest group permission.
116117
*/
117-
static generateNodeHtml(groupsDictionary, root){
118+
static generateNodeHtml(groupsDictionary, root, baseNode = root){
118119
let html = `<ul id="group-dropdown-ul" class="geotabPrimaryFill select-buttons">`
119120
let name = groupsDictionary[root].name;
120121
let checked = groupsDictionary[root].selected ? 'checked' : '';
121122

122-
if(root !== 'GroupCompanyId'){
123+
if(root !== baseNode){
123124
html += `<li onchange="${this.generateFilterEventListener(root)}">
124125
<input id="group-go-to-${root}" type="checkbox" class="geotabSwitchButton navButton" ${checked}>
125126
<label for="group-go-to-${root}" class="geotabButton" style="width:100%;">

0 commit comments

Comments
 (0)