Sean Condon | d6f95bf | 2020-01-21 10:10:23 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2020-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 | |
| 17 | import {Component, OnInit, OnDestroy} from '@angular/core'; |
| 18 | import {WebSocketService, LogService, FnService, SortDir, TableBaseImpl, TableResponse} from 'gui2-fw-lib/public_api'; |
| 19 | |
| 20 | /** |
| 21 | * Model of the response from the WebSocket |
| 22 | */ |
| 23 | export interface YangModel { |
| 24 | id: string; |
| 25 | revision: string; |
| 26 | modelId: string; |
| 27 | } |
| 28 | |
| 29 | export interface YangModelDataResponse { |
| 30 | yangModels: YangModel[]; |
| 31 | } |
| 32 | |
| 33 | @Component({ |
| 34 | selector: 'onos-yangtable', |
| 35 | templateUrl: './yangtable.component.html', |
| 36 | styleUrls: [ |
| 37 | './yangtable.component.scss', 'yangtable.theme.scss', |
| 38 | '../../../../../web/gui2-fw-lib/lib/widget/table.css', '../../../../../web/gui2-fw-lib/lib/widget/table.theme.css' |
| 39 | ] |
| 40 | }) |
| 41 | export class YangTableComponent extends TableBaseImpl implements OnInit, OnDestroy { |
| 42 | selectedModel: YangModel = undefined; |
| 43 | |
| 44 | constructor( |
| 45 | protected log: LogService, |
| 46 | protected fs: FnService, |
| 47 | protected wss: WebSocketService, |
| 48 | ) { |
| 49 | super(fs, log, wss, 'yangModel'); |
| 50 | this.log.debug('YangTableComponent constructed'); |
| 51 | this.parentSelCb = this.rowSelectionParent; |
| 52 | |
| 53 | this.sortParams = { |
| 54 | firstCol: 'id', |
| 55 | firstDir: SortDir.desc, |
| 56 | secondCol: 'revision', |
| 57 | secondDir: SortDir.asc, |
| 58 | }; |
| 59 | } |
| 60 | |
| 61 | ngOnInit() { |
| 62 | this.init(); |
| 63 | this.log.debug('YangTableComponent initialized'); |
| 64 | } |
| 65 | |
| 66 | ngOnDestroy() { |
| 67 | this.destroy(); |
| 68 | this.log.debug('YangTableComponent destroyed'); |
| 69 | } |
| 70 | |
| 71 | /** |
| 72 | * When the upload button is clicked pass this on to the file input (hidden) |
| 73 | */ |
| 74 | triggerForm() { |
| 75 | document.getElementById('uploadFile') |
| 76 | .dispatchEvent(new MouseEvent('click')); |
| 77 | } |
| 78 | |
| 79 | /** |
| 80 | * called when a row is selected - sets the state of control icons |
| 81 | */ |
| 82 | rowSelectionParent(event: any, selRow: any) { |
| 83 | this.selectedModel = selRow; |
| 84 | } |
| 85 | } |