diff --git a/public/app/features/dashboard/viewStateSrv.js b/public/app/features/dashboard/viewStateSrv.js index 63bb999e3ca..c523cd709d7 100644 --- a/public/app/features/dashboard/viewStateSrv.js +++ b/public/app/features/dashboard/viewStateSrv.js @@ -167,7 +167,11 @@ function (angular, _, $) { self.panelScopes.push(panelScope); if (self.state.panelId === panelScope.ctrl.panel.id) { - self.enterFullscreen(panelScope); + if (self.state.edit) { + panelScope.ctrl.editPanel(); + } else { + panelScope.ctrl.viewPanel(); + } } panelScope.$on('$destroy', function() { diff --git a/public/app/features/panel/panel.ts b/public/app/features/panel/panel.ts index a3bf35db9a4..550f453260b 100644 --- a/public/app/features/panel/panel.ts +++ b/public/app/features/panel/panel.ts @@ -1,17 +1,26 @@ /// -import PanelMeta from './panel_meta3'; +import config from 'app/core/config'; + +function generalOptionsTabEditorTab() { + return {templateUrl: 'public/app/partials/panelgeneral.html'}; +} export class PanelCtrl { - meta: any; panel: any; row: any; dashboard: any; - tabIndex: number; + editorTabIndex: number; + name: string; + icon: string; + editorTabs: any; constructor(private scope) { - this.meta = new PanelMeta(this.panel); - this.tabIndex = 0; + var plugin = config.panels[this.panel.type]; + + this.name = plugin.name; + this.icon = plugin.info.icon; + this.editorTabIndex = 0; this.publishAppEvent('panel-instantiated', {scope: scope}); } @@ -30,12 +39,30 @@ export class PanelCtrl { } editPanel() { + if (!this.editorTabs) { + this.initEditorTabs(); + } + this.changeView(true, true); } exitFullscreen() { this.changeView(false, false); } + + initEditorTabs() { + this.editorTabs = []; + this.editorTabs.push({title: 'General', directiveFn: generalOptionsTabEditorTab}); + } + + getMenu() { + let menu = []; + menu.push({text: 'View', click: 'ctrl.viewPanel(); dismiss();'}); + menu.push({text: 'Edit', click: 'ctrl.editPanel(); dismiss();', role: 'Editor'}); + menu.push({text: 'Duplicate', click: 'ctrl.duplicate()', role: 'Editor' }); + menu.push({text: 'Share', click: 'ctrl.share(); dismiss();'}); + return menu; + } } export class PanelDirective { diff --git a/public/app/features/panel/panel_menu.js b/public/app/features/panel/panel_menu.js index 16ee311ff52..5ec5129dc38 100644 --- a/public/app/features/panel/panel_menu.js +++ b/public/app/features/panel/panel_menu.js @@ -13,7 +13,7 @@ function (angular, $, _) { '' + '{{ctrl.panel.title | interpolateTemplateVars:this}}' + '' + - ' {{ctrl.panelMeta.timeInfo}}' + + ' {{ctrl.timeInfo}}' + ''; function createExternalLinkMenu(ctrl) { @@ -44,7 +44,7 @@ function (angular, $, _) { template += '
'; template += ''; - _.each(ctrl.meta.menu, function(item) { + _.each(ctrl.getMenu(), function(item) { // skip edit actions if not editor if (item.role === 'Editor' && !ctrl.dashboard.meta.canEdit) { return; @@ -64,7 +64,7 @@ function (angular, $, _) { } function getExtendedMenu(ctrl) { - return angular.copy(ctrl.meta.extendedMenu); + return angular.copy(ctrl.extendedMenu); } return { diff --git a/public/app/features/panel/panel_meta3.ts b/public/app/features/panel/panel_meta3.ts deleted file mode 100644 index 056a75d5ee3..00000000000 --- a/public/app/features/panel/panel_meta3.ts +++ /dev/null @@ -1,56 +0,0 @@ -/// - -import config from 'app/core/config'; - -function panelOptionsTab() { - return {templateUrl: 'app/partials/panelgeneral.html'}; -} - -export default class PanelMeta { - description: any; - icon: any; - name: any; - menu: any; - editorTabs: any; - extendedMenu: any; - - constructor(panel) { - let panelInfo = config.panels[panel.type]; - console.log(panelInfo); - - this.icon = panelInfo.icon; - this.name = panelInfo.name; - this.menu = []; - this.editorTabs = []; - this.extendedMenu = []; - - if (panelInfo.fullscreen) { - this.addMenuItem('View', 'icon-eye-open', 'ctrl.viewPanel(); dismiss();'); - } - - this.addMenuItem('Edit', 'icon-cog', 'ctrl.editPanel(); dismiss();', 'Editor'); - this.addMenuItem('Duplicate', 'icon-copy', 'ctrl.duplicate()', 'Editor'); - this.addMenuItem('Share', 'icon-share', 'ctrl.share(); dismiss();'); - - this.addEditorTab('General', panelOptionsTab); - - if (panelInfo.metricsEditor) { - this.addEditorTab('Metrics', 'app/partials/metrics.html'); - } - - this.addExtendedMenuItem('Panel JSON', '', 'ctrl.editPanelJson(); dismiss();'); - } - - addMenuItem (text, icon, click, role?) { - this.menu.push({text: text, icon: icon, click: click, role: role}); - } - - addExtendedMenuItem (text, icon, click, role?) { - this.extendedMenu.push({text: text, icon: icon, click: click, role: role}); - } - - addEditorTab(title, directiveFn) { - this.editorTabs.push({title: title, directiveFn: directiveFn}); - } -} - diff --git a/public/app/features/panel/partials/panel.html b/public/app/features/panel/partials/panel.html index c3fb0090241..bf946d16fc3 100644 --- a/public/app/features/panel/partials/panel.html +++ b/public/app/features/panel/partials/panel.html @@ -1,12 +1,12 @@
- - + + - + @@ -23,12 +23,12 @@
- - {{ctrl.meta.name}} + + {{ctrl.name}}
-
-
+
+
@@ -38,7 +38,7 @@
-
+
diff --git a/public/app/plugins/panel/test/module.ts b/public/app/plugins/panel/test/module.ts index da1682544a4..47eab73f936 100644 --- a/public/app/plugins/panel/test/module.ts +++ b/public/app/plugins/panel/test/module.ts @@ -12,15 +12,6 @@ class TestPanelCtrl extends PanelCtrl { class TestPanel extends PanelDirective { templateUrl = `app/plugins/panel/test/module.html`; controller = TestPanelCtrl; - - constructor($http) { - super(); - console.log('panel ctor: ', $http); - } - - link(scope) { - console.log('panel link: ', scope.ctrl.panel.id); - } } export {