diff options
author | Sara Weiss <sara.weiss@intl.att.com> | 2019-11-07 14:53:21 +0200 |
---|---|---|
committer | Ittay Stern <ittay.stern@att.com> | 2019-11-10 11:45:04 +0000 |
commit | 35c827230a79c5bdab7afa6d9e641e663f15416f (patch) | |
tree | 04b9e33ee07e5f42e7074d7e04a8c471eb3d002e /vid-webpack-master/src/app/drawingBoard/service-planning/drawing-board-tree/dragAndDrop/dragAndDrop.service.ts | |
parent | 002ed9c356ce2352e7c6ac90e3c6fd061897b91b (diff) |
Unit test drag and drop service
Issue-ID: VID-253
Signed-off-by: Sara Weiss <sara.weiss@intl.att.com>
Change-Id: I5915f005a4e428a4268e2a88e827e3f98519087a
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.ts | 100 |
1 files changed, 64 insertions, 36 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 index 15da89ad3..96e50178b 100644 --- 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 @@ -8,11 +8,29 @@ import * as _ from 'lodash'; @Injectable() export class DragAndDropService { - constructor(private store: NgRedux<AppState>){} + constructor(private store: NgRedux<AppState>) { + } - isAllow(): boolean { + isFlagOn(): boolean { return FeatureFlagsService.getFlagState(Features.FLAG_1911_INSTANTIATION_ORDER_IN_ASYNC_ALACARTE, this.store); } + + + /*********************************************************************************************** + if the falg is ON and nodes have same parent + ***********************************************************************************************/ + isAllowDrop(from: any, to: any): boolean { + return this.isFlagOn() && this.isSameParent(from, to); + } + + private isSameParent(from: any, to: any): boolean { + try { + return from.parent.data.trackById === to.parent.parent.data.trackById; + } catch (e) { //parent not found + return false; + } + } + /******************************************************************** * manage drawing-board drag and drop operation * @param nodes - array with elements data. @@ -22,57 +40,67 @@ export class DragAndDropService { * @param to - element to information ************************************************************/ - drag(store, instanceId : string , nodes, {from, to}) :void{ - if (!store.getState().global.flags["FLAG_1911_INSTANTIATION_ORDER_IN_ASYNC_ALACARTE"]) return; + drop(store, instanceId: string, nodes, {from, to}): void { + + if (!this.isFlagOn()) return; - let firstLevelNames : DragAndDropModel[] = [ + if (this.isAllowDrop(from, to)) { + let vfModules = nodes.find((parent) => { + return parent.trackById === to.parent.parent.data.trackById; + }).children; + this.array_move(vfModules, from.index, to.parent.index, instanceId, to.parent.parent.data.vnfStoreKey); + } + + /* 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); + ]; + + 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]); + array_move(arr, originalPosition, destPosition, instanceId: string, parentStoreKey?): Array<any> { + + let moved_node = arr[originalPosition] + + arr.splice(originalPosition, 1); + + arr.splice(destPosition, 0, moved_node); + arr.forEach((item, index) => { - if(item.position !== index){ - item.position = index; + if (item.position !== index + 1) { + item.position = index + 1; item.updatePoistionFunction(this, item, instanceId, parentStoreKey); } }); + + return arr; }; } |