From 988d63babbbcbe05fbbee30a490b91e0df82d4d9 Mon Sep 17 00:00:00 2001 From: Jaden Diefenbaugh <blakcap@users.noreply.github.com> Date: Wed, 17 May 2017 16:10:21 +0200 Subject: [PATCH] fix tablefield generation using startswith instead of actual matching, #21 --- .../app/directives/edit/tableFieldSelector.js | 24 ++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) 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 f3ac84adc..b16c73944 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' -- GitLab