From 6acd29f7d441792a5420faad21ee6bc644f73568 Mon Sep 17 00:00:00 2001 From: Rashid Khan Date: Fri, 28 Feb 2014 14:44:32 -0700 Subject: [PATCH] Added type-to-filter to dashboard loading pulldown --- src/kibana/apps/dashboard/directives/grid.js | 2 +- src/kibana/apps/dashboard/index.js | 73 +++++++++++++------ .../dashboard/partials/load_dashboard.html | 8 +- 3 files changed, 57 insertions(+), 26 deletions(-) diff --git a/src/kibana/apps/dashboard/directives/grid.js b/src/kibana/apps/dashboard/directives/grid.js index 5814e8825d8a7..976747d483d21 100644 --- a/src/kibana/apps/dashboard/directives/grid.js +++ b/src/kibana/apps/dashboard/directives/grid.js @@ -42,7 +42,7 @@ define(function (require) { gridster = elem.gridster({ autogenerate_stylesheet: false, widget_margins: [5, 5], - widget_base_dimensions: [((width - 80) / 12), 100], + widget_base_dimensions: [((width - 100) / 12), 100], min_cols: 12, max_cols: 12, resize: { diff --git a/src/kibana/apps/dashboard/index.js b/src/kibana/apps/dashboard/index.js index c63e3de63936c..414b52c2bfd26 100644 --- a/src/kibana/apps/dashboard/index.js +++ b/src/kibana/apps/dashboard/index.js @@ -17,12 +17,58 @@ define(function (require) { app.controller('dashboard', function ($scope, courier) { - $scope.$broadcast('application.load'); + $scope.dashboard = { + title: 'New Dashboard', + panels: [] + }; // Passed in the grid attr to the directive so we can access the directive's function from // the controller and view $scope.gridControl = {}; + $scope.input = { + search: '' + }; + + $scope.$watch('configurable.input.search', function (newVal) { + dashboardSearch(newVal); + }); + + var init = function () { + $scope.configurable = { + dashboard: $scope.dashboard, + load: $scope.load, + input: { + search: $scope.input.search + } + }; + }; + + var dashboardSearch = function (query) { + var search; + + if (_.isString(query) && query.length > 0) { + + query = {match: {title: {query: query, type: 'phrase_prefix'}}}; + } else { + query = {match_all: {}}; + } + + search = courier.createSource('search') + .index(configFile.kibanaIndex) + .type('dashboard') + .size(20) + .query(query) + .$scope($scope) + .inherits(courier.rootSearchSource) + .on('results', function (res) { + $scope.configurable.searchResults = res.hits.hits; + }); + + search.fetch(); + + }; + var setConfigTemplate = function (template) { // Close if already open if ($scope.configTemplate === template) { @@ -44,19 +90,7 @@ define(function (require) { $scope.openLoad = function () { setConfigTemplate(require('text!./partials/load_dashboard.html')); - var search = courier.createSource('search') - .index(configFile.kibanaIndex) - .type('dashboard') - .size(20) - .$scope($scope) - .inherits(courier.rootSearchSource) - .on('results', function (res) { - console.log(res.hits); - $scope.configurable.searchResults = res.hits.hits; - }); - - // TODO: Find out why results is fired twice - search.fetch(); + if ($scope.configTemplate) dashboardSearch($scope.configurable.input.search); }; $scope.save = function (title) { @@ -78,15 +112,8 @@ define(function (require) { $scope.gridControl.unserializeGrid($scope.dashboard.panels); }; - $scope.dashboard = { - title: 'New Dashboard', - panels: [] - }; - - $scope.configurable = { - dashboard: $scope.dashboard, - load: $scope.load - }; + init(); + $scope.$broadcast('application.load'); }); }); \ No newline at end of file diff --git a/src/kibana/apps/dashboard/partials/load_dashboard.html b/src/kibana/apps/dashboard/partials/load_dashboard.html index a4f2484386a5f..a455bcc58f3df 100644 --- a/src/kibana/apps/dashboard/partials/load_dashboard.html +++ b/src/kibana/apps/dashboard/partials/load_dashboard.html @@ -1,5 +1,9 @@ +
+ + +
\ No newline at end of file