grafana/src/app/services/dashboard/dashboardModel.js

100 lines
2.4 KiB
JavaScript
Raw Normal View History

2013-09-13 15:52:13 -05:00
define([
'angular',
'jquery',
'kbn',
2014-06-13 06:50:09 -05:00
'underscore'
2013-09-13 15:52:13 -05:00
],
function (angular, $, kbn, _) {
2013-09-13 15:52:13 -05:00
'use strict';
var module = angular.module('kibana.services');
2014-06-08 07:40:44 -05:00
module.service('dashboard', function(timer, $rootScope, $timeout) {
function DashboardModel (data) {
2014-06-08 13:46:30 -05:00
2014-06-08 09:08:12 -05:00
if (!data) {
data = {};
2014-06-08 09:09:36 -05:00
}
2014-06-08 09:08:12 -05:00
this.title = data.title;
this.tags = data.tags || [];
this.style = data.style || "dark";
this.timezone = data.browser || 'browser';
this.editable = data.editble || true;
this.rows = data.rows || [];
this.pulldowns = data.pulldowns || [];
this.nav = data.nav || [];
this.services = data.services || {};
2014-06-08 09:08:12 -05:00
this.loader = data.loader || {};
_.defaults(this.loader, {
2013-09-13 15:52:13 -05:00
save_gist: false,
save_elasticsearch: true,
save_default: true,
save_temp: true,
save_temp_ttl_enable: true,
save_temp_ttl: '30d',
load_gist: false,
2013-09-13 15:52:13 -05:00
load_elasticsearch: true,
hide: false
});
if (this.nav.length === 0) {
this.nav.push({ type: 'timepicker' });
}
if (!_.findWhere(this.pulldowns, {type: 'filtering'})) {
this.pulldowns.push({ type: 'filtering', enable: false });
}
if (!_.findWhere(this.pulldowns, {type: 'annotations'})) {
this.pulldowns.push({ type: 'annotations', enable: false });
}
_.each(this.rows, function(row) {
_.each(row.panels, function(panel) {
if (panel.type === 'graphite') {
panel.type = 'graph';
}
});
});
}
var p = DashboardModel.prototype;
2014-06-07 14:00:05 -05:00
p.emit_refresh = function() {
$rootScope.$broadcast('refresh');
};
2014-06-22 12:01:04 -05:00
p.start_scheduled_refresh = function (after_ms) {
this.cancel_scheduled_refresh();
this.refresh_timer = timer.register($timeout(function () {
this.start_scheduled_refresh(after_ms);
this.emit_refresh();
}.bind(this), after_ms));
};
p.cancel_scheduled_refresh = function () {
timer.cancel(this.refresh_timer);
};
2014-06-22 12:01:04 -05:00
p.set_interval = function (interval) {
this.refresh = interval;
if (interval) {
var _i = kbn.interval_to_ms(interval);
2014-06-22 12:01:04 -05:00
this.start_scheduled_refresh(_i);
} else {
2014-06-22 12:01:04 -05:00
this.cancel_scheduled_refresh();
}
};
return {
create: function(dashboard) {
return new DashboardModel(dashboard);
}
};
});
});