From 7069d1233dc8bb597236bbc5640fc839df7901a1 Mon Sep 17 00:00:00 2001
From: Jaden Diefenbaugh <blakcap@users.noreply.github.com>
Date: Thu, 9 Mar 2017 15:12:25 +0100
Subject: [PATCH] add opt groups to table col selector

---
 .../app/directives/groupTableFieldSelector.js | 29 ++++++++++++++++++-
 1 file changed, 28 insertions(+), 1 deletion(-)

diff --git a/beat/web/reports/static/reports/app/directives/groupTableFieldSelector.js b/beat/web/reports/static/reports/app/directives/groupTableFieldSelector.js
index ac5d36318..162f77c86 100644
--- a/beat/web/reports/static/reports/app/directives/groupTableFieldSelector.js
+++ b/beat/web/reports/static/reports/app/directives/groupTableFieldSelector.js
@@ -75,6 +75,18 @@ angular.module('reportApp')
 				return !isRepeat;
 			};
 
+			scope.tableablesGroups = () => {
+				let groupNames = scope.tableables()
+				.filter(f => f.includes('.'))
+				.map(f => f.split('.')[0]);
+
+				console.log(groupNames);
+
+				return Array.from(new Set(groupNames)).sort();
+			};
+
+			scope.subfieldName = (field) => field.includes('.') ? field.split('.').slice(1).join('.') : field;
+
 			console.log(scope.buttonText);
 		},
 		template: `
@@ -85,7 +97,22 @@ angular.module('reportApp')
 <div class='dropdown-menu' ng-click="$event.stopPropagation();">
 	<h4>Select columns to show in Table</h4>
 	<select multiple ng-model='colsSelected'>
-		<option ng-repeat='fName in tableables()' ng-if='isUniqueTableable(fName)'>{{ fName }}</option>
+		<optgroup label='General'>
+			<option
+				ng-repeat='fName in tableables()'
+				ng-if="isUniqueTableable(fName) && !fName.includes('.')"
+				value='{{ fName }}'>
+				{{ fName }}
+			</option>
+		</optgroup>
+		<optgroup ng-repeat='gName in tableablesGroups()' label='{{ gName }}'>
+			<option
+				ng-repeat='fName in tableables()'
+				ng-if='isUniqueTableable(fName) && fName.startsWith(gName)'
+				value='{{ fName }}'>
+				{{ subfieldName(fName) }}
+			</option>
+		</optgroup>
 	</select>
 	<button class='btn btn-default' ng-click='clickButton($event)'>{{ buttonText }}</button>
 </div>
-- 
GitLab