Skip to content

Commit

Permalink
Changing the inheritance chain so it's resolved at merge time
Browse files Browse the repository at this point in the history
  • Loading branch information
simianhacker committed Jul 24, 2014
1 parent 2d6eda1 commit 7ff55bf
Show file tree
Hide file tree
Showing 12 changed files with 134 additions and 93 deletions.
42 changes: 18 additions & 24 deletions src/kibana/apps/dashboard/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,41 +71,35 @@ define(function (require) {
$scope.openAdd = _.partial($scope.configTemplate.toggle, 'pickVis');
$scope.refresh = _.bindKey(courier, 'fetch');


timefilter.enabled(true);
$scope.timefilter = timefilter;
$scope.$watchCollection('globalState.time', $scope.refresh);

courier.setRootSearchSource(dash.searchSource);

function init() {
updateQueryOnRootSource()
.then(function () {
$scope.$broadcast('application.load');
});
updateQueryOnRootSource();
$scope.$broadcast('application.load');
}

function updateQueryOnRootSource() {
return courier.getRootSearch()
.then(function (rootSource) {
if ($state.query) {
rootSource.set('filter', {
query: {
query_string: {
query: $state.query
}
if ($state.query) {
dash.searchSource.set('filter', {
query: {
query_string: {
query: $state.query
}
});
} else {
rootSource.set('query', null);
}
});
}
});
} else {
dash.searchSource.set('filter', null);
}
}

$scope.filterResults = function () {
updateQueryOnRootSource()
.then(function () {
$state.commit();
courier.fetch();
});
updateQueryOnRootSource();
$state.commit();
courier.fetch();
};

$scope.save = function () {
Expand Down Expand Up @@ -162,4 +156,4 @@ define(function (require) {
}
};
});
});
});
6 changes: 4 additions & 2 deletions src/kibana/apps/dashboard/services/_saved_dashboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@ define(function (require) {
hits: 0,
description: '',
panelsJSON: '[]'
}
},

searchSource: true
});
}

Expand All @@ -41,4 +43,4 @@ define(function (require) {

return SavedDashboard;
});
});
});
2 changes: 1 addition & 1 deletion src/kibana/apps/discover/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -88,4 +88,4 @@ <h2>Searching</h2>
</div>
</div>
</div>
</div>
</div>
10 changes: 3 additions & 7 deletions src/kibana/apps/visualize/saved_visualizations/_adhoc_vis.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,8 @@ define(function (require) {
return opts.searchSource;
}

return courier.getRootSearch()
.then(function (rootSearch) {
var searchSource = courier.createSource('search');
searchSource.inherits(rootSearch);
return searchSource;
});
return courier.createSource('search');

}()))
.then(function (searchSource) {
// TODO: Should we abtract out the agg building stuff?
Expand Down Expand Up @@ -132,4 +128,4 @@ define(function (require) {

return AdhocVis;
});
});
});
32 changes: 13 additions & 19 deletions src/kibana/apps/visualize/saved_visualizations/_saved_vis.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,26 +73,20 @@ define(function (require) {
return savedSearches.get(vis.savedSearchId);
}

return courier.getRootSearch()
.then(function (rootSearch) {

if (relatedPattern) {
return indexPatterns.get(relatedPattern)
.then(function (indexPattern) {
// create a new search source that inherits from the parent and uses the indexPattern
return {
searchSource: rootSearch.extend().index(indexPattern)
};
});
}
var fakeSavedSearch = {
searchSource: courier.createSource('search')
};

if (relatedPattern) {
return indexPatterns.get(relatedPattern)
.then(function (indexPattern) {
fakeSavedSearch.searchSource.index(indexPattern);
return fakeSavedSearch;
});
}

// default parent is the rootSearch, can be overridden (like in discover)
// but we mimic the searchSource prop from saved objects here
return {
searchSource: rootSearch
};
return Promise.resolve(fakeSavedSearch);

});
}());

return promisedParent
Expand Down Expand Up @@ -223,4 +217,4 @@ define(function (require) {

return SavedVis;
});
});
});
17 changes: 10 additions & 7 deletions src/kibana/components/courier/_get_root_search.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,16 @@ define(function (require) {
});
};

var init = function () {
globalSource = new SearchSource();
globalSource = new SearchSource();

globalSource.filter(function (globalSource) {
// dynamic time filter will be called in the _flatten phase of things
return timefilter.get(globalSource.get('index'));
});
// searchSourceManager.registerGlobal(globalSource);

globalSource.filter(function (globalSource) {
// dynamic time filter will be called in the _flatten phase of things
return timefilter.get(globalSource.get('index'));
});

var init = function () {

appSource = new SearchSource();
appSource.inherits(globalSource);
Expand All @@ -36,4 +39,4 @@ define(function (require) {
return prom || init();
};
};
});
});
5 changes: 3 additions & 2 deletions src/kibana/components/courier/courier.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ define(function (require) {
var docLooper = Private(require('components/courier/looper/doc'));

// expose some internal modules
courier.getRootSearch = Private(require('components/courier/_get_root_search'));
courier.setRootSearchSource = Private(require('components/courier/data_source/_root_search_source')).set;

courier.SavedObject = Private(require('components/courier/saved_object/saved_object'));
courier.indexPatterns = indexPatterns;
courier.redirectWhenMissing = Private(require('components/courier/_redirect_when_missing'));
Expand Down Expand Up @@ -117,4 +118,4 @@ define(function (require) {

return new Courier();
});
});
});
20 changes: 15 additions & 5 deletions src/kibana/components/courier/data_source/_abstract.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,13 @@ define(function (require) {
}, handler);
};

