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 {
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);
+ }
+ };
+ }
}
TENANT_ID = 'tenantId',
ROLLBACK_ON_FAILURE = 'rollbackOnFailure',
SDN_C_PRE_LOAD = 'sdncPreLoad',
- SUPPLEMENTARY_FILE = 'supplementaryFile'
}
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);
}
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);
}
}
- 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;