1 import {Injectable} from "@angular/core";
2 import {NgRedux} from "@angular-redux/store";
3 import {AppState} from "../../../../shared/store/reducers";
4 import {DragAndDropModel} from "./dragAndDrop.model";
5 import {FeatureFlagsService, Features} from "../../../../shared/services/featureFlag/feature-flags.service";
6 import * as _ from 'lodash';
9 export class DragAndDropService {
11 constructor(private store: NgRedux<AppState>){}
14 return FeatureFlagsService.getFlagState(Features.FLAG_1911_INSTANTIATION_ORDER_IN_ASYNC_ALACARTE, this.store);
16 /********************************************************************
17 * manage drawing-board drag and drop operation
18 * @param nodes - array with elements data.
19 * @param tree - tree instance
20 * @param node - element information
21 * @param from - element from information
22 * @param to - element to information
23 ************************************************************/
25 drag(store, instanceId : string , nodes, {from, to}) :void{
26 if (!store.getState().global.flags["FLAG_1911_INSTANTIATION_ORDER_IN_ASYNC_ALACARTE"]) return;
28 let firstLevelNames : DragAndDropModel[] = [
29 new DragAndDropModel('VF',true),
30 new DragAndDropModel('VL',true),
31 new DragAndDropModel('VFmodule',false)
34 const fromObject = _.find(firstLevelNames, ['type', from.data.type]);
35 const toObject = _.find(firstLevelNames, ['type', to.parent.data.type]);
37 /***********************************************************************************************
38 if the type are the same and there in same level + same parent -> then change element position
39 ***********************************************************************************************/
40 if(fromObject.isFirstLevel === toObject.isFirstLevel){ // moving element in the same level and in the first level
41 if(fromObject.isFirstLevel){
42 this.array_move(nodes, from.index , to.parent.index, instanceId);
43 } else if(fromObject.isFirstLevel === toObject.isFirstLevel){
44 /* check if they have the same parent */
45 if(from.parent.data.trackById === to.parent.parent.data.trackById){
46 let vfModules = nodes.find((parents)=> {
47 return parents.trackById === to.parent.parent.data.trackById;
49 this.array_move(vfModules, from.index , to.parent.index, instanceId, to.parent.parent.data.vnfStoreKey);
56 /********************************************************************
57 * move element inside array with elements position
58 * @param arr - array with elements data.
59 * @param originalPosition - element original position
60 * @param destPosition - element dest position
61 * @param destPinstanceIdosition - instance id
62 ******************************************************************/
63 array_move(arr, originalPosition, destPosition, instanceId : string, parentStoreKey?) {
64 if (destPosition >= arr.length) {
65 let k = destPosition - arr.length + 1;
70 arr.splice(destPosition, 0, arr.splice(originalPosition, 1)[0]);
71 arr.forEach((item, index) => {
72 if(item.position !== index){
73 item.position = index;
74 item.updatePoistionFunction(this, item, instanceId, parentStoreKey);