aboutsummaryrefslogtreecommitdiffstats
path: root/vid-webpack-master/src/app
diff options
context:
space:
mode:
authorAmir Skalka <amir.skalka@intl.att.com>2019-11-25 16:36:55 +0200
committerEylon Malin <eylon.malin@intl.att.com>2019-11-26 09:46:47 +0200
commit3347f70dcd726595e8eef7f65fb80abf13f62845 (patch)
treeabd4d0d094d518cf3e347ae8372a791f1abe8fc8 /vid-webpack-master/src/app
parentbda996b9faf9d5d443d2256c0626620bd8104269 (diff)
Extract getSupplementaryFile out of VFM controller
Issue-ID: VID-603 Change-Id: I8ccc2e3cdc79faded73f5811fee99cc78c8ebd47 Signed-off-by: Amir Skalka <amir.skalka@intl.att.com> Signed-off-by: Eylon Malin <eylon.malin@intl.att.com>
Diffstat (limited to 'vid-webpack-master/src/app')
-rw-r--r--vid-webpack-master/src/app/shared/components/genericForm/formControlsServices/basic.control.generator.spec.ts9
-rw-r--r--vid-webpack-master/src/app/shared/components/genericForm/formControlsServices/basic.control.generator.ts54
-rw-r--r--vid-webpack-master/src/app/shared/components/genericForm/formControlsServices/vfModuleGenerator/vfModule.control.generator.ts51
3 files changed, 65 insertions, 49 deletions
diff --git a/vid-webpack-master/src/app/shared/components/genericForm/formControlsServices/basic.control.generator.spec.ts b/vid-webpack-master/src/app/shared/components/genericForm/formControlsServices/basic.control.generator.spec.ts
index fc2eed4ae..8705fa8ff 100644
--- a/vid-webpack-master/src/app/shared/components/genericForm/formControlsServices/basic.control.generator.spec.ts
+++ b/vid-webpack-master/src/app/shared/components/genericForm/formControlsServices/basic.control.generator.spec.ts
@@ -5,6 +5,7 @@ import {FeatureFlagsService} from "../../../services/featureFlag/feature-flags.s
import {BasicControlGenerator} from "./basic.control.generator";
import {NgRedux} from '@angular-redux/store';
import {HttpClientTestingModule, HttpTestingController} from '@angular/common/http/testing';
+import {FileFormControl} from "../../../models/formControlModels/fileFormControl.model";
class MockAppStore<T> {}
@@ -44,5 +45,13 @@ describe('Basic Control Generator', () => {
const legacyRegionControl: FormControlModel = service.getLegacyRegion(instance);
expect(legacyRegionControl.isVisible).toBeFalsy();
});
+
+ test('given instance, get supp file from getSupplementaryFile ', () => {
+ const instance = {};
+ const suppFileForInstance: FileFormControl = service.getSupplementaryFile(instance);
+ expect(suppFileForInstance.isVisible).toBeTruthy();
+ expect(suppFileForInstance.hiddenFile.length).toBeGreaterThanOrEqual(1);
+ expect(suppFileForInstance.hiddenFile[0].validations[0].validatorName).toEqual("isFileTooBig");
+ });
});
diff --git a/vid-webpack-master/src/app/shared/components/genericForm/formControlsServices/basic.control.generator.ts b/vid-webpack-master/src/app/shared/components/genericForm/formControlsServices/basic.control.generator.ts
index cbbff3c39..0261a72a4 100644
--- a/vid-webpack-master/src/app/shared/components/genericForm/formControlsServices/basic.control.generator.ts
+++ b/vid-webpack-master/src/app/shared/components/genericForm/formControlsServices/basic.control.generator.ts
@@ -21,7 +21,9 @@ import {FormGeneralErrorsService} from "../../formGeneralErrors/formGeneralError
import {Observable, of} from "rxjs";
import {NodeModel} from "../../../models/nodeModel";
import {Constants} from "../../../utils/constants";
+import {FileUnit} from "../../formControls/component/file/fileUnit.enum";
+const SUPPLEMENTARY_FILE = 'supplementaryFile';
@Injectable()
export class BasicControlGenerator {
@@ -237,4 +239,56 @@ export class BasicControlGenerator {
return initialInstanceName;
}
+ getSupplementaryFile(instance: any): FileFormControl {
+ return new FileFormControl({
+ controlName: SUPPLEMENTARY_FILE,
+ displayName: 'Supplementary Data File (JSON format)',
+ dataTestId: 'SupplementaryFile',
+ placeHolder: 'Choose file',
+ selectedFile: !_.isNil(instance) ? instance.supplementaryFileName: null,
+ isVisible: true,
+ acceptedExtentions: "application/json",
+ hiddenFile : [new InputFormControl({
+ controlName: SUPPLEMENTARY_FILE + "_hidden",
+ isVisible: false,
+ validations: [new ValidatorModel(CustomValidatorOptions.isFileTooBig, "File size exceeds 5MB.", [FileUnit.MB, 5])]
+ }),
+ new InputFormControl({
+ controlName: SUPPLEMENTARY_FILE + "_hidden_content",
+ isVisible: false,
+ validations: [new ValidatorModel(CustomValidatorOptions.isValidJson,
+ "File is invalid, please make sure a legal JSON file is uploaded using name:value pairs.",[]),
+ new ValidatorModel(CustomValidatorOptions.isStringContainTags,
+ "File is invalid, please remove tags <>.",[])],
+ value: !_.isNil(instance) ? (instance.supplementaryFile_hidden_content): null,
+ })
+ ],
+ onDelete : this.getOnDeleteForSupplementaryFile(),
+ onChange : this.getOnChangeForSupplementaryFile()
+ })
+ };
+
+ private getOnDeleteForSupplementaryFile() {
+ return (form: FormGroup) => {
+ form.controls[SUPPLEMENTARY_FILE + "_hidden"].setValue(null);
+ form.controls[SUPPLEMENTARY_FILE + "_hidden_content"].setValue(null);
+ };
+ }
+
+ private getOnChangeForSupplementaryFile() {
+ return (files: FileList, form: FormGroup) => {
+ if (files.length > 0) {
+ const file = files.item(0);
+ let reader = new FileReader();
+ reader.onload = function (event) {
+ form.controls[SUPPLEMENTARY_FILE + "_hidden_content"].setValue(reader.result);
+ form.controls[SUPPLEMENTARY_FILE + "_hidden"].setValue(file);
+ };
+ reader.readAsText(file);
+ } else {
+ form.controls[SUPPLEMENTARY_FILE + "_hidden"].setValue(null);
+ form.controls[SUPPLEMENTARY_FILE + "_hidden_content"].setValue(null);
+ }
+ };
+ }
}
diff --git a/vid-webpack-master/src/app/shared/components/genericForm/formControlsServices/vfModuleGenerator/vfModule.control.generator.ts b/vid-webpack-master/src/app/shared/components/genericForm/formControlsServices/vfModuleGenerator/vfModule.control.generator.ts
index 7b72d3bfa..a2dd52197 100644
--- a/vid-webpack-master/src/app/shared/components/genericForm/formControlsServices/vfModuleGenerator/vfModule.control.generator.ts
+++ b/vid-webpack-master/src/app/shared/components/genericForm/formControlsServices/vfModuleGenerator/vfModule.control.generator.ts
@@ -38,7 +38,6 @@ export enum FormControlNames {
TENANT_ID = 'tenantId',
ROLLBACK_ON_FAILURE = 'rollbackOnFailure',
SDN_C_PRE_LOAD = 'sdncPreLoad',
- SUPPLEMENTARY_FILE = 'supplementaryFile'
}
@@ -106,7 +105,7 @@ export class VfModuleControlGenerator {
result = this.pushInstanceAndVGToForm(result, vfModuleInstance, serviceId, vnfModel, false);
}
if(this.store.getState().global.flags['FLAG_SUPPLEMENTARY_FILE']) {
- let suppFileInput:FileFormControl = <FileFormControl>(this.getSupplementaryFile(vfModuleInstance));
+ let suppFileInput:FileFormControl = <FileFormControl>(this._basicControlGenerator.getSupplementaryFile(vfModuleInstance));
result.push(suppFileInput);
result = result.concat(suppFileInput.hiddenFile);
}
@@ -143,7 +142,7 @@ export class VfModuleControlGenerator {
result.push(this.getRollbackOnFailureControl(vfModuleInstance, result));
result.push(this.getSDNCControl(vfModuleInstance, result));
if(this.store.getState().global.flags['FLAG_SUPPLEMENTARY_FILE']) {
- let suppFileInput:FileFormControl = <FileFormControl>(this.getSupplementaryFile(vfModuleInstance));
+ let suppFileInput:FileFormControl = <FileFormControl>(this._basicControlGenerator.getSupplementaryFile(vfModuleInstance));
result.push(suppFileInput);
result = result.concat(suppFileInput.hiddenFile);
}
@@ -211,52 +210,6 @@ export class VfModuleControlGenerator {
}
- getSupplementaryFile(instance: any): FormControlModel {
- return new FileFormControl({
- controlName: FormControlNames.SUPPLEMENTARY_FILE,
- displayName: 'Supplementary Data File (JSON format)',
- dataTestId: 'SupplementaryFile',
- placeHolder: 'Choose file',
- selectedFile: !_.isNil(instance) ? instance.supplementaryFileName: null,
- isVisible: true,
- acceptedExtentions: "application/json",
- hiddenFile : [new InputFormControl({
- controlName: FormControlNames.SUPPLEMENTARY_FILE + "_hidden",
- isVisible: false,
- validations: [new ValidatorModel(CustomValidatorOptions.isFileTooBig, "File size exceeds 5MB.", [FileUnit.MB, 5])]
- }),
- new InputFormControl({
- controlName: FormControlNames.SUPPLEMENTARY_FILE + "_hidden_content",
- isVisible: false,
- validations: [new ValidatorModel(CustomValidatorOptions.isValidJson,
- "File is invalid, please make sure a legal JSON file is uploaded using name:value pairs.",[]),
- new ValidatorModel(CustomValidatorOptions.isStringContainTags,
- "File is invalid, please remove tags <>.",[])],
- value: !_.isNil(instance) ? (instance.supplementaryFile_hidden_content): null,
- })
- ],
- onDelete : (form : FormGroup) => {
- form.controls[FormControlNames.SUPPLEMENTARY_FILE + "_hidden"].setValue(null);
- form.controls[FormControlNames.SUPPLEMENTARY_FILE + "_hidden_content"].setValue(null);
- },
- onChange : (files: FileList, form : FormGroup) => {
- if (files.length > 0) {
- const file = files.item(0);
- let reader = new FileReader();
- reader.onload = function(event) {
- form.controls[FormControlNames.SUPPLEMENTARY_FILE + "_hidden_content"].setValue(reader.result);
- form.controls[FormControlNames.SUPPLEMENTARY_FILE + "_hidden"].setValue(file);
- };
- reader.readAsText(file);
- }
- else {
- form.controls[FormControlNames.SUPPLEMENTARY_FILE + "_hidden"].setValue(null);
- form.controls[FormControlNames.SUPPLEMENTARY_FILE + "_hidden_content"].setValue(null);
- }
- }
- })
- };
-
getTenantControl = (serviceId: string, instance: any, controls: FormControlModel[]): DropdownFormControl => {
const service = this.store.getState().service.serviceInstance[serviceId];
const globalCustomerId: string = service.globalSubscriberId;