Linted, moved shared functions to kbn object

This commit is contained in:
Rashid Khan
2013-07-20 14:56:59 -07:00
parent 7c9f14ad5e
commit 5a3028f784
17 changed files with 955 additions and 920 deletions
+36 -28
View File
@@ -1,3 +1,6 @@
/*jshint globalstrict:true */
/*global angular:true */
/*
## Map
@@ -22,6 +25,8 @@
*/
'use strict';
angular.module('kibana.map', [])
.controller('map', function($scope, $rootScope, query, dashboard, filterSrv) {
@@ -36,37 +41,39 @@ angular.module('kibana.map', [])
spyable : true,
group : "default",
index_limit : 0
}
_.defaults($scope.panel,_d)
};
_.defaults($scope.panel,_d);
$scope.init = function() {
$scope.$on('refresh',function(){$scope.get_data()})
$scope.$on('refresh',function(){$scope.get_data();});
$scope.get_data();
}
};
$scope.get_data = function() {
// Make sure we have everything for the request to complete
if(dashboard.indices.length == 0) {
return
if(dashboard.indices.length === 0) {
return;
}
$scope.panel.loading = true;
var request = $scope.ejs.Request().indices(dashboard.indices);
var boolQuery = ejs.BoolQuery();
var request;
request = $scope.ejs.Request().indices(dashboard.indices);
var boolQuery = $scope.ejs.BoolQuery();
_.each(query.list,function(q) {
boolQuery = boolQuery.should(ejs.QueryStringQuery(q.query || '*'))
})
boolQuery = boolQuery.should($scope.ejs.QueryStringQuery(q.query || '*'));
});
// Then the insert into facet and make the request
var request = request
.facet(ejs.TermsFacet('map')
request = request
.facet($scope.ejs.TermsFacet('map')
.field($scope.panel.field)
.size($scope.panel['size'])
.size($scope.panel.size)
.exclude($scope.panel.exclude)
.facetFilter(ejs.QueryFilter(
ejs.FilteredQuery(
.facetFilter($scope.ejs.QueryFilter(
$scope.ejs.FilteredQuery(
boolQuery,
filterSrv.getBoolFilter(filterSrv.ids)
)))).size(0);
@@ -83,9 +90,9 @@ angular.module('kibana.map', [])
_.each(results.facets.map.terms, function(v) {
$scope.data[v.term.toUpperCase()] = v.count;
});
$scope.$emit('render')
$scope.$emit('render');
});
}
};
// I really don't like this function, too much dom manip. Break out into directive?
$scope.populate_modal = function(request) {
@@ -95,13 +102,13 @@ angular.module('kibana.map', [])
'curl -XGET '+config.elasticsearch+'/'+dashboard.indices+"/_search?pretty -d'\n"+
angular.toJson(JSON.parse(request.toString()),true)+
"'</pre>",
}
}
};
};
$scope.build_search = function(field,value) {
filterSrv.set({type:'querystring',mandate:'must',query:field+":"+value})
filterSrv.set({type:'querystring',mandate:'must',query:field+":"+value});
dashboard.refresh();
}
};
})
.directive('map', function() {
@@ -109,7 +116,7 @@ angular.module('kibana.map', [])
restrict: 'A',
link: function(scope, elem, attrs) {
elem.html('<center><img src="common/img/load_big.gif"></center>')
elem.html('<center><img src="common/img/load_big.gif"></center>');
// Receive render events
scope.$on('render',function(){
@@ -124,7 +131,7 @@ angular.module('kibana.map', [])
function render_panel() {
// Using LABjs, wait until all scripts are loaded before rendering panel
var scripts = $LAB.script("panels/map/lib/jquery.jvectormap.min.js").wait()
.script("panels/map/lib/map."+scope.panel.map+".js")
.script("panels/map/lib/map."+scope.panel.map+".js");
// Populate element. Note that jvectormap appends, does not replace.
scripts.wait(function(){
@@ -143,7 +150,7 @@ angular.module('kibana.map', [])
}]
},
onRegionLabelShow: function(event, label, code){
elem.children('.map-legend').show()
elem.children('.map-legend').show();
var count = _.isUndefined(scope.data[code]) ? 0 : scope.data[code];
elem.children('.map-legend').text(label.text() + ": " + count);
},
@@ -152,13 +159,14 @@ angular.module('kibana.map', [])
},
onRegionClick: function(event, code) {
var count = _.isUndefined(scope.data[code]) ? 0 : scope.data[code];
if (count != 0)
scope.build_search(scope.panel.field,code)
if (count !== 0) {
scope.build_search(scope.panel.field,code);
}
}
});
elem.prepend('<span class="map-legend"></span>');
$('.map-legend').hide();
})
});
}
}
};