Sean Condon | 8377568 | 2018-05-27 18:59:59 +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 | */ |
Sean Condon | 2aa8609 | 2018-07-16 09:04:05 +0100 | [diff] [blame] | 16 | import { Component, Input, Output, OnChanges, SimpleChange, EventEmitter } from '@angular/core'; |
Sean Condon | 5ca0026 | 2018-09-06 17:55:25 +0100 | [diff] [blame] | 17 | import { LogService } from '../../log.service'; |
Sean Condon | 8377568 | 2018-05-27 18:59:59 +0100 | [diff] [blame] | 18 | import { trigger, state, style, animate, transition } from '@angular/animations'; |
| 19 | |
| 20 | /** |
| 21 | * ONOS GUI -- Layer -- Flash Component |
| 22 | * |
| 23 | * Replaces Flash Service in old GUI. |
| 24 | * Provides a mechanism to flash short informational messages to the screen |
| 25 | * to alert the user of something, e.g. "Hosts visible" or "Hosts hidden". |
| 26 | * |
Sean Condon | 2aa8609 | 2018-07-16 09:04:05 +0100 | [diff] [blame] | 27 | * It can be used in a warning mode, where text will appear in red |
| 28 | * The dwell time (milliseconds) can be controlled or the default is 1200ms |
| 29 | * |
Sean Condon | 8377568 | 2018-05-27 18:59:59 +0100 | [diff] [blame] | 30 | * To use add an element to the template like |
Sean Condon | 2aa8609 | 2018-07-16 09:04:05 +0100 | [diff] [blame] | 31 | * <onos-flash message="Hosts visible" dwell="2000" warning="true"></onos-flash> |
| 32 | * This whole element can be disabled until needed with an ngIf, but if this is done |
| 33 | * the animated fade-in and fade-out will not happen |
| 34 | * There is also a (closed) event that tells you when the message is closed, or |
| 35 | * fades-out |
Sean Condon | 8377568 | 2018-05-27 18:59:59 +0100 | [diff] [blame] | 36 | */ |
| 37 | @Component({ |
| 38 | selector: 'onos-flash', |
| 39 | templateUrl: './flash.component.html', |
Sean Condon | 2aa8609 | 2018-07-16 09:04:05 +0100 | [diff] [blame] | 40 | styleUrls: [ |
| 41 | './flash.component.css', |
| 42 | '../dialog.css', |
| 43 | '../dialog.theme.css', |
| 44 | ], |
Sean Condon | 8377568 | 2018-05-27 18:59:59 +0100 | [diff] [blame] | 45 | animations: [ |
| 46 | trigger('flashState', [ |
Sean Condon | 2aa8609 | 2018-07-16 09:04:05 +0100 | [diff] [blame] | 47 | state('false', style({ |
| 48 | // transform: 'translateY(-400%)', |
Sean Condon | 8377568 | 2018-05-27 18:59:59 +0100 | [diff] [blame] | 49 | opacity: '0.0', |
| 50 | })), |
Sean Condon | 2aa8609 | 2018-07-16 09:04:05 +0100 | [diff] [blame] | 51 | state('true', style({ |
| 52 | // transform: 'translateY(0%)', |
Sean Condon | 8377568 | 2018-05-27 18:59:59 +0100 | [diff] [blame] | 53 | opacity: '1.0', |
| 54 | })), |
Sean Condon | 2aa8609 | 2018-07-16 09:04:05 +0100 | [diff] [blame] | 55 | transition('0 => 1', animate('200ms ease-in')), |
| 56 | transition('1 => 0', animate('200ms ease-out')) |
Sean Condon | 8377568 | 2018-05-27 18:59:59 +0100 | [diff] [blame] | 57 | ]) |
| 58 | ] |
| 59 | }) |
Sean Condon | 2aa8609 | 2018-07-16 09:04:05 +0100 | [diff] [blame] | 60 | export class FlashComponent implements OnChanges { |
| 61 | @Input() message: string; |
| 62 | @Input() dwell: number = 1200; // milliseconds |
| 63 | @Input() warning: boolean = false; |
| 64 | @Output() closed: EventEmitter<boolean> = new EventEmitter(); |
Sean Condon | 8377568 | 2018-05-27 18:59:59 +0100 | [diff] [blame] | 65 | |
Sean Condon | 2aa8609 | 2018-07-16 09:04:05 +0100 | [diff] [blame] | 66 | public visible: boolean = false; |
Sean Condon | 8377568 | 2018-05-27 18:59:59 +0100 | [diff] [blame] | 67 | |
| 68 | /** |
| 69 | * Flash a message up for 1200ms then disappear again. |
| 70 | * See animation parameter for the ease in and ease out params |
| 71 | */ |
Sean Condon | 2aa8609 | 2018-07-16 09:04:05 +0100 | [diff] [blame] | 72 | ngOnChanges(changes: {[propertyName: string]: SimpleChange}) { |
| 73 | if (changes['message'] && this.message && this.message !== '') { |
| 74 | this.visible = true; |
Sean Condon | 8377568 | 2018-05-27 18:59:59 +0100 | [diff] [blame] | 75 | |
Sean Condon | 2aa8609 | 2018-07-16 09:04:05 +0100 | [diff] [blame] | 76 | setTimeout(() => { |
| 77 | this.visible = false; |
| 78 | this.closed.emit(false); |
| 79 | }, this.dwell); |
| 80 | } |
| 81 | } |
| 82 | |
| 83 | /** |
| 84 | * The message will flash up for 'dwell' milliseconds |
| 85 | * If dwell is > 2000ms, then there will be a button that allows it to be dismissed now |
| 86 | */ |
| 87 | closeNow() { |
| 88 | this.visible = false; |
| 89 | this.closed.emit(false); |
Sean Condon | 8377568 | 2018-05-27 18:59:59 +0100 | [diff] [blame] | 90 | } |
| 91 | } |