Sean Condon | 83fc39f | 2018-04-19 18:56:13 +0100 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright 2015-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, OnInit, Input } from '@angular/core'; |
| 17 | import { IconService, glyphMapping } from '../icon.service'; |
| 18 | import { LogService } from '../../../log.service'; |
| 19 | import * as d3 from 'd3'; |
| 20 | |
| 21 | /** |
| 22 | * Icon Component |
| 23 | * |
| 24 | * Note: This is an alternative to the Icon Directive from ONOS 1.0.0 |
| 25 | * It has been implemented as a Component because it was inadvertently adding |
| 26 | * in a template through d3 DOM manipulations - it's better to make it a Comp |
| 27 | * and build a template the Angular 6 way |
| 28 | * |
| 29 | * Remember: The CSS files applied here only apply to this component |
| 30 | */ |
| 31 | @Component({ |
| 32 | selector: 'onos-icon', |
| 33 | templateUrl: './icon.component.html', |
| 34 | styleUrls: ['./icon.component.css', './icon.theme.css', './glyph.css', './glyph-theme.css'] |
| 35 | }) |
| 36 | export class IconComponent implements OnInit { |
| 37 | @Input() iconId: string; |
| 38 | @Input() iconSize: number = 20; |
| 39 | |
| 40 | constructor( |
| 41 | private is: IconService, |
| 42 | private log: LogService |
| 43 | ) { |
| 44 | // Note: iconId is not available until initialization |
| 45 | this.log.debug('IconComponent constructed'); |
| 46 | } |
| 47 | |
| 48 | ngOnInit() { |
| 49 | this.is.loadIconDef(this.iconId); |
| 50 | this.log.debug('IconComponent initialized for ', this.iconId); |
| 51 | } |
| 52 | |
| 53 | /** |
| 54 | * Get the corresponding iconTag from the glyphMapping in the iconService |
| 55 | * @returns The iconTag corresponding to the iconId of this instance |
| 56 | */ |
| 57 | iconTag(): string { |
| 58 | return '#' + glyphMapping.get(this.iconId); |
| 59 | } |
| 60 | } |