|
@@ -1,11 +1,9 @@
|
|
|
///<reference path="../../../headers/common.d.ts" />
|
|
///<reference path="../../../headers/common.d.ts" />
|
|
|
|
|
|
|
|
import _ from 'lodash';
|
|
import _ from 'lodash';
|
|
|
-import $ from 'jquery';
|
|
|
|
|
-import angular from 'angular';
|
|
|
|
|
|
|
|
|
|
import config from 'app/core/config';
|
|
import config from 'app/core/config';
|
|
|
-import {coreModule} from 'app/core/core';
|
|
|
|
|
|
|
+import {coreModule, appEvents} from 'app/core/core';
|
|
|
|
|
|
|
|
import './options';
|
|
import './options';
|
|
|
import './add_panel';
|
|
import './add_panel';
|
|
@@ -19,28 +17,63 @@ export class DashRowCtrl {
|
|
|
constructor(private $scope, private $rootScope, private $timeout, private uiSegmentSrv, private $q) {
|
|
constructor(private $scope, private $rootScope, private $timeout, private uiSegmentSrv, private $q) {
|
|
|
this.row.title = this.row.title || 'Row title';
|
|
this.row.title = this.row.title || 'Row title';
|
|
|
|
|
|
|
|
- if (this.dashboard.meta.isNew) {
|
|
|
|
|
|
|
+ if (this.row.isNew) {
|
|
|
this.dropView = 1;
|
|
this.dropView = 1;
|
|
|
delete this.row.isNew;
|
|
delete this.row.isNew;
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
onDrop(panelId, dropTarget) {
|
|
onDrop(panelId, dropTarget) {
|
|
|
- var info = this.dashboard.getPanelInfoById(panelId);
|
|
|
|
|
|
|
+ var dragObject;
|
|
|
|
|
+
|
|
|
|
|
+ // if string it's a panel type
|
|
|
|
|
+ if (_.isString(panelId)) {
|
|
|
|
|
+ // setup new panel
|
|
|
|
|
+ dragObject = {
|
|
|
|
|
+ row: this.row,
|
|
|
|
|
+ panel: {
|
|
|
|
|
+ title: config.new_panel_title,
|
|
|
|
|
+ type: panelId,
|
|
|
|
|
+ id: this.dashboard.getNextPanelId(),
|
|
|
|
|
+ },
|
|
|
|
|
+ isNew: true,
|
|
|
|
|
+ };
|
|
|
|
|
+ } else {
|
|
|
|
|
+ dragObject = this.dashboard.getPanelInfoById(panelId);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
if (dropTarget) {
|
|
if (dropTarget) {
|
|
|
- var dropInfo = this.dashboard.getPanelInfoById(dropTarget.id);
|
|
|
|
|
- dropInfo.row.panels[dropInfo.index] = info.panel;
|
|
|
|
|
- info.row.panels[info.index] = dropTarget;
|
|
|
|
|
- var dragSpan = info.panel.span;
|
|
|
|
|
- info.panel.span = dropTarget.span;
|
|
|
|
|
- dropTarget.span = dragSpan;
|
|
|
|
|
|
|
+ dropTarget = this.dashboard.getPanelInfoById(dropTarget.id);
|
|
|
|
|
+ // if draging new panel onto existing panel split it
|
|
|
|
|
+ if (dragObject.isNew) {
|
|
|
|
|
+ dragObject.panel.span = dropTarget.panel.span = dropTarget.panel.span/2;
|
|
|
|
|
+ // insert after
|
|
|
|
|
+ dropTarget.row.panels.splice(dropTarget.index+1, 0, dragObject.panel);
|
|
|
|
|
+ } else if (this.row === dragObject.row) {
|
|
|
|
|
+ // just move element
|
|
|
|
|
+ this.row.movePanel(dropTarget.index, dragObject.index);
|
|
|
|
|
+ } else {
|
|
|
|
|
+ // split drop target space
|
|
|
|
|
+ dragObject.panel.span = dropTarget.panel.span = dropTarget.panel.span/2;
|
|
|
|
|
+ // insert after
|
|
|
|
|
+ dropTarget.row.panels.splice(dropTarget.index+1, 0, dragObject.panel);
|
|
|
|
|
+ // remove from source row
|
|
|
|
|
+ dragObject.row.removePanel(dragObject.panel);
|
|
|
|
|
+ }
|
|
|
} else {
|
|
} else {
|
|
|
- info.row.panels.splice(info.index, 1);
|
|
|
|
|
- info.panel.span = 12 - this.dashboard.rowSpan(this.row);
|
|
|
|
|
- this.row.panels.push(info.panel);
|
|
|
|
|
|
|
+ dragObject.panel.span = 12 - this.row.span;
|
|
|
|
|
+ this.row.panels.push(dragObject.panel);
|
|
|
|
|
+
|
|
|
|
|
+ // if not new remove from source row
|
|
|
|
|
+ if (!dragObject.isNew) {
|
|
|
|
|
+ dragObject.row.removePanel(dragObject.panel);
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- this.$rootScope.$broadcast('render');
|
|
|
|
|
|
|
+ this.row.panelSpanChanged();
|
|
|
|
|
+ this.$timeout(() => {
|
|
|
|
|
+ this.$rootScope.$broadcast('render');
|
|
|
|
|
+ });
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
setHeight(height) {
|
|
setHeight(height) {
|
|
@@ -51,28 +84,8 @@ export class DashRowCtrl {
|
|
|
moveRow(direction) {
|
|
moveRow(direction) {
|
|
|
var rowsList = this.dashboard.rows;
|
|
var rowsList = this.dashboard.rows;
|
|
|
var rowIndex = _.indexOf(rowsList, this.row);
|
|
var rowIndex = _.indexOf(rowsList, this.row);
|
|
|
- var newIndex = rowIndex;
|
|
|
|
|
- switch (direction) {
|
|
|
|
|
- case 'up': {
|
|
|
|
|
- newIndex = rowIndex - 1;
|
|
|
|
|
- break;
|
|
|
|
|
- }
|
|
|
|
|
- case 'down': {
|
|
|
|
|
- newIndex = rowIndex + 1;
|
|
|
|
|
- break;
|
|
|
|
|
- }
|
|
|
|
|
- case 'top': {
|
|
|
|
|
- newIndex = 0;
|
|
|
|
|
- break;
|
|
|
|
|
- }
|
|
|
|
|
- case 'bottom': {
|
|
|
|
|
- newIndex = rowsList.length - 1;
|
|
|
|
|
- break;
|
|
|
|
|
- }
|
|
|
|
|
- default: {
|
|
|
|
|
- newIndex = rowIndex;
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ var newIndex = rowIndex + direction;
|
|
|
|
|
+
|
|
|
if (newIndex >= 0 && newIndex <= (rowsList.length - 1)) {
|
|
if (newIndex >= 0 && newIndex <= (rowsList.length - 1)) {
|
|
|
_.move(rowsList, rowIndex, newIndex);
|
|
_.move(rowsList, rowIndex, newIndex);
|
|
|
}
|
|
}
|
|
@@ -93,7 +106,7 @@ export class DashRowCtrl {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-export function rowDirective($rootScope) {
|
|
|
|
|
|
|
+coreModule.directive('dashRow', function($rootScope) {
|
|
|
return {
|
|
return {
|
|
|
restrict: 'E',
|
|
restrict: 'E',
|
|
|
templateUrl: 'public/app/features/dashboard/row/row.html',
|
|
templateUrl: 'public/app/features/dashboard/row/row.html',
|
|
@@ -121,10 +134,7 @@ export function rowDirective($rootScope) {
|
|
|
}, scope);
|
|
}, scope);
|
|
|
}
|
|
}
|
|
|
};
|
|
};
|
|
|
-}
|
|
|
|
|
-
|
|
|
|
|
-coreModule.directive('dashRow', rowDirective);
|
|
|
|
|
-
|
|
|
|
|
|
|
+});
|
|
|
|
|
|
|
|
coreModule.directive('panelWidth', function($rootScope) {
|
|
coreModule.directive('panelWidth', function($rootScope) {
|
|
|
return function(scope, element) {
|
|
return function(scope, element) {
|
|
@@ -180,7 +190,6 @@ coreModule.directive('panelDropZone', function($timeout) {
|
|
|
|
|
|
|
|
function hidePanel() {
|
|
function hidePanel() {
|
|
|
element.hide();
|
|
element.hide();
|
|
|
- // element.removeClass('panel-drop-zone--empty');
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
function updateState() {
|
|
function updateState() {
|
|
@@ -190,7 +199,7 @@ coreModule.directive('panelDropZone', function($timeout) {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
var dropZoneSpan = 12 - scope.ctrl.dashboard.rowSpan(scope.ctrl.row);
|
|
var dropZoneSpan = 12 - scope.ctrl.dashboard.rowSpan(scope.ctrl.row);
|
|
|
- if (dropZoneSpan > 1) {
|
|
|
|
|
|
|
+ if (dropZoneSpan > 0) {
|
|
|
if (indrag) {
|
|
if (indrag) {
|
|
|
return showPanel(dropZoneSpan, 'Drop Here');
|
|
return showPanel(dropZoneSpan, 'Drop Here');
|
|
|
} else {
|
|
} else {
|
|
@@ -200,26 +209,22 @@ coreModule.directive('panelDropZone', function($timeout) {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
if (indrag === true) {
|
|
if (indrag === true) {
|
|
|
- return showPanel(dropZoneSpan, 'Drop Here');
|
|
|
|
|
|
|
+ var dropZoneSpan = 12 - scope.ctrl.dashboard.rowSpan(scope.ctrl.row);
|
|
|
|
|
+ if (dropZoneSpan > 1) {
|
|
|
|
|
+ return showPanel(dropZoneSpan, 'Drop Here');
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
hidePanel();
|
|
hidePanel();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- scope.row.events.on('panel-added', updateState);
|
|
|
|
|
- scope.row.events.on('span-changed', updateState);
|
|
|
|
|
|
|
+ row.events.on('span-changed', updateState, scope);
|
|
|
|
|
|
|
|
- scope.$watchGroup(['ctrl.row.panels.length', 'ctrl.dashboard.editMode', 'ctrl.row.span'], updateState);
|
|
|
|
|
|
|
+ scope.$watchGroup(['ctrl.dashboard.editMode'], updateState);
|
|
|
|
|
|
|
|
scope.$on("ANGULAR_DRAG_START", function() {
|
|
scope.$on("ANGULAR_DRAG_START", function() {
|
|
|
indrag = true;
|
|
indrag = true;
|
|
|
updateState();
|
|
updateState();
|
|
|
- // $timeout(function() {
|
|
|
|
|
- // var dropZoneSpan = 12 - scope.ctrl.dashboard.rowSpan(scope.ctrl.row);
|
|
|
|
|
- // if (dropZoneSpan > 0) {
|
|
|
|
|
- // showPanel(dropZoneSpan, 'Panel Drop Zone');
|
|
|
|
|
- // }
|
|
|
|
|
- // });
|
|
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
scope.$on("ANGULAR_DRAG_END", function() {
|
|
scope.$on("ANGULAR_DRAG_END", function() {
|