From f1687acaf9931a087bf774771ce351fddd063c3d Mon Sep 17 00:00:00 2001 From: Rashid Khan Date: Tue, 7 Apr 2015 13:48:22 -0700 Subject: [PATCH] Add remove button to table header --- .../doc_table/components/table_header.html | 9 +++---- .../doc_table/components/table_header.js | 11 ++++++++- src/kibana/components/doc_table/doc_table.js | 6 ++--- .../field_chooser/field_chooser.html | 6 ++--- .../components/field_chooser/field_chooser.js | 5 ++-- .../plugins/discover/controllers/discover.js | 23 ++++-------------- test/unit/fixtures/hits.js | 20 ++++++++-------- test/unit/fixtures/logstash_fields.js | 7 +++--- .../apps/discover/directives/field_chooser.js | 24 ++++++++++--------- .../specs/components/doc_table/doc_table.js | 2 +- 10 files changed, 56 insertions(+), 57 deletions(-) diff --git a/src/kibana/components/doc_table/components/table_header.html b/src/kibana/components/doc_table/components/table_header.html index 9a0c1e036ec541..0e43596bec8c2f 100644 --- a/src/kibana/components/doc_table/components/table_header.html +++ b/src/kibana/components/doc_table/components/table_header.html @@ -3,11 +3,12 @@ Time - - {{name | shortDots}} + + {{name | shortDots}} - - + + + \ No newline at end of file diff --git a/src/kibana/components/doc_table/components/table_header.js b/src/kibana/components/doc_table/components/table_header.js index c4611e6c1cda1b..3b73ca129001c9 100644 --- a/src/kibana/components/doc_table/components/table_header.js +++ b/src/kibana/components/doc_table/components/table_header.js @@ -18,13 +18,18 @@ define(function (require) { var sortableField = function (field) { if (!$scope.indexPattern) return; - return $scope.indexPattern.fields.byName[field].sortable; + var sortable = _.deepGet($scope.indexPattern.fields.byName[field], 'sortable'); + return sortable; }; $scope.tooltip = function (column) { if (!sortableField(column)) return ''; else return 'Sort by ' + shortDotsFilter(column); }; + $scope.canRemove = function (name) { + return (name !== '_source' || $scope.columns.length !== 1); + }; + $scope.headerClass = function (column) { if (!sortableField(column)) return; @@ -49,6 +54,10 @@ define(function (require) { _.move($scope.columns, index, ++index); }; + $scope.toggleColumn = function (fieldName) { + _.toggleInOut($scope.columns, fieldName); + }; + $scope.sort = function (column) { if (!column || !sortableField(column)) return; diff --git a/src/kibana/components/doc_table/doc_table.js b/src/kibana/components/doc_table/doc_table.js index 97f0d56e3fec02..e7e9e28f558cdc 100644 --- a/src/kibana/components/doc_table/doc_table.js +++ b/src/kibana/components/doc_table/doc_table.js @@ -56,11 +56,11 @@ define(function (require) { }; $scope.$watchCollection('columns', function (columns, oldColumns) { - if (oldColumns.length === 1 && oldColumns[0] === '_source' && columns.length > 1) { - _.pull(columns, '_source'); + if (oldColumns.length === 1 && oldColumns[0] === '_source' && $scope.columns.length > 1) { + _.pull($scope.columns, '_source'); } - if (columns.length === 0) columns.push('_source'); + if ($scope.columns.length === 0) $scope.columns.push('_source'); }); diff --git a/src/kibana/plugins/discover/components/field_chooser/field_chooser.html b/src/kibana/plugins/discover/components/field_chooser/field_chooser.html index 706eeb7b55907d..07a06d7df1eebc 100644 --- a/src/kibana/plugins/discover/components/field_chooser/field_chooser.html +++ b/src/kibana/plugins/discover/components/field_chooser/field_chooser.html @@ -31,7 +31,7 @@
Selected Fields
diff --git a/src/kibana/plugins/discover/components/field_chooser/field_chooser.js b/src/kibana/plugins/discover/components/field_chooser/field_chooser.js index 350061f4bc7d41..4f625463db731c 100644 --- a/src/kibana/plugins/discover/components/field_chooser/field_chooser.js +++ b/src/kibana/plugins/discover/components/field_chooser/field_chooser.js @@ -91,6 +91,7 @@ define(function (require) { }); $scope.toggle = function (fieldName) { + $scope.increaseFieldCounter(fieldName); _.toggleInOut($scope.columns, fieldName); }; @@ -156,8 +157,8 @@ define(function (require) { }); }); - $scope.increaseFieldCounter = function (field) { - $scope.indexPattern.popularizeField(field.name, 1); + $scope.increaseFieldCounter = function (fieldName) { + $scope.indexPattern.popularizeField(fieldName, 1); }; $scope.runAgg = function (field) { diff --git a/src/kibana/plugins/discover/controllers/discover.js b/src/kibana/plugins/discover/controllers/discover.js index 0636e33f6d85ea..13994cda8c06d1 100644 --- a/src/kibana/plugins/discover/controllers/discover.js +++ b/src/kibana/plugins/discover/controllers/discover.js @@ -111,6 +111,10 @@ define(function (require) { $state.index = $scope.indexPattern.id; $state.sort = getSort.array($state.sort, $scope.indexPattern); + $scope.$watchCollection('state.columns', function (columns) { + $state.save(); + }); + var metaFields = config.get('metaFields'); filterManager.init($state); @@ -397,25 +401,12 @@ define(function (require) { .set('filter', $state.filters || []); }); - // This is a hacky optimization for comparing the contents of a large array to a short one. - function arrayToKeys(array, value) { - var obj = {}; - _.each(array, function (key) { - obj[key] = value || true; - }); - return obj; - } - // TODO: On array fields, negating does not negate the combination, rather all terms $scope.filterQuery = function (field, values, operation) { $scope.indexPattern.popularizeField(field, 1); filterManager.add(field, values, operation, $state.index); }; - $scope.toggleField = function (fieldName) { - _.toggleInOut($state.columns, fieldName); - }; - $scope.toTop = function () { $window.scrollTo(0, 0); }; @@ -430,12 +421,6 @@ define(function (require) { return str; }; - // TODO: Move to utility class - // https://stackoverflow.com/questions/3561493/is-there-a-regexp-escape-function-in-javascript - var regexEscape = function (str) { - return str.replace(/[-\/\\^$*+?.()|[\]{}]/g, '\\$&'); - }; - var loadingVis; var setupVisualization = function () { // If we're not setting anything up we need to return an empty promise diff --git a/test/unit/fixtures/hits.js b/test/unit/fixtures/hits.js index 61fef38a06817e..b368d2ab1e3c21 100644 --- a/test/unit/fixtures/hits.js +++ b/test/unit/fixtures/hits.js @@ -1,16 +1,16 @@ define(function (require) { var _ = require('lodash'); return _.map([ - {_source: {timestamp: 0, bytes: 10, request: 'foo'}}, - {_source: {timestamp: 1, bytes: 20, request: 'bar'}}, - {_source: {timestamp: 2, bytes: 30, request: 'bar'}}, - {_source: {timestamp: 3, bytes: 30, request: 'baz'}}, - {_source: {timestamp: 4, bytes: 30, request: 'baz'}}, - {_source: {timestamp: 5, bytes: 30, request: 'baz'}}, - {_source: {timestamp: 6, bytes: 40.1415926535, request: 'bat'}}, - {_source: {timestamp: 7, bytes: 40.1415926535, request: 'bat'}}, - {_source: {timestamp: 8, bytes: 40.1415926535, request: 'bat'}}, - {_source: {timestamp: 9, bytes: 40.1415926535, request: 'bat'}}, + {_source: {'@timestamp': 0, ssl: true, ip: '192.168.0.1', extension: 'php', 'machine.os': 'Linux', bytes: 10, request: 'foo'}}, + {_source: {'@timestamp': 1, ssl: true, ip: '192.168.0.1', extension: 'php', 'machine.os': 'Linux', bytes: 20, request: 'bar'}}, + {_source: {'@timestamp': 2, ssl: true, ip: '192.168.0.1', extension: 'php', 'machine.os': 'Linux', bytes: 30, request: 'bar'}}, + {_source: {'@timestamp': 3, ssl: true, ip: '192.168.0.1', extension: 'php', 'machine.os': 'Linux', bytes: 30, request: 'baz'}}, + {_source: {'@timestamp': 4, ssl: true, ip: '192.168.0.1', extension: 'php', 'machine.os': 'Linux', bytes: 30, request: 'baz'}}, + {_source: {'@timestamp': 5, ssl: true, ip: '192.168.0.1', extension: 'php', 'machine.os': 'Linux', bytes: 30, request: 'baz'}}, + {_source: {'@timestamp': 6, ssl: true, ip: '192.168.0.1', extension: 'php', 'machine.os': 'Linux', bytes: 40.141592, request: 'bat'}}, + {_source: {'@timestamp': 7, ssl: true, ip: '192.168.0.1', extension: 'php', 'machine.os': 'Linux', bytes: 40.141592, request: 'bat'}}, + {_source: {'@timestamp': 8, ssl: true, ip: '192.168.0.1', extension: 'php', 'machine.os': 'Linux', bytes: 40.141592, request: 'bat'}}, + {_source: {'@timestamp': 9, ssl: true, ip: '192.168.0.1', extension: 'php', 'machine.os': 'Linux', bytes: 40.141592, request: 'bat'}}, ], function (p, i) { return _.merge({}, p, { _score: 1, diff --git a/test/unit/fixtures/logstash_fields.js b/test/unit/fixtures/logstash_fields.js index 17dacf06205759..b7b0479a738fa4 100644 --- a/test/unit/fixtures/logstash_fields.js +++ b/test/unit/fixtures/logstash_fields.js @@ -16,9 +16,10 @@ define(function (require) { { name: 'geo.src', type: 'string', indexed: true, analyzed: true, sortable: true, filterable: true }, { name: '_type', type: 'string', indexed: true, analyzed: true, sortable: true, filterable: true }, { name: '_id', type: 'string', indexed: false, analyzed: false, sortable: false, filterable: true}, - { name: 'custom_user_field', type: 'conflict', indexed: false, analyzed: false }, - { name: 'script string', type: 'string', scripted: true, script: '\'i am a string\'', lang: 'expression'}, - { name: 'script number', type: 'number', scripted: true, script: '1234', lang: 'expression'}, + { name: '_source', type: 'string', indexed: false, analyzed: false, sortable: false, filterable: false}, + { name: 'custom_user_field', type: 'conflict', indexed: false, analyzed: false, sortable: false, filterable: true }, + { name: 'script string', type: 'string', scripted: true, script: '\'i am a string\'', lang: 'expression'}, + { name: 'script number', type: 'number', scripted: true, script: '1234', lang: 'expression'}, ].map(function (field) { field.count = field.count || 0; field.scripted = field.scripted || false; diff --git a/test/unit/specs/apps/discover/directives/field_chooser.js b/test/unit/specs/apps/discover/directives/field_chooser.js index 3b6238fda43294..50b4b57b321ef2 100644 --- a/test/unit/specs/apps/discover/directives/field_chooser.js +++ b/test/unit/specs/apps/discover/directives/field_chooser.js @@ -12,12 +12,17 @@ define(function (require) { // Sets up the directive, take an element, and a list of properties to attach to the parent scope. var init = function ($elem, props) { - inject(function ($rootScope, $compile, _config_) { + inject(function ($rootScope, $compile, $timeout, _config_) { config = _config_; $parentScope = $rootScope; _.assign($parentScope, props); $compile($elem)($parentScope); - $elem.scope().$digest(); + + // Required for test to run solo. Sigh + $timeout(function () { + $elem.scope().$digest(); + }, 0); + $scope = $elem.isolateScope(); }); }; @@ -30,7 +35,7 @@ define(function (require) { describe('discover field chooser directives', function () { var $elem = angular.element( '