Skip to content

Commit

Permalink
Merge pull request #4656 from rashidkpc/enhancement/saved_obj_registry
Browse files Browse the repository at this point in the history
Saved Object Registry
  • Loading branch information
spalger committed Aug 14, 2015
2 parents 3a8b664 + 60152ba commit 13b242a
Show file tree
Hide file tree
Showing 12 changed files with 64 additions and 33 deletions.
4 changes: 4 additions & 0 deletions src/plugins/kibana/public/dashboard/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ define(function (require) {
require('plugins/kibana/dashboard/services/saved_dashboards');
require('plugins/kibana/dashboard/styles/main.less');

require('ui/saved_objects/saved_object_registry').register(require('plugins/kibana/dashboard/services/saved_dashboard_register'));


var app = require('ui/modules').get('app/dashboard', [
'elasticsearch',
'ngRoute',
Expand Down Expand Up @@ -49,6 +52,7 @@ define(function (require) {
app.directive('dashboardApp', function (Notifier, courier, AppState, timefilter, kbnUrl) {
return {
controller: function ($scope, $route, $routeParams, $location, Private, getAppState) {

var queryFilter = Private(require('ui/filter_bar/query_filter'));

var notify = new Notifier({
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
define(function (require) {
return function savedDashboardFn(savedDashboards) {
return savedDashboards;
};
});
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,13 @@ define(function (require) {
this.type = SavedDashboard.type;
this.Class = SavedDashboard;


this.loaderProperties = {
name: 'dashboards',
noun: 'Dashboard',
nouns: 'dashboards'
};

// Returns a single dashboard by ID, should be the name of the dashboard
this.get = function (id) {

Expand Down
3 changes: 3 additions & 0 deletions src/plugins/kibana/public/discover/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,7 @@ define(function (require, module, exports) {

// preload
require('ui/doc_table/components/table_row');

require('ui/saved_objects/saved_object_registry').register(require('plugins/kibana/discover/saved_searches/saved_search_register'));

});
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
define(function (require) {
return function savedSearchObjectFn(savedSearches) {
return savedSearches;
};
});
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@ define(function (require) {
this.type = SavedSearch.type;
this.Class = SavedSearch;

this.loaderProperties = {
name: 'searches',
noun: 'Saved Search',
nouns: 'saved searches'
};

this.get = function (id) {
return (new SavedSearch(id)).init();
};
Expand Down
4 changes: 4 additions & 0 deletions src/plugins/kibana/public/visualize/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,8 @@ define(function (require) {
require('plugins/kibana/visualize/editor/vis_options');
require('plugins/kibana/visualize/saved_visualizations/_saved_vis');
require('plugins/kibana/visualize/saved_visualizations/saved_visualizations');

require('ui/saved_objects/saved_object_registry')
.register(require('plugins/kibana/visualize/saved_visualizations/saved_visualization_register'));

});
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
define(function (require) {
return function savedVisualizationFn(savedVisualizations) {
return savedVisualizations;
};
});
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@ define(function (require) {
this.type = SavedVis.type;
this.Class = SavedVis;

this.loaderProperties = {
name: 'visualizations',
noun: 'Visualization',
nouns: 'visualizations'
};

this.get = function (id) {
return (new SavedVis(id)).init();
};
Expand Down
39 changes: 9 additions & 30 deletions src/ui/public/directives/saved_object_finder.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,9 @@ define(function (require) {
var rison = require('ui/utils/rison');
var keymap = require('ui/utils/key_map');

module.directive('savedObjectFinder', function (savedSearches, savedVisualizations, savedDashboards, $location, kbnUrl) {

var types = {
searches: {
service: savedSearches,
name: 'searches',
noun: 'Saved Search',
nouns: 'saved searches'
},
visualizations: {
service: savedVisualizations,
name: 'visualizations',
noun: 'Visualization',
nouns: 'visualizations'
},
dashboards: {
service: savedDashboards,
name: 'dashboards',
noun: 'Dashboard',
nouns: 'dashboards'
}
};
module.directive('savedObjectFinder', function ($location, $injector, kbnUrl, Private) {

var services = Private(require('ui/saved_objects/saved_object_registry')).byLoaderPropertiesName;

return {
restrict: 'E',
Expand Down Expand Up @@ -54,13 +35,11 @@ define(function (require) {
// the most recently entered search/filter
var prevSearch;

// the service we will use to find records
var service;

// the list of hits, used to render display
self.hits = [];

self.objectType = types[$scope.type];
self.service = services[$scope.type];
self.properties = self.service.loaderProperties;

filterResults();

Expand Down Expand Up @@ -230,7 +209,7 @@ define(function (require) {
};

self.hitCountNoun = function () {
return ((self.hitCount === 1) ? self.objectType.noun : self.objectType.nouns).toLowerCase();
return ((self.hitCount === 1) ? self.properties.noun : self.properties.nouns).toLowerCase();
};

function selectTopHit() {
Expand All @@ -241,8 +220,8 @@ define(function (require) {
}

function filterResults() {
if (!self.objectType) return;
if (!self.objectType.service) return;
if (!self.service) return;
if (!self.properties) return;

// track the filter that we use for this search,
// but ensure that we don't search for the same
Expand All @@ -252,7 +231,7 @@ define(function (require) {
if (prevSearch === filter) return;

prevSearch = filter;
self.objectType.service.find(filter)
self.service.find(filter)
.then(function (hits) {
// ensure that we don't display old results
// as we can't really cancel requests
Expand Down
6 changes: 3 additions & 3 deletions src/ui/public/partials/saved_object_finder.html
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
<form role="form">
<div class="form-group finder-form">
<div class="finder-form-options">
<a class="small" ng-click="finder.manageObjects(finder.objectType.name)">manage {{finder.objectType.name}}</a>
<a class="small" ng-click="finder.manageObjects(finder.properties.name)">manage {{finder.properties.nouns}}</a>
</div>
<div class="clearfix visible-xs-block"></div>
<input
input-focus
ng-model="filter"
ng-attr-placeholder="{{finder.objectType.noun}} Filter"
ng-attr-placeholder="{{finder.properties.noun}} Filter"
ng-keydown="finder.filterKeyDown($event)"
class="form-control"
name="filter"
Expand Down Expand Up @@ -40,7 +40,7 @@
<li
class="list-group-item list-group-no-results"
ng-if="finder.hits.length === 0">
<p ng-bind="'No matching ' + finder.objectType.nouns + ' found.'"></p>
<p ng-bind="'No matching ' + finder.properties.nouns + ' found.'"></p>
</li>
</ul>
</paginate>
7 changes: 7 additions & 0 deletions src/ui/public/saved_objects/saved_object_registry.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
define(function (require) {
return require('ui/registry/_registry')({
name: 'savedObjects',
index: ['loaderProperties.name'],
order: ['loaderProperties.name']
});
});

0 comments on commit 13b242a

Please sign in to comment.