X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;f=dashboard%2Fwebapp-frontend%2Fsrc%2Fapp%2Fpolicy-control%2Fpolicy-instance.component.ts;fp=dashboard%2Fwebapp-frontend%2Fsrc%2Fapp%2Fpolicy-control%2Fpolicy-instance.component.ts;h=354427564d810018b03279b87c8a60ded4af1492;hb=a2bc79c5f0027e953815d6e98814a748b36827aa;hp=0000000000000000000000000000000000000000;hpb=25501ccf6b73c3afded66eade70ee59af102844f;p=nonrtric.git diff --git a/dashboard/webapp-frontend/src/app/policy-control/policy-instance.component.ts b/dashboard/webapp-frontend/src/app/policy-control/policy-instance.component.ts new file mode 100644 index 00000000..35442756 --- /dev/null +++ b/dashboard/webapp-frontend/src/app/policy-control/policy-instance.component.ts @@ -0,0 +1,113 @@ +/*- + * ========================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=================================== + */ + +import { MatSort } from '@angular/material'; +import { Component, OnInit, ViewChild, Input, AfterViewInit } from '@angular/core'; +import { MatDialog } from '@angular/material/dialog'; +import { PolicyType } from '../interfaces/policy.types'; +import { PolicyInstanceDataSource } from './policy-instance.datasource'; +import { ErrorDialogService } from '../services/ui/error-dialog.service'; +import { NotificationService } from '../services/ui/notification.service'; +import { PolicyService } from '../services/policy/policy.service'; +import { ConfirmDialogService } from './../services/ui/confirm-dialog.service'; +import { PolicyInstance } from '../interfaces/policy.types'; +import { PolicyInstanceDialogComponent } from './policy-instance-dialog.component'; +import { getPolicyDialogProperties } from './policy-instance-dialog.component'; +import { HttpErrorResponse, HttpResponse } from '@angular/common/http'; +import { Observable } from 'rxjs'; + +@Component({ + selector: 'rd-policy-instance', + templateUrl: './policy-instance.component.html', + styleUrls: ['./policy-instance.component.scss'] +}) + + +export class PolicyInstanceComponent implements OnInit, AfterViewInit { + instanceDataSource: PolicyInstanceDataSource; + @Input() policyType: PolicyType; + @Input() expanded: Observable; + @ViewChild(MatSort, { static: true }) sort: MatSort; + + constructor( + private policySvc: PolicyService, + private dialog: MatDialog, + private errorDialogService: ErrorDialogService, + private notificationService: NotificationService, + private confirmDialogService: ConfirmDialogService) { + } + + ngOnInit() { + this.instanceDataSource = new PolicyInstanceDataSource(this.policySvc, this.sort, this.notificationService, this.policyType); + this.expanded.subscribe((isExpanded: boolean) => this.onExpand(isExpanded)); + } + + ngAfterViewInit() { + this.instanceDataSource.sort = this.sort; + } + + private onExpand(isExpanded: boolean) { + if (isExpanded) { + this.instanceDataSource.loadTable(); + } + } + + modifyInstance(instance: PolicyInstance): void { + this.policySvc.getPolicy(this.policyType.policy_type_id, instance.instanceId).subscribe( + (refreshedJson: any) => { + instance.instance = JSON.stringify(refreshedJson); + this.dialog.open(PolicyInstanceDialogComponent, getPolicyDialogProperties(this.policyType, instance)); + }, + (httpError: HttpErrorResponse) => { + this.notificationService.error('Could not refresh instance ' + httpError.message); + this.dialog.open(PolicyInstanceDialogComponent, getPolicyDialogProperties(this.policyType, instance)); + } + ); + } + + hasInstances(): boolean { + return this.instanceDataSource.rowCount > 0; + } + + deleteInstance(instance: PolicyInstance): void { + this.confirmDialogService + .openConfirmDialog('Are you sure you want to delete this policy instance?') + .afterClosed().subscribe( + (res: any) => { + if (res) { + this.policySvc.deletePolicy(this.policyType.policy_type_id, instance.instanceId) + .subscribe( + (response: HttpResponse) => { + switch (response.status) { + case 200: + this.notificationService.success('Delete succeeded!'); + this.instanceDataSource.loadTable(); + break; + default: + this.notificationService.warn('Delete failed.'); + } + }, + (error: HttpErrorResponse) => { + this.errorDialogService.displayError(error.message); + }); + } + }); + } +}