Explorar el Código

ux(dashboard): worked on single row edit mode, #6442

Torkel Ödegaard hace 9 años
padre
commit
075c722527

+ 1 - 0
public/app/features/dashboard/model.ts

@@ -192,6 +192,7 @@ export class DashboardModel {
 
     this.editMode = !this.editMode;
     this.updateSubmenuVisibility();
+    this.events.emit('edit-mode-changed', this.editMode);
   }
 
   setPanelFocus(id) {

+ 1 - 1
public/app/features/dashboard/row/add_panel.ts

@@ -93,7 +93,7 @@ export class AddPanelCtrl {
       isNew: true,
     };
 
-    this.rowCtrl.dropView = 0;
+    this.rowCtrl.closeDropView();
     this.dashboard.addPanel(panel, this.row);
     this.$timeout(() => {
       this.$rootScope.$broadcast('render');

+ 2 - 2
public/app/features/dashboard/row/row.html

@@ -1,4 +1,4 @@
-<div ng-if="ctrl.dashboard.editMode">
+<div ng-if="ctrl.editMode">
   <div class="dash-row-header">
     <a class="dash-row-header-title" ng-click="ctrl.toggleCollapse()">
       <span class="dash-row-collapse-toggle pointer">
@@ -40,7 +40,7 @@
   </div>
 </div>
 
-<div ng-if="!ctrl.dashboard.editMode">
+<div ng-if="!ctrl.editMode">
   <div class="row-open">
     <div class='row-tab dropdown' ng-show="dashboardMeta.canEdit" ng-hide="dashboard.meta.fullscreen">
       <span class="row-tab-button dropdown-toggle" data-toggle="dropdown">

+ 16 - 5
public/app/features/dashboard/row/row_ctrl.ts

@@ -12,6 +12,7 @@ export class DashRowCtrl {
   dashboard: any;
   row: any;
   dropView: number;
+  editMode: boolean;
 
   /** @ngInject */
   constructor(private $scope, private $rootScope, private $timeout, private uiSegmentSrv, private $q) {
@@ -21,6 +22,12 @@ export class DashRowCtrl {
       this.dropView = 1;
       delete this.row.isNew;
     }
+
+    this.dashboard.events.on('edit-mode-changed', this.editModeChanged.bind(this), $scope);
+  }
+
+  editModeChanged() {
+    this.editMode = this.dashboard.editMode;
   }
 
   onDrop(panelId, dropTarget) {
@@ -107,15 +114,20 @@ export class DashRowCtrl {
   }
 
   onMenuAddPanel() {
-    this.dashboard.toggleEditMode();
+    this.editMode = true;
     this.dropView = 1;
   }
 
   onMenuRowOptions() {
-    this.dashboard.toggleEditMode();
+    this.editMode = true;
     this.dropView = 2;
   }
 
+  closeDropView() {
+    this.dropView = 0;
+    this.editMode = this.dashboard.editMode;
+  }
+
   onMenuDeleteRow() {
     this.dashboard.removeRow(this.row);
   }
@@ -208,7 +220,7 @@ coreModule.directive('panelDropZone', function($timeout) {
     }
 
     function updateState() {
-      if (scope.ctrl.dashboard.editMode) {
+      if (scope.ctrl.editMode) {
         if (row.panels.length === 0 && indrag === false) {
           return showPanel(12, 'Empty Space');
         }
@@ -234,8 +246,7 @@ coreModule.directive('panelDropZone', function($timeout) {
     }
 
     row.events.on('span-changed', updateState, scope);
-
-    scope.$watchGroup(['ctrl.dashboard.editMode'], updateState);
+    scope.$watchGroup(['ctrl.editMode'], updateState);
 
     scope.$on("ANGULAR_DRAG_START", function() {
       indrag = true;