2 * ========================LICENSE_START=================================
5 * Copyright (C) 2019 AT&T Intellectual Property and Nokia
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, ViewEncapsulation } from '@angular/core';
21 import { LocalDataSource } from 'ng2-smart-table';
22 import { XappMgrService } from '../services/xapp-mgr/xapp-mgr.service';
23 import { Router } from '@angular/router';
24 import { ConfirmDialogService } from './../services/ui/confirm-dialog.service'
25 import { NotificationService } from './../services/ui/notification.service'
26 import { XMXapp } from '../interfaces/xapp-mgr.types';
30 selector: 'app-control',
31 templateUrl: './control.component.html',
32 styleUrls: ['./control.component.css'],
33 encapsulation: ViewEncapsulation.Emulated,
35 export class ControlComponent implements OnInit {
40 columnTitle: 'Actions',
45 { name: 'view', title: '<i class="material-icons">visibility</i>', },
46 { name: 'undeploy', title: '<i class="material-icons red-close">close</i>', },
57 title: 'Instance Name',
83 source: LocalDataSource = new LocalDataSource();
86 private xappMgrSvc: XappMgrService,
87 private router: Router,
88 private confirmDialogService: ConfirmDialogService,
89 private notification: NotificationService) { }
92 this.xappMgrSvc.getAll().subscribe((xapps: XMXapp[]) => this.source.load(this.getInstance(xapps)));
95 onxAppControlAction(event) {
96 switch (event.action) {
101 this.undeploy(event);
108 this.router.navigate([url, event]);
111 undeploy(event): void {
112 this.confirmDialogService.openConfirmDialog('Are you sure you want to undeploy this xApp ?')
113 .afterClosed().subscribe(res => {
115 this.xappMgrSvc.undeployXapp(event.data.xapp).subscribe(
117 this.xappMgrSvc.getAll().subscribe((xapps: XMXapp[]) => this.source.load(this.getInstance(xapps)));
118 switch (response.status) {
120 this.notification.success('xApp undeployed successfully!');
123 this.notification.warn('xApp undeploy failed.');
131 getInstance(allxappdata: XMXapp[]) {
132 const xAppInstances = [];
133 for (const xappindex in allxappdata) {
134 const instancelist = allxappdata[xappindex].instances;
135 for (const instanceindex in instancelist) {
137 instance = instancelist[instanceindex];
138 instance.xapp = allxappdata[xappindex].name;
139 xAppInstances.push(instance);
142 return xAppInstances;