summaryrefslogtreecommitdiffstats
path: root/vid-webpack-master/src/app/components/vnf-popup/vnf-instance-details/vnf-instance-details.service.ts
blob: 677895e7249e896d82a9965580c6469630549a87 (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
import { Injectable } from '@angular/core';
import { isNullOrUndefined } from "util";
import { FormGroup } from '@angular/forms';
@Injectable()
export class VnfInstanceDetailsService {
  isUnique(serviceInstance : any, serviceId : string, name: string, isEqualToOriginalInstanceName : boolean) : boolean {
    const service = serviceInstance[serviceId];
    let countInstanceName = 0;
    let countVolumeGroupName = 0;
    if(service){
      if(service.instanceName === name) return false;
      if(service.vnfs){
        for(let key in service.vnfs){
          if(service.vnfs[key].instanceName === name) {
            countInstanceName++;
            if((isEqualToOriginalInstanceName && countInstanceName > 1) || (!isEqualToOriginalInstanceName)) return false;
          }
          if(service.vnfs[key].vfModules){
            for(let vfModule in service.vnfs[key].vfModules){
              if(service.vnfs[key].vfModules[vfModule]) {
                for(let module in service.vnfs[key].vfModules[vfModule]){
                  if(service.vnfs[key].vfModules[vfModule][module].instanceName === name ) {
                    countInstanceName++;
                    if((isEqualToOriginalInstanceName && countInstanceName > 1) || (!isEqualToOriginalInstanceName)) return false;
                  }

                  if(service.vnfs[key].vfModules[vfModule][module].volumeGroupName === name ) {
                    countVolumeGroupName++;
                    if((isEqualToOriginalInstanceName && countVolumeGroupName > 1) || (!isEqualToOriginalInstanceName)) return false;
                  }
                }
              }
            }
          }

        }
      }
    }
    return true;
  }

  hasApiError(controlName: string, data: Array<any>, form: FormGroup) {
    if (!isNullOrUndefined(data)) {
      if (!form.controls[controlName].disabled && data.length === 0) {
        return true;
      }
    }
    return false;
  }

  hasInstanceNameError(form : FormGroup) : boolean {
    if(!isNullOrUndefined(form) && !isNullOrUndefined(form.controls['instanceName'])){
      if (form.controls['instanceName'].touched && form.controls['instanceName'].errors && form.controls['instanceName'].errors.pattern) {
        return true;
      }
    }
    return false;
  }

  hasUniqueError(isNotUniqueInstanceName) : boolean {
    return isNotUniqueInstanceName;
  }

}