Sean Condon | 28ecc5f | 2018-06-25 12:50:16 +0100 | [diff] [blame] | 1 | /* |
| 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 | */ |
| 16 | import { Component, Input, OnInit, OnDestroy, OnChanges } from '@angular/core'; |
| 17 | import { trigger, state, style, animate, transition } from '@angular/animations'; |
Sean Condon | 5ca0026 | 2018-09-06 17:55:25 +0100 | [diff] [blame] | 18 | import { |
| 19 | FnService, |
| 20 | LionService, |
Sean Condon | 5ca0026 | 2018-09-06 17:55:25 +0100 | [diff] [blame] | 21 | LogService, |
| 22 | DetailsPanelBaseImpl, |
| 23 | WebSocketService |
Sean Condon | a3ad779 | 2020-01-04 19:26:34 +0000 | [diff] [blame^] | 24 | } from 'gui2-fw-lib/public_api'; |
Sean Condon | 28ecc5f | 2018-06-25 12:50:16 +0100 | [diff] [blame] | 25 | |
Sean Condon | 28ecc5f | 2018-06-25 12:50:16 +0100 | [diff] [blame] | 26 | import { 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 Condon | 98b6ddb | 2019-12-24 08:07:40 +0000 | [diff] [blame] | 45 | '../../../../../../../../gui2-fw-lib/lib/widget/panel.css', '../../../../../../../../gui2-fw-lib/lib/widget/panel-theme.css' |
Sean Condon | 28ecc5f | 2018-06-25 12:50:16 +0100 | [diff] [blame] | 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 | }) |
| 62 | export class AppsDetailsComponent extends DetailsPanelBaseImpl implements OnInit, OnDestroy, OnChanges { |
| 63 | @Input() id: string; |
| 64 | |
| 65 | lionFn; // Function |
| 66 | constructor( |
| 67 | protected fs: FnService, |
Sean Condon | 28ecc5f | 2018-06-25 12:50:16 +0100 | [diff] [blame] | 68 | protected log: LogService, |
| 69 | protected wss: WebSocketService, |
| 70 | protected lion: LionService, |
| 71 | ) { |
Sean Condon | 95fb574 | 2019-04-02 12:16:55 +0100 | [diff] [blame] | 72 | super(fs, log, wss, 'app'); |
Sean Condon | 28ecc5f | 2018-06-25 12:50:16 +0100 | [diff] [blame] | 73 | 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 | |
Bhavesh | 72ead49 | 2018-07-19 16:29:18 +0530 | [diff] [blame] | 103 | /** |
| 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 Condon | 28ecc5f | 2018-06-25 12:50:16 +0100 | [diff] [blame] | 108 | ngOnChanges() { |
Bhavesh | 72ead49 | 2018-07-19 16:29:18 +0530 | [diff] [blame] | 109 | if (this.id === '') { |
| 110 | return ''; |
| 111 | } else { |
| 112 | const query = { |
| 113 | 'id': this.id |
| 114 | }; |
| 115 | this.requestDetailsPanelData(query); |
| 116 | } |
Sean Condon | 28ecc5f | 2018-06-25 12:50:16 +0100 | [diff] [blame] | 117 | } |
| 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 | } |