Skip to content

Commit

Permalink
Fix for queries and filters losing references, closes #1089
Browse files Browse the repository at this point in the history
  • Loading branch information
Rashid Khan committed Mar 30, 2014
1 parent 4ed4fb0 commit 78b5aa3
Show file tree
Hide file tree
Showing 10 changed files with 57 additions and 51 deletions.
4 changes: 2 additions & 2 deletions src/app/filters/all.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ define([

module.filter('pinnedQuery', function(querySrv) {
return function( items, pinned) {
var ret = _.filter(querySrv.ids,function(id){
var v = querySrv.list[id];
var ret = _.filter(querySrv.ids(),function(id){
var v = querySrv.list()[id];
if(!_.isUndefined(v.pin) && v.pin === true && pinned === true) {
return true;
}
Expand Down
6 changes: 3 additions & 3 deletions src/app/panels/query/editors/topN.html
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
<fieldset>
<label class="small">Field</label><br>
<input ng-model="querySrv.list[id].field" type="text" bs-typeahead="fields.list" placeholder="Field">
<input ng-model="dashboard.current.services.query.list[id].field" type="text" bs-typeahead="fields.list" placeholder="Field">
<p>
<label class="small">Count</label><br>
<input ng-model="querySrv.list[id].size" type="number">
<input ng-model="dashboard.current.services.query.list[id].size" type="number">
<p>
<label class="small">Union</label><br>
<select class="input-small" ng-model="querySrv.list[id].union">
<select class="input-small" ng-model="dashboard.current.services.query.list[id].union">
<option ng-repeat="mode in ['none','AND','OR']">{{mode}}</option>
</select>
</fieldset>
14 changes: 7 additions & 7 deletions src/app/panels/query/meta.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,28 +7,28 @@
</style>

<fieldset>
<select class="input-small" ng-model="querySrv.list[id].type" ng-change="typeChange(querySrv.list[id])">
<select class="input-small" ng-model="dashboard.current.services.query.list[id].type" ng-change="typeChange(dashboard.current.services.query.list[id])">
<option ng-repeat="type in queryTypes">{{type}}</option>
</select> &nbsp<a href="" class="small" ng-click="queryHelp(querySrv.list[id].type)"> About the {{querySrv.list[id].type}} query</a>
</select> &nbsp<a href="" class="small" ng-click="queryHelp(dashboard.current.services.query.list[id].type)"> About the {{dashboard.current.services.query.list[id].type}} query</a>

<hr class="small">

<label class="small">Legend value</label>
<input type="text" ng-model="querySrv.list[id].alias" placeholder="Alias...">
<input type="text" ng-model="dashboard.current.services.query.list[id].alias" placeholder="Alias...">
</fieldset>

<div ng-include src="queryConfig(querySrv.list[id].type)"></div>
<div ng-include src="queryConfig(dashboard.current.services.query.list[id].type)"></div>


<hr class="small">
<div>
<i ng-repeat="color in querySrv.colors" class="pointer" ng-class="{'icon-circle-blank':querySrv.list[id].color == color,'icon-circle':querySrv.list[id].color != color}" ng-style="{color:color}" ng-click="querySrv.list[id].color = color;render();"> </i>
<i ng-repeat="color in querySrv.colors" class="pointer" ng-class="{'icon-circle-blank':dashboard.current.services.query.list[id].color == color,'icon-circle':dashboard.current.services.query.list[id].color != color}" ng-style="{color:color}" ng-click="dashboard.current.services.query.list[id].color = color;render();"> </i>
</div>


<div class="pull-right">
<a class="btn btn-mini" ng-click="querySrv.list[id].enable=false;dashboard.refresh();dismiss();" class="pointer">Deactivate</a>
<a class="btn btn-mini" ng-class="{active:querySrv.list[id].pin}" ng-click="toggle_pin(id);dismiss();" class="pointer">Pin <i class="icon-pushpin"></i></a>
<a class="btn btn-mini" ng-click="dashboard.current.services.query.list[id].enable=false;dashboard.refresh();dismiss();" class="pointer">Deactivate</a>
<a class="btn btn-mini" ng-class="{active:dashboard.current.services.query.list[id].pin}" ng-click="toggle_pin(id);dismiss();" class="pointer">Pin <i class="icon-pushpin"></i></a>
<input class="btn btn-mini" ng-click="dashboard.refresh();dismiss();" type="submit"/ value="Close">
</div>
</div>
18 changes: 9 additions & 9 deletions src/app/panels/query/module.html
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
<div ng-controller='query' ng-init="init()" class="query-panel">
<div ng-repeat="id in (unPinnedQueries = (querySrv.ids|pinnedQuery:false))" ng-class="{'short-query': unPinnedQueries.length>1}">
<div ng-repeat="id in (unPinnedQueries = (dashboard.current.services.query.ids|pinnedQuery:false))" ng-class="{'short-query': unPinnedQueries.length>1}">
<form class="form-search" style="position:relative;margin:5px 0;" ng-submit="refresh()">
<span class="begin-query">
<i class="pointer" ng-class="queryIcon(querySrv.list[id].type)" ng-show="querySrv.list[id].enable" data-unique="1" bs-popover="'app/panels/query/meta.html'" data-placement="bottomLeft" ng-style="{color: querySrv.list[id].color}"></i>
<i class="pointer icon-circle-blank" ng-click="querySrv.list[id].enable=true;dashboard.refresh();" ng-hide="querySrv.list[id].enable" bs-tooltip="'Activate query'" ng-style="{color: querySrv.list[id].color}"></i>
<i class="icon-remove-sign pointer remove-query" ng-show="querySrv.ids.length > 1" ng-click="querySrv.remove(id);refresh()"></i>
<i class="pointer" ng-class="queryIcon(dashboard.current.services.query.list[id].type)" ng-show="dashboard.current.services.query.list[id].enable" data-unique="1" bs-popover="'app/panels/query/meta.html'" data-placement="bottomLeft" ng-style="{color: dashboard.current.services.query.list[id].color}"></i>
<i class="pointer icon-circle-blank" ng-click="dashboard.current.services.query.list[id].enable=true;dashboard.refresh();" ng-hide="dashboard.current.services.query.list[id].enable" bs-tooltip="'Activate query'" ng-style="{color: dashboard.current.services.query.list[id].color}"></i>
<i class="icon-remove-sign pointer remove-query" ng-show="dashboard.current.services.query.ids.length > 1" ng-click="querySrv.remove(id);refresh()"></i>
</span>
<span>
<input class="search-query panel-query" ng-disabled="!querySrv.list[id].enable" ng-class="{ 'input-block-level': unPinnedQueries.length==1, 'last-query': $last, 'has-remove': querySrv.ids.length > 1 }" bs-typeahead="panel.history" data-min-length=0 data-items=100 type="text" ng-model="querySrv.list[id].query" />
<input class="search-query panel-query" ng-disabled="!dashboard.current.services.query.list[id].enable" ng-class="{ 'input-block-level': unPinnedQueries.length==1, 'last-query': $last, 'has-remove': dashboard.current.services.query.ids.length > 1 }" bs-typeahead="panel.history" data-min-length=0 data-items=100 type="text" ng-model="dashboard.current.services.query.list[id].query" />
</span>
<span class="end-query">
<i class="icon-search pointer" ng-click="refresh()" ng-show="$last"></i>
<i class="icon-plus pointer" ng-click="querySrv.set({})" ng-show="$last"></i>
</span>
</form>
</div>
<div style="display:inline-block" ng-repeat="id in querySrv.ids|pinnedQuery:true">
<div style="display:inline-block" ng-repeat="id in dashboard.current.services.query.ids|pinnedQuery:true">
<span class="pointer badge pins" ng-show="$first" ng-click="panel.pinned = !panel.pinned">Pinned <i ng-class="{'icon-caret-right':panel.pinned,'icon-caret-left':!panel.pinned}"></i></span>
<span ng-show="panel.pinned" class="badge pinned">
<i class="icon-circle pointer" ng-show="querySrv.list[id].enable" ng-style="{color: querySrv.list[id].color}" data-unique="1" bs-popover="'app/panels/query/meta.html'" data-placement="bottomLeft"></i>
<i class="pointer icon-circle-blank" bs-tooltip="'Activate query'" ng-click="querySrv.list[id].enable=true;dashboard.refresh();" ng-hide="querySrv.list[id].enable" ng-style="{color: querySrv.list[id].color}"></i>
<span bs-tooltip="querySrv.list[id].query | limitTo:45"> {{querySrv.list[id].alias || querySrv.list[id].query}}</span>
<i class="icon-circle pointer" ng-show="dashboard.current.services.query.list[id].enable" ng-style="{color: dashboard.current.services.query.list[id].color}" data-unique="1" bs-popover="'app/panels/query/meta.html'" data-placement="bottomLeft"></i>
<i class="pointer icon-circle-blank" bs-tooltip="'Activate query'" ng-click="dashboard.current.services.query.list[id].enable=true;dashboard.refresh();" ng-hide="dashboard.current.services.query.list[id].enable" ng-style="{color: dashboard.current.services.query.list[id].color}"></i>
<span bs-tooltip="dashboard.current.services.query.list[id].query | limitTo:45"> {{dashboard.current.services.query.list[id].alias || dashboard.current.services.query.list[id].query}}</span>
</span>
</div>
<span style="display:inline-block" ng-show="unPinnedQueries.length == 0">
Expand Down
7 changes: 4 additions & 3 deletions src/app/panels/query/module.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ define([
_.defaults($scope.panel,_d);

$scope.querySrv = querySrv;
$scope.dashboard = dashboard;

// A list of query types for the query config popover
$scope.queryTypes = querySrv.types;
Expand All @@ -51,7 +52,7 @@ define([
};

$scope.refresh = function() {
update_history(_.pluck($scope.querySrv.list,'query'));
update_history(_.pluck($scope.dashboard.current.services.query.list,'query'));
dashboard.refresh();
};

Expand All @@ -60,7 +61,7 @@ define([
};

$scope.toggle_pin = function(id) {
querySrv.list[id].pin = querySrv.list[id].pin ? false : true;
dashboard.current.services.query.list[id].pin = dashboard.current.services.query.list[id].pin ? false : true;
};

$scope.queryIcon = function(type) {
Expand Down Expand Up @@ -92,7 +93,7 @@ define([
alias: q.alias,
color: q.color
};
querySrv.list[_nq.id] = querySrv.defaults(_nq);
dashboard.current.services.query.list[_nq.id] = querySrv.defaults(_nq);
};

var update_history = function(query) {
Expand Down
1 change: 0 additions & 1 deletion src/app/panels/timepicker/module.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,6 @@ function (angular, app, _, moment, kbn) {
$scope.temptime.from.date.setHours(0,0,0,0);
$scope.temptime.to.date.setHours(0,0,0,0);

console.log(new Date().getTimezoneOffset());

// This is an ugly hack, but works.
if(new Date().getTimezoneOffset() < 0) {
Expand Down
2 changes: 0 additions & 2 deletions src/app/panels/trends/module.js
Original file line number Diff line number Diff line change
Expand Up @@ -174,8 +174,6 @@ function (angular, app, _, kbn) {
process_results(request.indices($scope.index[_segment]).doSearch(),_segment,query_id);
}

console.log(request);

};

// Populate scope when we have results
Expand Down
6 changes: 3 additions & 3 deletions src/app/partials/querySelect.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@
</div>
<div class="span9 querySelect" ng-show="panel.queries.mode == 'selected'">
<label class="small">Selected Queries</label>
<span ng-style="{'border-color': querySrv.list[id].color}" ng-class="{selected:_.contains(panel.queries.ids,id),unselected:!_.contains(panel.queries.ids,id)}" ng-repeat="id in querySrv.ids" ng-click="panel.queries.ids = _.toggleInOut(panel.queries.ids,id);set_refresh(true);" class="query pointer badge">
<i class="icon-circle" ng-style="{color: querySrv.list[id].color}"></i>
<span> {{querySrv.list[id].alias || querySrv.list[id].query}}</span>
<span ng-style="{'border-color': querySrv.list()[id].color}" ng-class="{selected:_.contains(panel.queries.ids,id),unselected:!_.contains(panel.queries.ids,id)}" ng-repeat="id in querySrv.ids()" ng-click="panel.queries.ids = _.toggleInOut(panel.queries.ids,id);set_refresh(true);" class="query pointer badge">
<i class="icon-circle" ng-style="{color: querySrv.list()[id].color}"></i>
<span> {{querySrv.list()[id].alias || querySrv.list()[id].query}}</span>
</span>
</div>
</div>
1 change: 0 additions & 1 deletion src/app/services/dashboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,6 @@ function (angular, $, kbn, _, config, moment, Modernizr) {
};

this.to_file = function() {
console.log(self.current.services.filter.list);
var blob = new Blob([angular.toJson(self.current,true)], {type: "application/json;charset=utf-8"});
// from filesaver.js
window.saveAs(blob, self.current.title+"-"+new Date().getTime());
Expand Down
49 changes: 29 additions & 20 deletions src/app/services/querySrv.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,19 +135,27 @@ function (angular, _, config, kbn) {
});
});


this.list = function () {
return dashboard.current.services.query.list;
};

this.ids = function () {
return dashboard.current.services.query.ids;
};

this.init = function() {
self.list = dashboard.current.services.query.list;
self.ids = dashboard.current.services.query.ids;

self.ids = dashboard.current.services.query.ids =
_.intersection(_.map(self.list,function(v,k){return parseInt(k,10);}),self.ids);
dashboard.current.services.query.ids =
_.intersection(_.map(dashboard.current.services.query.list,
function(v,k){return parseInt(k,10);}),self.ids());

// Check each query object, populate its defaults
_.each(self.list,function(query) {
_.each(dashboard.current.services.query.list,function(query) {
query = self.defaults(query);
});

if (self.ids.length === 0) {
if (dashboard.current.services.query.ids.length === 0) {
self.set({});
}
};
Expand All @@ -156,8 +164,8 @@ function (angular, _, config, kbn) {
// the query at that id is updated
this.set = function(query,id) {
if(!_.isUndefined(id)) {
if(!_.isUndefined(self.list[id])) {
_.extend(self.list[id],query);
if(!_.isUndefined(dashboard.current.services.query.list[id])) {
_.extend(dashboard.current.services.query.list[id],query);
return id;
} else {
return false;
Expand All @@ -168,8 +176,8 @@ function (angular, _, config, kbn) {
query.color = query.color || colorAt(query.id);
// Then it can get defaults
query = self.defaults(query);
self.list[query.id] = query;
self.ids.push(query.id);
dashboard.current.services.query.list[query.id] = query;
dashboard.current.services.query.ids.push(query.id);
return query.id;
}
};
Expand All @@ -182,10 +190,10 @@ function (angular, _, config, kbn) {
};

this.remove = function(id) {
if(!_.isUndefined(self.list[id])) {
delete self.list[id];
if(!_.isUndefined(dashboard.current.services.query.list[id])) {
delete dashboard.current.services.query.list[id];
// This must happen on the full path also since _.without returns a copy
self.ids = dashboard.current.services.query.ids = _.without(self.ids,id);
dashboard.current.services.query.ids = _.without(dashboard.current.services.query.ids,id);
return true;
} else {
return false;
Expand Down Expand Up @@ -222,24 +230,25 @@ function (angular, _, config, kbn) {
switch(config.mode)
{
case 'all':
return _.pluck(_.where(self.list,{enable:true}),'id');
return _.pluck(_.where(dashboard.current.services.query.list,{enable:true}),'id');
case 'pinned':
return _.pluck(_.where(self.list,{pin:true,enable:true}),'id');
return _.pluck(_.where(dashboard.current.services.query.list,{pin:true,enable:true}),'id');
case 'unpinned':
return _.pluck(_.where(self.list,{pin:false,enable:true}),'id');
return _.pluck(_.where(dashboard.current.services.query.list,{pin:false,enable:true}),'id');
case 'selected':
return _.intersection(_.pluck(_.where(self.list,{enable:true}),'id'),config.ids);
return _.intersection(_.pluck(_.where(dashboard.current.services.query.list,{enable:true}),'id'),config.ids);
default:
return _.pluck(_.where(self.list,{enable:true}),'id');
return _.pluck(_.where(dashboard.current.services.query.list,{enable:true}),'id');
}
};

// This populates the internal query list and returns a promise containing it
this.resolve = function() {
// Find ids of all abstract queries
// Get a list of resolvable ids, constrast with total list to get abstract ones
return $q.all(_.map(self.ids,function(q) {
return self.queryTypes[self.list[q].type].resolve(_.clone(self.list[q])).then(function(data){
return $q.all(_.map(dashboard.current.services.query.ids,function(q) {
return self.queryTypes[dashboard.current.services.query.list[q].type].resolve(
_.clone(dashboard.current.services.query.list[q])).then(function(data){
return data;
});
})).then(function(data) {
Expand Down

0 comments on commit 78b5aa3

Please sign in to comment.