import { Component, Input, OnInit } from '@angular/core'; import { isNullOrUndefinedOrEmpty } from '../../utils/check'; import { ANIMATION_TYPES, DnLoadingConfig, IDnLoadingConfig } from './dn-loading.config'; import { DnLoadingConfigService } from './dn-loading.service'; @Component({ selector: 'dn-loading', template: `
{{text}}
`, }) export class DnLoadingComponent implements OnInit { @Input() show: boolean; @Input() text: string; @Input() config: IDnLoadingConfig = new DnLoadingConfig(); public ANIMATION_TYPES = ANIMATION_TYPES; public loadingConfig: IDnLoadingConfig = { animationType: '', backdropBackgroundColour: '', backdropBorderRadius: '', fullScreenBackdrop: false, primaryColour: '', secondaryColour: '', tertiaryColour: '' }; private defaultConfig: IDnLoadingConfig = { animationType: ANIMATION_TYPES.threeBounce, backdropBackgroundColour: 'rgba(0, 0, 0, 0.3)', backdropBorderRadius: '0px', fullScreenBackdrop: false, primaryColour: '#ffffff', secondaryColour: '#ffffff', tertiaryColour: '#ffffff' }; constructor(private loadingConfigService: DnLoadingConfigService) { } public getAnimationType(animationType: string): string { let animationTypeSet: string; switch (animationType) { case ANIMATION_TYPES.threeBounce: animationTypeSet = ANIMATION_TYPES.threeBounce; break; case ANIMATION_TYPES.rectangleBounce: animationTypeSet = ANIMATION_TYPES.rectangleBounce; break; case ANIMATION_TYPES.rotatingPlane: animationTypeSet = ANIMATION_TYPES.rotatingPlane; break; case ANIMATION_TYPES.wanderingCubes: animationTypeSet = ANIMATION_TYPES.wanderingCubes; break; default: animationTypeSet = ANIMATION_TYPES.threeBounce; } return animationTypeSet; } ngOnInit() { for (const option in this.defaultConfig) { if (typeof this.loadingConfig[option] === 'boolean') { this.loadingConfig[option] = this.config[option] != null ? this.config[option] : false; if (this.loadingConfig[option] === false) { this.loadingConfig[option] = this.loadingConfigService.loadingConfig[option] != null ? this.loadingConfigService.loadingConfig[option] : this.defaultConfig[option]; } } else { this.loadingConfig[option] = this.config[option] != null ? this.config[option] : ''; if (this.loadingConfig[option] === '') { this.loadingConfig[option] = this.loadingConfigService.loadingConfig[option] != null ? this.loadingConfigService.loadingConfig[option] : this.defaultConfig[option]; } } } } showText() { return !isNullOrUndefinedOrEmpty(this.text); } }