blob: bee217bea1fb457a6a0afde58ff5a515f44038df [file] [log] [blame]
Sean Condon28ecc5f2018-06-25 12:50:16 +01001/*
2 * Copyright 2018-present Open Networking Foundation
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16import { Component, Input, OnInit, OnDestroy, OnChanges } from '@angular/core';
17import { trigger, state, style, animate, transition } from '@angular/animations';
Sean Condon5ca00262018-09-06 17:55:25 +010018import {
19 FnService,
20 LionService,
Sean Condon5ca00262018-09-06 17:55:25 +010021 LogService,
22 DetailsPanelBaseImpl,
23 WebSocketService
Sean Condona3ad7792020-01-04 19:26:34 +000024} from 'gui2-fw-lib/public_api';
Sean Condon28ecc5f2018-06-25 12:50:16 +010025
Sean Condon28ecc5f2018-06-25 12:50:16 +010026import { App, APPURLPREFIX, ICONURLSUFFIX } from '../apps/apps.component';
27
28/**
29 * The details view when an app is clicked from the apps view
30 *
31 * This is expected to be passed an 'id' and it makes a call
32 * to the WebSocket with an appDetailsRequest, and gets back an
33 * appDetailsResponse.
34 *
35 * The animated fly-in is controlled by the animation below
36 * The appDetailsState is attached to application-details-panel
37 * and is false (flies out) when id='' and true (flies in) when
38 * id has a value
39 */
40@Component({
41 selector: 'onos-appsdetails',
42 templateUrl: './appsdetails.component.html',
43 styleUrls: [
44 './appsdetails.component.css',
Sean Condon98b6ddb2019-12-24 08:07:40 +000045 '../../../../../../../../gui2-fw-lib/lib/widget/panel.css', '../../../../../../../../gui2-fw-lib/lib/widget/panel-theme.css'
Sean Condon28ecc5f2018-06-25 12:50:16 +010046 ],
47 animations: [
48 trigger('appDetailsState', [
49 state('true', style({
50 transform: 'translateX(-100%)',
51 opacity: '100'
52 })),
53 state('false', style({
54 transform: 'translateX(0%)',
55 opacity: '0'
56 })),
57 transition('0 => 1', animate('100ms ease-in')),
58 transition('1 => 0', animate('100ms ease-out'))
59 ])
60 ]
61})
62export class AppsDetailsComponent extends DetailsPanelBaseImpl implements OnInit, OnDestroy, OnChanges {
63 @Input() id: string;
64
65 lionFn; // Function
66 constructor(
67 protected fs: FnService,
Sean Condon28ecc5f2018-06-25 12:50:16 +010068 protected log: LogService,
69 protected wss: WebSocketService,
70 protected lion: LionService,
71 ) {
Sean Condon95fb5742019-04-02 12:16:55 +010072 super(fs, log, wss, 'app');
Sean Condon28ecc5f2018-06-25 12:50:16 +010073 if (this.lion.ubercache.length === 0) {
74 this.lionFn = this.dummyLion;
75 this.lion.loadCbs.set('appsdetails', () => this.doLion());
76 } else {
77 this.doLion();
78 }
79 }
80
81 /**
82 * There is a possibility that a previous selection
83 * is already registered for call - if so wait 100ms
84 * for it to deregister - this is because in the list of
85 * apps we might have selected one higher up the list and
86 * it is now being processed here before an older selection
87 * farther down the list has been removed
88 */
89 ngOnInit() {
90 this.init();
91 this.log.debug('App Details Component initialized:', this.id);
92 }
93
94 /**
95 * Stop listening to appDetailsResponse on WebSocket
96 */
97 ngOnDestroy() {
98 this.lion.loadCbs.delete('appsdetails');
99 this.destroy();
100 this.log.debug('App Details Component destroyed');
101 }
102
Bhavesh72ead492018-07-19 16:29:18 +0530103 /**
104 * Details Panel Data Request on row selection changes
105 * Should be called whenever id changes
106 * If id is empty, no request is made
107 */
Sean Condon28ecc5f2018-06-25 12:50:16 +0100108 ngOnChanges() {
Bhavesh72ead492018-07-19 16:29:18 +0530109 if (this.id === '') {
110 return '';
111 } else {
112 const query = {
113 'id': this.id
114 };
115 this.requestDetailsPanelData(query);
116 }
Sean Condon28ecc5f2018-06-25 12:50:16 +0100117 }
118
119 iconUrl(appId: string): string {
120 return APPURLPREFIX + appId + ICONURLSUFFIX;
121 }
122
123 /**
124 * Read the LION bundle for App and set up the lionFn
125 */
126 doLion() {
127 this.lionFn = this.lion.bundle('core.view.App');
128 }
129
130}