Skip to content

Commit

Permalink
Merge pull request #744 from rashidkpc/master
Browse files Browse the repository at this point in the history
Remove idQueue from services
  • Loading branch information
Rashid Khan committed Dec 2, 2013
2 parents e73ea48 + 3fe9473 commit 81bbc5b
Show file tree
Hide file tree
Showing 8 changed files with 34 additions and 67 deletions.
20 changes: 20 additions & 0 deletions src/app/components/kbn.js
Original file line number Diff line number Diff line change
Expand Up @@ -479,6 +479,26 @@ function($, _, moment) {
});
};

// Find the smallest missing number in an array
kbn.smallestMissing = function(arr,start,end) {
start = start || 0;
end = end || arr.length-1;

if(start > end) {
return end + 1;
}
if(start !== arr[start]) {
return start;
}
var middle = Math.floor((start + end) / 2);

if (arr[middle] > middle) {
return kbn.smallestMissing(arr, start, middle);
} else {
return kbn.smallestMissing(arr, middle + 1, end);
}
};

kbn.byteFormat = function(size, decimals) {
var ext, steps = 0;
decimals = decimals || 2;
Expand Down
11 changes: 0 additions & 11 deletions src/app/dashboards/blank.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,6 @@
"title": "New Dashboard",
"services": {
"query": {
"idQueue": [
1,
2,
3,
4
],
"list": {
"0": {
"query": "*",
Expand All @@ -21,11 +15,6 @@
]
},
"filter": {
"idQueue": [
0,
1,
2
],
"list": {},
"ids": []
}
Expand Down
11 changes: 0 additions & 11 deletions src/app/dashboards/default.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,6 @@
"title": "Introduction",
"services": {
"query": {
"idQueue": [
1,
2,
3,
4
],
"list": {
"0": {
"query": "*",
Expand All @@ -23,11 +17,6 @@
]
},
"filter": {
"idQueue": [
0,
1,
2
],
"list": {},
"ids": []
}
Expand Down
11 changes: 0 additions & 11 deletions src/app/dashboards/guided.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,6 @@
"title": "Your Basic Dashboard",
"services": {
"query": {
"idQueue": [
1,
2,
3,
4
],
"list": {
"0": {
"query": "*",
Expand All @@ -23,11 +17,6 @@
]
},
"filter": {
"idQueue": [
0,
1,
2
],
"list": {},
"ids": []
}
Expand Down
6 changes: 0 additions & 6 deletions src/app/dashboards/logstash.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@
"title": "Logstash Search",
"services": {
"query": {
"idQueue": [
1
],
"list": {
"0": {
"query": "{{ARGS.query || '*'}}",
Expand All @@ -20,9 +17,6 @@
]
},
"filter": {
"idQueue": [
1
],
"list": {
"0": {
"type": "time",
Expand Down
11 changes: 0 additions & 11 deletions src/app/dashboards/noted.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,6 @@
"title": "A few notes",
"services": {
"query": {
"idQueue": [
1,
2,
3,
4
],
"list": {
"0": {
"query": "*",
Expand All @@ -23,11 +17,6 @@
]
},
"filter": {
"idQueue": [
0,
1,
2
],
"list": {},
"ids": []
}
Expand Down
15 changes: 7 additions & 8 deletions src/app/services/filterSrv.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,12 @@ define([

// Defaults for it
var _d = {
idQueue : [],
list : {},
ids : []
};

// For convenience
var ejs = ejsResource(config.elasticsearch);
var _f = dashboard.current.services.filter;

// Save a reference to this
var self = this;
Expand All @@ -34,7 +32,6 @@ define([
// Accessors
self.list = dashboard.current.services.filter.list;
self.ids = dashboard.current.services.filter.ids;
_f = dashboard.current.services.filter;

_.each(self.list,function(f) {
self.set(f,f.id,true);
Expand Down Expand Up @@ -97,8 +94,6 @@ define([
delete self.list[id];
// This must happen on the full path also since _.without returns a copy
self.ids = dashboard.current.services.filter.ids = _.without(self.ids,id);
_f.idQueue.unshift(id);
_f.idQueue.sort(function(v,k){return v-k;});
_r = true;
} else {
_r = false;
Expand Down Expand Up @@ -230,10 +225,14 @@ define([
};

var nextId = function() {
if(_f.idQueue.length > 0) {
return _f.idQueue.shift();
var idCount = dashboard.current.services.filter.ids.length;
if(idCount > 0) {
// Make a sorted copy of the ids array
var ids = _.clone(dashboard.current.services.filter.ids).sort();
return kbn.smallestMissing(ids);
} else {
return self.ids.length;
// No ids currently in list
return 0;
}
};

Expand Down
16 changes: 7 additions & 9 deletions src/app/services/querySrv.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ function (angular, _, config, kbn) {
// Create an object to hold our service state on the dashboard
dashboard.current.services.query = dashboard.current.services.query || {};
_.defaults(dashboard.current.services.query,{
idQueue : [],
list : {},
ids : [],
});
Expand All @@ -31,7 +30,6 @@ function (angular, _, config, kbn) {

// For convenience
var ejs = ejsResource(config.elasticsearch);
var _q = dashboard.current.services.query;

// Holds all actual queries, including all resolved abstract queries
var resolvedQueries = [];
Expand Down Expand Up @@ -176,10 +174,6 @@ function (angular, _, config, kbn) {
delete self.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);
_q.idQueue.unshift(id);
_q.idQueue.sort(function(v,k){
return v-k;
});
return true;
} else {
return false;
Expand Down Expand Up @@ -246,10 +240,14 @@ function (angular, _, config, kbn) {
};

var nextId = function() {
if(_q.idQueue.length > 0) {
return _q.idQueue.shift();
var idCount = dashboard.current.services.query.ids.length;
if(idCount > 0) {
// Make a sorted copy of the ids array
var ids = _.clone(dashboard.current.services.query.ids).sort();
return kbn.smallestMissing(ids);
} else {
return self.ids.length;
// No ids currently in list
return 0;
}
};

Expand Down

0 comments on commit 81bbc5b

Please sign in to comment.