implement the querybar logic

This commit is contained in:
Joe Fleming 2014-07-21 17:36:48 -07:00 committed by Spencer Alger
parent b5fd704fa4
commit 84f3322a98
3 changed files with 49 additions and 14 deletions

View file

@ -53,7 +53,8 @@ define(function (require) {
var stateDefaults = {
title: dash.title,
panels: dash.panelsJSON ? JSON.parse(dash.panelsJSON) : []
panels: dash.panelsJSON ? JSON.parse(dash.panelsJSON) : [],
query: ''
};
var $state = $scope.state = new AppState(stateDefaults);
@ -76,13 +77,30 @@ define(function (require) {
$scope.timefilter = timefilter;
$scope.$watchCollection('globalState.time', $scope.refresh);
$scope.filterResults = function () {
var root = courier.getRootSearch();
root.then(function (rootSource) {
rootSource.set('query', {
query_string: { query: $scope.state.query }
});
function init() {
updateQueryOnRootSource()
.then(function () {
$scope.$broadcast('application.load');
});
}
function updateQueryOnRootSource() {
return courier.getRootSearch()
.then(function (rootSource) {
if ($state.query) {
rootSource.set('query', {
query_string: { query: $state.query }
});
} else {
rootSource.set('query', null);
}
});
}
$scope.filterResults = function () {
updateQueryOnRootSource()
.then(function () {
$state.commit();
courier.fetch();
});
};
@ -137,7 +155,7 @@ define(function (require) {
}
};
$scope.$broadcast('application.load');
init();
}
};
});

View file

@ -2,27 +2,33 @@ define(function (require) {
return function RootSearchFactory(Private, config, $rootScope, timefilter, indexPatterns, Promise) {
var SearchSource = Private(require('components/courier/data_source/search_source'));
var source; // the actual search source
var globalSource; // the global search source - EVERYTHING inherits from this
var appSource; // the app-level search source - reset with each app change
var prom; // promise that must be resolved before the source is acurrate (updated by loadDefaultPattern)
var loadDefaultPattern = function () {
var defId = config.get('defaultIndex');
return prom = Promise.cast(defId && indexPatterns.get(defId)).then(function (pattern) {
source.set('index', pattern);
return source;
globalSource.set('index', pattern);
return appSource;
});
};
var init = function () {
source = new SearchSource();
source.filter(function (source) {
globalSource = new SearchSource();
globalSource.filter(function (globalSource) {
// dynamic time filter will be called in the _flatten phase of things
return timefilter.get(source.get('index'));
return timefilter.get(globalSource.get('index'));
});
appSource = new SearchSource();
appSource.inherits(globalSource);
$rootScope.$on('change:config.defaultIndex', loadDefaultPattern);
$rootScope.$on('init:config', loadDefaultPattern);
return loadDefaultPattern();
};

View file

@ -110,6 +110,17 @@ 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);