فهرست منبع

feat(panels): fixing broken stuff

Torkel Ödegaard 10 سال پیش
والد
کامیت
f0f7da9ff0

+ 0 - 25
public/app/features/dashboard/rowCtrl.js

@@ -116,32 +116,7 @@ function (angular, _, config) {
       $scope.$broadcast('render');
     };
 
-    $scope.removePanel = function(panel) {
-      $scope.appEvent('confirm-modal', {
-        title: 'Are you sure you want to remove this panel?',
-        icon: 'fa-trash',
-        yesText: 'Delete',
-        onConfirm: function() {
-          $scope.row.panels = _.without($scope.row.panels, panel);
-        }
-      });
-    };
-
-    $scope.replacePanel = function(newPanel, oldPanel) {
-      var row = $scope.row;
-      var index = _.indexOf(row.panels, oldPanel);
-      row.panels.splice(index, 1);
-
-      // adding it back needs to be done in next digest
-      $timeout(function() {
-        newPanel.id = oldPanel.id;
-        newPanel.span = oldPanel.span;
-        row.panels.splice(index, 0, newPanel);
-      });
-    };
-
     $scope.init();
-
   });
 
   module.directive('rowHeight', function() {

+ 29 - 5
public/app/features/panel/panel_ctrl.ts

@@ -21,16 +21,17 @@ export class PanelCtrl {
   editorHelpIndex: number;
 
   constructor($scope, $injector) {
-    var plugin = config.panels[this.panel.type];
-
     this.$injector = $injector;
     this.$scope = $scope;
     this.$timeout = $injector.get('$timeout');
-    this.pluginName = plugin.name;
-    this.pluginId = plugin.id;
-    this.icon = plugin.info.icon;
     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());
   }
 
@@ -97,6 +98,10 @@ export class PanelCtrl {
     return menu;
   }
 
+  getExtendedMenu() {
+    return [{text: 'Panel JSON', click: 'ctrl.editPanelJson(); dismiss();'}];
+  }
+
   otherPanelInFullscreenMode() {
     return this.dashboard.meta.fullscreen && !this.fullscreen;
   }
@@ -135,4 +140,23 @@ export class PanelCtrl {
     });
   }
 
+  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);
+    });
+  }
 }

+ 1 - 2
public/app/features/panel/panel_directive.js

@@ -17,7 +17,6 @@ function (angular, $) {
         var panelContainer = elem.find('.panel-container');
         var ctrl = scope.ctrl;
         scope.$watchGroup(['ctrl.fullscreen', 'ctrl.height', 'ctrl.panel.height', 'ctrl.row.height'], function() {
-          console.log('height: ', ctrl.height);
           panelContainer.css({ minHeight: ctrl.height || ctrl.panel.height || ctrl.row.height, display: 'block' });
           elem.toggleClass('panel-fullscreen', ctrl.fullscreen ? true : false);
         });
@@ -80,7 +79,7 @@ function (angular, $) {
 
         function dragEndHandler() {
           // if close to 12
-          var rowSpan = ctrl.dashboard.rowSpan(scope.row);
+          var rowSpan = ctrl.dashboard.rowSpan(ctrl.row);
           if (rowSpan < 12 && rowSpan > 11) {
             lastPanel.span +=  12 - rowSpan;
           }

+ 2 - 2
public/app/features/panel/panel_loader.ts

@@ -41,6 +41,7 @@ function panelLoader($compile, dynamicDirectiveSrv, $http, $q, $injector) {
       function addPanel(name, Panel) {
         if (Panel.registered) {
           addPanelAndCompile(name);
+          return;
         }
 
         if (Panel.promise) {
@@ -62,14 +63,13 @@ function panelLoader($compile, dynamicDirectiveSrv, $http, $q, $injector) {
           Panel.registered = true;
           addPanelAndCompile(name);
         });
-
-        return;
       }
 
       var panelElemName = 'panel-directive-' + scope.panel.type;
       let panelInfo = config.panels[scope.panel.type];
       if (!panelInfo) {
         addPanel(panelElemName, UnknownPanel);
+        return;
       }
 
       System.import(panelInfo.module).then(function(panelModule) {

+ 1 - 1
public/app/features/panel/panel_menu.js

@@ -64,7 +64,7 @@ function (angular, $, _) {
       }
 
       function getExtendedMenu(ctrl) {
-        return angular.copy(ctrl.extendedMenu);
+        return ctrl.getExtendedMenu();
       }
 
       return {

+ 1 - 0
public/app/plugins/panel/text/module.ts

@@ -59,6 +59,7 @@ export class TextPanelCtrl extends PanelCtrl {
       this.updateContent(this.converter.makeHtml(text));
     } else {
       System.import('vendor/showdown').then(Showdown => {
+        console.log(this);
         this.converter = new Showdown.converter();
         this.$scope.$apply(() => {
           this.updateContent(this.converter.makeHtml(text));

+ 6 - 1
public/app/plugins/panel/unknown/module.ts

@@ -2,10 +2,15 @@
 
 import {PanelDirective} from '../../../features/panel/panel';
 
-export class UnknownPanel extends PanelDirective {
+class UnknownPanel extends PanelDirective {
   template = `<div class="text-center" style="padding-top: 2rem">
                 Unknown panel type: <strong>{{ctrl.panel.type}}</strong>
               </div>`;
 }
 
 
+export {
+  UnknownPanel,
+  UnknownPanel as Panel
+}
+