added sorting

This commit is contained in:
Rashid Khan 2013-01-31 20:24:27 -07:00
parent 06b8dc3809
commit 896a6f7c10
2 changed files with 29 additions and 0 deletions

5
panels/sort/module.html Normal file
View File

@ -0,0 +1,5 @@
<div ng-controller='sort'>
<h4 ng-hide="_.isUndefined(panel.title)">{{panel.title}}</h4>
<select ng-model="panel.sort[0]" ng-options="f for f in fields"></select>
<i ng-click="toggle_sort()" ng-class="{'icon-chevron-up': panel.sort[1] == 'asc','icon-chevron-down': panel.sort[1] == 'desc'}"></i>
</div>

24
panels/sort/module.js Normal file
View File

@ -0,0 +1,24 @@
angular.module('kibana.sort', [])
.controller('sort', function($scope, $rootScope) {
// Set and populate defaults
var _d = {
query : "*",
size : 100,
sort : [config.timefield,'desc'],
}
_.each(_d, function(v, k) {
$scope.panel[k] = _.isUndefined($scope.panel[k])
? _d[k] : $scope.panel[k];
});
$scope.toggle_sort = function() {
$scope.panel.sort[1] = $scope.panel.sort[1] == 'asc' ? 'desc' : 'asc';
}
$scope.fields = [];
$scope.$on($scope.panel.group+"-fields", function(event, fields) {
$scope.panel.sort = fields.sort;
$scope.fields = _.union(fields.all,$scope.fields);
});
})