blob: 7dd721d4fb6e49688389834e9ce5dff1a0a16607 [file] [log] [blame]
Sean Condon83775682018-05-27 18:59:59 +01001/*
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 Condon2aa86092018-07-16 09:04:05 +010016import { Component, Input, Output, OnChanges, SimpleChange, EventEmitter } from '@angular/core';
Sean Condon5ca00262018-09-06 17:55:25 +010017import { LogService } from '../../log.service';
Sean Condon83775682018-05-27 18:59:59 +010018import { 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 Condon2aa86092018-07-16 09:04:05 +010027 * 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 Condon83775682018-05-27 18:59:59 +010030 * To use add an element to the template like
Sean Condon2aa86092018-07-16 09:04:05 +010031 * <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 Condon83775682018-05-27 18:59:59 +010036 */
37@Component({
38 selector: 'onos-flash',
39 templateUrl: './flash.component.html',
Sean Condon2aa86092018-07-16 09:04:05 +010040 styleUrls: [
41 './flash.component.css',
42 '../dialog.css',
43 '../dialog.theme.css',
44 ],
Sean Condon83775682018-05-27 18:59:59 +010045 animations: [
46 trigger('flashState', [
Sean Condon2aa86092018-07-16 09:04:05 +010047 state('false', style({
48// transform: 'translateY(-400%)',
Sean Condon83775682018-05-27 18:59:59 +010049 opacity: '0.0',
50 })),
Sean Condon2aa86092018-07-16 09:04:05 +010051 state('true', style({
52// transform: 'translateY(0%)',
Sean Condon83775682018-05-27 18:59:59 +010053 opacity: '1.0',
54 })),
Sean Condon2aa86092018-07-16 09:04:05 +010055 transition('0 => 1', animate('200ms ease-in')),
56 transition('1 => 0', animate('200ms ease-out'))
Sean Condon83775682018-05-27 18:59:59 +010057 ])
58 ]
59})
Sean Condon2aa86092018-07-16 09:04:05 +010060export 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 Condon83775682018-05-27 18:59:59 +010065
Sean Condon2aa86092018-07-16 09:04:05 +010066 public visible: boolean = false;
Sean Condon83775682018-05-27 18:59:59 +010067
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 Condon2aa86092018-07-16 09:04:05 +010072 ngOnChanges(changes: {[propertyName: string]: SimpleChange}) {
73 if (changes['message'] && this.message && this.message !== '') {
74 this.visible = true;
Sean Condon83775682018-05-27 18:59:59 +010075
Sean Condon2aa86092018-07-16 09:04:05 +010076 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 Condon83775682018-05-27 18:59:59 +010090 }
91}