From 800ab849929561945135745ba64ac563f816f333 Mon Sep 17 00:00:00 2001 From: elinuxhenrik Date: Wed, 10 Mar 2021 17:15:32 +0100 Subject: [PATCH] First version of common policy edit dialog Change-Id: I63c579bd1374ad0f1c7b15b9a13d3b8869d3d558 Signed-off-by: elinuxhenrik Issue-ID: NONRTRIC-463 --- .../no-type-policy-instance-dialog.component.html | 52 ----- .../no-type-policy-instance-dialog.component.scss | 73 ------- .../no-type-policy-instance-dialog.component.ts | 97 --------- .../src/app/policy/policy-control.component.ts | 15 +- .../policy-instance-dialog.component.html | 43 ++-- .../policy-instance-dialog.component.scss | 29 +-- .../policy-instance-dialog.component.spec.ts} | 60 +++--- .../policy-instance-dialog.component.ts | 227 +++++++++++---------- .../policy-instance/policy-instance.component.ts | 26 +-- webapp-frontend/src/app/policy/policy.module.ts | 4 +- .../typed-policy-editor.component.html | 4 +- .../typed-policy-editor.component.ts | 10 +- 12 files changed, 191 insertions(+), 449 deletions(-) delete mode 100644 webapp-frontend/src/app/policy/no-type-policy-instance-dialog/no-type-policy-instance-dialog.component.html delete mode 100644 webapp-frontend/src/app/policy/no-type-policy-instance-dialog/no-type-policy-instance-dialog.component.scss delete mode 100644 webapp-frontend/src/app/policy/no-type-policy-instance-dialog/no-type-policy-instance-dialog.component.ts rename webapp-frontend/src/app/policy/{no-type-policy-instance-dialog/no-type-policy-instance-dialog.component.spec.ts => policy-instance-dialog/policy-instance-dialog.component.spec.ts} (74%) diff --git a/webapp-frontend/src/app/policy/no-type-policy-instance-dialog/no-type-policy-instance-dialog.component.html b/webapp-frontend/src/app/policy/no-type-policy-instance-dialog/no-type-policy-instance-dialog.component.html deleted file mode 100644 index afba575..0000000 --- a/webapp-frontend/src/app/policy/no-type-policy-instance-dialog/no-type-policy-instance-dialog.component.html +++ /dev/null @@ -1,52 +0,0 @@ - - - -
- -
- -
- - - -

- Properties -