/**
* Noop
*/
SourceAbstract.prototype.getParent = function () {
return Promise.resolve(false);
};

/**
* similar to onResults, but allows a seperate loopy code path
* for error handling.
Expand Down Expand Up @@ -221,10 +228,13 @@ define(function (require) {
}))
.then(function () {
// move to this sources parent
current = current._parent;

// keep calling until we reach the top parent
if (current) return ittr();
return current.getParent().then(function (parent) {
// keep calling until we reach the top parent
if (parent) {
current = parent;
return ittr();
}
});
});
}())
.then(function () {
Expand Down Expand Up @@ -260,4 +270,4 @@ define(function (require) {

return SourceAbstract;
};
});
});
49 changes: 49 additions & 0 deletions src/kibana/components/courier/data_source/_root_search_source.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
define(function (require) {
return function RootSearchSource(Private, $rootScope, config, Promise, indexPatterns, timefilter) {
var prom; // promise that must be resolved before the source is acurrate (updated by loadDefaultPattern)
var appSource;
var SearchSource = Private(require('components/courier/data_source/search_source'));

var get = function () {
return prom || loadDefaultPattern();
};

var set = function (source) {
source.inherits(globalSource);
appSource = source;
};

var loadDefaultPattern = function () {
var defId = config.get('defaultIndex');

return prom = Promise.cast(defId && indexPatterns.get(defId)).then(function (pattern) {
globalSource.set('index', pattern);
return appSource;
});
};

var globalSource = new SearchSource();
globalSource.inherits(false);
set(new SearchSource());

globalSource.filter(function (globalSource) {
// dynamic time filter will be called in the _flatten phase of things
return timefilter.get(globalSource.get('index'));
});

$rootScope.$on('change:config.defaultIndex', loadDefaultPattern);
$rootScope.$on('init:config', loadDefaultPattern);

function onRouteChangeStart() {
appSource = new SearchSource();
}

$rootScope.$on('$routeChangeStart', onRouteChangeStart);
$rootScope.$on('$routeUpdate', onRouteChangeStart);

return {
get: get,
set: set
};
};
});
23 changes: 16 additions & 7 deletions src/kibana/components/courier/data_source/search_source.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
define(function (require) {
var inherits = require('utils/inherits');
var _ = require('lodash');
var errors = require('errors');

return function SearchSourceFactory(Promise, Private) {
var inherits = require('utils/inherits');
var _ = require('lodash');
var errors = require('errors');
var SourceAbstract = Private(require('components/courier/data_source/_abstract'));

var getRootSourcePromise = new Promise(function (resolve) {
require(['components/courier/data_source/_root_search_source'], _.compose(resolve, Private));
});

var FetchFailure = errors.FetchFailure;
var RequestFailure = errors.RequestFailure;

Expand Down Expand Up @@ -62,10 +66,15 @@ define(function (require) {

/**
* Get the parent of this SearchSource
* @return {SearchSource}
* @return {Promise}
*/
SearchSource.prototype.parent = function () {
return this._parent;
SearchSource.prototype.getParent = function () {
var self = this;
return getRootSourcePromise.then(function (rootSearchSource) {
if (self._parent === false) return false;
if (self._parent) return self._parent;
return rootSearchSource.get();
});
};

/**
Expand Down Expand Up @@ -144,4 +153,4 @@ define(function (require) {

return SearchSource;
};
});
});
10 changes: 2 additions & 8 deletions src/kibana/components/courier/saved_object/saved_object.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,14 +61,8 @@ define(function (require) {
.type(type)
.id(obj.id);

// by default, the search source should inherit from the rootSearch
return Promise.cast(obj.searchSource && getRootSearch())
.then(function (rootSearch) {
if (rootSearch) obj.searchSource.inherits(rootSearch);

// check that the mapping for this type is defined
return mappingSetup.isDefined(type);
})
// check that the mapping for this type is defined
return mappingSetup.isDefined(type)
.then(function (defined) {
// if it is already defined skip this step
if (defined) return true;
Expand Down
11 changes: 0 additions & 11 deletions src/kibana/controllers/kibana.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,17 +110,6 @@ define(function (require) {
$rootScope.$on('$routeChangeSuccess', onRouteChange);
$rootScope.$on('$routeUpdate', onRouteChange);

function onRouteChangeStart() {
// Reset appSource
courier.getRootSearch()
.then(function (rootSearch) {
rootSearch.set({});
});
}

$rootScope.$on('$routeChangeStart', onRouteChangeStart);
$rootScope.$on('$routeUpdate', onRouteChangeStart);

var writeGlobalStateToLastPaths = function () {
var currentUrl = $location.url();
var _g = rison.encode(globalState);
Expand Down

0 comments on commit 7ff55bf

Please sign in to comment.