1 import {Injectable} from "@angular/core";
2 import {NgRedux} from "@angular-redux/store";
3 import {AppState} from "../../../../shared/store/reducers";
4 import {FeatureFlagsService, Features} from "../../../../shared/services/featureFlag/feature-flags.service";
7 export class DragAndDropService {
9 constructor(private store: NgRedux<AppState>) {
12 checkFeatureFlag(flagValue):boolean {
13 let featureFlag :boolean;
14 featureFlag = FeatureFlagsService.getFlagState(flagValue, this.store);
18 /***********************************************************************************************
19 if the dragged node is a base module instance
20 ***********************************************************************************************/
21 isBaseModule(serviceInstanceId, from): boolean {
23 let baseModuleFlag = this.store.getState().service.serviceHierarchy[serviceInstanceId].vnfs[from.parent.data.modelName].vfModules[from.data.modelName].properties.baseModule;
24 return (baseModuleFlag != 'undefined' ? baseModuleFlag : false);
31 /***********************************************************************************************
32 if the flag is ON and nodes have same parent
33 ***********************************************************************************************/
34 isAllowDrop(from: any, to: any): boolean {
35 return this.checkFeatureFlag(Features.FLAG_1911_INSTANTIATION_ORDER_IN_ASYNC_ALACARTE) && this.isSameParent(from, to);
38 private isSameParent(from: any, to: any): boolean {
40 return from.parent.data.trackById === to.parent.parent.data.trackById;
41 } catch (e) { //parent not found
46 /********************************************************************
47 * manage drawing-board drag and drop operation
48 * @param nodes - array with elements data.
49 * @param tree - tree instance
50 * @param node - element information
51 * @param from - element from information
52 * @param to - element to information
53 ************************************************************/
55 drop(store, instanceId: string, nodes, {from, to}): void {
57 if (!this.checkFeatureFlag(Features.FLAG_1911_INSTANTIATION_ORDER_IN_ASYNC_ALACARTE)) return;
59 if(this.checkFeatureFlag(Features.FLAG_2008_DISABLE_DRAG_FOR_BASE_MODULE)) {
60 if ((to.parent.index == 0 && this.isBaseModule(instanceId, to.parent)) || this.isBaseModule(instanceId, from )) return;
63 if (this.isAllowDrop(from, to)) {
64 let vfModules = nodes.find((parent) => {
65 return parent.trackById === to.parent.parent.data.trackById;
67 this.array_move(vfModules, from.index, to.parent.index, instanceId, to.parent.parent.data.vnfStoreKey);
70 /* let firstLevelNames : DragAndDropModel[] = [
71 new DragAndDropModel('VF',true),
72 new DragAndDropModel('VL',true),
73 new DragAndDropModel('VFmodule',false)
76 const fromObject = _.find(firstLevelNames, ['type', from.data.type]);
77 const toObject = _.find(firstLevelNames, ['type', to.parent.data.type]);
79 /!***********************************************************************************************
80 if the type are the same and there in same level + same parent -> then change element position
81 ***********************************************************************************************!/
82 if(fromObject.isFirstLevel === toObject.isFirstLevel){ // moving element in the same level and in the first level
83 if(fromObject.isFirstLevel){
84 this.array_move(nodes, from.index , to.parent.index, instanceId);
85 } else if(fromObject.isFirstLevel === toObject.isFirstLevel){
86 /!* check if they have the same parent *!/
87 if(from.parent.data.trackById === to.parent.parent.data.trackById){
88 let vfModules = nodes.find((parents)=> {
89 return parents.trackById === to.parent.parent.data.trackById;
91 this.array_move(vfModules, from.index , to.parent.index, instanceId, to.parent.parent.data.vnfStoreKey);
98 /********************************************************************
99 * move element inside array with elements position
100 * @param arr - array with elements data.
101 * @param originalPosition - element original position
102 * @param destPosition - element dest position
103 * @param destPinstanceIdosition - instance id
104 ******************************************************************/
105 array_move(arr, originalPosition, destPosition, instanceId: string, parentStoreKey?): Array<any> {
107 let moved_node = arr[originalPosition]
109 arr.splice(originalPosition, 1);
111 arr.splice(destPosition, 0, moved_node);
113 arr.forEach((item, index) => {
114 if (item.position !== index + 1) {
115 item.position = index + 1;
116 item.updatePoistionFunction(this, item, instanceId, parentStoreKey);
123 drag(store, serviceModelId: string, fromObj): boolean {
124 if(!this.checkFeatureFlag(Features.FLAG_1911_INSTANTIATION_ORDER_IN_ASYNC_ALACARTE)) {
127 if (this.checkFeatureFlag(Features.FLAG_2008_DISABLE_DRAG_FOR_BASE_MODULE)) {
128 if(this.isBaseModule(serviceModelId,fromObj)) {