summaryrefslogtreecommitdiffstats
path: root/vid-webpack-master/src/app/drawingBoard/service-planning/drawing-board-tree/dragAndDrop/dragAndDrop.service.ts
diff options
context:
space:
mode:
authorIttay Stern <ittay.stern@att.com>2018-08-29 17:01:32 +0300
committerIttay Stern <ittay.stern@att.com>2019-02-18 18:35:30 +0200
commit6f900cc45d7dd7f97430812b86b5c1d1693c8ae3 (patch)
tree936005c364dc5a7264d6304d4777c3d83494db22 /vid-webpack-master/src/app/drawingBoard/service-planning/drawing-board-tree/dragAndDrop/dragAndDrop.service.ts
parent67d99f816cc583643c35193197594cf78d8ce60a (diff)
merge from ecomp a88f0072 - Modern UI
Issue-ID: VID-378 Change-Id: Ibcb23dd27f550cf32ce2fe0239f0f496ae014ff6 Signed-off-by: Ittay Stern <ittay.stern@att.com>
Diffstat (limited to 'vid-webpack-master/src/app/drawingBoard/service-planning/drawing-board-tree/dragAndDrop/dragAndDrop.service.ts')
-rw-r--r--vid-webpack-master/src/app/drawingBoard/service-planning/drawing-board-tree/dragAndDrop/dragAndDrop.service.ts78
1 files changed, 78 insertions, 0 deletions
diff --git a/vid-webpack-master/src/app/drawingBoard/service-planning/drawing-board-tree/dragAndDrop/dragAndDrop.service.ts b/vid-webpack-master/src/app/drawingBoard/service-planning/drawing-board-tree/dragAndDrop/dragAndDrop.service.ts
new file mode 100644
index 000000000..01763c685
--- /dev/null
+++ b/vid-webpack-master/src/app/drawingBoard/service-planning/drawing-board-tree/dragAndDrop/dragAndDrop.service.ts
@@ -0,0 +1,78 @@
+import {Injectable} from "@angular/core";
+import {NgRedux} from "@angular-redux/store";
+import {AppState} from "../../../../shared/store/reducers";
+import {DragAndDropModel} from "./dragAndDrop.model";
+import {FeatureFlagsService, Features} from "../../../../shared/services/featureFlag/feature-flags.service";
+import * as _ from 'lodash';
+
+@Injectable()
+export class DragAndDropService {
+
+ constructor(private store: NgRedux<AppState>){}
+
+ isAllow(): boolean {
+ return FeatureFlagsService.getFlagState(Features.DRAG_AND_DROP_OPERATION, this.store);
+ }
+ /********************************************************************
+ * manage drawing-board drag and drop operation
+ * @param nodes - array with elements data.
+ * @param tree - tree instance
+ * @param node - element information
+ * @param from - element from information
+ * @param to - element to information
+ ************************************************************/
+
+ drag(store, instanceId : string , nodes, {from, to}) :void{
+ if (!store.getState().global.flags["DRAG_AND_DROP_OPERATION"]) return;
+
+ let firstLevelNames : DragAndDropModel[] = [
+ new DragAndDropModel('VF',true),
+ new DragAndDropModel('VL',true),
+ new DragAndDropModel('VFmodule',false)
+ ];
+
+ const fromObject = _.find(firstLevelNames, ['type', from.data.type]);
+ const toObject = _.find(firstLevelNames, ['type', to.parent.data.type]);
+
+ /***********************************************************************************************
+ if the type are the same and there in same level + same parent -> then change element position
+ ***********************************************************************************************/
+ if(fromObject.isFirstLevel === toObject.isFirstLevel){ // moving element in the same level and in the first level
+ if(fromObject.isFirstLevel){
+ this.array_move(nodes, from.index , to.parent.index, instanceId);
+ } else if(fromObject.isFirstLevel === toObject.isFirstLevel){
+ /* check if they have the same parent */
+ if(from.parent.data.trackById === to.parent.parent.data.trackById){
+ let vfModules = nodes.find((parents)=> {
+ return parents.trackById === to.parent.parent.data.trackById;
+ }).children;
+ this.array_move(vfModules, from.index , to.parent.index, instanceId, to.parent.parent.data.vnfStoreKey);
+ }
+ }
+ }
+ }
+
+
+ /********************************************************************
+ * move element inside array with elements position
+ * @param arr - array with elements data.
+ * @param originalPosition - element original position
+ * @param destPosition - element dest position
+ * @param destPinstanceIdosition - instance id
+ ******************************************************************/
+ array_move(arr, originalPosition, destPosition, instanceId : string, parentStoreKey?) {
+ if (destPosition >= arr.length) {
+ let k = destPosition - arr.length + 1;
+ while (k--) {
+ arr.push(undefined);
+ }
+ }
+ arr.splice(destPosition, 0, arr.splice(originalPosition, 1)[0]);
+ arr.forEach((item, index) => {
+ if(item.position !== index){
+ item.position = index;
+ item.updatePoistionFunction(this, item, instanceId, parentStoreKey);
+ }
+ });
+ };
+}