blob: 1e6ed29a58ee0b9faa5433670a5d54275bdb5e57 [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';
18
19import { FnService } from '../../../fw/util/fn.service';
20import { LionService } from '../../../fw/util/lion.service';
21import { LoadingService } from '../../../fw/layer/loading.service';
22import { LogService } from '../../../log.service';
23import { WebSocketService } from '../../../fw/remote/websocket.service';
24
25import { DetailsPanelBaseImpl } from '../../../fw/widget/detailspanel.base';
26import { 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',
45 '../../../fw/widget/panel.css', '../../../fw/widget/panel-theme.css'
46 ],
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,
68 protected ls: LoadingService,
69 protected log: LogService,
70 protected wss: WebSocketService,
71 protected lion: LionService,
72 ) {
73 super(fs, ls, log, wss, 'app');
74 if (this.lion.ubercache.length === 0) {
75 this.lionFn = this.dummyLion;
76 this.lion.loadCbs.set('appsdetails', () => this.doLion());
77 } else {
78 this.doLion();
79 }
80 }
81
82 /**
83 * There is a possibility that a previous selection
84 * is already registered for call - if so wait 100ms
85 * for it to deregister - this is because in the list of
86 * apps we might have selected one higher up the list and
87 * it is now being processed here before an older selection
88 * farther down the list has been removed
89 */
90 ngOnInit() {
91 this.init();
92 this.log.debug('App Details Component initialized:', this.id);
93 }
94
95 /**
96 * Stop listening to appDetailsResponse on WebSocket
97 */
98 ngOnDestroy() {
99 this.lion.loadCbs.delete('appsdetails');
100 this.destroy();
101 this.log.debug('App Details Component destroyed');
102 }
103
104 ngOnChanges() {
105 this.requestDetailsPanelData(this.id);
106 }
107
108 iconUrl(appId: string): string {
109 return APPURLPREFIX + appId + ICONURLSUFFIX;
110 }
111
112 /**
113 * Read the LION bundle for App and set up the lionFn
114 */
115 doLion() {
116 this.lionFn = this.lion.bundle('core.view.App');
117 }
118
119}