prettier: ran on all files again, sorry. now settings are defined in package.json

This commit is contained in:
Torkel Ödegaard
2017-12-21 08:39:31 +01:00
parent af34f9977e
commit 3a1f52d8a2
262 changed files with 3996 additions and 7431 deletions

View File

@@ -6,11 +6,7 @@ import _ from 'lodash';
export class AclCtrl {
dashboard: any;
items: DashboardAcl[];
permissionOptions = [
{ value: 1, text: 'View' },
{ value: 2, text: 'Edit' },
{ value: 4, text: 'Admin' },
];
permissionOptions = [{ value: 1, text: 'View' }, { value: 2, text: 'Edit' }, { value: 4, text: 'Admin' }];
aclTypes = [
{ value: 'Group', text: 'Team' },
{ value: 'User', text: 'User' },
@@ -38,25 +34,18 @@ export class AclCtrl {
}
get(dashboardId: number) {
return this.backendSrv
.get(`/api/dashboards/id/${dashboardId}/acl`)
.then(result => {
this.items = _.map(result, this.prepareViewModel.bind(this));
this.sortItems();
});
return this.backendSrv.get(`/api/dashboards/id/${dashboardId}/acl`).then(result => {
this.items = _.map(result, this.prepareViewModel.bind(this));
this.sortItems();
});
}
sortItems() {
this.items = _.orderBy(
this.items,
['sortRank', 'sortName'],
['desc', 'asc']
);
this.items = _.orderBy(this.items, ['sortRank', 'sortName'], ['desc', 'asc']);
}
prepareViewModel(item: DashboardAcl): DashboardAcl {
item.inherited =
!this.dashboard.meta.isFolder && this.dashboard.id !== item.dashboardId;
item.inherited = !this.dashboard.meta.isFolder && this.dashboard.id !== item.dashboardId;
item.sortRank = 0;
if (item.userId > 0) {
@@ -71,9 +60,7 @@ export class AclCtrl {
item.sortRank = 20;
} else if (item.role) {
item.icon = 'fa fa-fw fa-street-view';
item.nameHtml = this.$sce.trustAsHtml(
`Everyone with <span class="query-keyword">${item.role}</span> Role`
);
item.nameHtml = this.$sce.trustAsHtml(`Everyone with <span class="query-keyword">${item.role}</span> Role`);
item.sortName = item.role;
item.sortRank = 30;
if (item.role === 'Viewer') {
@@ -103,11 +90,9 @@ export class AclCtrl {
});
}
return this.backendSrv
.post(`/api/dashboards/id/${this.dashboard.id}/acl`, { items: updated })
.then(() => {
return this.dismiss();
});
return this.backendSrv.post(`/api/dashboards/id/${this.dashboard.id}/acl`, { items: updated }).then(() => {
return this.dismiss();
});
}
typeChanged() {
@@ -156,9 +141,7 @@ export class AclCtrl {
return (
(origItem.role && newItem.role && origItem.role === newItem.role) ||
(origItem.userId &&
newItem.userId &&
origItem.userId === newItem.userId) ||
(origItem.userId && newItem.userId && origItem.userId === newItem.userId) ||
(origItem.teamId && newItem.teamId && origItem.teamId === newItem.teamId)
);
}

View File

@@ -1,11 +1,4 @@
import {
describe,
beforeEach,
it,
expect,
sinon,
angularMocks,
} from 'test/lib/common';
import { describe, beforeEach, it, expect, sinon, angularMocks } from 'test/lib/common';
import { AclCtrl } from '../acl';
describe('AclCtrl', () => {
@@ -81,9 +74,7 @@ describe('AclCtrl', () => {
done();
});
expect(backendSrv.post.getCall(0).args[0]).to.eql(
'/api/dashboards/id/1/acl'
);
expect(backendSrv.post.getCall(0).args[0]).to.eql('/api/dashboards/id/1/acl');
expect(backendSrv.post.getCall(0).args[1].items[0].role).to.eql('Viewer');
expect(backendSrv.post.getCall(0).args[1].items[0].permission).to.eql(1);
expect(backendSrv.post.getCall(0).args[1].items[1].role).to.eql('Editor');

View File

@@ -23,11 +23,7 @@ export class AdHocFiltersCtrl {
value: '-- remove filter --',
});
this.buildSegmentModel();
this.$rootScope.onAppEvent(
'template-variable-value-updated',
this.buildSegmentModel.bind(this),
$scope
);
this.$rootScope.onAppEvent('template-variable-value-updated', this.buildSegmentModel.bind(this), $scope);
}
buildSegmentModel() {
@@ -53,9 +49,7 @@ export class AdHocFiltersCtrl {
getOptions(segment, index) {
if (segment.type === 'operator') {
return this.$q.when(
this.uiSegmentSrv.newOperators(['=', '!=', '<', '>', '=~', '!~'])
);
return this.$q.when(this.uiSegmentSrv.newOperators(['=', '!=', '<', '>', '=~', '!~']));
}
if (segment.type === 'condition') {
@@ -107,13 +101,7 @@ export class AdHocFiltersCtrl {
this.segments.splice(index, 0, this.uiSegmentSrv.newCondition('AND'));
}
this.segments.push(this.uiSegmentSrv.newOperator('='));
this.segments.push(
this.uiSegmentSrv.newFake(
'select tag value',
'value',
'query-segment-value'
)
);
this.segments.push(this.uiSegmentSrv.newFake('select tag value', 'value', 'query-segment-value'));
segment.type = 'key';
segment.cssClass = 'query-segment-key';
}

View File

@@ -8,12 +8,7 @@ export class CreateFolderCtrl {
validationError: any;
/** @ngInject **/
constructor(
private backendSrv,
private $location,
private validationSrv,
navModelSrv
) {
constructor(private backendSrv, private $location, private validationSrv, navModelSrv) {
this.navModel = navModelSrv.getNav('dashboards', 'manage-dashboards', 0);
}
@@ -25,9 +20,7 @@ export class CreateFolderCtrl {
return this.backendSrv.createDashboardFolder(this.title).then(result => {
appEvents.emit('alert-success', ['Folder Created', 'OK']);
var folderUrl = `/dashboards/folder/${result.dashboard.id}/${
result.meta.slug
}`;
var folderUrl = `/dashboards/folder/${result.dashboard.id}/${result.meta.slug}`;
this.$location.url(folderUrl);
});
}

View File

@@ -66,9 +66,7 @@ export class DashboardCtrl implements PanelContainer {
// TODO refactor ViewStateSrv
this.$scope.dashboard = dashboard;
this.dashboardViewState = this.dashboardViewStateSrv.create(
this.$scope
);
this.dashboardViewState = this.dashboardViewStateSrv.create(this.$scope);
this.keybindingSrv.setupDashboardBindings(this.$scope, dashboard);
@@ -134,10 +132,7 @@ export class DashboardCtrl implements PanelContainer {
init(dashboard) {
this.$scope.onAppEvent('show-json-editor', this.showJsonEditor.bind(this));
this.$scope.onAppEvent(
'template-variable-value-updated',
this.templateVariableUpdated.bind(this)
);
this.$scope.onAppEvent('template-variable-value-updated', this.templateVariableUpdated.bind(this));
this.setupDashboard(dashboard);
}
}

View File

@@ -18,14 +18,7 @@ export class DashboardImportCtrl {
nameValidationError: any;
/** @ngInject */
constructor(
private backendSrv,
private validationSrv,
navModelSrv,
private $location,
private $scope,
$routeParams
) {
constructor(private backendSrv, private validationSrv, navModelSrv, private $location, private $scope, $routeParams) {
this.navModel = navModelSrv.getNav('create', 'import');
this.step = 1;
@@ -76,8 +69,7 @@ export class DashboardImportCtrl {
});
if (sources.length === 0) {
inputModel.info =
'No data sources of type ' + input.pluginName + ' found';
inputModel.info = 'No data sources of type ' + input.pluginName + ' found';
} else if (!inputModel.info) {
inputModel.info = 'Select a ' + input.pluginName + ' data source';
}

View File

@@ -394,10 +394,7 @@ export class DashboardMigrator {
}
// Add special "row" panels if even one row is collapsed, repeated or has visible title
const showRows = _.some(
old.rows,
row => row.collapse || row.showTitle || row.repeat
);
const showRows = _.some(old.rows, row => row.collapse || row.showTitle || row.repeat);
for (let row of old.rows) {
if (row.repeatIteration) {
@@ -433,9 +430,7 @@ export class DashboardMigrator {
for (let panel of row.panels) {
panel.span = panel.span || DEFAULT_PANEL_SPAN;
const panelWidth = Math.floor(panel.span) * widthFactor;
const panelHeight = panel.height
? getGridHeight(panel.height)
: rowGridHeight;
const panelHeight = panel.height ? getGridHeight(panel.height) : rowGridHeight;
let panelPos = rowArea.getPanelPosition(panelHeight, panelWidth);
yPos = rowArea.yPos;
@@ -539,11 +534,7 @@ class RowArea {
}
}
if (
startPlace !== undefined &&
endPlace !== undefined &&
endPlace - startPlace >= panelWidth - 1
) {
if (startPlace !== undefined && endPlace !== undefined && endPlace - startPlace >= panelWidth - 1) {
const yPos = _.max(this.area.slice(startPlace));
place = {
x: startPlace,

View File

@@ -75,10 +75,7 @@ export class DashboardModel {
this.version = data.version || 0;
this.links = data.links || [];
this.gnetId = data.gnetId || null;
this.panels = _.map(
data.panels || [],
panelData => new PanelModel(panelData)
);
this.panels = _.map(data.panels || [], panelData => new PanelModel(panelData));
this.initMeta(meta);
this.updateSchema(data);
@@ -135,10 +132,7 @@ export class DashboardModel {
// make clone
var copy: any = {};
for (var property in this) {
if (
DashboardModel.nonPersistedProperties[property] ||
!this.hasOwnProperty(property)
) {
if (DashboardModel.nonPersistedProperties[property] || !this.hasOwnProperty(property)) {
continue;
}
@@ -147,10 +141,7 @@ export class DashboardModel {
// get variable save models
copy.templating = {
list: _.map(
this.templating.list,
variable => (variable.getSaveModel ? variable.getSaveModel() : variable)
),
list: _.map(this.templating.list, variable => (variable.getSaveModel ? variable.getSaveModel() : variable)),
};
// get panel save models
@@ -261,10 +252,7 @@ export class DashboardModel {
if (!cleanUpOnly) {
this.repeatPanel(panel, i);
}
} else if (
panel.repeatPanelId &&
panel.repeatIteration !== this.iteration
) {
} else if (panel.repeatPanelId && panel.repeatIteration !== this.iteration) {
panelsToRemove.push(panel);
}
}
@@ -355,10 +343,7 @@ export class DashboardModel {
// set width based on how many are selected
// assumed the repeated panels should take up full row width
copy.gridPos.w = Math.max(
GRID_COLUMN_COUNT / selectedOptions.length,
minWidth
);
copy.gridPos.w = Math.max(GRID_COLUMN_COUNT / selectedOptions.length, minWidth);
copy.gridPos.x = xPos;
copy.gridPos.y = yPos;
@@ -382,11 +367,7 @@ export class DashboardModel {
panel.scopedVars[variable.name] = variableOption;
}
for (
let optionIndex = 0;
optionIndex < selectedOptions.length;
optionIndex++
) {
for (let optionIndex = 0; optionIndex < selectedOptions.length; optionIndex++) {
let option = selectedOptions[optionIndex];
let rowCopy = this.getRowRepeatClone(panel, optionIndex, panelIndex);
setScopedVars(rowCopy, option);
@@ -468,8 +449,7 @@ export class DashboardModel {
}
removeRow(row: PanelModel, removePanels: boolean) {
const needToogle =
(!removePanels && row.collapsed) || (removePanels && !row.collapsed);
const needToogle = (!removePanels && row.collapsed) || (removePanels && !row.collapsed);
if (needToogle) {
this.toggleRow(row);
@@ -488,18 +468,12 @@ export class DashboardModel {
return true;
}
var visibleVars = _.filter(
this.templating.list,
variable => variable.hide !== 2
);
var visibleVars = _.filter(this.templating.list, variable => variable.hide !== 2);
if (visibleVars.length > 0) {
return true;
}
var visibleAnnotations = _.filter(
this.annotations.list,
annotation => annotation.hide !== true
);
var visibleAnnotations = _.filter(this.annotations.list, annotation => annotation.hide !== true);
if (visibleAnnotations.length > 0) {
return true;
}
@@ -551,9 +525,7 @@ export class DashboardModel {
format = format || 'YYYY-MM-DD HH:mm:ss';
let timezone = this.getTimezone();
return timezone === 'browser'
? moment(date).format(format)
: moment.utc(date).format(format);
return timezone === 'browser' ? moment(date).format(format) : moment.utc(date).format(format);
}
destroy() {
@@ -593,11 +565,7 @@ export class DashboardModel {
const pushDownAmount = yMax - row.gridPos.y;
// push panels below down
for (
let panelIndex = insertPos;
panelIndex < this.panels.length;
panelIndex++
) {
for (let panelIndex = insertPos; panelIndex < this.panels.length; panelIndex++) {
this.panels[panelIndex].gridPos.y += pushDownAmount;
}
@@ -668,9 +636,7 @@ export class DashboardModel {
getRelativeTime(date) {
date = moment.isMoment(date) ? date : moment(date);
return this.timezone === 'browser'
? moment(date).fromNow()
: moment.utc(date).fromNow();
return this.timezone === 'browser' ? moment(date).fromNow() : moment.utc(date).fromNow();
}
getNextQueryLetter(panel) {

View File

@@ -56,8 +56,7 @@ export class DashboardSrv {
this.$rootScope.appEvent('confirm-modal', {
title: 'Plugin Dashboard',
text: err.data.message,
text2:
'Your changes will be lost when you update the plugin. Use Save As to create custom version.',
text2: 'Your changes will be lost when you update the plugin. Use Save As to create custom version.',
yesText: 'Overwrite',
icon: 'fa-warning',
altActionText: 'Save As',
@@ -115,16 +114,14 @@ export class DashboardSrv {
showSaveAsModal() {
this.$rootScope.appEvent('show-modal', {
templateHtml:
'<save-dashboard-as-modal dismiss="dismiss()"></save-dashboard-as-modal>',
templateHtml: '<save-dashboard-as-modal dismiss="dismiss()"></save-dashboard-as-modal>',
modalClass: 'modal--narrow',
});
}
showSaveModal() {
this.$rootScope.appEvent('show-modal', {
templateHtml:
'<save-dashboard-modal dismiss="dismiss()"></save-dashboard-modal>',
templateHtml: '<save-dashboard-modal dismiss="dismiss()"></save-dashboard-modal>',
modalClass: 'modal--narrow',
});
}
@@ -133,17 +130,13 @@ export class DashboardSrv {
let promise;
if (isStarred) {
promise = this.backendSrv
.delete('/api/user/stars/dashboard/' + dashboardId)
.then(() => {
return false;
});
promise = this.backendSrv.delete('/api/user/stars/dashboard/' + dashboardId).then(() => {
return false;
});
} else {
promise = this.backendSrv
.post('/api/user/stars/dashboard/' + dashboardId)
.then(() => {
return true;
});
promise = this.backendSrv.post('/api/user/stars/dashboard/' + dashboardId).then(() => {
return true;
});
}
return promise.then(res => {

View File

@@ -10,8 +10,7 @@ export class PanelLoader {
constructor(private $compile, private $rootScope) {}
load(elem, panel, dashboard): AttachedPanel {
var template =
'<plugin-component type="panel" class="panel-height-helper"></plugin-component>';
var template = '<plugin-component type="panel" class="panel-height-helper"></plugin-component>';
var panelScope = this.$rootScope.$new();
panelScope.panel = panel;
panelScope.dashboard = dashboard;

View File

@@ -9,20 +9,14 @@ export class DashNavCtrl {
titleTooltip: string;
/** @ngInject */
constructor(
private $scope,
private dashboardSrv,
private $location,
public playlistSrv
) {
constructor(private $scope, private dashboardSrv, private $location, public playlistSrv) {
appEvents.on('save-dashboard', this.saveDashboard.bind(this), $scope);
if (this.dashboard.meta.isSnapshot) {
var meta = this.dashboard.meta;
this.titleTooltip = 'Created: &nbsp;' + moment(meta.created).calendar();
if (meta.expires) {
this.titleTooltip +=
'<br>Expires: &nbsp;' + moment(meta.expires).fromNow() + '<br>';
this.titleTooltip += '<br>Expires: &nbsp;' + moment(meta.expires).fromNow() + '<br>';
}
}
}
@@ -50,11 +44,9 @@ export class DashNavCtrl {
}
starDashboard() {
this.dashboardSrv
.starDashboard(this.dashboard.id, this.dashboard.meta.isStarred)
.then(newState => {
this.dashboard.meta.isStarred = newState;
});
this.dashboardSrv.starDashboard(this.dashboard.id, this.dashboard.meta.isStarred).then(newState => {
this.dashboard.meta.isStarred = newState;
});
}
shareDashboard(tabIndex) {
@@ -81,10 +73,7 @@ export class DashNavCtrl {
}
addPanel() {
if (
this.dashboard.panels.length > 0 &&
this.dashboard.panels[0].type === 'add-panel'
) {
if (this.dashboard.panels.length > 0 && this.dashboard.panels[0].type === 'add-panel') {
this.dashboard.removePanel(this.dashboard.panels[0]);
return;
}

View File

@@ -10,12 +10,7 @@ export class DashExportCtrl {
dismiss: () => void;
/** @ngInject */
constructor(
private dashboardSrv,
datasourceSrv,
private $scope,
private $rootScope
) {
constructor(private dashboardSrv, datasourceSrv, private $scope, private $rootScope) {
this.exporter = new DashboardExporter(datasourceSrv);
this.exporter.makeExportable(this.dashboardSrv.getCurrent()).then(dash => {

View File

@@ -120,8 +120,7 @@ export class DashboardExporter {
// templatize constants
for (let variable of saveModel.templating.list) {
if (variable.type === 'constant') {
var refName =
'VAR_' + variable.name.replace(' ', '_').toUpperCase();
var refName = 'VAR_' + variable.name.replace(' ', '_').toUpperCase();
inputs.push({
name: refName,
type: 'constant',

View File

@@ -14,17 +14,9 @@ export class ExportDataModalCtrl {
fileExport.exportTableDataToCsv(this.data, this.excel);
} else {
if (this.asRows) {
fileExport.exportSeriesListToCsv(
this.data,
this.dateTimeFormat,
this.excel
);
fileExport.exportSeriesListToCsv(this.data, this.dateTimeFormat, this.excel);
} else {
fileExport.exportSeriesListToCsvColumns(
this.data,
this.dateTimeFormat,
this.excel
);
fileExport.exportSeriesListToCsvColumns(this.data, this.dateTimeFormat, this.excel);
}
}
@@ -39,8 +31,7 @@ export class ExportDataModalCtrl {
export function exportDataModal() {
return {
restrict: 'E',
templateUrl:
'public/app/features/dashboard/export_data/export_data_modal.html',
templateUrl: 'public/app/features/dashboard/export_data/export_data_modal.html',
controller: ExportDataModalCtrl,
controllerAs: 'ctrl',
scope: {
@@ -51,6 +42,4 @@ export function exportDataModal() {
};
}
angular
.module('grafana.directives')
.directive('exportDataModal', exportDataModal);
angular.module('grafana.directives').directive('exportDataModal', exportDataModal);

View File

@@ -11,10 +11,7 @@ export class FolderPageLoader {
subTitle: 'Manage folder dashboards & permissions',
url: '',
text: '',
breadcrumbs: [
{ title: 'Dashboards', url: '/dashboards' },
{ title: ' ' },
],
breadcrumbs: [{ title: 'Dashboards', url: '/dashboards' }, { title: ' ' }],
children: [
{
active: activeChildId === 'manage-folder-dashboards',
@@ -41,39 +38,30 @@ export class FolderPageLoader {
},
};
return this.backendSrv
.getDashboard('db', this.$routeParams.slug)
.then(result => {
const folderTitle = result.dashboard.title;
ctrl.navModel.main.text = '';
ctrl.navModel.main.breadcrumbs = [
{ title: 'Dashboards', url: '/dashboards' },
{ title: folderTitle },
];
return this.backendSrv.getDashboard('db', this.$routeParams.slug).then(result => {
const folderTitle = result.dashboard.title;
ctrl.navModel.main.text = '';
ctrl.navModel.main.breadcrumbs = [{ title: 'Dashboards', url: '/dashboards' }, { title: folderTitle }];
const folderUrl = this.createFolderUrl(
folderId,
result.meta.type,
result.meta.slug
);
const folderUrl = this.createFolderUrl(folderId, result.meta.type, result.meta.slug);
const dashTab = _.find(ctrl.navModel.main.children, {
id: 'manage-folder-dashboards',
});
dashTab.url = folderUrl;
const permTab = _.find(ctrl.navModel.main.children, {
id: 'manage-folder-permissions',
});
permTab.url = folderUrl + '/permissions';
const settingsTab = _.find(ctrl.navModel.main.children, {
id: 'manage-folder-settings',
});
settingsTab.url = folderUrl + '/settings';
return result;
const dashTab = _.find(ctrl.navModel.main.children, {
id: 'manage-folder-dashboards',
});
dashTab.url = folderUrl;
const permTab = _.find(ctrl.navModel.main.children, {
id: 'manage-folder-permissions',
});
permTab.url = folderUrl + '/permissions';
const settingsTab = _.find(ctrl.navModel.main.children, {
id: 'manage-folder-settings',
});
settingsTab.url = folderUrl + '/settings';
return result;
});
}
createFolderUrl(folderId: number, type: string, slug: string) {

View File

@@ -9,11 +9,7 @@ export class FolderPermissionsCtrl {
if (this.$routeParams.folderId && this.$routeParams.slug) {
this.folderId = $routeParams.folderId;
new FolderPageLoader(this.backendSrv, this.$routeParams).load(
this,
this.folderId,
'manage-folder-permissions'
);
new FolderPageLoader(this.backendSrv, this.$routeParams).load(this, this.folderId, 'manage-folder-permissions');
}
}
}

View File

@@ -85,18 +85,16 @@ export class FolderPickerCtrl {
evt.preventDefault();
}
return this.backendSrv
.createDashboardFolder(this.newFolderName)
.then(result => {
appEvents.emit('alert-success', ['Folder Created', 'OK']);
return this.backendSrv.createDashboardFolder(this.newFolderName).then(result => {
appEvents.emit('alert-success', ['Folder Created', 'OK']);
this.closeCreateFolder();
this.folder = {
text: result.dashboard.title,
value: result.dashboard.id,
};
this.onFolderChange(this.folder);
});
this.closeCreateFolder();
this.folder = {
text: result.dashboard.title,
value: result.dashboard.id,
};
this.onFolderChange(this.folder);
});
}
cancelCreateFolder(evt) {
@@ -147,8 +145,7 @@ export class FolderPickerCtrl {
export function folderPicker() {
return {
restrict: 'E',
templateUrl:
'public/app/features/dashboard/folder_picker/folder_picker.html',
templateUrl: 'public/app/features/dashboard/folder_picker/folder_picker.html',
controller: FolderPickerCtrl,
bindToController: true,
controllerAs: 'ctrl',

View File

@@ -12,27 +12,17 @@ export class FolderSettingsCtrl {
hasChanged: boolean;
/** @ngInject */
constructor(
private backendSrv,
navModelSrv,
private $routeParams,
private $location
) {
constructor(private backendSrv, navModelSrv, private $routeParams, private $location) {
if (this.$routeParams.folderId && this.$routeParams.slug) {
this.folderId = $routeParams.folderId;
this.folderPageLoader = new FolderPageLoader(
this.backendSrv,
this.$routeParams
);
this.folderPageLoader
.load(this, this.folderId, 'manage-folder-settings')
.then(result => {
this.dashboard = result.dashboard;
this.meta = result.meta;
this.canSave = result.meta.canSave;
this.title = this.dashboard.title;
});
this.folderPageLoader = new FolderPageLoader(this.backendSrv, this.$routeParams);
this.folderPageLoader.load(this, this.folderId, 'manage-folder-settings').then(result => {
this.dashboard = result.dashboard;
this.meta = result.meta;
this.canSave = result.meta.canSave;
this.title = this.dashboard.title;
});
}
}
@@ -48,11 +38,7 @@ export class FolderSettingsCtrl {
return this.backendSrv
.saveDashboard(this.dashboard, { overwrite: false })
.then(result => {
var folderUrl = this.folderPageLoader.createFolderUrl(
this.folderId,
this.meta.type,
result.slug
);
var folderUrl = this.folderPageLoader.createFolderUrl(this.folderId, this.meta.type, result.slug);
if (folderUrl !== this.$location.path()) {
this.$location.url(folderUrl + '/settings');
}
@@ -64,8 +50,7 @@ export class FolderSettingsCtrl {
}
titleChanged() {
this.hasChanged =
this.dashboard.title.toLowerCase() !== this.title.trim().toLowerCase();
this.hasChanged = this.dashboard.title.toLowerCase() !== this.title.trim().toLowerCase();
}
delete(evt) {
@@ -81,10 +66,7 @@ export class FolderSettingsCtrl {
yesText: 'Delete',
onConfirm: () => {
return this.backendSrv.deleteDashboard(this.meta.slug).then(() => {
appEvents.emit('alert-success', [
'Folder Deleted',
`${this.dashboard.title} has been deleted`,
]);
appEvents.emit('alert-success', ['Folder Deleted', `${this.dashboard.title} has been deleted`]);
this.$location.url('/dashboards');
});
},
@@ -110,9 +92,7 @@ export class FolderSettingsCtrl {
if (err.data && err.data.status === 'name-exists') {
err.isHandled = true;
appEvents.emit('alert-error', [
'A folder or dashboard with this name exists already.',
]);
appEvents.emit('alert-error', ['A folder or dashboard with this name exists already.']);
}
}
}

View File

@@ -5,12 +5,7 @@ import angular from 'angular';
import moment from 'moment';
import { DashboardModel } from '../dashboard_model';
import {
HistoryListOpts,
RevisionsModel,
CalculateDiffOptions,
HistorySrv,
} from './history_srv';
import { HistoryListOpts, RevisionsModel, CalculateDiffOptions, HistorySrv } from './history_srv';
export class HistoryListCtrl {
appending: boolean;
@@ -46,11 +41,7 @@ export class HistoryListCtrl {
this.start = 0;
this.canCompare = false;
this.$rootScope.onAppEvent(
'dashboard-saved',
this.onDashboardSaved.bind(this),
$scope
);
this.$rootScope.onAppEvent('dashboard-saved', this.onDashboardSaved.bind(this), $scope);
this.resetFromSource();
}
@@ -85,8 +76,7 @@ export class HistoryListCtrl {
formatBasicDate(date) {
const now = this.dashboard.timezone === 'browser' ? moment() : moment.utc();
const then =
this.dashboard.timezone === 'browser' ? moment(date) : moment.utc(date);
const then = this.dashboard.timezone === 'browser' ? moment(date) : moment.utc(date);
return then.from(now);
}
@@ -168,9 +158,7 @@ export class HistoryListCtrl {
this.delta = { basic: '', json: '' };
this.diff = 'basic';
this.mode = 'list';
this.revisions = _.map(this.revisions, rev =>
_.extend({}, rev, { checked: false })
);
this.revisions = _.map(this.revisions, rev => _.extend({}, rev, { checked: false }));
this.canCompare = false;
this.start = 0;
this.isNewLatest = false;
@@ -199,10 +187,7 @@ export class HistoryListCtrl {
.then(response => {
this.$location.path('dashboard/db/' + response.slug);
this.$route.reload();
this.$rootScope.appEvent('alert-success', [
'Dashboard restored',
'Restored from version ' + version,
]);
this.$rootScope.appEvent('alert-success', ['Dashboard restored', 'Restored from version ' + version]);
})
.catch(() => {
this.mode = 'list';
@@ -224,6 +209,4 @@ export function dashboardHistoryDirective() {
};
}
angular
.module('grafana.directives')
.directive('gfDashboardHistory', dashboardHistoryDirective);
angular.module('grafana.directives').directive('gfDashboardHistory', dashboardHistoryDirective);

View File

@@ -36,9 +36,7 @@ export class HistorySrv {
getHistoryList(dashboard: DashboardModel, options: HistoryListOpts) {
const id = dashboard && dashboard.id ? dashboard.id : void 0;
return id
? this.backendSrv.get(`api/dashboards/id/${id}/versions`, options)
: this.$q.when([]);
return id ? this.backendSrv.get(`api/dashboards/id/${id}/versions`, options) : this.$q.when([]);
}
calculateDiff(options: CalculateDiffOptions) {
@@ -48,9 +46,7 @@ export class HistorySrv {
restoreDashboard(dashboard: DashboardModel, version: number) {
const id = dashboard && dashboard.id ? dashboard.id : void 0;
const url = `api/dashboards/id/${id}/restore`;
return id && _.isNumber(version)
? this.backendSrv.post(url, { version })
: this.$q.when({});
return id && _.isNumber(version) ? this.backendSrv.post(url, { version }) : this.$q.when({});
}
}

View File

@@ -16,29 +16,22 @@ export class MoveToFolderCtrl {
}
save() {
return this.backendSrv
.moveDashboards(this.dashboards, this.folder)
.then(result => {
if (result.successCount > 0) {
const header = `Dashboard${
result.successCount === 1 ? '' : 's'
} Moved`;
const msg = `${result.successCount} dashboard${
result.successCount === 1 ? '' : 's'
} moved to ${this.folder.title}`;
appEvents.emit('alert-success', [header, msg]);
}
return this.backendSrv.moveDashboards(this.dashboards, this.folder).then(result => {
if (result.successCount > 0) {
const header = `Dashboard${result.successCount === 1 ? '' : 's'} Moved`;
const msg = `${result.successCount} dashboard${result.successCount === 1 ? '' : 's'} moved to ${
this.folder.title
}`;
appEvents.emit('alert-success', [header, msg]);
}
if (result.totalCount === result.alreadyInFolderCount) {
appEvents.emit('alert-error', [
'Error',
`Dashboards already belongs to folder ${this.folder.title}`,
]);
}
if (result.totalCount === result.alreadyInFolderCount) {
appEvents.emit('alert-error', ['Error', `Dashboards already belongs to folder ${this.folder.title}`]);
}
this.dismiss();
return this.afterSave();
});
this.dismiss();
return this.afterSave();
});
}
onEnterFolderCreation() {
@@ -53,8 +46,7 @@ export class MoveToFolderCtrl {
export function moveToFolderModal() {
return {
restrict: 'E',
templateUrl:
'public/app/features/dashboard/move_to_folder_modal/move_to_folder.html',
templateUrl: 'public/app/features/dashboard/move_to_folder_modal/move_to_folder.html',
controller: MoveToFolderCtrl,
bindToController: true,
controllerAs: 'ctrl',

View File

@@ -14,13 +14,7 @@ export class SettingsCtrl {
sections: any[];
/** @ngInject */
constructor(
private $scope,
private $location,
private $rootScope,
private backendSrv,
private dashboardSrv
) {
constructor(private $scope, private $location, private $rootScope, private backendSrv, private dashboardSrv) {
// temp hack for annotations and variables editors
// that rely on inherited scope
$scope.dashboard = this.dashboard;
@@ -36,11 +30,7 @@ export class SettingsCtrl {
this.buildSectionList();
this.onRouteUpdated();
$rootScope.onAppEvent(
'$routeUpdate',
this.onRouteUpdated.bind(this),
$scope
);
$rootScope.onAppEvent('$routeUpdate', this.onRouteUpdated.bind(this), $scope);
}
buildSectionList() {
@@ -139,12 +129,10 @@ export class SettingsCtrl {
makeEditable() {
this.dashboard.editable = true;
return this.dashboardSrv
.saveDashboard({ makeEditable: true, overwrite: false })
.then(() => {
// force refresh whole page
window.location.href = window.location.href;
});
return this.dashboardSrv.saveDashboard({ makeEditable: true, overwrite: false }).then(() => {
// force refresh whole page
window.location.href = window.location.href;
});
}
deleteDashboard() {
@@ -176,10 +164,7 @@ export class SettingsCtrl {
deleteDashboardConfirmed() {
this.backendSrv.deleteDashboard(this.dashboard.meta.slug).then(() => {
appEvents.emit('alert-success', [
'Dashboard Deleted',
this.dashboard.title + ' has been deleted',
]);
appEvents.emit('alert-success', ['Dashboard Deleted', this.dashboard.title + ' has been deleted']);
this.$location.url('/');
});
}

View File

@@ -4,15 +4,7 @@ import config from 'app/core/config';
export class ShareModalCtrl {
/** @ngInject */
constructor(
$scope,
$rootScope,
$location,
$timeout,
timeSrv,
templateSrv,
linkSrv
) {
constructor($scope, $rootScope, $location, $timeout, timeSrv, templateSrv, linkSrv) {
$scope.options = {
forCurrent: true,
includeTemplateVars: true,
@@ -81,18 +73,12 @@ export class ShareModalCtrl {
$scope.shareUrl = linkSrv.addParamsToUrl(baseUrl, params);
var soloUrl = baseUrl.replace(
config.appSubUrl + '/dashboard/',
config.appSubUrl + '/dashboard-solo/'
);
var soloUrl = baseUrl.replace(config.appSubUrl + '/dashboard/', config.appSubUrl + '/dashboard-solo/');
delete params.fullscreen;
delete params.edit;
soloUrl = linkSrv.addParamsToUrl(soloUrl, params);
$scope.iframeHtml =
'<iframe src="' +
soloUrl +
'" width="450" height="200" frameborder="0"></iframe>';
$scope.iframeHtml = '<iframe src="' + soloUrl + '" width="450" height="200" frameborder="0"></iframe>';
$scope.imageUrl = soloUrl.replace(
config.appSubUrl + '/dashboard-solo/',
@@ -109,6 +95,4 @@ export class ShareModalCtrl {
}
}
angular
.module('grafana.controllers')
.controller('ShareModalCtrl', ShareModalCtrl);
angular.module('grafana.controllers').controller('ShareModalCtrl', ShareModalCtrl);

View File

@@ -19,19 +19,10 @@ describe('DashboardImportCtrl', function() {
};
validationSrv = {
validateNewDashboardOrFolderName: jest
.fn()
.mockReturnValue(Promise.resolve()),
validateNewDashboardOrFolderName: jest.fn().mockReturnValue(Promise.resolve()),
};
ctx.ctrl = new DashboardImportCtrl(
backendSrv,
validationSrv,
navModelSrv,
{},
{},
{}
);
ctx.ctrl = new DashboardImportCtrl(backendSrv, validationSrv, navModelSrv, {}, {}, {});
});
describe('when uploading json', function() {

View File

@@ -54,10 +54,7 @@ describe('DashboardModel', function() {
{
type: 'table',
legend: true,
styles: [
{ thresholds: ['10', '20', '30'] },
{ thresholds: ['100', '200', '300'] },
],
styles: [{ thresholds: ['10', '20', '30'] }, { thresholds: ['100', '200', '300'] }],
targets: [{ refId: 'A' }, {}],
},
],
@@ -156,19 +153,13 @@ describe('DashboardModel', function() {
model.rows = [createRow({ collapse: false, height: 8 }, [[6], [6]])];
let dashboard = new DashboardModel(model);
let panelGridPos = getGridPositions(dashboard);
let expectedGrid = [
{ x: 0, y: 0, w: 12, h: 8 },
{ x: 12, y: 0, w: 12, h: 8 },
];
let expectedGrid = [{ x: 0, y: 0, w: 12, h: 8 }, { x: 12, y: 0, w: 12, h: 8 }];
expect(panelGridPos).toEqual(expectedGrid);
});
it('should add special "row" panel if row is collapsed', function() {
model.rows = [
createRow({ collapse: true, height: 8 }, [[6], [6]]),
createRow({ height: 8 }, [[12]]),
];
model.rows = [createRow({ collapse: true, height: 8 }, [[6], [6]]), createRow({ height: 8 }, [[12]])];
let dashboard = new DashboardModel(model);
let panelGridPos = getGridPositions(dashboard);
let expectedGrid = [
@@ -222,10 +213,7 @@ describe('DashboardModel', function() {
});
it('should add all rows if even one collapsed or titled row is present', function() {
model.rows = [
createRow({ collapse: true, height: 8 }, [[6], [6]]),
createRow({ height: 8 }, [[12]]),
];
model.rows = [createRow({ collapse: true, height: 8 }, [[6], [6]]), createRow({ height: 8 }, [[12]])];
let dashboard = new DashboardModel(model);
let panelGridPos = getGridPositions(dashboard);
let expectedGrid = [
@@ -258,9 +246,7 @@ describe('DashboardModel', function() {
});
it('should place panel to the right side of panel having bigger height', function() {
model.rows = [
createRow({ height: 6 }, [[4], [2, 3], [4, 6], [2, 3], [2, 3]]),
];
model.rows = [createRow({ height: 6 }, [[4], [2, 3], [4, 6], [2, 3], [2, 3]])];
let dashboard = new DashboardModel(model);
let panelGridPos = getGridPositions(dashboard);
let expectedGrid = [
@@ -275,9 +261,7 @@ describe('DashboardModel', function() {
});
it('should fill current row if it possible', function() {
model.rows = [
createRow({ height: 9 }, [[4], [2, 3], [4, 6], [2, 3], [2, 3], [8, 3]]),
];
model.rows = [createRow({ height: 9 }, [[4], [2, 3], [4, 6], [2, 3], [2, 3], [8, 3]])];
let dashboard = new DashboardModel(model);
let panelGridPos = getGridPositions(dashboard);
let expectedGrid = [
@@ -293,9 +277,7 @@ describe('DashboardModel', function() {
});
it('should fill current row if it possible (2)', function() {
model.rows = [
createRow({ height: 8 }, [[4], [2, 3], [4, 6], [2, 3], [2, 3], [8, 3]]),
];
model.rows = [createRow({ height: 8 }, [[4], [2, 3], [4, 6], [2, 3], [2, 3], [8, 3]])];
let dashboard = new DashboardModel(model);
let panelGridPos = getGridPositions(dashboard);
let expectedGrid = [
@@ -311,9 +293,7 @@ describe('DashboardModel', function() {
});
it('should fill current row if panel height more than row height', function() {
model.rows = [
createRow({ height: 6 }, [[4], [2, 3], [4, 8], [2, 3], [2, 3]]),
];
model.rows = [createRow({ height: 6 }, [[4], [2, 3], [4, 8], [2, 3], [2, 3]])];
let dashboard = new DashboardModel(model);
let panelGridPos = getGridPositions(dashboard);
let expectedGrid = [
@@ -345,10 +325,7 @@ describe('DashboardModel', function() {
it('should add repeated row if repeat set', function() {
model.rows = [
createRow(
{ showTitle: true, title: 'Row', height: 8, repeat: 'server' },
[[6]]
),
createRow({ showTitle: true, title: 'Row', height: 8, repeat: 'server' }, [[6]]),
createRow({ height: 8 }, [[12]]),
];
let dashboard = new DashboardModel(model);
@@ -369,10 +346,7 @@ describe('DashboardModel', function() {
it('should ignore repeated row', function() {
model.rows = [
createRow(
{ showTitle: true, title: 'Row1', height: 8, repeat: 'server' },
[[6]]
),
createRow({ showTitle: true, title: 'Row1', height: 8, repeat: 'server' }, [[6]]),
createRow(
{
showTitle: true,

View File

@@ -216,15 +216,11 @@ describe('DashboardModel', function() {
});
it('Should format timestamp with second resolution even if second format is passed as parameter', function() {
expect(dashboard.formatDate(1234567890007, 'YYYY-MM-DD HH:mm:ss')).toBe(
'2009-02-13 23:31:30'
);
expect(dashboard.formatDate(1234567890007, 'YYYY-MM-DD HH:mm:ss')).toBe('2009-02-13 23:31:30');
});
it('Should format timestamp with millisecond resolution if format is passed as parameter', function() {
expect(
dashboard.formatDate(1234567890007, 'YYYY-MM-DD HH:mm:ss.SSS')
).toBe('2009-02-13 23:31:30.007');
expect(dashboard.formatDate(1234567890007, 'YYYY-MM-DD HH:mm:ss.SSS')).toBe('2009-02-13 23:31:30.007');
});
});

View File

@@ -1,11 +1,4 @@
import {
describe,
beforeEach,
it,
sinon,
expect,
angularMocks,
} from 'test/lib/common';
import { describe, beforeEach, it, sinon, expect, angularMocks } from 'test/lib/common';
import _ from 'lodash';
import { HistoryListCtrl } from 'app/features/dashboard/history/history';
@@ -95,9 +88,7 @@ describe('HistoryListCtrl', function() {
});
it('should add a checked property to each revision', function() {
var actual = _.filter(ctx.ctrl.revisions, rev =>
rev.hasOwnProperty('checked')
);
var actual = _.filter(ctx.ctrl.revisions, rev => rev.hasOwnProperty('checked'));
expect(actual.length).to.be(4);
});
@@ -139,18 +130,12 @@ describe('HistoryListCtrl', function() {
it('should listen for the `dashboard-saved` appEvent', function() {
expect($rootScope.onAppEvent.calledOnce).to.be(true);
expect($rootScope.onAppEvent.getCall(0).args[0]).to.be(
'dashboard-saved'
);
expect($rootScope.onAppEvent.getCall(0).args[0]).to.be('dashboard-saved');
});
it('should call `onDashboardSaved` when the appEvent is received', function() {
expect($rootScope.onAppEvent.getCall(0).args[1]).to.not.be(
ctx.ctrl.onDashboardSaved
);
expect($rootScope.onAppEvent.getCall(0).args[1].toString).to.be(
ctx.ctrl.onDashboardSaved.toString
);
expect($rootScope.onAppEvent.getCall(0).args[1]).to.not.be(ctx.ctrl.onDashboardSaved);
expect($rootScope.onAppEvent.getCall(0).args[1].toString).to.be(ctx.ctrl.onDashboardSaved.toString);
});
});
});

View File

@@ -163,29 +163,8 @@ export function restore(version, restoredFrom?) {
to: 'now',
},
timepicker: {
refresh_intervals: [
'5s',
'10s',
'30s',
'1m',
'5m',
'15m',
'30m',
'1h',
'2h',
'1d',
],
time_options: [
'5m',
'15m',
'1h',
'6h',
'12h',
'24h',
'2d',
'7d',
'30d',
],
refresh_intervals: ['5s', '10s', '30s', '1m', '5m', '15m', '30m', '1h', '2h', '1d'],
time_options: ['5m', '15m', '1h', '6h', '12h', '24h', '2d', '7d', '30d'],
},
timezone: 'utc',
title: 'History Dashboard',

View File

@@ -1,10 +1,4 @@
import {
describe,
beforeEach,
it,
expect,
angularMocks,
} from 'test/lib/common';
import { describe, beforeEach, it, expect, angularMocks } from 'test/lib/common';
import helpers from 'test/specs/helpers';
import '../history/history_srv';
@@ -21,9 +15,7 @@ describe('historySrv', function() {
beforeEach(
angularMocks.inject(function($httpBackend) {
ctx.$httpBackend = $httpBackend;
$httpBackend
.whenRoute('GET', 'api/dashboards/id/:id/versions')
.respond(versionsResponse);
$httpBackend.whenRoute('GET', 'api/dashboards/id/:id/versions').respond(versionsResponse);
$httpBackend
.whenRoute('POST', 'api/dashboards/id/:id/restore')
.respond(function(method, url, data, headers, params) {
@@ -76,11 +68,9 @@ describe('historySrv', function() {
let version = 6;
return wrapPromise(
ctx,
ctx.service
.restoreDashboard({ id: 1 }, version)
.then(function(response) {
expect(response).to.eql(restoreResponse(version));
})
ctx.service.restoreDashboard({ id: 1 }, version).then(function(response) {
expect(response).to.eql(restoreResponse(version));
})
);
});

View File

@@ -232,16 +232,7 @@ describe('given dashboard with row repeat', function() {
it('should not repeat only row', function() {
const panel_types = _.map(dashboard.panels, 'type');
expect(panel_types).toEqual([
'row',
'graph',
'graph',
'row',
'graph',
'graph',
'row',
'graph',
]);
expect(panel_types).toEqual(['row', 'graph', 'graph', 'row', 'graph', 'graph', 'row', 'graph']);
});
it('should set scopedVars for each panel', function() {
@@ -262,17 +253,7 @@ describe('given dashboard with row repeat', function() {
})
);
expect(scopedVars).toEqual([
'se1',
'se1',
'se1',
'se2',
'se2',
'se2',
'se3',
'se3',
'se3',
]);
expect(scopedVars).toEqual(['se1', 'se1', 'se1', 'se2', 'se2', 'se2', 'se3', 'se3', 'se3']);
});
it('should repeat only configured row', function() {

View File

@@ -57,19 +57,11 @@ describe('saving dashboard as', () => {
expect(ctx.panel.thresholds).toBe(undefined);
});
scenario(
'singlestat should keep threshold',
{ id: 1, type: 'singlestat', thresholds: { value: 3000 } },
ctx => {
expect(ctx.panel.thresholds).not.toBe(undefined);
}
);
scenario('singlestat should keep threshold', { id: 1, type: 'singlestat', thresholds: { value: 3000 } }, ctx => {
expect(ctx.panel.thresholds).not.toBe(undefined);
});
scenario(
'table should keep threshold',
{ id: 1, type: 'table', thresholds: { value: 3000 } },
ctx => {
expect(ctx.panel.thresholds).not.toBe(undefined);
}
);
scenario('table should keep threshold', { id: 1, type: 'table', thresholds: { value: 3000 } }, ctx => {
expect(ctx.panel.thresholds).not.toBe(undefined);
});
});

View File

@@ -1,11 +1,4 @@
import {
describe,
beforeEach,
it,
expect,
sinon,
angularMocks,
} from 'test/lib/common';
import { describe, beforeEach, it, expect, sinon, angularMocks } from 'test/lib/common';
import helpers from 'test/specs/helpers';
import '../shareModalCtrl';
import config from 'app/core/config';
@@ -46,22 +39,17 @@ describe('ShareModalCtrl', function() {
ctx.scope.panel = { id: 22 };
ctx.scope.init();
expect(ctx.scope.shareUrl).to.be(
'http://server/#!/test?from=1000&to=2000&orgId=1&panelId=22&fullscreen'
);
expect(ctx.scope.shareUrl).to.be('http://server/#!/test?from=1000&to=2000&orgId=1&panelId=22&fullscreen');
});
it('should generate render url', function() {
ctx.$location.$$absUrl =
'http://dashboards.grafana.com/dashboard/db/my-dash';
ctx.$location.$$absUrl = 'http://dashboards.grafana.com/dashboard/db/my-dash';
ctx.scope.panel = { id: 22 };
ctx.scope.init();
var base =
'http://dashboards.grafana.com/render/dashboard-solo/db/my-dash';
var params =
'?from=1000&to=2000&orgId=1&panelId=22&width=1000&height=500&tz=UTC';
var base = 'http://dashboards.grafana.com/render/dashboard-solo/db/my-dash';
var params = '?from=1000&to=2000&orgId=1&panelId=22&width=1000&height=500&tz=UTC';
expect(ctx.scope.imageUrl).to.contain(base + params);
});
@@ -71,9 +59,7 @@ describe('ShareModalCtrl', function() {
ctx.scope.panel = null;
ctx.scope.init();
expect(ctx.scope.shareUrl).to.be(
'http://server/#!/test?from=1000&to=2000&orgId=1'
);
expect(ctx.scope.shareUrl).to.be('http://server/#!/test?from=1000&to=2000&orgId=1');
});
it('should add theme when specified', function() {
@@ -82,9 +68,7 @@ describe('ShareModalCtrl', function() {
ctx.scope.panel = null;
ctx.scope.init();
expect(ctx.scope.shareUrl).to.be(
'http://server/#!/test?from=1000&to=2000&orgId=1&theme=light'
);
expect(ctx.scope.shareUrl).to.be('http://server/#!/test?from=1000&to=2000&orgId=1&theme=light');
});
it('should remove fullscreen from image url when is first param in querystring and modeSharePanel is true', function() {
@@ -94,12 +78,8 @@ describe('ShareModalCtrl', function() {
ctx.scope.buildUrl();
expect(ctx.scope.shareUrl).to.contain(
'?fullscreen&edit&from=1000&to=2000&orgId=1&panelId=1'
);
expect(ctx.scope.imageUrl).to.contain(
'?from=1000&to=2000&orgId=1&panelId=1&width=1000&height=500&tz=UTC'
);
expect(ctx.scope.shareUrl).to.contain('?fullscreen&edit&from=1000&to=2000&orgId=1&panelId=1');
expect(ctx.scope.imageUrl).to.contain('?from=1000&to=2000&orgId=1&panelId=1&width=1000&height=500&tz=UTC');
});
it('should remove edit from image url when is first param in querystring and modeSharePanel is true', function() {
@@ -109,12 +89,8 @@ describe('ShareModalCtrl', function() {
ctx.scope.buildUrl();
expect(ctx.scope.shareUrl).to.contain(
'?edit&fullscreen&from=1000&to=2000&orgId=1&panelId=1'
);
expect(ctx.scope.imageUrl).to.contain(
'?from=1000&to=2000&orgId=1&panelId=1&width=1000&height=500&tz=UTC'
);
expect(ctx.scope.shareUrl).to.contain('?edit&fullscreen&from=1000&to=2000&orgId=1&panelId=1');
expect(ctx.scope.imageUrl).to.contain('?from=1000&to=2000&orgId=1&panelId=1&width=1000&height=500&tz=UTC');
});
it('should include template variables in url', function() {

View File

@@ -1,11 +1,4 @@
import {
describe,
beforeEach,
it,
expect,
sinon,
angularMocks,
} from 'test/lib/common';
import { describe, beforeEach, it, expect, sinon, angularMocks } from 'test/lib/common';
import helpers from 'test/specs/helpers';
import '../time_srv';
@@ -55,24 +48,16 @@ describe('timeSrv', function() {
ctx.$location.search({ from: '20140410T052010', to: '20140520T031022' });
ctx.service.init(_dashboard);
var time = ctx.service.timeRange(true);
expect(time.from.valueOf()).to.equal(
new Date('2014-04-10T05:20:10Z').getTime()
);
expect(time.to.valueOf()).to.equal(
new Date('2014-05-20T03:10:22Z').getTime()
);
expect(time.from.valueOf()).to.equal(new Date('2014-04-10T05:20:10Z').getTime());
expect(time.to.valueOf()).to.equal(new Date('2014-05-20T03:10:22Z').getTime());
});
it('should handle formated dates without time', function() {
ctx.$location.search({ from: '20140410', to: '20140520' });
ctx.service.init(_dashboard);
var time = ctx.service.timeRange(true);
expect(time.from.valueOf()).to.equal(
new Date('2014-04-10T00:00:00Z').getTime()
);
expect(time.to.valueOf()).to.equal(
new Date('2014-05-20T00:00:00Z').getTime()
);
expect(time.from.valueOf()).to.equal(new Date('2014-04-10T00:00:00Z').getTime());
expect(time.to.valueOf()).to.equal(new Date('2014-05-20T00:00:00Z').getTime());
});
it('should handle epochs', function() {

View File

@@ -1,11 +1,4 @@
import {
describe,
beforeEach,
it,
expect,
sinon,
angularMocks,
} from 'test/lib/common';
import { describe, beforeEach, it, expect, sinon, angularMocks } from 'test/lib/common';
import 'app/features/dashboard/unsavedChangesSrv';
import 'app/features/dashboard/dashboard_srv';
@@ -28,12 +21,7 @@ describe('unsavedChangesSrv', function() {
);
beforeEach(
angularMocks.inject(function(
unsavedChangesSrv,
$location,
$rootScope,
dashboardSrv
) {
angularMocks.inject(function(unsavedChangesSrv, $location, $rootScope, dashboardSrv) {
_unsavedChangesSrv = unsavedChangesSrv;
_dashboardSrv = dashboardSrv;
_rootScope = $rootScope;

View File

@@ -1,10 +1,4 @@
import {
describe,
beforeEach,
it,
expect,
angularMocks,
} from 'test/lib/common';
import { describe, beforeEach, it, expect, angularMocks } from 'test/lib/common';
import 'app/features/dashboard/view_state_srv';
import config from 'app/core/config';

View File

@@ -41,6 +41,4 @@ export function submenuDirective() {
};
}
angular
.module('grafana.directives')
.directive('dashboardSubmenu', submenuDirective);
angular.module('grafana.directives').directive('dashboardSubmenu', submenuDirective);

View File

@@ -16,13 +16,7 @@ class TimeSrv {
private autoRefreshBlocked: boolean;
/** @ngInject **/
constructor(
private $rootScope,
private $timeout,
private $location,
private timer,
private contextSrv
) {
constructor(private $rootScope, private $timeout, private $location, private timer, private contextSrv) {
// default time
this.time = { from: '6h', to: 'now' };
@@ -115,10 +109,7 @@ class TimeSrv {
}
private timeHasChangedSinceLoad() {
return (
this.timeAtLoad.from !== this.time.from ||
this.timeAtLoad.to !== this.time.to
);
return this.timeAtLoad.from !== this.time.from || this.timeAtLoad.to !== this.time.to;
}
setAutoRefresh(interval) {
@@ -209,9 +200,7 @@ class TimeSrv {
timeRange() {
// make copies if they are moment (do not want to return out internal moment, because they are mutable!)
var raw = {
from: moment.isMoment(this.time.from)
? moment(this.time.from)
: this.time.from,
from: moment.isMoment(this.time.from) ? moment(this.time.from) : this.time.from,
to: moment.isMoment(this.time.to) ? moment(this.time.to) : this.time.to,
};

View File

@@ -8,18 +8,7 @@ export class TimePickerCtrl {
static tooltipFormat = 'MMM D, YYYY HH:mm:ss';
static defaults = {
time_options: ['5m', '15m', '1h', '6h', '12h', '24h', '2d', '7d', '30d'],
refresh_intervals: [
'5s',
'10s',
'30s',
'1m',
'5m',
'15m',
'30m',
'1h',
'2h',
'1d',
],
refresh_intervals: ['5s', '10s', '30s', '1m', '5m', '15m', '30m', '1h', '2h', '1d'],
};
dashboard: any;
@@ -113,10 +102,7 @@ export class TimePickerCtrl {
this.onRefresh();
this.editTimeRaw = this.timeRaw;
this.timeOptions = rangeUtil.getRelativeTimesList(
this.panel,
this.rangeString
);
this.timeOptions = rangeUtil.getRelativeTimesList(this.panel, this.rangeString);
this.refresh = {
value: this.dashboard.refresh,
options: _.map(this.panel.refresh_intervals, (interval: any) => {
@@ -138,9 +124,7 @@ export class TimePickerCtrl {
}
absoluteFromChanged() {
this.editTimeRaw.from = this.getAbsoluteMomentForTimezone(
this.absolute.fromJs
);
this.editTimeRaw.from = this.getAbsoluteMomentForTimezone(this.absolute.fromJs);
}
absoluteToChanged() {
@@ -148,9 +132,7 @@ export class TimePickerCtrl {
}
getAbsoluteMomentForTimezone(jsDate) {
return this.dashboard.isTimezoneUtc()
? moment(jsDate).utc()
: moment(jsDate);
return this.dashboard.isTimezoneUtc() ? moment(jsDate).utc() : moment(jsDate);
}
setRelativeFilter(timespan) {
@@ -191,14 +173,8 @@ export function timePickerDirective() {
};
}
angular
.module('grafana.directives')
.directive('gfTimePickerSettings', settingsDirective);
angular
.module('grafana.directives')
.directive('gfTimePicker', timePickerDirective);
angular.module('grafana.directives').directive('gfTimePickerSettings', settingsDirective);
angular.module('grafana.directives').directive('gfTimePicker', timePickerDirective);
import { inputDateDirective } from './input_date';
angular
.module('grafana.directives')
.directive('inputDatetime', inputDateDirective);
angular.module('grafana.directives').directive('inputDatetime', inputDateDirective);

View File

@@ -28,10 +28,7 @@ function uploadDashboardDirective(timer, alertSrv, $location) {
dash = JSON.parse(e.target.result);
} catch (err) {
console.log(err);
scope.appEvent('alert-error', [
'Import failed',
'JSON -> JS Serialization failed: ' + err.message,
]);
scope.appEvent('alert-error', ['Import failed', 'JSON -> JS Serialization failed: ' + err.message]);
return;
}
@@ -52,15 +49,9 @@ function uploadDashboardDirective(timer, alertSrv, $location) {
// Check for the various File API support.
if (wnd.File && wnd.FileReader && wnd.FileList && wnd.Blob) {
// Something
document
.getElementById('dashupload')
.addEventListener('change', file_selected, false);
document.getElementById('dashupload').addEventListener('change', file_selected, false);
} else {
alertSrv.set(
'Oops',
'Sorry, the HTML5 File APIs are not fully supported in this browser.',
'error'
);
alertSrv.set('Oops', 'Sorry, the HTML5 File APIs are not fully supported in this browser.', 'error');
}
},
};

View File

@@ -75,8 +75,7 @@ export class DashboardViewState {
}
// remember if editStateChanged
this.editStateChanged =
(state.edit || false) !== (this.state.edit || false);
this.editStateChanged = (state.edit || false) !== (this.state.edit || false);
_.extend(this.state, state);
this.dashboard.meta.fullscreen = this.state.fullscreen;
@@ -117,10 +116,7 @@ export class DashboardViewState {
if (this.fullscreenPanel) {
// if already fullscreen
if (
this.fullscreenPanel === panelScope &&
this.editStateChanged === false
) {
if (this.fullscreenPanel === panelScope && this.editStateChanged === false) {
return;
} else {
this.leaveFullscreen(false);
@@ -213,6 +209,4 @@ export function dashboardViewStateSrv($location, $timeout, $rootScope) {
};
}
angular
.module('grafana.services')
.factory('dashboardViewStateSrv', dashboardViewStateSrv);
angular.module('grafana.services').factory('dashboardViewStateSrv', dashboardViewStateSrv);