aboutsummaryrefslogtreecommitdiffstats
path: root/vid-webpack-master/src/app/drawingBoard/service-planning/available-models-tree/available-models-tree.service.ts
blob: c9a89cf6f7f697df095d6d61f7e5214b3b2f9677 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
import {Injectable} from '@angular/core';
import {DefaultDataGeneratorService} from "../../../shared/services/defaultDataServiceGenerator/default.data.generator.service";
import {NgRedux} from "@angular-redux/store";
import {AppState} from "../../../shared/store/reducers";
import {MessageBoxData} from "../../../shared/components/messageBox/messageBox.data";
import {MessageBoxService} from "../../../shared/components/messageBox/messageBox.service";
import {SdcUiCommon} from "onap-ui-angular";
import {SharedTreeService} from "../objectsToTree/shared.tree.service";
import {VrfModel} from "../../../shared/models/vrfModel";
import {clearAllGenericModalhelper} from "../../../shared/storeUtil/utils/global/global.actions";
import * as _ from "lodash";

export class AvailableNodeIcons {
   addIcon: boolean;
   vIcon: boolean;

  constructor(addIcon: boolean, vIcon: boolean) {
    this.addIcon = addIcon;
    this.vIcon = vIcon;
  }

}

@Injectable()
export class AvailableModelsTreeService {
  constructor(private _defaultDataGeneratorService: DefaultDataGeneratorService,
              private store: NgRedux<AppState>,
              public _sharedTreeService : SharedTreeService) {
  }



  shouldOpenDialog(type: string, dynamicInputs: any, isEcompGeneratedNaming: boolean): boolean {
    if (!isEcompGeneratedNaming || this._defaultDataGeneratorService.requiredFields[type].length > 0) {
      return true;
    }

    if (dynamicInputs) {
      for(let input of dynamicInputs) {
        if (input.isRequired && _.isEmpty(input.value)) {
          return true;
        }
      }
    }
    return false;
  }

  getOptionalVNFs(serviceUUID: string, vnfModelUniqueId: string) : any[] {
    let result = [];
    if(!_.isNil(this.store.getState().service.serviceInstance) && !_.isNil(this.store.getState().service.serviceInstance[serviceUUID])){
      const serviceVNFsInstances = this.store.getState().service.serviceInstance[serviceUUID].vnfs;
      for(let vnfKey in serviceVNFsInstances){
        if (this._sharedTreeService.modelUniqueId(serviceVNFsInstances[vnfKey]) === vnfModelUniqueId) {
          serviceVNFsInstances[vnfKey].vnfStoreKey = vnfKey;
          result.push(serviceVNFsInstances[vnfKey]);
        }
      }
    }
    return result;
  }



  addingAlertAddingNewVfModuleModal() : void {
    let messageBoxData : MessageBoxData = new MessageBoxData(
      "Select a parent",  // modal title
      "There are multiple instances on the right side that can contain this vf-module Please select the VNF instance, to add this vf-module to, on the right side and then click the + sign",
      SdcUiCommon.ModalType.warning,
      SdcUiCommon.ModalSize.medium,
      [
        {text:"Close", size:"medium", closeModal:true}
      ]);

    MessageBoxService.openModal.next(messageBoxData);
  }

  shouldOpenVRFModal(nodes, serviceModelId: string , service)  {
    for(const node of nodes){
      if(node.type === 'VRF' && service.serviceInstance[serviceModelId].existingVRFCounterMap && !service.serviceInstance[serviceModelId].existingVRFCounterMap[node.modelUniqueId]){
        const vrfModel : VrfModel = node.getModel(node.name, node, service.serviceInstance[serviceModelId]);
        const vrfCounter : number = service.serviceInstance[serviceModelId].existingVRFCounterMap[node.modelUniqueId];
        console.log('vrfCounter', vrfCounter);
        if(vrfModel.min > 0 && (_.isNil(vrfCounter) || vrfCounter === 0)){
          node.data = node;
          this.store.dispatch(clearAllGenericModalhelper());
          return node;
        }
      }
    }
    return null;
  }

}