2020-09-29 16:04:25 -07:00
|
|
|
import Component from '@glimmer/component';
|
2018-08-09 08:27:16 -07:00
|
|
|
import { get, set } from '@ember/object';
|
2020-09-29 16:04:25 -07:00
|
|
|
import BannerService, { IBanner } from '@datahub/shared/services/banners';
|
2019-08-31 20:51:14 -07:00
|
|
|
import { bannerAnimationSpeed } from '@datahub/utils/constants/notifications';
|
|
|
|
import { inject as service } from '@ember/service';
|
|
|
|
import { alias } from '@ember/object/computed';
|
|
|
|
import { action } from '@ember/object';
|
2018-05-01 11:37:30 -07:00
|
|
|
|
|
|
|
export default class BannerAlerts extends Component {
|
2018-05-01 22:50:04 -07:00
|
|
|
/**
|
|
|
|
* Keeps the base banner animation speed as a property to attach as a data attribute to the rendered
|
|
|
|
* banner-alert elements in the template
|
|
|
|
*/
|
|
|
|
bannerAnimationSpeed = bannerAnimationSpeed;
|
|
|
|
|
2018-05-01 11:37:30 -07:00
|
|
|
/**
|
2018-08-09 08:27:16 -07:00
|
|
|
* Imports the service used to handle actual activation and dismissal of banners. The service also
|
|
|
|
* maintains the banners list
|
|
|
|
* @type {ComputedProperty<BannerService>}
|
2018-05-01 11:37:30 -07:00
|
|
|
*/
|
2018-08-09 08:27:16 -07:00
|
|
|
@service
|
2020-09-29 16:04:25 -07:00
|
|
|
banners!: BannerService;
|
2018-05-01 11:37:30 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* References the banners service computation on whether or not we should be showing banners
|
|
|
|
*/
|
2018-08-09 08:27:16 -07:00
|
|
|
@alias('banners.isShowingBanners')
|
2020-09-29 16:04:25 -07:00
|
|
|
isShowingBanners!: boolean;
|
2018-08-09 08:27:16 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Triggered by the user by clicking the dismiss icon on the banner, triggers the exiting state on the
|
|
|
|
* topmost (first in queue) banner and starts the timer/css animation for the dismissal action
|
|
|
|
* @param {IBanner} banner - the banner as a subject for the dismissal action
|
|
|
|
*/
|
|
|
|
@action
|
2019-08-31 20:51:14 -07:00
|
|
|
onDismissBanner(this: BannerAlerts, banner: IBanner): void {
|
2018-08-09 08:27:16 -07:00
|
|
|
const banners = get(this, 'banners');
|
|
|
|
|
|
|
|
set(banner, 'isExiting', true);
|
|
|
|
banners.dequeue();
|
|
|
|
}
|
2018-05-01 11:37:30 -07:00
|
|
|
}
|