- -
- - -
-
-
\ No newline at end of file diff --git a/webapp-frontend/src/app/policy/no-type-policy-instance-dialog/no-type-policy-instance-dialog.component.scss b/webapp-frontend/src/app/policy/no-type-policy-instance-dialog/no-type-policy-instance-dialog.component.scss deleted file mode 100644 index accb527..0000000 --- a/webapp-frontend/src/app/policy/no-type-policy-instance-dialog/no-type-policy-instance-dialog.component.scss +++ /dev/null @@ -1,73 +0,0 @@ -/*- - * ========================LICENSE_START================================= - * O-RAN-SC - * %% - * Copyright (C) 2019 Nordix Foundation - * %% - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ========================LICENSE_END=================================== - */ - - -.logo__text { - fill: #2B244D; -} - -.logo__text-dark { - fill: #ffffff; -} - -.header-dark { - background: #2B244D; -} - -.logo { - margin-left: 10px; -} - -.logo__icon { - height: 2rem; - margin-left: 1rem; -} - -.submitBtn { - background-color: #4CAF50; - /* Green */ - margin-right: 10px; -} - -.header { - background: linear-gradient(to bottom, white 0%, grayscale($color: #eeeaea) 100%); - font-size: 40px; - margin-top: 10px; - margin-bottom: 10px; - margin-left: 2px; - margin-right: 2px; -} - -.header-dark { - background: #2B244D; -} - - -.card { - height: 100%; - width: 100%; - margin-left: 2px; - margin-right: 2px; - background-color: grayscale($color: #eeeaea); -} - -.card-dark { - background-color: #1c1c24; -} diff --git a/webapp-frontend/src/app/policy/no-type-policy-instance-dialog/no-type-policy-instance-dialog.component.ts b/webapp-frontend/src/app/policy/no-type-policy-instance-dialog/no-type-policy-instance-dialog.component.ts deleted file mode 100644 index 855d718..0000000 --- a/webapp-frontend/src/app/policy/no-type-policy-instance-dialog/no-type-policy-instance-dialog.component.ts +++ /dev/null @@ -1,97 +0,0 @@ -/*- - * ========================LICENSE_START================================= - * O-RAN-SC - * %% - * Copyright (C) 2020 Nordix Foundation - * %% - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ========================LICENSE_END=================================== - */ -import { Component, Inject, OnInit, ViewChild } from '@angular/core'; -import { FormGroup } from '@angular/forms'; -import { MatDialogRef, MAT_DIALOG_DATA } from '@angular/material/dialog'; -import { PolicyService } from '../../services/policy/policy.service'; -import { NotificationService } from '../../services/ui/notification.service'; -import { UiService } from '../../services/ui/ui.service'; -import { HttpErrorResponse } from '@angular/common/http'; -import { ErrorDialogService } from '../../services/ui/error-dialog.service'; -import * as uuid from 'uuid'; -import { CreatePolicyInstance } from '../../interfaces/policy.types'; -import { RicSelectorComponent } from '../ric-selector/ric-selector.component'; -import { formatJsonString, NoTypePolicyEditorComponent } from '../no-type-policy-editor/no-type-policy-editor.component'; - -@Component({ - selector: 'nrcp-no-type-policy-instance-dialog', - templateUrl: './no-type-policy-instance-dialog.component.html', - styleUrls: ['./no-type-policy-instance-dialog.component.scss'] -}) -export class NoTypePolicyInstanceDialogComponent implements OnInit { - instanceForm: FormGroup; - @ViewChild(RicSelectorComponent) - private ricSelectorComponent: RicSelectorComponent; - @ViewChild(NoTypePolicyEditorComponent) - private policyEditorComponent: NoTypePolicyEditorComponent; - policyInstanceId: string; // null if not yet created - policyJson: string; - darkMode: boolean; - ric: string; - allRicIds: string[] = []; - - constructor( - public dialogRef: MatDialogRef, - private policySvc: PolicyService, - private errorService: ErrorDialogService, - private notificationService: NotificationService, - @Inject(MAT_DIALOG_DATA) private data, - private ui: UiService) { - this.policyInstanceId = data.instanceId; - this.policyJson = data.instanceJson ? formatJsonString(data.instanceJson) : '{}'; - this.ric = data.ric; - } - - ngOnInit() { - this.ui.darkModeState.subscribe((isDark) => { - this.darkMode = isDark; - }); - this.instanceForm = new FormGroup({}); - } - - onSubmit() { - if (this.policyInstanceId == null) { - this.policyInstanceId = uuid.v4(); - } - const self: NoTypePolicyInstanceDialogComponent = this; - let createPolicyInstance: CreatePolicyInstance = this.createPolicyInstance(this.policyEditorComponent.policyJsonTextArea.value); - this.policySvc.putPolicy(createPolicyInstance).subscribe( - { - next(_) { - self.notificationService.success('Policy without type:' + self.policyInstanceId + ' submitted'); - self.dialogRef.close(); - }, - error(error: HttpErrorResponse) { - self.errorService.displayError('Submit failed: ' + error.error); - }, - complete() { } - }); - } - - private createPolicyInstance(policyJson: string): CreatePolicyInstance { - let createPolicyInstance = {} as CreatePolicyInstance; - createPolicyInstance.policy_data = JSON.parse(policyJson); - createPolicyInstance.policy_id = this.policyInstanceId; - createPolicyInstance.policytype_id = ''; - createPolicyInstance.ric_id = this.ricSelectorComponent ? this.ricSelectorComponent.selectedRic : this.ric; - createPolicyInstance.service_id = 'controlpanel'; - return createPolicyInstance; - } -} diff --git a/webapp-frontend/src/app/policy/policy-control.component.ts b/webapp-frontend/src/app/policy/policy-control.component.ts index 01c38b6..28253c8 100644 --- a/webapp-frontend/src/app/policy/policy-control.component.ts +++ b/webapp-frontend/src/app/policy/policy-control.component.ts @@ -23,7 +23,6 @@ import { MatDialog } from '@angular/material/dialog'; import { BehaviorSubject, Observable } from 'rxjs'; -import { NoTypePolicyInstanceDialogComponent } from './no-type-policy-instance-dialog/no-type-policy-instance-dialog.component'; import { PolicyTypeSchema } from '../interfaces/policy.types'; import { PolicyTypeDataSource } from './policy-type/policy-type.datasource'; import { getPolicyDialogProperties } from './policy-instance-dialog/policy-instance-dialog.component'; @@ -67,14 +66,8 @@ export class PolicyControlComponent implements OnInit { } createPolicyInstance(policyTypeSchema: PolicyTypeSchema): void { - let dialogRef; - if (this.isSchemaEmpty(policyTypeSchema)) { - dialogRef = this.dialog.open(NoTypePolicyInstanceDialogComponent, - getPolicyDialogProperties(policyTypeSchema, null, this.darkMode)); - } else { - dialogRef = this.dialog.open(PolicyInstanceDialogComponent, - getPolicyDialogProperties(policyTypeSchema, null, this.darkMode)); - } + let dialogRef = this.dialog.open(PolicyInstanceDialogComponent, + getPolicyDialogProperties(policyTypeSchema, null, this.darkMode)); const info: PolicyTypeInfo = this.getPolicyTypeInfo(policyTypeSchema); dialogRef.afterClosed().subscribe( (_) => { @@ -88,10 +81,6 @@ export class PolicyControlComponent implements OnInit { info.isExpanded.next(!info.isExpanded.getValue()); } - private isSchemaEmpty(policyTypeSchema: PolicyTypeSchema): boolean { - return policyTypeSchema.schemaObject === '{}'; - } - getPolicyTypeInfo(policyTypeSchema: PolicyTypeSchema): PolicyTypeInfo { let info: PolicyTypeInfo = this.policyTypeInfo.get(policyTypeSchema.name); if (!info) { 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 695dc6d..0b85c58 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 @@ -2,7 +2,7 @@ ========================LICENSE_START================================= O-RAN-SC %% - Copyright (C) 2019 Nordix Foundation + Copyright (C) 2020 Nordix Foundation %% Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -19,7 +19,7 @@ -->