From: elinuxhenrik Date: Thu, 18 Mar 2021 16:41:19 +0000 (+0100) Subject: Clean up and format X-Git-Tag: 2.2.0~56^2 X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=commitdiff_plain;h=a2a4491f5e44b5979f0d84a3065bcf76f3b01b93;p=portal%2Fnonrtric-controlpanel.git Clean up and format Change-Id: Ic7b6a9d35786cd6aa609827b3ba408c03cf2303f Signed-off-by: elinuxhenrik Issue-ID: NONRTRIC-463 --- diff --git a/webapp-frontend/src/app/policy/no-type-policy-editor/no-type-policy-editor.component.spec.ts b/webapp-frontend/src/app/policy/no-type-policy-editor/no-type-policy-editor.component.spec.ts index 7fb64c4..c87a656 100644 --- a/webapp-frontend/src/app/policy/no-type-policy-editor/no-type-policy-editor.component.spec.ts +++ b/webapp-frontend/src/app/policy/no-type-policy-editor/no-type-policy-editor.component.spec.ts @@ -22,7 +22,6 @@ import { HarnessLoader } from "@angular/cdk/testing"; import { TestbedHarnessEnvironment } from "@angular/cdk/testing/testbed"; import { Component, ViewChild, CUSTOM_ELEMENTS_SCHEMA } from "@angular/core"; import { ComponentFixture, TestBed } from "@angular/core/testing"; -import { FormBuilder, FormGroup } from "@angular/forms"; import { MatButtonModule } from "@angular/material/button"; import { MatButtonHarness } from "@angular/material/button/testing"; import { MatFormFieldModule } from "@angular/material/form-field"; @@ -34,7 +33,6 @@ import { BrowserAnimationsModule } from "@angular/platform-browser/animations"; import { NoTypePolicyEditorComponent } from "./no-type-policy-editor.component"; describe("NoTypePolicyEditorComponent", () => { - let formGroup: FormGroup = new FormGroup({}); let component: TestNoTypePolicyEditorComponentHostComponent; let fixture: ComponentFixture; @@ -54,7 +52,6 @@ describe("NoTypePolicyEditorComponent", () => { NoTypePolicyEditorComponent, TestNoTypePolicyEditorComponentHostComponent, ], - providers: [FormBuilder], }).compileComponents(); fixture = TestBed.createComponent( @@ -82,7 +79,9 @@ describe("NoTypePolicyEditorComponent", () => { }); it("Format button should be disabled when json not valid", async () => { - const ele = component.noTypePolicyEditorComponent.instanceForm.get("policyJsonTextArea"); + const ele = component.noTypePolicyEditorComponent.instanceForm.get( + "policyJsonTextArea" + ); ele.setValue("{"); let formatButton: MatButtonHarness = await loader.getHarness( @@ -92,7 +91,9 @@ describe("NoTypePolicyEditorComponent", () => { }); it("should format unformatted json", async () => { - const textArea = component.noTypePolicyEditorComponent.instanceForm.get("policyJsonTextArea"); + const textArea = component.noTypePolicyEditorComponent.instanceForm.get( + "policyJsonTextArea" + ); textArea.setValue('{"A":"A"}'); component.noTypePolicyEditorComponent.formatJsonInput(); expect(component.noTypePolicyEditorComponent.policyJson).toEqual( diff --git a/webapp-frontend/src/app/policy/no-type-policy-editor/no-type-policy-editor.component.ts b/webapp-frontend/src/app/policy/no-type-policy-editor/no-type-policy-editor.component.ts index 5fa92d9..d231b00 100644 --- a/webapp-frontend/src/app/policy/no-type-policy-editor/no-type-policy-editor.component.ts +++ b/webapp-frontend/src/app/policy/no-type-policy-editor/no-type-policy-editor.component.ts @@ -18,15 +18,25 @@ // ========================LICENSE_END=================================== // / -import { Component, Input, OnInit, Output } from '@angular/core'; -import { AbstractControl, ControlContainer, FormBuilder, FormControl, FormGroup, FormGroupDirective, ValidatorFn, Validators } from '@angular/forms'; -import { EventEmitter } from '@angular/core'; +import { Component, Input, OnInit, Output } from "@angular/core"; +import { + AbstractControl, + ControlContainer, + FormControl, + FormGroup, + FormGroupDirective, + ValidatorFn, + Validators, +} from "@angular/forms"; +import { EventEmitter } from "@angular/core"; @Component({ - selector: 'nrcp-no-type-policy-editor', - templateUrl: './no-type-policy-editor.component.html', - styleUrls: ['./no-type-policy-editor.component.scss'], - viewProviders: [{ provide: ControlContainer, useExisting: FormGroupDirective }] + selector: "nrcp-no-type-policy-editor", + templateUrl: "./no-type-policy-editor.component.html", + styleUrls: ["./no-type-policy-editor.component.scss"], + viewProviders: [ + { provide: ControlContainer, useExisting: FormGroupDirective }, + ], }) export class NoTypePolicyEditorComponent implements OnInit { @Input() policyJson: string = null; @@ -34,31 +44,35 @@ export class NoTypePolicyEditorComponent implements OnInit { instanceForm: FormGroup = new FormGroup({}); - constructor( - private formBuilder: FormBuilder) { } + constructor() {} - ngOnInit(): void { - this.instanceForm.addControl( - 'policyJsonTextArea', new FormControl(this.policyJson, [ - Validators.required, - this.jsonValidator() - ]) - ) - } + ngOnInit(): void { + this.instanceForm.addControl( + "policyJsonTextArea", + new FormControl(this.policyJson, [ + Validators.required, + this.jsonValidator(), + ]) + ); + } - get policyJsonTextArea(): AbstractControl { - return this.instanceForm ? this.instanceForm.get('policyJsonTextArea') : null; + get policyJsonTextArea(): AbstractControl { + return this.instanceForm + ? this.instanceForm.get("policyJsonTextArea") + : null; } formatJsonInput(): void { - this.policyJson = formatJsonString(JSON.parse(this.policyJsonTextArea.value)); + this.policyJson = formatJsonString( + JSON.parse(this.policyJsonTextArea.value) + ); } jsonValidator(): ValidatorFn { return (control: AbstractControl): { [key: string]: any } | null => { const notValid = !this.isJsonValid(control.value); this.handleJsonChangeEvent(notValid, control.value); - return notValid ? { 'invalidJson': { value: control.value } } : null; + return notValid ? { invalidJson: { value: control.value } } : null; }; } diff --git a/webapp-frontend/src/app/policy/policy-instance-dialog/policy-instance-dialog.component.html b/webapp-frontend/src/app/policy/policy-instance-dialog/policy-instance-dialog.component.html index a3654b4..2d1187f 100644 --- a/webapp-frontend/src/app/policy/policy-instance-dialog/policy-instance-dialog.component.html +++ b/webapp-frontend/src/app/policy/policy-instance-dialog/policy-instance-dialog.component.html @@ -19,7 +19,8 @@ -->