Merge branch 'master' into react-panels

This commit is contained in:
Torkel Ödegaard
2018-09-10 15:42:36 +02:00
597 changed files with 13109 additions and 9258 deletions

View File

@@ -95,7 +95,7 @@ export class DashboardModel {
addBuiltInAnnotationQuery() {
let found = false;
for (let item of this.annotations.list) {
for (const item of this.annotations.list) {
if (item.builtIn === 1) {
found = true;
break;
@@ -138,14 +138,14 @@ export class DashboardModel {
// cleans meta data and other non persistent state
getSaveModelClone(options?) {
let defaults = _.defaults(options || {}, {
const defaults = _.defaults(options || {}, {
saveVariables: true,
saveTimerange: true,
});
// make clone
var copy: any = {};
for (var property in this) {
let copy: any = {};
for (const property in this) {
if (DashboardModel.nonPersistedProperties[property] || !this.hasOwnProperty(property)) {
continue;
}
@@ -160,8 +160,8 @@ export class DashboardModel {
if (!defaults.saveVariables) {
for (let i = 0; i < copy.templating.list.length; i++) {
let current = copy.templating.list[i];
let original = _.find(this.originalTemplating, { name: current.name, type: current.type });
const current = copy.templating.list[i];
const original = _.find(this.originalTemplating, { name: current.name, type: current.type });
if (!original) {
continue;
@@ -246,13 +246,13 @@ export class DashboardModel {
getNextPanelId() {
let max = 0;
for (let panel of this.panels) {
for (const panel of this.panels) {
if (panel.id > max) {
max = panel.id;
}
if (panel.collapsed) {
for (let rowPanel of panel.panels) {
for (const rowPanel of panel.panels) {
if (rowPanel.id > max) {
max = rowPanel.id;
}
@@ -270,7 +270,7 @@ export class DashboardModel {
}
getPanelById(id) {
for (let panel of this.panels) {
for (const panel of this.panels) {
if (panel.id === id) {
return panel;
}
@@ -281,7 +281,7 @@ export class DashboardModel {
addPanel(panelData) {
panelData.id = this.getNextPanelId();
let panel = new PanelModel(panelData);
const panel = new PanelModel(panelData);
this.panels.unshift(panel);
@@ -291,7 +291,7 @@ export class DashboardModel {
}
sortPanelsByGridPos() {
this.panels.sort(function(panelA, panelB) {
this.panels.sort((panelA, panelB) => {
if (panelA.gridPos.y === panelB.gridPos.y) {
return panelA.gridPos.x - panelB.gridPos.x;
} else {
@@ -306,15 +306,15 @@ export class DashboardModel {
}
this.iteration = (this.iteration || new Date().getTime()) + 1;
let panelsToRemove = [];
const panelsToRemove = [];
// cleanup scopedVars
for (let panel of this.panels) {
for (const panel of this.panels) {
delete panel.scopedVars;
}
for (let i = 0; i < this.panels.length; i++) {
let panel = this.panels[i];
const panel = this.panels[i];
if ((!panel.repeat || panel.repeatedByRow) && panel.repeatPanelId && panel.repeatIteration !== this.iteration) {
panelsToRemove.push(panel);
}
@@ -337,7 +337,7 @@ export class DashboardModel {
this.iteration = (this.iteration || new Date().getTime()) + 1;
for (let i = 0; i < this.panels.length; i++) {
let panel = this.panels[i];
const panel = this.panels[i];
if (panel.repeat) {
this.repeatPanel(panel, i);
}
@@ -348,9 +348,9 @@ export class DashboardModel {
}
cleanUpRowRepeats(rowPanels) {
let panelsToRemove = [];
const panelsToRemove = [];
for (let i = 0; i < rowPanels.length; i++) {
let panel = rowPanels[i];
const panel = rowPanels[i];
if (!panel.repeat && panel.repeatPanelId) {
panelsToRemove.push(panel);
}
@@ -366,16 +366,16 @@ export class DashboardModel {
let rowPanels = row.panels;
if (!row.collapsed) {
let rowPanelIndex = _.findIndex(this.panels, p => p.id === row.id);
const rowPanelIndex = _.findIndex(this.panels, p => p.id === row.id);
rowPanels = this.getRowPanels(rowPanelIndex);
}
this.cleanUpRowRepeats(rowPanels);
for (let i = 0; i < rowPanels.length; i++) {
let panel = rowPanels[i];
const panel = rowPanels[i];
if (panel.repeat) {
let panelIndex = _.findIndex(this.panels, p => p.id === panel.id);
const panelIndex = _.findIndex(this.panels, p => p.id === panel.id);
this.repeatPanel(panel, panelIndex);
}
}
@@ -387,7 +387,7 @@ export class DashboardModel {
return sourcePanel;
}
let clone = new PanelModel(sourcePanel.getSaveModel());
const clone = new PanelModel(sourcePanel.getSaveModel());
clone.id = this.getNextPanelId();
// insert after source panel + value index
@@ -403,13 +403,13 @@ export class DashboardModel {
// if first clone return source
if (valueIndex === 0) {
if (!sourceRowPanel.collapsed) {
let rowPanels = this.getRowPanels(sourcePanelIndex);
const rowPanels = this.getRowPanels(sourcePanelIndex);
sourceRowPanel.panels = rowPanels;
}
return sourceRowPanel;
}
let clone = new PanelModel(sourceRowPanel.getSaveModel());
const clone = new PanelModel(sourceRowPanel.getSaveModel());
// for row clones we need to figure out panels under row to clone and where to insert clone
let rowPanels, insertPos;
if (sourceRowPanel.collapsed) {
@@ -430,7 +430,7 @@ export class DashboardModel {
}
repeatPanel(panel: PanelModel, panelIndex: number) {
let variable = _.find(this.templating.list, { name: panel.repeat });
const variable = _.find(this.templating.list, { name: panel.repeat });
if (!variable) {
return;
}
@@ -440,13 +440,13 @@ export class DashboardModel {
return;
}
let selectedOptions = this.getSelectedVariableOptions(variable);
let minWidth = panel.minSpan || 6;
const selectedOptions = this.getSelectedVariableOptions(variable);
const minWidth = panel.minSpan || 6;
let xPos = 0;
let yPos = panel.gridPos.y;
for (let index = 0; index < selectedOptions.length; index++) {
let option = selectedOptions[index];
const option = selectedOptions[index];
let copy;
copy = this.getPanelRepeatClone(panel, index, panelIndex);
@@ -476,9 +476,9 @@ export class DashboardModel {
}
// Update gridPos for panels below
let yOffset = yPos - panel.gridPos.y;
const yOffset = yPos - panel.gridPos.y;
if (yOffset > 0) {
let panelBelowIndex = panelIndex + selectedOptions.length;
const panelBelowIndex = panelIndex + selectedOptions.length;
for (let i = panelBelowIndex; i < this.panels.length; i++) {
this.panels[i].gridPos.y += yOffset;
}
@@ -486,7 +486,7 @@ export class DashboardModel {
}
repeatRow(panel: PanelModel, panelIndex: number, variable) {
let selectedOptions = this.getSelectedVariableOptions(variable);
const selectedOptions = this.getSelectedVariableOptions(variable);
let yPos = panel.gridPos.y;
function setScopedVars(panel, variableOption) {
@@ -495,12 +495,12 @@ export class DashboardModel {
}
for (let optionIndex = 0; optionIndex < selectedOptions.length; optionIndex++) {
let option = selectedOptions[optionIndex];
let rowCopy = this.getRowRepeatClone(panel, optionIndex, panelIndex);
const option = selectedOptions[optionIndex];
const rowCopy = this.getRowRepeatClone(panel, optionIndex, panelIndex);
setScopedVars(rowCopy, option);
let rowHeight = this.getRowHeight(rowCopy);
let rowPanels = rowCopy.panels || [];
const rowHeight = this.getRowHeight(rowCopy);
const rowPanels = rowCopy.panels || [];
let panelBelowIndex;
if (panel.collapsed) {
@@ -516,11 +516,11 @@ export class DashboardModel {
panelBelowIndex = panelIndex + optionIndex + 1;
} else {
// insert after 'row' panel
let insertPos = panelIndex + (rowPanels.length + 1) * optionIndex + 1;
const insertPos = panelIndex + (rowPanels.length + 1) * optionIndex + 1;
_.each(rowPanels, (rowPanel, i) => {
setScopedVars(rowPanel, option);
if (optionIndex > 0) {
let cloneRowPanel = new PanelModel(rowPanel);
const cloneRowPanel = new PanelModel(rowPanel);
this.updateRepeatedPanelIds(cloneRowPanel, true);
// For exposed row additionally set proper Y grid position and add it to dashboard panels
cloneRowPanel.gridPos.y += rowHeight * optionIndex;
@@ -575,7 +575,7 @@ export class DashboardModel {
}
removePanel(panel: PanelModel) {
var index = _.indexOf(this.panels, panel);
const index = _.indexOf(this.panels, panel);
this.panels.splice(index, 1);
this.events.emit('panel-removed', panel);
}
@@ -592,7 +592,7 @@ export class DashboardModel {
expandRows() {
for (let i = 0; i < this.panels.length; i++) {
var panel = this.panels[i];
const panel = this.panels[i];
if (panel.type !== 'row') {
continue;
@@ -606,7 +606,7 @@ export class DashboardModel {
collapseRows() {
for (let i = 0; i < this.panels.length; i++) {
var panel = this.panels[i];
const panel = this.panels[i];
if (panel.type !== 'row') {
continue;
@@ -628,12 +628,12 @@ export class DashboardModel {
return true;
}
var visibleVars = _.filter(this.templating.list, variable => variable.hide !== 2);
const 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);
const visibleAnnotations = _.filter(this.annotations.list, annotation => annotation.hide !== true);
if (visibleAnnotations.length > 0) {
return true;
}
@@ -683,29 +683,29 @@ export class DashboardModel {
formatDate(date, format?) {
date = moment.isMoment(date) ? date : moment(date);
format = format || 'YYYY-MM-DD HH:mm:ss';
let timezone = this.getTimezone();
const timezone = this.getTimezone();
return timezone === 'browser' ? moment(date).format(format) : moment.utc(date).format(format);
}
destroy() {
this.events.removeAllListeners();
for (let panel of this.panels) {
for (const panel of this.panels) {
panel.destroy();
}
}
toggleRow(row: PanelModel) {
let rowIndex = _.indexOf(this.panels, row);
const rowIndex = _.indexOf(this.panels, row);
if (row.collapsed) {
row.collapsed = false;
let hasRepeat = _.some(row.panels, p => p.repeat);
const hasRepeat = _.some(row.panels, p => p.repeat);
if (row.panels.length > 0) {
// Use first panel to figure out if it was moved or pushed
let firstPanel = row.panels[0];
let yDiff = firstPanel.gridPos.y - (row.gridPos.y + row.gridPos.h);
const firstPanel = row.panels[0];
const yDiff = firstPanel.gridPos.y - (row.gridPos.y + row.gridPos.h);
// start inserting after row
let insertPos = rowIndex + 1;
@@ -713,7 +713,7 @@ export class DashboardModel {
// needed to know home much panels below should be pushed down
let yMax = row.gridPos.y;
for (let panel of row.panels) {
for (const panel of row.panels) {
// make sure y is adjusted (in case row moved while collapsed)
// console.log('yDiff', yDiff);
panel.gridPos.y -= yDiff;
@@ -746,7 +746,7 @@ export class DashboardModel {
return;
}
let rowPanels = this.getRowPanels(rowIndex);
const rowPanels = this.getRowPanels(rowIndex);
// remove panels
_.pull(this.panels, ...rowPanels);
@@ -762,10 +762,10 @@ export class DashboardModel {
* Will return all panels after rowIndex until it encounters another row
*/
getRowPanels(rowIndex: number): PanelModel[] {
let rowPanels = [];
const rowPanels = [];
for (let index = rowIndex + 1; index < this.panels.length; index++) {
let panel = this.panels[index];
const panel = this.panels[index];
// break when encountering another row
if (panel.type === 'row') {
@@ -806,10 +806,10 @@ export class DashboardModel {
}
getNextQueryLetter(panel) {
var letters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
const letters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
return _.find(letters, function(refId) {
return _.every(panel.targets, function(other) {
return _.find(letters, refId => {
return _.every(panel.targets, other => {
return other.refId !== refId;
});
});
@@ -824,7 +824,7 @@ export class DashboardModel {
}
private updateSchema(old) {
let migrator = new DashboardMigrator(this);
const migrator = new DashboardMigrator(this);
migrator.updateSchema(old);
}
@@ -875,12 +875,20 @@ export class DashboardModel {
})
);
// Consider navbar and submenu controls, padding and margin
let visibleHeight = window.innerHeight - 55 - 20;
const navbarHeight = 55;
const margin = 20;
const submenuHeight = 50;
// Remove submenu if visible
if (this.meta.submenuEnabled) {
visibleHeight -= 50;
let visibleHeight = viewHeight - navbarHeight - margin;
// Remove submenu height if visible
if (this.meta.submenuEnabled && !this.meta.kiosk) {
visibleHeight -= submenuHeight;
}
// add back navbar height
if (this.meta.kiosk === 'b') {
visibleHeight += 55;
}
const visibleGridHeight = Math.floor(visibleHeight / (GRID_CELL_HEIGHT + GRID_CELL_VMARGIN));