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'; |
| 18 | |
| 19 | import { FnService } from '../../../fw/util/fn.service'; |
| 20 | import { LionService } from '../../../fw/util/lion.service'; |
| 21 | import { LoadingService } from '../../../fw/layer/loading.service'; |
| 22 | import { LogService } from '../../../log.service'; |
| 23 | import { WebSocketService } from '../../../fw/remote/websocket.service'; |
| 24 | |
| 25 | import { DetailsPanelBaseImpl } from '../../../fw/widget/detailspanel.base'; |
| 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', |
| 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 | }) |
| 62 | export 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 | |
Bhavesh | 72ead49 | 2018-07-19 16:29:18 +0530 | [diff] [blame^] | 104 | /** |
| 105 | * Details Panel Data Request on row selection changes |
| 106 | * Should be called whenever id changes |
| 107 | * If id is empty, no request is made |
| 108 | */ |
Sean Condon | 28ecc5f | 2018-06-25 12:50:16 +0100 | [diff] [blame] | 109 | ngOnChanges() { |
Bhavesh | 72ead49 | 2018-07-19 16:29:18 +0530 | [diff] [blame^] | 110 | if (this.id === '') { |
| 111 | return ''; |
| 112 | } else { |
| 113 | const query = { |
| 114 | 'id': this.id |
| 115 | }; |
| 116 | this.requestDetailsPanelData(query); |
| 117 | } |
Sean Condon | 28ecc5f | 2018-06-25 12:50:16 +0100 | [diff] [blame] | 118 | } |
| 119 | |
| 120 | iconUrl(appId: string): string { |
| 121 | return APPURLPREFIX + appId + ICONURLSUFFIX; |
| 122 | } |
| 123 | |
| 124 | /** |
| 125 | * Read the LION bundle for App and set up the lionFn |
| 126 | */ |
| 127 | doLion() { |
| 128 | this.lionFn = this.lion.bundle('core.view.App'); |
| 129 | } |
| 130 | |
| 131 | } |