File

app/dxa/dxa-entity/views/cookies-banner/cookies-banner/cookies-banner.component.ts

Implements

OnInit

Metadata

selector [cookies-banner]
styleUrls ./cookies-banner.component.scss
templateUrl ./cookies-banner.component.html

Index

Properties
Methods

Constructor

constructor(cookieService: CookieService, util: UtilService, dataService: DataResolverService, publicationService: PublicationService)
Parameters :
Name Type Optional
cookieService CookieService No
util UtilService No
dataService DataResolverService No
publicationService PublicationService No

Methods

Public accept
accept()
Returns : void
Public fetchCookiesBanner
fetchCookiesBanner()
Returns : void
ngOnInit
ngOnInit()
Returns : void

Properties

buttonLabel
Type : string
cookieInformationLabel
Type : string
cookiesBannerUrl
Type : string
cookiesContent
hasAcceptedCookies
Type : boolean
titleLabel
Type : string
import { Component, OnInit, Input } from '@angular/core';
import { CookieService } from 'ngx-cookie-service';
import { UtilService } from 'src/app/core/services/util-service/util.service';
import { AppConfig } from 'src/app/app.config';
import { DataResolverService } from 'src/app/core/services/data-resolver/data-resolver.service';
import { PublicationService } from 'src/app/core/services/publication-service/publication.service';

@Component({
  selector: '[cookies-banner]',
  templateUrl: './cookies-banner.component.html',
  styleUrls: ['./cookies-banner.component.scss'],

})
export class CookiesBannerComponent implements OnInit {

  cookiesContent;
  hasAcceptedCookies: boolean;
  titleLabel: string;
  buttonLabel: string;
  cookieInformationLabel: string;

  cookiesBannerUrl: string;
  
  
  constructor(private cookieService: CookieService, private util: UtilService, 
    private dataService: DataResolverService, private publicationService: PublicationService) 
  {
    this.cookiesBannerUrl = `${this.publicationService.getPublicationPath()}/system-pages/cookiesbanner.html`;
  }

  ngOnInit() {
    this.hasAcceptedCookies = this.cookieService.get(AppConfig.settings.cookiesConfig.acceptCookie) === 'yes';

    if(!this.hasAcceptedCookies) {
      this.fetchCookiesBanner();
    }
    
  }

  public accept() {
    
    this.cookieService.set(AppConfig.settings.cookiesConfig.acceptCookie, 'yes', 365, 
    AppConfig.settings.cookiesConfig.path, AppConfig.settings.cookiesConfig.domain);

    this.hasAcceptedCookies = true;
  }

  public fetchCookiesBanner(): void {
    this.dataService.getPageData(this.cookiesBannerUrl).then(page => {
      this.cookiesContent = page;
      
      const entity = this.util.extract(this.cookiesContent, 'Regions', region => region.Name === 'main', 'Entities', '0');
      this.titleLabel = entity.Title;
      this.cookieInformationLabel = entity.Text.BodyText;
      this.buttonLabel = entity.ButtonText;
    });
  }

}
<div class="cookies-banner" *ngIf="!hasAcceptedCookies && cookiesContent" [ngClass]="{'container': isDesktop, 'container-fluid': !isDesktop}">
    <h3 class="text-white cookies-title">{{titleLabel}}</h3>
    
    <div [innerHtml]="cookieInformationLabel" id="cookies-info"></div>    
    <button class="btn btn-green mr-1 mb-1" (click)="accept()">{{ buttonLabel }}</button>
</div>


./cookies-banner.component.scss

@import "src/app/styles/helpers";

.cookies-banner {
    padding: calc-rem(30);
    background-color: $dark-slate;
    text-align: center;
}

.cookies-title {
    margin: calc-rem(10);
    margin-bottom: calc-rem(20);
}

#cookies-info {
    color: $white;
    margin-bottom: calc-rem(20);
    padding-left: calc-rem(35);
    padding-right: calc-rem(35);
}

#cookies-info {
    ::ng-deep {
        p {
            margin: calc-rem(5);
        }
    }
}

#cookies-info {
    ::ng-deep {
        p > a {
            color: $light-blue;
        }
    } 
}

Legend
Html element
Component
Html element with directive

result-matching ""

    No results matching ""