2013-09-13 15:52:13 -05:00
|
|
|
define([
|
|
|
|
'angular',
|
2013-09-16 12:48:08 -05:00
|
|
|
'jquery',
|
|
|
|
'kbn',
|
2014-08-05 03:15:27 -05:00
|
|
|
'underscore',
|
|
|
|
'../timer',
|
2013-09-13 15:52:13 -05:00
|
|
|
],
|
2014-06-07 12:43:15 -05:00
|
|
|
function (angular, $, kbn, _) {
|
2013-09-13 15:52:13 -05:00
|
|
|
'use strict';
|
|
|
|
|
2014-07-28 11:11:52 -05:00
|
|
|
var module = angular.module('grafana.services');
|
2013-09-13 15:52:13 -05:00
|
|
|
|
2014-06-08 07:40:44 -05:00
|
|
|
module.service('dashboard', function(timer, $rootScope, $timeout) {
|
2014-06-07 12:43:15 -05:00
|
|
|
|
|
|
|
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
|
|
|
|
2014-08-05 03:15:27 -05:00
|
|
|
this.title = data.title || 'No Title';
|
2014-06-07 12:43:15 -05:00
|
|
|
this.tags = data.tags || [];
|
|
|
|
this.style = data.style || "dark";
|
2014-07-21 11:49:30 -05:00
|
|
|
this.timezone = data.timezone || 'browser';
|
2014-06-07 12:43:15 -05:00
|
|
|
this.editable = data.editble || true;
|
|
|
|
this.rows = data.rows || [];
|
|
|
|
this.pulldowns = data.pulldowns || [];
|
|
|
|
this.nav = data.nav || [];
|
2014-08-05 03:15:27 -05:00
|
|
|
this.time = data.time || { from: 'now-6h', to: 'now' };
|
|
|
|
this.templating = data.templating || { list: [] };
|
2014-08-07 00:20:56 -05:00
|
|
|
this.refresh = data.refresh;
|
2014-06-07 12:43:15 -05:00
|
|
|
|
|
|
|
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 });
|
|
|
|
}
|
|
|
|
|
2014-08-05 03:15:27 -05:00
|
|
|
this.updateSchema(data);
|
2014-06-07 12:43:15 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
var p = DashboardModel.prototype;
|
|
|
|
|
2014-06-07 14:00:05 -05:00
|
|
|
p.emit_refresh = function() {
|
2014-06-07 12:43:15 -05:00
|
|
|
$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-07 12:43:15 -05:00
|
|
|
|
2014-06-22 12:01:04 -05:00
|
|
|
p.set_interval = function (interval) {
|
|
|
|
this.refresh = interval;
|
2014-06-07 12:43:15 -05:00
|
|
|
if (interval) {
|
|
|
|
var _i = kbn.interval_to_ms(interval);
|
2014-06-22 12:01:04 -05:00
|
|
|
this.start_scheduled_refresh(_i);
|
2014-06-07 12:43:15 -05:00
|
|
|
} else {
|
2014-06-22 12:01:04 -05:00
|
|
|
this.cancel_scheduled_refresh();
|
2014-06-07 12:43:15 -05:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2014-08-05 03:15:27 -05:00
|
|
|
p.updateSchema = function(old) {
|
|
|
|
var i, j, row, panel;
|
|
|
|
var isChanged = false;
|
|
|
|
|
|
|
|
if (this.version === 2) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (old.services) {
|
|
|
|
if (old.services.filter) {
|
|
|
|
this.time = old.services.filter.time;
|
|
|
|
this.templating.list = old.services.filter.list;
|
|
|
|
}
|
|
|
|
delete this.services;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < this.rows.length; i++) {
|
|
|
|
row = this.rows[i];
|
|
|
|
for (j = 0; j < row.panels.length; j++) {
|
|
|
|
panel = row.panels[j];
|
|
|
|
if (panel.type === 'graphite') {
|
|
|
|
panel.type = 'graph';
|
|
|
|
isChanged = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (panel.type === 'graph') {
|
|
|
|
if (_.isBoolean(panel.legend)) {
|
|
|
|
panel.legend = { show: panel.legend };
|
|
|
|
}
|
|
|
|
|
|
|
|
if (panel.grid) {
|
|
|
|
if (panel.grid.min) {
|
|
|
|
panel.grid.leftMin = panel.grid.min;
|
|
|
|
delete panel.grid.min;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (panel.grid.max) {
|
|
|
|
panel.grid.leftMax = panel.grid.max;
|
|
|
|
delete panel.grid.max;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (panel.y_format) {
|
|
|
|
panel.y_formats[0] = panel.y_format;
|
|
|
|
delete panel.y_format;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (panel.y2_format) {
|
|
|
|
panel.y_formats[1] = panel.y2_format;
|
|
|
|
delete panel.y2_format;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
this.version = 2;
|
|
|
|
};
|
|
|
|
|
2014-06-07 12:43:15 -05:00
|
|
|
return {
|
|
|
|
create: function(dashboard) {
|
|
|
|
return new DashboardModel(dashboard);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
});
|
2013-10-09 03:36:41 -05:00
|
|
|
});
|