added refresh interval settings to the main kibana nav bar, config directive makes the configObject available by it's name on it's iso scope

This commit is contained in:
Spencer Alger 2014-02-28 09:00:44 -07:00
parent bc89b88148
commit 81fa4337e1
3 changed files with 67 additions and 2 deletions

View file

@ -20,7 +20,17 @@
<a href="#/{{app.id}}">{{app.name}}</a>
</li>
</ul>
<ul class="nav navbar-nav pull-right">
<li>
<a ng-click="configure()"><i class="fa fa-gear"></i></a>
</li>
</ul>
</nav>
<config
config-template="configureTemplateUrl"
config-object="opts"
config-submit="saveOpts">
</config>
<div class="application" kbn-view></div>
<!-- Required to be able to stretch the -->

View file

@ -2,16 +2,70 @@ define(function (require) {
var angular = require('angular');
var _ = require('lodash');
var $ = require('jquery');
var moment = require('moment');
require('services/config');
require('services/courier');
angular
.module('kibana/controllers')
.controller('kibana', function ($scope, courier, configFile) {
.controller('kibana', function ($scope, courier, config, configFile) {
$scope.apps = configFile.apps;
$scope.activeApp = '';
$scope.opts = {
activeFetchInterval: void 0,
fetchIntervals: [
{ display: '5s', val: 5000 },
{ display: '10s', val: 10000 },
{ display: '30s', val: 30000 },
{ display: '1m', val: 60000 },
{ display: '5m', val: 300000 },
{ display: '15m', val: 900000 },
{ display: '30m', val: 1.8e+6 },
{ display: '1h', val: 3.6e+6 },
{ display: '2h', val: 7.2e+6 },
{ display: '1d', val: 8.64e+7 }
]
};
$scope.configure = function () {
$scope.configureTemplateUrl = 'kibana/partials/global_config.html';
};
/**
* Persist current settings
* @return {[type]} [description]
*/
$scope.saveOpts = function () {
config.set('refreshInterval', $scope.opts.activeFetchInterval.val);
};
$scope.setFetchInterval = function (option) {
var opts = $scope.opts;
if (option && typeof option !== 'object') {
var val = option;
option = _.find($scope.opts.fetchIntervals, { val: val });
if (!option) {
// create a custom option for this value
option = { display: moment.duration(val).humanize(), val: val };
$scope.opts.unshift(option);
}
}
if (option === opts.activeFetchInterval) return;
opts.activeFetchInterval = option;
if (option) {
courier.fetchInterval(option.val);
} else {
courier.stop();
}
};
config.$watch('refreshInterval', $scope.setFetchInterval);
$scope.$watch('opts.activeFetchInterval', $scope.setFetchInterval);
$scope.$on('application.load', function () {
courier.start();
});

View file

@ -23,7 +23,8 @@ define(function (require) {
configSubmit: '=',
configObject: '='
},
link: function ($scope) {
link: function ($scope, element, attr) {
$scope[attr.configObject] = $scope.configObject;
$scope.close = function () {
if (_.isFunction($scope.configClose)) $scope.configClose();
$scope.configTemplate = undefined;