mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
tech: ran pretttier on all typescript files
This commit is contained in:
@@ -1,14 +1,14 @@
|
||||
import moment from 'moment';
|
||||
import _ from 'lodash';
|
||||
import moment from "moment";
|
||||
import _ from "lodash";
|
||||
|
||||
import {GRID_COLUMN_COUNT, REPEAT_DIR_VERTICAL} from 'app/core/constants';
|
||||
import {DEFAULT_ANNOTATION_COLOR} from 'app/core/utils/colors';
|
||||
import {Emitter} from 'app/core/utils/emitter';
|
||||
import {contextSrv} from 'app/core/services/context_srv';
|
||||
import sortByKeys from 'app/core/utils/sort_by_keys';
|
||||
import { GRID_COLUMN_COUNT, REPEAT_DIR_VERTICAL } from "app/core/constants";
|
||||
import { DEFAULT_ANNOTATION_COLOR } from "app/core/utils/colors";
|
||||
import { Emitter } from "app/core/utils/emitter";
|
||||
import { contextSrv } from "app/core/services/context_srv";
|
||||
import sortByKeys from "app/core/utils/sort_by_keys";
|
||||
|
||||
import {PanelModel} from './panel_model';
|
||||
import {DashboardMigrator} from './dashboard_migration';
|
||||
import { PanelModel } from "./panel_model";
|
||||
import { DashboardMigrator } from "./dashboard_migration";
|
||||
|
||||
export class DashboardModel {
|
||||
id: any;
|
||||
@@ -43,11 +43,11 @@ export class DashboardModel {
|
||||
meta: any;
|
||||
events: Emitter;
|
||||
|
||||
static nonPersistedProperties: {[str: string]: boolean} = {
|
||||
static nonPersistedProperties: { [str: string]: boolean } = {
|
||||
events: true,
|
||||
meta: true,
|
||||
panels: true, // needs special handling
|
||||
templating: true, // needs special handling
|
||||
templating: true // needs special handling
|
||||
};
|
||||
|
||||
constructor(data, meta?) {
|
||||
@@ -58,15 +58,15 @@ export class DashboardModel {
|
||||
this.events = new Emitter();
|
||||
this.id = data.id || null;
|
||||
this.revision = data.revision;
|
||||
this.title = data.title || 'No Title';
|
||||
this.title = data.title || "No Title";
|
||||
this.autoUpdate = data.autoUpdate;
|
||||
this.description = data.description;
|
||||
this.tags = data.tags || [];
|
||||
this.style = data.style || 'dark';
|
||||
this.timezone = data.timezone || '';
|
||||
this.style = data.style || "dark";
|
||||
this.timezone = data.timezone || "";
|
||||
this.editable = data.editable !== false;
|
||||
this.graphTooltip = data.graphTooltip || 0;
|
||||
this.time = data.time || {from: 'now-6h', to: 'now'};
|
||||
this.time = data.time || { from: "now-6h", to: "now" };
|
||||
this.timepicker = data.timepicker || {};
|
||||
this.templating = this.ensureListExist(data.templating);
|
||||
this.annotations = this.ensureListExist(data.annotations);
|
||||
@@ -77,7 +77,10 @@ export class DashboardModel {
|
||||
this.links = data.links || [];
|
||||
this.gnetId = data.gnetId || null;
|
||||
this.folderId = data.folderId || 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);
|
||||
@@ -100,13 +103,13 @@ export class DashboardModel {
|
||||
}
|
||||
|
||||
this.annotations.list.unshift({
|
||||
datasource: '-- Grafana --',
|
||||
name: 'Annotations & Alerts',
|
||||
type: 'dashboard',
|
||||
datasource: "-- Grafana --",
|
||||
name: "Annotations & Alerts",
|
||||
type: "dashboard",
|
||||
iconColor: DEFAULT_ANNOTATION_COLOR,
|
||||
enable: true,
|
||||
hide: true,
|
||||
builtIn: 1,
|
||||
builtIn: 1
|
||||
});
|
||||
}
|
||||
|
||||
@@ -134,7 +137,10 @@ 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;
|
||||
}
|
||||
|
||||
@@ -143,7 +149,10 @@ 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
|
||||
@@ -161,7 +170,7 @@ export class DashboardModel {
|
||||
|
||||
panel.setViewMode(fullscreen, this.meta.isEditing);
|
||||
|
||||
this.events.emit('view-mode-changed', panel);
|
||||
this.events.emit("view-mode-changed", panel);
|
||||
}
|
||||
|
||||
private ensureListExist(data) {
|
||||
@@ -218,7 +227,7 @@ export class DashboardModel {
|
||||
|
||||
this.sortPanelsByGridPos();
|
||||
|
||||
this.events.emit('panel-added', panel);
|
||||
this.events.emit("panel-added", panel);
|
||||
}
|
||||
|
||||
sortPanelsByGridPos() {
|
||||
@@ -254,7 +263,10 @@ 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);
|
||||
}
|
||||
}
|
||||
@@ -263,7 +275,7 @@ export class DashboardModel {
|
||||
_.pull(this.panels, ...panelsToRemove);
|
||||
|
||||
this.sortPanelsByGridPos();
|
||||
this.events.emit('repeats-processed');
|
||||
this.events.emit("repeats-processed");
|
||||
}
|
||||
|
||||
getPanelRepeatClone(sourcePanel, valueIndex, sourcePanelIndex) {
|
||||
@@ -276,7 +288,7 @@ export class DashboardModel {
|
||||
clone.id = this.getNextPanelId();
|
||||
|
||||
// insert after source panel + value index
|
||||
this.panels.splice(sourcePanelIndex+valueIndex, 0, clone);
|
||||
this.panels.splice(sourcePanelIndex + valueIndex, 0, clone);
|
||||
|
||||
clone.repeatIteration = this.iteration;
|
||||
clone.repeatPanelId = sourcePanel.id;
|
||||
@@ -306,7 +318,7 @@ export class DashboardModel {
|
||||
rowPanels = this.getRowPanels(sourcePanelIndex);
|
||||
clone.panels = _.map(rowPanels, panel => panel.getSaveModel());
|
||||
// insert copied row after preceding row's panels
|
||||
insertPos = sourcePanelIndex + ((rowPanels.length + 1)*valueIndex);
|
||||
insertPos = sourcePanelIndex + (rowPanels.length + 1) * valueIndex;
|
||||
}
|
||||
this.panels.splice(insertPos, 0, clone);
|
||||
|
||||
@@ -315,12 +327,12 @@ export class DashboardModel {
|
||||
}
|
||||
|
||||
repeatPanel(panel: PanelModel, panelIndex: number) {
|
||||
let variable = _.find(this.templating.list, {name: panel.repeat});
|
||||
let variable = _.find(this.templating.list, { name: panel.repeat });
|
||||
if (!variable) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (panel.type === 'row') {
|
||||
if (panel.type === "row") {
|
||||
this.repeatRow(panel, panelIndex, variable);
|
||||
return;
|
||||
}
|
||||
@@ -345,7 +357,10 @@ 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;
|
||||
|
||||
@@ -369,7 +384,11 @@ 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);
|
||||
@@ -391,7 +410,7 @@ export class DashboardModel {
|
||||
panelBelowIndex = panelIndex + optionIndex + 1;
|
||||
} else {
|
||||
// insert after 'row' panel
|
||||
let insertPos = panelIndex + ((rowPanels.length + 1) * optionIndex) + 1;
|
||||
let insertPos = panelIndex + (rowPanels.length + 1) * optionIndex + 1;
|
||||
_.each(rowPanels, (rowPanel, i) => {
|
||||
setScopedVars(rowPanel, option);
|
||||
if (optionIndex > 0) {
|
||||
@@ -399,17 +418,17 @@ export class DashboardModel {
|
||||
this.updateRepeatedPanelIds(cloneRowPanel);
|
||||
// For exposed row additionally set proper Y grid position and add it to dashboard panels
|
||||
cloneRowPanel.gridPos.y += rowHeight * optionIndex;
|
||||
this.panels.splice(insertPos+i, 0, cloneRowPanel);
|
||||
this.panels.splice(insertPos + i, 0, cloneRowPanel);
|
||||
}
|
||||
});
|
||||
rowCopy.panels = [];
|
||||
rowCopy.gridPos.y += rowHeight * optionIndex;
|
||||
yPos += rowHeight;
|
||||
panelBelowIndex = insertPos+rowPanels.length;
|
||||
panelBelowIndex = insertPos + rowPanels.length;
|
||||
}
|
||||
|
||||
// Update gridPos for panels below
|
||||
for (let i = panelBelowIndex; i< this.panels.length; i++) {
|
||||
for (let i = panelBelowIndex; i < this.panels.length; i++) {
|
||||
this.panels[i].gridPos.y += yPos;
|
||||
}
|
||||
}
|
||||
@@ -425,10 +444,10 @@ export class DashboardModel {
|
||||
|
||||
getSelectedVariableOptions(variable) {
|
||||
let selectedOptions;
|
||||
if (variable.current.text === 'All') {
|
||||
if (variable.current.text === "All") {
|
||||
selectedOptions = variable.options.slice(1, variable.options.length);
|
||||
} else {
|
||||
selectedOptions = _.filter(variable.options, {selected: true});
|
||||
selectedOptions = _.filter(variable.options, { selected: true });
|
||||
}
|
||||
return selectedOptions;
|
||||
}
|
||||
@@ -437,8 +456,8 @@ export class DashboardModel {
|
||||
if (!rowPanel.panels || rowPanel.panels.length === 0) {
|
||||
return 0;
|
||||
}
|
||||
const positions = _.map(rowPanel.panels, 'gridPos');
|
||||
const maxPos = _.maxBy(positions, (pos) => {
|
||||
const positions = _.map(rowPanel.panels, "gridPos");
|
||||
const maxPos = _.maxBy(positions, pos => {
|
||||
return pos.y + pos.h;
|
||||
});
|
||||
return maxPos.h + 1;
|
||||
@@ -447,7 +466,7 @@ export class DashboardModel {
|
||||
removePanel(panel: PanelModel) {
|
||||
var index = _.indexOf(this.panels, panel);
|
||||
this.panels.splice(index, 1);
|
||||
this.events.emit('panel-removed', panel);
|
||||
this.events.emit("panel-removed", panel);
|
||||
}
|
||||
|
||||
setPanelFocus(id) {
|
||||
@@ -460,12 +479,18 @@ 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;
|
||||
}
|
||||
@@ -479,7 +504,7 @@ export class DashboardModel {
|
||||
if (this.panels[i].id === panelId) {
|
||||
return {
|
||||
panel: this.panels[i],
|
||||
index: i,
|
||||
index: i
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -514,10 +539,12 @@ export class DashboardModel {
|
||||
|
||||
formatDate(date, format?) {
|
||||
date = moment.isMoment(date) ? date : moment(date);
|
||||
format = format || 'YYYY-MM-DD HH:mm:ss';
|
||||
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() {
|
||||
@@ -539,7 +566,7 @@ export class DashboardModel {
|
||||
let yDiff = firstPanel.gridPos.y - (row.gridPos.y + row.gridPos.h);
|
||||
|
||||
// start inserting after row
|
||||
let insertPos = rowIndex+1;
|
||||
let insertPos = rowIndex + 1;
|
||||
// y max will represent the bottom y pos after all panels have been added
|
||||
// needed to know home much panels below should be pushed down
|
||||
let yMax = row.gridPos.y;
|
||||
@@ -557,7 +584,11 @@ 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;
|
||||
}
|
||||
|
||||
@@ -568,7 +599,7 @@ export class DashboardModel {
|
||||
this.sortPanelsByGridPos();
|
||||
|
||||
// emit change event
|
||||
this.events.emit('row-expanded');
|
||||
this.events.emit("row-expanded");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -581,7 +612,7 @@ export class DashboardModel {
|
||||
row.collapsed = true;
|
||||
|
||||
// emit change event
|
||||
this.events.emit('row-collapsed');
|
||||
this.events.emit("row-collapsed");
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -590,11 +621,11 @@ export class DashboardModel {
|
||||
getRowPanels(rowIndex: number): PanelModel[] {
|
||||
let rowPanels = [];
|
||||
|
||||
for (let index = rowIndex+1; index < this.panels.length; index++) {
|
||||
for (let index = rowIndex + 1; index < this.panels.length; index++) {
|
||||
let panel = this.panels[index];
|
||||
|
||||
// break when encountering another row
|
||||
if (panel.type === 'row') {
|
||||
if (panel.type === "row") {
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -628,11 +659,13 @@ 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) {
|
||||
var letters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
|
||||
var letters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
|
||||
|
||||
return _.find(letters, function(refId) {
|
||||
return _.every(panel.targets, function(other) {
|
||||
@@ -642,7 +675,7 @@ export class DashboardModel {
|
||||
}
|
||||
|
||||
isTimezoneUtc() {
|
||||
return this.getTimezone() === 'utc';
|
||||
return this.getTimezone() === "utc";
|
||||
}
|
||||
|
||||
getTimezone() {
|
||||
|
||||
Reference in New Issue
Block a user