diff --git a/beat/web/reports/static/reports/app/directives/edit/tableFieldSelector.js b/beat/web/reports/static/reports/app/directives/edit/tableFieldSelector.js index f3ac84adc688d70cdb29cbc589c353bde7444a1b..b16c7394463f24b72569ea8ce5bcb256fe8e8e57 100644 --- a/beat/web/reports/static/reports/app/directives/edit/tableFieldSelector.js +++ b/beat/web/reports/static/reports/app/directives/edit/tableFieldSelector.js @@ -63,7 +63,9 @@ angular.module('reportApp') // converting to and from a Set is a simple way of // removing dups - return Array.from(new Set(fieldArr)); + const arr = Array.from(new Set(fieldArr)); + + return arr; }; // has this fieldName already been processed? @@ -101,12 +103,28 @@ angular.module('reportApp') .filter(f => f.includes('.')) .map(f => f.split('.')[0]); - return Array.from(new Set(groupNames)).sort((a, b) => groupNames.indexOf(a) - groupNames.indexOf(b)); + const sorted = Array.from(new Set(groupNames)) + .sort((a, b) => groupNames.indexOf(a) - groupNames.indexOf(b)) + + return sorted; }; + // finds the actual field name whether its in a field group or not + scope.groupName = (field) => field.includes('.') ? field.split('.')[0] : field; + // finds the actual field name whether its in a field group or not scope.subfieldName = (field) => field.includes('.') ? field.split('.').slice(1).join('.') : field; + scope.shouldShowField = (fName, gName) => { + const isUnique = scope.isUniqueTableable(fName); + const isInGroup = scope.groupName(fName) == gName; + + // console.log(`for field "${fName}" and group "${gName}":`); + // console.log(`isUnique: ${isUnique}; isInGroup: ${isInGroup}`); + + return isUnique && isInGroup; + } + // toggle the selection of a field scope.toggleField = (fName) => { let idx = scope.colsSelected.indexOf(fName); @@ -145,7 +163,7 @@ angular.module('reportApp') <h4>{{ gName }}</h4> <div ng-repeat='fName in tableables()' - ng-if='isUniqueTableable(fName) && fName.startsWith(gName)'> + ng-if='shouldShowField(fName, gName)'> <label> <input type='checkbox'