blob: 57dc4b40911316f4d20ed08b674609d1373b5328 [file] [log] [blame]
Sonsino, Ofir (os0695)ff76b5e2018-07-10 15:57:37 +03001import {Injectable} from '@angular/core';
2import * as _ from "lodash";
3import {ServicePlanningService} from "../../services/service-planning.service";
4
5@Injectable()
6export class AvailableModelsTreeService {
7 constructor(private _servicePlanningService: ServicePlanningService) {
8 }
9
10 shouldShowAddIcon(node: any, serviceHierarchy: any, serviceModelId: string, currentNodeCount: number): boolean {
11 let maxNodes: number = 1;
12 if (node.data.children !== null && node.data.children.length == 0) {
13 let vnfModules = serviceHierarchy[serviceModelId].vfModules;
14 if (vnfModules[node.data.name]) {
15 maxNodes = vnfModules[node.data.name].properties.maxCountInstances || 1;
16 }
17 }
18 return !node.data.disabled && currentNodeCount < maxNodes
19 }
20
21 shouldOpenDialog(type: string, dynamicInputs: any, userProvidedNaming: boolean): boolean {
22 if (userProvidedNaming || this._servicePlanningService.requiredFields[type].length > 0) {
23 return true;
24 }
25
26 if (dynamicInputs) {
27 for(let input of dynamicInputs) {
28 if (input.isRequired && _.isEmpty(input.value)) {
29 return true;
30 }
31 }
32 }
33 return false;
34 }
35
36}