Skip to content

Commit

Permalink
Added type-to-filter to dashboard loading pulldown
Browse files Browse the repository at this point in the history
  • Loading branch information
Rashid Khan committed Feb 28, 2014
1 parent 30398ad commit 6acd29f
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 26 deletions.
2 changes: 1 addition & 1 deletion src/kibana/apps/dashboard/directives/grid.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down
73 changes: 50 additions & 23 deletions src/kibana/apps/dashboard/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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) {
Expand All @@ -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');

});
});
8 changes: 6 additions & 2 deletions src/kibana/apps/dashboard/partials/load_dashboard.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
<div class="container-fluid">
<label>Filter Dashboards</label>
<input type="text" ng-model="configurable.input.search" class="form-control"/>
</div>
<ul class="nav nav-pills">
<li ng-repeat="res in configObject.searchResults | orderBy:'_source.title'" ng-class="{active: configObject.dashboard.title == res._source.title}">
<a ng-click="configObject.load(res._source)">{{res._source.title}}</a>
<li ng-repeat="res in configurable.searchResults | orderBy:'_source.title'" ng-class="{active: configurable.dashboard.title == res._source.title}">
<a ng-click="configurable.load(res._source)">{{res._source.title}}</a>
</li>
</ul>

0 comments on commit 6acd29f

Please sign in to comment.