diff --git a/src/app/app.component.html b/src/app/app.component.html index 8fdd966d..b2c3257b 100644 --- a/src/app/app.component.html +++ b/src/app/app.component.html @@ -4,4 +4,7 @@ +@if(!cookiesAllowed){ + +} diff --git a/src/app/app.component.ts b/src/app/app.component.ts index 690abf6a..8c34df71 100644 --- a/src/app/app.component.ts +++ b/src/app/app.component.ts @@ -2,7 +2,7 @@ import {Component, OnInit} from '@angular/core'; import { initFlowbite } from 'flowbite'; import { TranslateService } from '@ngx-translate/core'; import {LocalStorageService} from "./services/local-storage.service"; -import {Category} from "./models/interfaces"; +import {Category, CookieInfo} from "./models/interfaces"; import {EventMessageService} from "./services/event-message.service"; import { ActivatedRoute } from '@angular/router'; import { Router } from '@angular/router'; @@ -20,6 +20,7 @@ import * as moment from 'moment'; export class AppComponent implements OnInit { title = 'YUMKET deployed by the DOME Project'; showPanel = false; + cookiesAllowed:boolean=false; constructor(private translate: TranslateService, private localStorage: LocalStorageService, @@ -64,6 +65,12 @@ export class AppComponent implements OnInit { //this.refreshApi.startInterval(3000, ev.value); } + if(ev.type=='CookiesAllowed'){ + this.cookiesAllowed=true; + } + if(ev.type=='CookiesDisabled'){ + this.cookiesAllowed=false; + } }) let aux =this.localStorage.getObject('login_items') as LoginInfo; if(JSON.stringify(aux) === '{}'){ @@ -77,6 +84,10 @@ export class AppComponent implements OnInit { console.log('token') console.log(aux.token) } + let cookieInfo = this.localStorage.getObject('cookie_info') as CookieInfo; + if(cookieInfo.allowed==true){ + this.cookiesAllowed=true; + } } checkPanel() { diff --git a/src/app/app.module.ts b/src/app/app.module.ts index 40718730..5172349a 100644 --- a/src/app/app.module.ts +++ b/src/app/app.module.ts @@ -67,6 +67,7 @@ import { CategoriesComponent } from './pages/admin/categories/categories.compone import { CreateCategoryComponent } from './pages/admin/categories/create-category/create-category.component'; import { UpdateCategoryComponent } from './pages/admin/categories/update-category/update-category.component'; import { CategoriesRecursionListComponent } from './shared/categories-recursion-list/categories-recursion-list.component'; +import { CookieCardComponent } from './shared/cookie-card/cookie-card.component'; import { ContactUsComponent } from './offerings/contact-us/contact-us.component'; import { provideMatomo } from 'ngx-matomo-client'; import { withRouter } from 'ngx-matomo-client' @@ -128,7 +129,8 @@ import { appConfigFactory } from './app-config-factory'; CreateCategoryComponent, UpdateCategoryComponent, CategoriesRecursionListComponent, - ContactUsComponent + ContactUsComponent, + CookieCardComponent ], imports: [ BrowserModule, diff --git a/src/app/models/interfaces.ts b/src/app/models/interfaces.ts index 23025e66..a7a4011a 100644 --- a/src/app/models/interfaces.ts +++ b/src/app/models/interfaces.ts @@ -30,6 +30,11 @@ export interface LoginInfo { logged_as: string } +export interface CookieInfo { + allowed: boolean, + expire: number +} + export interface productSpecCharacteristicValueCart { characteristic: ProductSpecificationCharacteristic, value?: CharacteristicValueSpecification diff --git a/src/app/services/cookie-renewal.service.spec.ts b/src/app/services/cookie-renewal.service.spec.ts new file mode 100644 index 00000000..e17beb45 --- /dev/null +++ b/src/app/services/cookie-renewal.service.spec.ts @@ -0,0 +1,16 @@ +import { TestBed } from '@angular/core/testing'; + +import { CookieRenewalService } from './cookie-renewal.service'; + +describe('CookieRenewalService', () => { + let service: CookieRenewalService; + + beforeEach(() => { + TestBed.configureTestingModule({}); + service = TestBed.inject(CookieRenewalService); + }); + + it('should be created', () => { + expect(service).toBeTruthy(); + }); +}); diff --git a/src/app/services/cookie-renewal.service.ts b/src/app/services/cookie-renewal.service.ts new file mode 100644 index 00000000..170447e0 --- /dev/null +++ b/src/app/services/cookie-renewal.service.ts @@ -0,0 +1,50 @@ +import { Injectable } from '@angular/core'; +import { Observable, Subscription, interval } from 'rxjs'; +import * as moment from 'moment'; +import {LocalStorageService} from "./local-storage.service"; +import { CookieInfo } from '../models/interfaces'; +import { environment } from "src/environments/environment"; +import { Router } from '@angular/router'; +import {EventMessageService} from "./event-message.service"; + +@Injectable({ + providedIn: 'root' +}) +export class CookieRenewalService { + + private intervalObservable: Observable; + private intervalSubscription: Subscription | undefined; + + constructor( + private localStorage: LocalStorageService, + private eventMessage: EventMessageService + ) { + } + + startCookieInterval(intervalDuration: number): void { + this.intervalObservable = interval(intervalDuration); + console.log('start interval') + console.log(intervalDuration) + + this.intervalSubscription = this.intervalObservable.subscribe(() => { + console.log('cookie subscription') + + //let aux = this.localStorage.getObject('cookie_info') as CookieInfo; + this.stopCookieInterval(); + this.localStorage.setObject('cookie_info',{ + "allowed": false, + "expire": environment.COOKIE_INTERVAL + }); + //this.startCookieInterval(moment().unix()); + this.eventMessage.emitCookiesDisabled(); + + }); + } + + stopCookieInterval(): void { + if (this.intervalSubscription) { + console.log('stop cookie interval') + this.intervalSubscription.unsubscribe(); + } + } +} diff --git a/src/app/services/event-message.service.ts b/src/app/services/event-message.service.ts index 4b4472b5..4af34491 100644 --- a/src/app/services/event-message.service.ts +++ b/src/app/services/event-message.service.ts @@ -8,7 +8,7 @@ export interface EventMessage { 'SellerProductSpec' | 'SellerCreateProductSpec' | 'SellerServiceSpec' | 'SellerCreateServiceSpec' | 'SellerResourceSpec' | 'SellerCreateResourceSpec' | 'SellerOffer' | 'SellerCreateOffer' | 'SellerUpdateProductSpec' | 'SellerUpdateServiceSpec' | 'SellerUpdateResourceSpec' | 'SellerUpdateOffer' | 'SellerCatalog' | 'SellerCatalogCreate' | 'SellerCatalogUpdate' | 'CategoryAdded' | 'CategoryRemoved' | 'ChangedSession' | 'CloseCartCard'| - 'AdminCategories' | 'CreateCategory' | 'UpdateCategory' | 'ShowCartToast' | 'HideCartToast' | 'CloseContact'; + 'AdminCategories' | 'CreateCategory' | 'UpdateCategory' | 'ShowCartToast' | 'HideCartToast' | 'CloseContact' | 'CookiesAllowed' | 'CookiesDisabled'; text?: string, value?: object | boolean } @@ -157,4 +157,12 @@ export class EventMessageService { emitCloseContact(close:boolean){ this.eventMessageSubject.next({type: 'CloseContact', value: close}) } + + emitCookiesAllowed(){ + this.eventMessageSubject.next({type: 'CookiesAllowed', value: true}) + } + + emitCookiesDisabled(){ + this.eventMessageSubject.next({type: 'CookiesDisabled', value: true}) + } } diff --git a/src/app/shared/cookie-card/cookie-card.component.css b/src/app/shared/cookie-card/cookie-card.component.css new file mode 100644 index 00000000..e69de29b diff --git a/src/app/shared/cookie-card/cookie-card.component.html b/src/app/shared/cookie-card/cookie-card.component.html new file mode 100644 index 00000000..e721c25e --- /dev/null +++ b/src/app/shared/cookie-card/cookie-card.component.html @@ -0,0 +1,23 @@ + + + + + + Cookie Policy + + + + We use cookies to enhance your experience. By continuing to visit this site, you agree to our use of + cookies. + + + + Accept + + + + + + \ No newline at end of file diff --git a/src/app/shared/cookie-card/cookie-card.component.spec.ts b/src/app/shared/cookie-card/cookie-card.component.spec.ts new file mode 100644 index 00000000..bda2462f --- /dev/null +++ b/src/app/shared/cookie-card/cookie-card.component.spec.ts @@ -0,0 +1,23 @@ +import { ComponentFixture, TestBed } from '@angular/core/testing'; + +import { CookieCardComponent } from './cookie-card.component'; + +describe('CookieCardComponent', () => { + let component: CookieCardComponent; + let fixture: ComponentFixture; + + beforeEach(async () => { + await TestBed.configureTestingModule({ + imports: [CookieCardComponent] + }) + .compileComponents(); + + fixture = TestBed.createComponent(CookieCardComponent); + component = fixture.componentInstance; + fixture.detectChanges(); + }); + + it('should create', () => { + expect(component).toBeTruthy(); + }); +}); diff --git a/src/app/shared/cookie-card/cookie-card.component.ts b/src/app/shared/cookie-card/cookie-card.component.ts new file mode 100644 index 00000000..a21c5dac --- /dev/null +++ b/src/app/shared/cookie-card/cookie-card.component.ts @@ -0,0 +1,29 @@ +import { Component, OnInit } from '@angular/core'; +import { CookieRenewalService } from "src/app/services/cookie-renewal.service"; +import {LocalStorageService} from "../../services/local-storage.service"; +import {EventMessageService} from "../../services/event-message.service"; +import { CookieInfo } from 'src/app/models/interfaces'; +import { environment } from 'src/environments/environment'; +import * as moment from 'moment'; + +@Component({ + selector: 'cookie-card', + templateUrl: './cookie-card.component.html', + styleUrl: './cookie-card.component.css' +}) +export class CookieCardComponent { + constructor( + private localStorage: LocalStorageService, + private eventMessage: EventMessageService, + private cookieService: CookieRenewalService + ) { } + + allowCookies(){ + this.localStorage.setObject('cookie_info',{ + "allowed": true, + "expire": environment.COOKIE_INTERVAL + }); + this.cookieService.startCookieInterval(environment.COOKIE_INTERVAL); + this.eventMessage.emitCookiesAllowed(); + } +} diff --git a/src/environments/environment.development.ts b/src/environments/environment.development.ts index 75b801a0..730cb361 100644 --- a/src/environments/environment.development.ts +++ b/src/environments/environment.development.ts @@ -39,5 +39,7 @@ export const environment = { TICKETING_SYSTEM_URL: "", KNOWLEDGE_BASE_URL: "", SEARCH_ENABLED: true, - PURCHASE_ENABLED: false + PURCHASE_ENABLED: false, + //Cookie lasting time in milis - set to 15 days + COOKIE_INTERVAL: 1296000000 }; diff --git a/src/environments/environment.production.ts b/src/environments/environment.production.ts index cadf968a..1b48fe9b 100644 --- a/src/environments/environment.production.ts +++ b/src/environments/environment.production.ts @@ -38,5 +38,7 @@ export const environment = { TICKETING_SYSTEM_URL: "", KNOWLEDGE_BASE_URL: "", SEARCH_ENABLED: true, - PURCHASE_ENABLED: false + PURCHASE_ENABLED: false, + //Cookie lasting time in milis - set to 15 days + COOKIE_INTERVAL: 1296000000 }; diff --git a/src/environments/environment.ts b/src/environments/environment.ts index 00464980..0b164db5 100644 --- a/src/environments/environment.ts +++ b/src/environments/environment.ts @@ -40,5 +40,7 @@ export const environment = { TICKETING_SYSTEM_URL: "", KNOWLEDGE_BASE_URL: "", SEARCH_ENABLED: true, - PURCHASE_ENABLED: false + PURCHASE_ENABLED: false, + //Cookie lasting time in milis - set to 15 days + COOKIE_INTERVAL: 1296000000 };
+ We use cookies to enhance your experience. By continuing to visit this site, you agree to our use of + cookies. +