Implements Cookie Consent Popup
This commit is contained in:
44
src/app/shared/cookie-consent/cookie-consent.module.ts
Normal file
44
src/app/shared/cookie-consent/cookie-consent.module.ts
Normal file
@@ -0,0 +1,44 @@
|
||||
import {NgModule} from '@angular/core';
|
||||
import {CommonModule} from '@angular/common';
|
||||
import {NgcCookieConsentConfig, NgcCookieConsentModule} from "ngx-cookieconsent";
|
||||
|
||||
|
||||
const cookieConfig: NgcCookieConsentConfig = {
|
||||
"cookie": {
|
||||
"domain": "tinesoft.github.io"
|
||||
},
|
||||
"position": "bottom-right",
|
||||
"theme": "classic",
|
||||
"palette": {
|
||||
"popup": {
|
||||
"background": "#4e4e4e",
|
||||
"text": "#ffffff",
|
||||
"link": "#ffffff"
|
||||
},
|
||||
"button": {
|
||||
"background": "#fa2f22",
|
||||
"text": "#ffffff",
|
||||
"border": "transparent"
|
||||
}
|
||||
},
|
||||
"type": "opt-in",
|
||||
"content": {
|
||||
"message": "This website uses cookies to ensure you get the best experience on our website.",
|
||||
"dismiss": "Got it!",
|
||||
"deny": "Refuse cookies",
|
||||
"link": "",
|
||||
"href": "",
|
||||
"policy": "Cookie Policy"
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@NgModule({
|
||||
declarations: [],
|
||||
imports: [
|
||||
CommonModule,
|
||||
NgcCookieConsentModule.forRoot(cookieConfig)
|
||||
]
|
||||
})
|
||||
export class CookieConsentModule {
|
||||
}
|
||||
16
src/app/shared/cookie-consent/cookie-consert.service.spec.ts
Normal file
16
src/app/shared/cookie-consent/cookie-consert.service.spec.ts
Normal file
@@ -0,0 +1,16 @@
|
||||
import { TestBed } from '@angular/core/testing';
|
||||
|
||||
import { CookieConsertService } from './cookie-consert.service';
|
||||
|
||||
describe('CookieConsertService', () => {
|
||||
let service: CookieConsertService;
|
||||
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({});
|
||||
service = TestBed.inject(CookieConsertService);
|
||||
});
|
||||
|
||||
it('should be created', () => {
|
||||
expect(service).toBeTruthy();
|
||||
});
|
||||
});
|
||||
52
src/app/shared/cookie-consent/cookie-consert.service.ts
Normal file
52
src/app/shared/cookie-consent/cookie-consert.service.ts
Normal file
@@ -0,0 +1,52 @@
|
||||
import {Injectable} from '@angular/core';
|
||||
import {BehaviorSubject, Subject, Subscription} from "rxjs";
|
||||
import {CookieService} from "ngx-cookie-service";
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
})
|
||||
export class CookieConsertService {
|
||||
|
||||
private storage: Storage;
|
||||
|
||||
cookieStatusChangeSubscription!: BehaviorSubject<boolean>
|
||||
|
||||
constructor(private cookieService: CookieService) {
|
||||
this.storage = window.localStorage
|
||||
|
||||
this.cookieStatusChangeSubscription = new BehaviorSubject<boolean>(
|
||||
this.getCookieConsentStatusFromLocalStorage()
|
||||
);
|
||||
}
|
||||
|
||||
consent() {
|
||||
let status = true;
|
||||
|
||||
this.cookieStatusChangeSubscription.next(status);
|
||||
this.setCookieConsentStatusToLocalStorage(status);
|
||||
}
|
||||
|
||||
decline() {
|
||||
let status = false;
|
||||
|
||||
this.cookieStatusChangeSubscription.next(status);
|
||||
this.setCookieConsentStatusToLocalStorage(status);
|
||||
|
||||
this.cookieService.deleteAll();
|
||||
}
|
||||
|
||||
setCookieConsentStatusToLocalStorage(status: boolean) {
|
||||
this.storage.setItem('cookieConsentStatus', status.toString());
|
||||
}
|
||||
|
||||
getCookieConsentStatusFromLocalStorage(): boolean {
|
||||
let status = this.storage.getItem('cookieConsentStatus');
|
||||
|
||||
if (status === null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return status === 'true';
|
||||
}
|
||||
|
||||
}
|
||||
@@ -6,6 +6,7 @@ import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
|
||||
import { HttpClientModule } from '@angular/common/http';
|
||||
import { PopupComponent } from './components/popup/popup.component';
|
||||
import { FontAwesomeModule } from '@fortawesome/angular-fontawesome';
|
||||
import {CookieConsentModule} from "./cookie-consent/cookie-consent.module";
|
||||
|
||||
@NgModule({
|
||||
declarations: [
|
||||
@@ -18,6 +19,7 @@ import { FontAwesomeModule } from '@fortawesome/angular-fontawesome';
|
||||
HttpClientModule,
|
||||
BrowserAnimationsModule,
|
||||
FontAwesomeModule,
|
||||
CookieConsentModule
|
||||
],
|
||||
exports: [
|
||||
ClickedOutsideDirective,
|
||||
|
||||
Reference in New Issue
Block a user