2 * ========================LICENSE_START=================================
5 * Copyright (C) 2019 AT&T Intellectual Property
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ========================LICENSE_END===================================
20 import { Component, OnInit } from '@angular/core';
21 import { StatsService } from '../services/stats/stats.service';
22 import { ConfirmDialogService } from '../services/ui/confirm-dialog.service';
23 import { DomSanitizer, SafeResourceUrl } from '@angular/platform-browser';
24 import { MatDialog } from '@angular/material/dialog';
25 import { MatTabChangeEvent } from '@angular/material/tabs';
26 import { NotificationService } from '../services/ui/notification.service';
27 import { UiService } from '../services/ui/ui.service';
28 import { InstanceSelectorService } from '../services/instance-selector/instance-selector.service';
29 import { StatsDataSource } from './stats-datasource';
30 import { Subscription } from 'rxjs';
31 import { StatsDialogComponent } from './stats-dialog.component';
32 import { AppStats } from '../interfaces/e2-mgr.types';
33 import {FormControl} from '@angular/forms';
34 import { RicInstance} from '../interfaces/dashboard.types';
38 templateUrl: './stats.component.html',
39 styleUrls: ['./stats.component.scss']
41 export class StatsComponent implements OnInit {
46 displayedColumns: string[] = ['appName', 'metricUrl', 'editmetricUrl'];
47 dataSource: StatsDataSource;
48 private instanceChange: Subscription;
49 private instanceKey: string;
50 metricsUrl: SafeResourceUrl;
53 selected = new FormControl(0);
55 constructor(private statsservice: StatsService,
56 private sanitize: DomSanitizer,
57 private confirmDialogService: ConfirmDialogService,
58 private notificationService: NotificationService,
59 public instanceSelectorService: InstanceSelectorService,
60 public dialog: MatDialog,
61 public ui: UiService) {
65 this.dataSource = new StatsDataSource(this.statsservice, this.notificationService);
67 this.ui.darkModeState.subscribe((isDark) => {
68 this.darkMode = isDark;
71 this.instanceChange = this.instanceSelectorService.getSelectedInstance().subscribe((instance: RicInstance) => {
73 this.instanceKey = instance.key;
74 this.dataSource.loadTable(instance.key);
81 this.instanceChange.unsubscribe();
86 this.panelClass = 'dark-theme';
90 const dialogRef = this.dialog.open(StatsDialogComponent, {
91 panelClass: this.panelClass,
94 instanceKey: this.instanceKey
97 dialogRef.afterClosed()
98 .subscribe((result: boolean) => {
100 this.dataSource.loadTable(this.instanceKey);
105 editAppMetrics(stats?) {
106 const dialogRef = this.dialog.open(StatsDialogComponent, {
109 instanceKey: this.instanceKey,
110 appName: stats.statsDetails.appName ? stats.statsDetails.appName : '',
111 metricUrl: stats.statsDetails.metricUrl ? stats.statsDetails.metricUrl : '',
112 appId: stats.statsDetails.appId ? stats.statsDetails.appId : 0,
116 dialogRef.afterClosed()
117 .subscribe((result: boolean) => {
119 this.dataSource.loadTable(this.instanceKey);
124 viewAppMetrics(stats?) {
125 this.statsservice.getAppMetricsById(this.instanceKey, stats.statsDetails.appId) .subscribe((res: AppStats) => {
126 this.metricsUrl = this.sanitize.bypassSecurityTrustResourceUrl(res.statsDetails.metricUrl);
127 let tabNotThere:boolean = true;
128 if (this.tabs.length <= 0) {
130 this.selected.setValue(this.tabs.length - 1);
133 for(let i=0; i<this.tabs.length; i++){
134 if (this.tabs[i].statsDetails.appId == res.statsDetails.appId) {
135 this.tabs[i].statsDetails.appName = res.statsDetails.appName;
136 this.tabs[i].statsDetails.metricUrl = res.statsDetails.metricUrl;
137 this.selected.setValue(i);
144 this.selected.setValue(this.tabs.length - 1);
150 onTabChanged(event: MatTabChangeEvent) {
152 this.viewAppMetrics(this.tabs[event.index]);
155 deleteAppMetrics(stats?) {
156 this.confirmDialogService.openConfirmDialog('Are you sure you want to delete this entry?')
157 .afterClosed().subscribe((res: boolean) => {
160 this.statsservice.deleteAppMetrics(this.instanceKey, stats.statsDetails.appId).subscribe(() => {
161 for(let i=0; i<this.tabs.length; i++){
162 if (this.tabs[i].instanceKey === this.instanceKey && this.tabs[i].statsDetails.appId == stats.statsDetails.appId) {
163 this.tabs.splice(i, 1);
164 if (this.tabs.length>0) {
165 if (this.tabs[i] == null)
167 this.viewAppMetrics(this.tabs[i]);
172 this.dataSource.loadTable(this.instanceKey);