Sonsino, Ofir (os0695) | ff76b5e | 2018-07-10 15:57:37 +0300 | [diff] [blame] | 1 | import {Injectable} from '@angular/core'; |
| 2 | import {isNullOrUndefined} from "util"; |
| 3 | import {NumbersLettersUnderscoreValidator} from '../../shared/components/validators/numbersLettersUnderscore/numbersLettersUnderscore.validator'; |
| 4 | import {ServiceInstanceDetailsComponent} from './service-instance-details/service-instance-details.component'; |
| 5 | import {FormGroup} from '@angular/forms'; |
| 6 | import * as _ from "lodash"; |
| 7 | |
| 8 | @Injectable() |
| 9 | export 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 | } |