mirror of
https://github.com/GNS3/gns3-web-ui.git
synced 2025-02-22 10:20:48 +00:00
Dynamic AdButler component
This commit is contained in:
parent
e11281ddf6
commit
0f542c3e3b
@ -580,7 +580,8 @@ if (environment.production) {
|
|||||||
NavigationDialogComponent,
|
NavigationDialogComponent,
|
||||||
ScreenshotDialogComponent,
|
ScreenshotDialogComponent,
|
||||||
ConfirmationBottomSheetComponent,
|
ConfirmationBottomSheetComponent,
|
||||||
ConfigDialogComponent
|
ConfigDialogComponent,
|
||||||
|
AdbutlerComponent
|
||||||
],
|
],
|
||||||
bootstrap: [AppComponent]
|
bootstrap: [AppComponent]
|
||||||
})
|
})
|
||||||
|
@ -11,13 +11,12 @@ import { ToasterService } from '../../services/toaster.service';
|
|||||||
})
|
})
|
||||||
export class AdbutlerComponent implements OnInit {
|
export class AdbutlerComponent implements OnInit {
|
||||||
@ViewChild('ad', {static: false}) ad: ElementRef;
|
@ViewChild('ad', {static: false}) ad: ElementRef;
|
||||||
@Input() theme: string;
|
theme: string;
|
||||||
@Output() onLoad = new EventEmitter();
|
onLoad = new EventEmitter();
|
||||||
htmlCode: string;
|
htmlCode: string;
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
private httpClient: HttpClient,
|
private httpClient: HttpClient
|
||||||
private toasterService: ToasterService
|
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
ngOnInit() {
|
ngOnInit() {
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
<mat-progress-bar mode="determinate" [value]="progress"></mat-progress-bar>
|
<mat-progress-bar mode="determinate" [value]="progress"></mat-progress-bar>
|
||||||
<div style="display: flex; height: 102px;">
|
<div style="display: flex; height: 102px;">
|
||||||
<div class="content" [ngClass]="{lightTheme: isLightThemeEnabled}">
|
<div class="content" [ngClass]="{lightTheme: isLightThemeEnabled}">
|
||||||
<app-adbutler (onLoad)="onLoadingAdbutler($event)" theme="dark"></app-adbutler>
|
<template #dynamicComponentContainer></template>
|
||||||
<mat-icon (click)="closeNotification()" class="close-button">close</mat-icon>
|
<mat-icon (click)="closeNotification()" class="close-button">close</mat-icon>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
import { Component, OnInit, OnDestroy } from '@angular/core';
|
import { Component, OnInit, OnDestroy, ComponentFactoryResolver, ViewContainerRef, ViewChild } from '@angular/core';
|
||||||
import { timer, Observable, Subscription } from 'rxjs';
|
import { timer, Observable, Subscription } from 'rxjs';
|
||||||
import { ThemeService } from '../../services/theme.service';
|
import { ThemeService } from '../../services/theme.service';
|
||||||
|
import { AdbutlerComponent } from '../adbutler/adbutler.component';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'app-notification-box',
|
selector: 'app-notification-box',
|
||||||
@ -8,6 +9,8 @@ import { ThemeService } from '../../services/theme.service';
|
|||||||
styleUrls: ['./notification-box.component.scss']
|
styleUrls: ['./notification-box.component.scss']
|
||||||
})
|
})
|
||||||
export class NotificationBoxComponent implements OnInit, OnDestroy {
|
export class NotificationBoxComponent implements OnInit, OnDestroy {
|
||||||
|
@ViewChild('dynamicComponentContainer', {read: ViewContainerRef, static: false}) dynamicComponentContainer;
|
||||||
|
|
||||||
timer: Observable<number>;
|
timer: Observable<number>;
|
||||||
viewTimer: Observable<number>;
|
viewTimer: Observable<number>;
|
||||||
timerSubscription: Subscription;
|
timerSubscription: Subscription;
|
||||||
@ -26,7 +29,9 @@ export class NotificationBoxComponent implements OnInit, OnDestroy {
|
|||||||
isLightThemeEnabled: boolean = false;
|
isLightThemeEnabled: boolean = false;
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
private themeService: ThemeService
|
private themeService: ThemeService,
|
||||||
|
private componentFactoryResolver: ComponentFactoryResolver,
|
||||||
|
private viewContainerRef: ViewContainerRef
|
||||||
){}
|
){}
|
||||||
|
|
||||||
ngOnInit() {
|
ngOnInit() {
|
||||||
@ -34,6 +39,20 @@ export class NotificationBoxComponent implements OnInit, OnDestroy {
|
|||||||
this.themeService.getActualTheme() === 'light' ? this.isLightThemeEnabled = true : this.isLightThemeEnabled = false;
|
this.themeService.getActualTheme() === 'light' ? this.isLightThemeEnabled = true : this.isLightThemeEnabled = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ngAfterViewInit() {
|
||||||
|
this.createDynamicAdComponent();
|
||||||
|
}
|
||||||
|
|
||||||
|
createDynamicAdComponent() : void {
|
||||||
|
const factory = this.componentFactoryResolver.resolveComponentFactory(AdbutlerComponent);
|
||||||
|
const componentRef = this.dynamicComponentContainer.createComponent(factory);
|
||||||
|
componentRef.instance.theme = this.themeService.getActualTheme() === 'light';
|
||||||
|
componentRef.instance.onLoad.subscribe(event => {
|
||||||
|
this.onLoadingAdbutler(event);
|
||||||
|
})
|
||||||
|
componentRef.changeDetectorRef.detectChanges();
|
||||||
|
}
|
||||||
|
|
||||||
startTimer() {
|
startTimer() {
|
||||||
this.timer = timer(this.delayTime, 1000);
|
this.timer = timer(this.delayTime, 1000);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user