diff --git a/public/app/features/dashboard/viewStateSrv.js b/public/app/features/dashboard/viewStateSrv.js index c523cd709d7..abe1ec3279e 100644 --- a/public/app/features/dashboard/viewStateSrv.js +++ b/public/app/features/dashboard/viewStateSrv.js @@ -17,6 +17,7 @@ function (angular, _, $) { self.state = {}; self.panelScopes = []; self.$scope = $scope; + self.dashboard = $scope.dashboard; $scope.exitFullscreen = function() { if (self.state.fullscreen) { @@ -74,7 +75,7 @@ function (angular, _, $) { DashboardViewState.prototype.update = function(state, skipUrlSync) { _.extend(this.state, state); - this.fullscreen = this.state.fullscreen; + this.dashboard.meta.fullscreen = this.state.fullscreen; if (!this.state.fullscreen) { this.state.panelId = null; @@ -92,7 +93,7 @@ function (angular, _, $) { DashboardViewState.prototype.syncState = function() { if (this.panelScopes.length === 0) { return; } - if (this.fullscreen) { + if (this.dashboard.meta.fullscreen) { if (this.fullscreenPanel) { this.leaveFullscreen(false); } @@ -148,13 +149,13 @@ function (angular, _, $) { ctrl.editMode = this.state.edit && this.$scope.dashboardMeta.canEdit; ctrl.height = ctrl.editMode ? editHeight : fullscreenHeight; + ctrl.fullscreen = true; this.oldTimeRange = ctrl.range; this.fullscreenPanel = panelScope; $(window).scrollTop(0); - panelScope.fullscreen = true; this.$scope.appEvent('panel-fullscreen-enter', {panelId: ctrl.panel.id}); $timeout(function() { diff --git a/public/app/features/panel/metrics_panel_ctrl.ts b/public/app/features/panel/metrics_panel_ctrl.ts index 968bcea52b6..2ce1dfa847f 100644 --- a/public/app/features/panel/metrics_panel_ctrl.ts +++ b/public/app/features/panel/metrics_panel_ctrl.ts @@ -3,18 +3,64 @@ import config from 'app/core/config'; import {PanelCtrl} from './panel_ctrl'; -function metricsEditorTab() { - return {templateUrl: 'public/app/partials/metrics.html'}; -} - class MetricsPanelCtrl extends PanelCtrl { - constructor($scope) { + error: boolean; + loading: boolean; + datasource: any; + + constructor($scope, private $q, private datasourceSrv) { super($scope); + this.editorTabIndex = 1; + + if (!this.panel.targets) { + this.panel.targets = [{}]; + } } initEditorTabs() { - super.initEditorTabs(); - this.editorTabs.push({title: 'Metrics', directiveFn: metricsEditorTab}); + this.addEditorTab('Metrics', () => { + return { templateUrl: 'public/app/partials/metrics.html' }; + }); + } + + refresh() { + this.getData(); + } + + refreshData(data) { + // null op + return data; + } + + loadSnapshot(data) { + // null op + return data; + } + + getData() { + if (this.otherPanelInFullscreenMode()) { return; } + + if (this.panel.snapshotData) { + if (this.loadSnapshot) { + this.loadSnapshot(this.panel.snapshotData); + } + return; + } + + delete this.error; + this.loading = true; + + this.datasourceSrv.get(this.panel.datasource).then(datasource => { + this.datasource = datasource; + return this.refreshData(this.datasource) || this.$q.when({}); + }).then(() => { + this.loading = false; + }, err => { + console.log('Panel data error:', err); + this.loading = false; + this.error = err.message || "Timeseries data request error"; + this.inspector = {error: err}; + }); } } diff --git a/public/app/features/panel/panel.ts b/public/app/features/panel/panel.ts index 08ede83eb95..4d80bb9dade 100644 --- a/public/app/features/panel/panel.ts +++ b/public/app/features/panel/panel.ts @@ -29,7 +29,7 @@ class PanelDirective { }; } - link(scope) { + link(scope, elem) { return null; } } diff --git a/public/app/features/panel/panel_ctrl.ts b/public/app/features/panel/panel_ctrl.ts index 0fb94e660d5..9bceaa482c5 100644 --- a/public/app/features/panel/panel_ctrl.ts +++ b/public/app/features/panel/panel_ctrl.ts @@ -15,7 +15,8 @@ export class PanelCtrl { icon: string; editorTabs: any; $scope: any; - isMetricsPanel: boolean; + fullscreen: boolean; + inspector: any; constructor($scope) { var plugin = config.panels[this.panel.type]; @@ -77,4 +78,8 @@ export class PanelCtrl { menu.push({text: 'Share', click: 'ctrl.share(); dismiss();'}); return menu; } + + otherPanelInFullscreenMode() { + return this.dashboard.meta.fullscreen && !this.fullscreen; + } } diff --git a/public/app/features/panel/panel_editor_tab.ts b/public/app/features/panel/panel_editor_tab.ts index 56e3078962e..68b1e67c01c 100644 --- a/public/app/features/panel/panel_editor_tab.ts +++ b/public/app/features/panel/panel_editor_tab.ts @@ -9,7 +9,7 @@ var directiveModule = angular.module('grafana.directives'); function panelEditorTab(dynamicDirectiveSrv) { return dynamicDirectiveSrv.create({ scope: { - panelCtrl: "=", + ctrl: "=", editorTab: "=", }, directive: scope => { diff --git a/public/app/features/panel/partials/panel.html b/public/app/features/panel/partials/panel.html index bf946d16fc3..55ed28eafc4 100644 --- a/public/app/features/panel/partials/panel.html +++ b/public/app/features/panel/partials/panel.html @@ -1,4 +1,4 @@ -