File
Implements
Metadata
| selector |
cx-anonymous-consent-management-banner |
| templateUrl |
./anonymous-consent-management-banner.component.html |
Methods
|
ngOnDestroy
|
ngOnDestroy()
|
|
|
|
|
|
viewDetails
|
viewDetails()
|
|
|
|
|
|
bannerVisible$
|
Type : Observable<boolean>
|
Default value : this.anonymousConsentsService.isBannerVisible()
|
|
|
|
Private
subscriptions
|
Default value : new Subscription()
|
|
|
import { Component, OnDestroy, ViewContainerRef } from '@angular/core';
import { AnonymousConsentsService } from '@spartacus/core';
import { LaunchDialogService } from '../../../layout/launch-dialog/services/launch-dialog.service';
import { LAUNCH_CALLER } from '../../../layout/launch-dialog/config/launch-config';
import { Observable, Subscription } from 'rxjs';
import { tap } from 'rxjs/operators';
@Component({
selector: 'cx-anonymous-consent-management-banner',
templateUrl: './anonymous-consent-management-banner.component.html',
})
export class AnonymousConsentManagementBannerComponent implements OnDestroy {
private subscriptions = new Subscription();
bannerVisible$: Observable<boolean> =
this.anonymousConsentsService.isBannerVisible();
constructor(
protected anonymousConsentsService: AnonymousConsentsService,
protected vcr: ViewContainerRef,
protected launchDialogService: LaunchDialogService
) {}
viewDetails(): void {
this.hideBanner();
const dialog = this.launchDialogService.openDialog(
LAUNCH_CALLER.ANONYMOUS_CONSENT,
null,
this.vcr
);
if (dialog) {
this.subscriptions.add(dialog.subscribe());
}
}
allowAll(): void {
this.subscriptions.add(
this.anonymousConsentsService
.giveAllConsents()
.pipe(tap(() => this.hideBanner()))
.subscribe()
);
}
hideBanner(): void {
this.anonymousConsentsService.toggleBannerDismissed(true);
}
ngOnDestroy(): void {
this.subscriptions.unsubscribe();
}
}
<ng-container *ngIf="bannerVisible$ | async as bannerVisible">
<div
[ngClass]="{ 'anonymous-consent-banner-hidden': !bannerVisible }"
class="anonymous-consent-banner"
>
<div class="container">
<div class="row">
<div class="col-lg-8 col-xs-12">
<div class="cx-banner-title">
{{ 'anonymousConsents.banner.title' | cxTranslate }}
</div>
<div class="cx-banner-description">
{{ 'anonymousConsents.banner.description' | cxTranslate }}
</div>
</div>
<div class="col-lg-4 col-xs-12 cx-banner-buttons">
<button class="btn btn-action" (click)="viewDetails()">
{{ 'anonymousConsents.banner.viewDetails' | cxTranslate }}
</button>
<button class="btn btn-primary" (click)="allowAll()">
{{ 'anonymousConsents.banner.allowAll' | cxTranslate }}
</button>
</div>
</div>
</div>
</div>
</ng-container>
Legend
Html element with directive