blob: f6efd353b0939bc634ea68aef907bd7386ccedfc [file] [log] [blame]
Sonsino, Ofir (os0695)ff76b5e2018-07-10 15:57:37 +03001import {Injectable} from '@angular/core';
2import {isNullOrUndefined} from "util";
3import {NumbersLettersUnderscoreValidator} from '../../shared/components/validators/numbersLettersUnderscore/numbersLettersUnderscore.validator';
4import {ServiceInstanceDetailsComponent} from './service-instance-details/service-instance-details.component';
5import {FormGroup} from '@angular/forms';
6import * as _ from "lodash";
7
8@Injectable()
9export class ServicePopupService {
10 onControlError(serviceInstanceDetails : ServiceInstanceDetailsComponent, serviceInstanceDetailsFormGroup : FormGroup) : boolean{
11 if(!isNullOrUndefined(serviceInstanceDetailsFormGroup) && !isNullOrUndefined(serviceInstanceDetailsFormGroup.controls['instanceName']) && NumbersLettersUnderscoreValidator.valid(serviceInstanceDetailsFormGroup.controls['instanceName'].value) && serviceInstanceDetailsFormGroup.controls['instanceName'].value != null && serviceInstanceDetailsFormGroup.controls['instanceName'].value.length > 0){
12 return true;
13 }
14
15 const controlName : Array<string> = ['productFamilyId', 'lcpCloudRegionId', 'tenantId', 'owningEntityId', 'projectName', 'aicZoneId', 'subscriptionServiceType', 'globalSubscriberId', 'rollbackOnFailure'];
16 const selectDataName : Array<string> = ['productFamilies', 'lcpRegions', 'tenants', 'owningEntities', 'projects', 'aicZones', 'serviceTypes', 'subscribers', 'rollbackOnFailure'];
17 for(let i = 0 ; i < controlName.length ; i++){
18 if (!isNullOrUndefined(serviceInstanceDetails.servicePopupDataModel) && !isNullOrUndefined(serviceInstanceDetails.servicePopupDataModel[selectDataName[i]])) {
19 if (!serviceInstanceDetailsFormGroup.controls[controlName[i]].disabled && serviceInstanceDetails.servicePopupDataModel[selectDataName[i]].length === 0) {
20 return true;
21 }
22 }
23 }
24 return false;
25 }
26
27 resetDynamicInputs(serviceInstance : any, defaultDynamicInputs : any) : void {
28 for(let dynamicInput of serviceInstance.dynamicInputs){
29 const defaultDymanicInput = _.find(defaultDynamicInputs, {name:dynamicInput.name});
30 serviceInstance.serviceInstanceDetailsFormGroup.controls[dynamicInput.name].setValue(defaultDymanicInput.value);
31 }
32 }
33}