| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179 |
- ///<reference path="../../headers/common.d.ts" />
- import config from 'app/core/config';
- import _ from 'lodash';
- export class PanelCtrl {
- panel: any;
- row: any;
- dashboard: any;
- editorTabIndex: number;
- pluginName: string;
- pluginId: string;
- icon: string;
- editorTabs: any;
- $scope: any;
- $injector: any;
- $timeout: any;
- fullscreen: boolean;
- inspector: any;
- editModeInitiated: boolean;
- editorHelpIndex: number;
- constructor($scope, $injector) {
- this.$injector = $injector;
- this.$scope = $scope;
- this.$timeout = $injector.get('$timeout');
- this.editorTabIndex = 0;
- var plugin = config.panels[this.panel.type];
- if (plugin) {
- this.pluginId = plugin.id;
- this.pluginName = plugin.name;
- }
- $scope.$on("refresh", () => this.refresh());
- }
- init() {
- this.publishAppEvent('panel-instantiated', {scope: this.$scope});
- this.refresh();
- }
- renderingCompleted() {
- this.$scope.$root.performance.panelsRendered++;
- }
- refresh() {
- return;
- }
- publishAppEvent(evtName, evt) {
- this.$scope.$root.appEvent(evtName, evt);
- }
- changeView(fullscreen, edit) {
- this.publishAppEvent('panel-change-view', {
- fullscreen: fullscreen, edit: edit, panelId: this.panel.id
- });
- }
- viewPanel() {
- this.changeView(true, false);
- }
- editPanel() {
- if (!this.editModeInitiated) {
- this.editorTabs = [];
- this.addEditorTab('General', 'public/app/partials/panelgeneral.html');
- this.initEditMode();
- }
- this.changeView(true, true);
- }
- exitFullscreen() {
- this.changeView(false, false);
- }
- initEditMode() {
- return;
- }
- addEditorTab(title, directiveFn, index?) {
- var editorTab = {title, directiveFn};
- if (_.isString(directiveFn)) {
- editorTab.directiveFn = function() {
- return {templateUrl: directiveFn};
- };
- }
- if (index) {
- this.editorTabs.splice(index, 0, editorTab);
- } else {
- this.editorTabs.push(editorTab);
- }
- }
- 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.sharePanel(); dismiss();'});
- return menu;
- }
- getExtendedMenu() {
- return [{text: 'Panel JSON', click: 'ctrl.editPanelJson(); dismiss();'}];
- }
- otherPanelInFullscreenMode() {
- return this.dashboard.meta.fullscreen && !this.fullscreen;
- }
- broadcastRender(arg1?, arg2?) {
- this.$scope.$broadcast('render', arg1, arg2);
- }
- toggleEditorHelp(index) {
- if (this.editorHelpIndex === index) {
- this.editorHelpIndex = null;
- return;
- }
- this.editorHelpIndex = index;
- }
- duplicate() {
- this.dashboard.duplicatePanel(this.panel, this.row);
- }
- updateColumnSpan(span) {
- this.panel.span = Math.min(Math.max(Math.floor(this.panel.span + span), 1), 12);
- this.$timeout(() => {
- this.broadcastRender();
- });
- }
- removePanel() {
- this.publishAppEvent('confirm-modal', {
- title: 'Are you sure you want to remove this panel?',
- icon: 'fa-trash',
- yesText: 'Delete',
- onConfirm: () => {
- this.row.panels = _.without(this.row.panels, this.panel);
- }
- });
- }
- editPanelJson() {
- this.publishAppEvent('show-json-editor', {
- object: this.panel,
- updateHandler: this.replacePanel.bind(this)
- });
- }
- replacePanel(newPanel, oldPanel) {
- var row = this.row;
- var index = _.indexOf(this.row.panels, oldPanel);
- this.row.panels.splice(index, 1);
- // adding it back needs to be done in next digest
- this.$timeout(() => {
- newPanel.id = oldPanel.id;
- newPanel.span = oldPanel.span;
- this.row.panels.splice(index, 0, newPanel);
- });
- }
- sharePanel() {
- var shareScope = this.$scope.$new();
- shareScope.panel = this.panel;
- shareScope.dashboard = this.dashboard;
- this.publishAppEvent('show-modal', {
- src: './app/features/dashboard/partials/shareModal.html',
- scope: shareScope
- });
- }
- }
|