diff --git a/ngx-cookieconsent/.editorconfig b/ngx-cookieconsent/.editorconfig new file mode 100644 index 0000000..6e87a00 --- /dev/null +++ b/ngx-cookieconsent/.editorconfig @@ -0,0 +1,13 @@ +# Editor configuration, see http://editorconfig.org +root = true + +[*] +charset = utf-8 +indent_style = space +indent_size = 2 +insert_final_newline = true +trim_trailing_whitespace = true + +[*.md] +max_line_length = off +trim_trailing_whitespace = false diff --git a/ngx-cookieconsent/.eslintrc.json b/ngx-cookieconsent/.eslintrc.json new file mode 100644 index 0000000..d7e458c --- /dev/null +++ b/ngx-cookieconsent/.eslintrc.json @@ -0,0 +1,32 @@ +{ + "root": true, + "ignorePatterns": ["**/*"], + "plugins": ["@nrwl/nx"], + "overrides": [ + { + "files": ["*.ts", "*.tsx", "*.js", "*.jsx"], + "rules": { + "@nrwl/nx/enforce-module-boundaries": [ + "error", + { + "enforceBuildableLibDependency": true, + "allow": [], + "depConstraints": [ + { "sourceTag": "*", "onlyDependOnLibsWithTags": ["*"] } + ] + } + ] + } + }, + { + "files": ["*.ts", "*.tsx"], + "extends": ["plugin:@nrwl/nx/typescript"], + "rules": {} + }, + { + "files": ["*.js", "*.jsx"], + "extends": ["plugin:@nrwl/nx/javascript"], + "rules": {} + } + ] +} diff --git a/ngx-cookieconsent/.gitignore b/ngx-cookieconsent/.gitignore new file mode 100644 index 0000000..ee5c9d8 --- /dev/null +++ b/ngx-cookieconsent/.gitignore @@ -0,0 +1,39 @@ +# See http://help.github.com/ignore-files/ for more about ignoring files. + +# compiled output +/dist +/tmp +/out-tsc + +# dependencies +/node_modules + +# IDEs and editors +/.idea +.project +.classpath +.c9/ +*.launch +.settings/ +*.sublime-workspace + +# IDE - VSCode +.vscode/* +!.vscode/settings.json +!.vscode/tasks.json +!.vscode/launch.json +!.vscode/extensions.json + +# misc +/.sass-cache +/connect.lock +/coverage +/libpeerconnection.log +npm-debug.log +yarn-error.log +testem.log +/typings + +# System Files +.DS_Store +Thumbs.db diff --git a/ngx-cookieconsent/.prettierignore b/ngx-cookieconsent/.prettierignore new file mode 100644 index 0000000..d0b804d --- /dev/null +++ b/ngx-cookieconsent/.prettierignore @@ -0,0 +1,4 @@ +# Add files here to ignore them from prettier formatting + +/dist +/coverage diff --git a/ngx-cookieconsent/.prettierrc b/ngx-cookieconsent/.prettierrc new file mode 100644 index 0000000..92cde39 --- /dev/null +++ b/ngx-cookieconsent/.prettierrc @@ -0,0 +1,3 @@ +{ + "singleQuote": true +} \ No newline at end of file diff --git a/ngx-cookieconsent/.vscode/extensions.json b/ngx-cookieconsent/.vscode/extensions.json new file mode 100644 index 0000000..3cd27bf --- /dev/null +++ b/ngx-cookieconsent/.vscode/extensions.json @@ -0,0 +1,8 @@ +{ + "recommendations": [ + "angular.ng-template", + "nrwl.angular-console", + "esbenp.prettier-vscode", + "firsttris.vscode-jest-runner" + ] +} diff --git a/ngx-cookieconsent/CHANGELOG.md b/ngx-cookieconsent/CHANGELOG.md new file mode 100644 index 0000000..d51a8d8 --- /dev/null +++ b/ngx-cookieconsent/CHANGELOG.md @@ -0,0 +1,116 @@ +## [2.2.3](https://github.com/tinesoft/ngx-cookieconsent/compare/v2.2.2...v2.2.3) (2019-06-14) + + +### Features + +* **location:** allow activating location services in config and improve typings for `NgcLawOptions`, `NgcLocationOptions` ([306fe18](https://github.com/tinesoft/ngx-cookieconsent/commit/306fe18)), closes [#57](https://github.com/tinesoft/ngx-cookieconsent/issues/57) + + + +## [2.2.2](https://github.com/tinesoft/ngx-cookieconsent/compare/v2.2.1...v2.2.2) (2019-05-28) + + +### Bug Fixes + +* **NgcCookieOptions:** add missing export ([971b65e](https://github.com/tinesoft/ngx-cookieconsent/commit/971b65e)), closes [#53](https://github.com/tinesoft/ngx-cookieconsent/issues/53) +* **sponsorship:** fix github sponsorship of yours truly ([d3a7b3d](https://github.com/tinesoft/ngx-cookieconsent/commit/d3a7b3d)) + + + +## [2.2.1](https://github.com/tinesoft/ngx-cookieconsent/compare/v2.2.0...v2.2.1) (2019-05-14) + + +### Bug Fixes + +* **typings:** correct ` ERROR TS2411` when compiling with `strict` mode on ([4fb02eb](https://github.com/tinesoft/ngx-cookieconsent/commit/4fb02eb)), closes [#49](https://github.com/tinesoft/ngx-cookieconsent/issues/49) + + + +# [2.2.0](https://github.com/tinesoft/ngx-cookieconsent/compare/v2.1.1...v2.2.0) (2019-03-28) + + +### Features + +* **customLayout:** allow customizing the cookie bar layout and content ([4b32ce0](https://github.com/tinesoft/ngx-cookieconsent/commit/4b32ce0)) + + + +## [2.1.1](https://github.com/tinesoft/ngx-cookieconsent/compare/v2.1.0...v2.1.1) (2019-02-06) + + +### Bug Fixes + +* **typings:** fix lint isssue due to bad typings in NgcCookieConsentStatus ([27ebb55](https://github.com/tinesoft/ngx-cookieconsent/commit/27ebb55)), closes [#11](https://github.com/tinesoft/ngx-cookieconsent/issues/11) + + + +# [2.1.0](https://github.com/tinesoft/ngx-cookieconsent/compare/v2.0.0...v2.1.0) (2018-10-25) + + +### Features + +* **core:** update to `cookieconsent v3.1.0` and its features ([d674b93](https://github.com/tinesoft/ngx-cookieconsent/commit/d674b93)) +* **options:** add `policy` and `target` options to `NgcContentOptions` ([a0849f2](https://github.com/tinesoft/ngx-cookieconsent/commit/a0849f2)), closes [#23](https://github.com/tinesoft/ngx-cookieconsent/issues/23) + + + +# [2.0.0](https://github.com/tinesoft/ngx-cookieconsent/compare/v1.1.1...v2.0.0) (2018-07-19) + + +### Features + +* **ng6:** add support for angular 6 ([2ab9341](https://github.com/tinesoft/ngx-cookieconsent/commit/2ab9341)), closes [#17](https://github.com/tinesoft/ngx-cookieconsent/issues/17) [#18](https://github.com/tinesoft/ngx-cookieconsent/issues/18) +* **onNoCookieLaw:** add support for `onNoCookieLaw` callback ([2d960c8](https://github.com/tinesoft/ngx-cookieconsent/commit/2d960c8)) + + +### BREAKING CHANGES + +* **ng6:** - Minimum version of Angular is now v6+ +- Minimum version of Node is v8+ + + + +## [1.1.1](https://github.com/tinesoft/ngx-cookieconsent/compare/v1.1.0...v1.1.1) (2018-07-18) + + +### Bug Fixes + +* **initialize$:** callback was never called due to typo (`onInitialise`) ([6cd260f](https://github.com/tinesoft/ngx-cookieconsent/commit/6cd260f)), closes [#19](https://github.com/tinesoft/ngx-cookieconsent/issues/19) + + + +# [1.1.0](https://github.com/tinesoft/ngx-cookieconsent/compare/v1.0.1...v1.1.0) (2018-07-03) + + +### Bug Fixes + +* **demo:** fix wrong assets url on deployed demo app ([fedcbd9](https://github.com/tinesoft/ngx-cookieconsent/commit/fedcbd9)) + + +### Features + +* **close:** add `close` method to allow fully closing the 'Coookie Policy' bar ([02ada28](https://github.com/tinesoft/ngx-cookieconsent/commit/02ada28)), closes [#15](https://github.com/tinesoft/ngx-cookieconsent/issues/15) +* **demo:** add support for translated cookie consent messages + update docs ([e1bf9bf](https://github.com/tinesoft/ngx-cookieconsent/commit/e1bf9bf)), closes [#14](https://github.com/tinesoft/ngx-cookieconsent/issues/14) + + + +## [1.0.1](https://github.com/tinesoft/ngx-cookieconsent/compare/v1.0.0...v1.0.1) (2017-11-22) + + +### Features + +* **core:** make `cookie.domain`option mandatory in configuration service and update doc ([9835145](https://github.com/tinesoft/ngx-cookieconsent/commit/9835145)) +* **demo:** update demo app to Angular CLI `1.4.7` ([37371b6](https://github.com/tinesoft/ngx-cookieconsent/commit/37371b6)) +* **packaging:** relax `peerDependencies` versions ([02496e8](https://github.com/tinesoft/ngx-cookieconsent/commit/02496e8)), closes [#8](https://github.com/tinesoft/ngx-cookieconsent/issues/8) + + + +# [1.0.0](https://github.com/tinesoft/ngx-cookieconsent/compare/5f8a340...v1.0.0) (2017-09-07) + + +### Features + +* **all:** initial commit ([5f8a340](https://github.com/tinesoft/ngx-cookieconsent/commit/5f8a340)) + + + diff --git a/ngx-cookieconsent/LICENSE b/ngx-cookieconsent/LICENSE new file mode 100644 index 0000000..480a1ea --- /dev/null +++ b/ngx-cookieconsent/LICENSE @@ -0,0 +1,22 @@ +The MIT License (MIT) + +Copyright (c) 2018-2021 Tine Kondo + +Permission is hereby granted, free of charge, to any person obtaining +a copy of this software and associated documentation files (the +"Software"), to deal in the Software without restriction, including +without limitation the rights to use, copy, modify, merge, publish, +distribute, sublicense, and/or sell copies of the Software, and to +permit persons to whom the Software is furnished to do so, subject to +the following conditions: + +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/ngx-cookieconsent/README.md b/ngx-cookieconsent/README.md new file mode 100644 index 0000000..eb02e90 --- /dev/null +++ b/ngx-cookieconsent/README.md @@ -0,0 +1,350 @@ +
+ +
+ +# ngx-cookieconsent - [Cookie Consent](https://cookieconsent.insites.com/) module for Angular. + +[![npm version](https://badge.fury.io/js/ngx-cookieconsent.svg)](https://badge.fury.io/js/ngx-cookieconsent) +[![Build Status](https://travis-ci.org/tinesoft/ngx-cookieconsent.svg?branch=master)](https://travis-ci.org/tinesoft/ngx-cookieconsent) +[![Coverage Status](https://coveralls.io/repos/github/tinesoft/ngx-cookieconsent/badge.svg?branch=master)](https://coveralls.io/github/tinesoft/ngx-cookieconsent?branch=master) +[![dependency Status](https://david-dm.org/tinesoft/ngx-cookieconsent/status.svg)](https://david-dm.org/tinesoft/ngx-cookieconsent) +[![devDependency Status](https://david-dm.org/tinesoft/ngx-cookieconsent/dev-status.svg?branch=master)](https://david-dm.org/tinesoft/ngx-cookieconsent#info=devDependencies) +[![Greenkeeper Badge](https://badges.greenkeeper.io/tinesoft/ngx-cookieconsent.svg)](https://greenkeeper.io/) + +## Demo + +View the module in action at https://tinesoft.github.io/ngx-cookieconsent + +## Dependencies +* [Angular](https://angular.io) (*requires* Angular 6+, [v1.1.0](https://github.com/tinesoft/ngx-cookieconsent/tree/v1.1.0) is the latest version for Angular < 6 ) +* [Cookie Consent](https://cookieconsent.insites.com/) (*requires* Cookie Consent 3 or higher, tested with 3.1.0) + + +## Installation +Install above dependencies via *npm*. In particular for `Cookie Consent`: +```shell +npm install --save cookieconsent +``` + +Now install `ngx-cookieconsent` via: +```shell +npm install --save ngx-cookieconsent +``` + +--- +##### Angular-CLI +>**Note**: If you are using `angular-cli` to build your app, make sure that `cookieconsent` is properly listed as a [global library](https://github.com/angular/angular-cli/wiki/stories-global-scripts), and as [global style](https://github.com/angular/angular-cli/wiki/stories-global-styles). + +To do so, edit your `angular-cli.json` as such: +``` + "scripts": [ + "node_modules/cookieconsent/build/cookieconsent.min.js" + ], + + "styles": [ + "node_modules/cookieconsent/build/cookieconsent.min.css" + ], + +``` + +##### SystemJS +>**Note**:If you are using `SystemJS`, you should adjust your configuration to point to the UMD bundle. +In your systemjs config file, `map` needs to tell the System loader where to look for `ngx-cookieconsent`: +```js +map: { + 'ngx-cookieconsent': 'node_modules/ngx-cookieconsent/bundles/ngx-cookieconsent.umd.js', +} +``` +In your systemjs config file, `meta` needs to tell the System loader how to load `cookieconsent`: +```js + meta: { + './node_modules/cookieconsent/build/cookieconsent.min.js': { + format: 'amd' + } + } +``` +In your index.html file, add script and link tags to load `cookieconsent` globally: +```html + + + + + +``` + +--- + +Once installed you need to import the main module: +```ts +import {NgcCookieConsentModule} from 'ngx-cookieconsent'; +``` +The only remaining part is to list the imported module in your application module. The exact method will be slightly +different for the root (top-level) module for which you should end up with the code similar to (notice `NgcCookieConsentModule.forRoot()`): +```ts +import {NgcCookieConsentModule, NgcCookieConsentConfig} from 'ngx-cookieconsent'; + +const cookieConfig:NgcCookieConsentConfig = { + cookie: { + domain: 'localhost' // or 'your.domain.com' // it is mandatory to set a domain, for cookies to work properly (see https://goo.gl/S2Hy2A) + }, + palette: { + popup: { + background: '#000' + }, + button: { + background: '#f1d600' + } + }, + theme: 'edgeless', + type: 'opt-out' +}; + + +@NgModule({ + declarations: [AppComponent, ...], + imports: [NgcCookieConsentModule.forRoot(cookieConfig), ...], + bootstrap: [AppComponent] +}) +export class AppModule { +} +``` + +Other modules in your application can simply import `NgcCookieConsentModule`: + +```ts +import {NgcCookieConsentModule} from 'ngx-cookieconsent'; + +@NgModule({ + declarations: [OtherComponent, ...], + imports: [NgcCookieConsentModule, ...], +}) +export class OtherModule { +} +``` + +## Usage + +Inject the `NgcCookieContentService` in your main component (i.e. `AppComponent`) to show the cookie consent popup after the component is loaded. You don't need to explicitly call its `init()` method (done automatically when the service's constructor gets called upon instantiation By Angular). + +Also, you can use the injected `NgcCookieContentService` to update the config (using `init()`), subscribe to events and do stuff like disabling cookies or other. + +Here is how it works: + +```ts +import { Component, OnInit, OnDestroy } from '@angular/core'; +import { NgcCookieConsentService } from 'ngx-cookieconsent'; +import { Subscription } from 'rxjs'; + +@Component({ + selector: 'app-root', + templateUrl: './app.component.html', + styleUrls: ['./app.component.scss'] +}) +export class AppComponent implements OnInit, OnDestroy { + + //keep refs to subscriptions to be able to unsubscribe later + private popupOpenSubscription: Subscription; + private popupCloseSubscription: Subscription; + private initializeSubscription: Subscription; + private statusChangeSubscription: Subscription; + private revokeChoiceSubscription: Subscription; + private noCookieLawSubscription: Subscription; + + constructor(private ccService: NgcCookieConsentService){} + + ngOnInit() { + // subscribe to cookieconsent observables to react to main events + this.popupOpenSubscription = this.ccService.popupOpen$.subscribe( + () => { + // you can use this.ccService.getConfig() to do stuff... + }); + + this.popupCloseSubscription = this.ccService.popupClose$.subscribe( + () => { + // you can use this.ccService.getConfig() to do stuff... + }); + + this.initializeSubscription = this.ccService.initialize$.subscribe( + (event: NgcInitializeEvent) => { + // you can use this.ccService.getConfig() to do stuff... + }); + + this.statusChangeSubscription = this.ccService.statusChange$.subscribe( + (event: NgcStatusChangeEvent) => { + // you can use this.ccService.getConfig() to do stuff... + }); + + this.revokeChoiceSubscription = this.ccService.revokeChoice$.subscribe( + () => { + // you can use this.ccService.getConfig() to do stuff... + }); + + this.noCookieLawSubscription = this.ccService.noCookieLaw$.subscribe( + (event: NgcNoCookieLawEvent) => { + // you can use this.ccService.getConfig() to do stuff... + }); + } + + ngOnDestroy() { + // unsubscribe to cookieconsent observables to prevent memory leaks + this.popupOpenSubscription.unsubscribe(); + this.popupCloseSubscription.unsubscribe(); + this.initializeSubscription.unsubscribe(); + this.statusChangeSubscription.unsubscribe(); + this.revokeChoiceSubscription.unsubscribe(); + this.noCookieLawSubscription.unsubscribe(); + } +} + +``` + +See [Cookie Consent Documentation](https://cookieconsent.insites.com/documentation/about-cookie-consent/) to see more about how to customize the UI or interact with user interactions. + +## I18n Support + +Messages displayed in the Cookie Consent Bar can easily be translated, using libraries like [ngx-translate](https://github.com/ngx-translate/core). +Basically this involved the following steps (using ngx-translate + Anglar CLI): + +* [Install](https://github.com/ngx-translate/core#installation) and [configure](https://github.com/ngx-translate/core#usage) `ngx-translate` + +* Provide the translation JSON files in `src/assets/`, for e.g: `en.json`, `fr.json`, ... + +```JSON +{ + "cookie": { + "header": "Cookies used on the website!", + "message": "This website uses cookies to ensure you get the best experience on our website.", + "dismiss": "Got it!", + "allow": "Allow cookies", + "deny": "Decline", + "link": "Learn more", + "policy": "Cookie Policy" + } +} +``` + +> **Note:** see [content-options.ts](https://github.com/tinesoft/ngx-cookieconsent/blob/master/src/model/content-options.ts) for complete list of messages that can be translated. + +* Configure your main component `AppComponent` + +```ts +import { Component, OnInit } from '@angular/core'; +import { TranslateService } from '@ngx-translate/core'; + +@Component({ + selector: 'app-root', + templateUrl: './app.component.html', + styleUrls: ['./app.component.scss'] +}) +export class AppComponent { + + constructor(private ccService: NgcCookieConsentService, private translateService:TranslateService) { + } + + ngOnInit() { + // Support for translated cookies messages + this.translateService.addLangs(['en', 'fr']); + this.translateService.setDefaultLang('en'); + + const browserLang = this.translateService.getBrowserLang(); + this.translateService.use(browserLang.match(/en|fr/) ? browserLang : 'en'); + + this.translateService// + .get(['cookie.header', 'cookie.message', 'cookie.dismiss', 'cookie.allow', 'cookie.deny', 'cookie.link', 'cookie.policy']) + .subscribe(data => { + + this.ccService.getConfig().content = this.ccService.getConfig().content || {} ; + // Override default messages with the translated ones + this.ccService.getConfig().content.header = data['cookie.header']; + this.ccService.getConfig().content.message = data['cookie.message']; + this.ccService.getConfig().content.dismiss = data['cookie.dismiss']; + this.ccService.getConfig().content.allow = data['cookie.allow']; + this.ccService.getConfig().content.deny = data['cookie.deny']; + this.ccService.getConfig().content.link = data['cookie.link']; + this.ccService.getConfig().content.policy = data['cookie.policy']; + + this.ccService.destroy(); // remove previous cookie bar (with default messages) + this.ccService.init(this.ccService.getConfig()); // update config with translated messages + }); + } +} +``` + +## Custom Layout Support + +Cookie Consent supports [custom layouts](https://cookieconsent.insites.com/documentation/javascript-api/#layout_options), and so does `ngx-cookieconsent`. +So if your are not happy with the default appearance of the cookie bar, you can totally customize it to better suit your needs. This involves overriding a few options: + +* [NgcCookieConsentConfig.layout](https://github.com/tinesoft/ngx-cookieconsent/blob/master/src/service/cookieconsent-config.ts#L78): to define the name of your custom layout to use. For e.g `my-custom-layout` +* [NgcCookieConsentConfig.layouts](https://github.com/tinesoft/ngx-cookieconsent/blob/master/src/service/cookieconsent-config.ts#L73): to define your custom layout HTML. Elements between `{{` and `}}` will be replaced by their content (see in `[NgcCookieConsentConfig.content` below) +* [NgcCookieConsentConfig.elements](https://github.com/tinesoft/ngx-cookieconsent/blob/master/src/model/cookieconsent-config.ts#L44) : html elements referenced in the custom layout (between `{{` and `}}`) +* [NgcCookieConsentConfig.content](https://github.com/tinesoft/ngx-cookieconsent/blob/master/src/model/cookieconsent-config.ts#L36) : content of elements referenced in the custom elements above (between `{{` and `}}`) + +Here is a example of a **custom layout**, that is inspired from the default 'basic' layout , but simply changes the message and links that are displayed in the bar. + ++ +
+ +```ts +import {NgcCookieConsentModule, NgcCookieConsentConfig} from 'ngx-cookieconsent'; + +const cookieConfig:NgcCookieConsentConfig = { + cookie: { + domain: 'localhost'// it is recommended to set your domain, for cookies to work properly + }, + palette: { + popup: { + background: '#000' + }, + button: { + background: '#f1d600' + } + }, + theme: 'edgeless', + type: 'opt-out', + layout: 'my-custom-layout', + layouts: { + "my-custom-layout": '{{messagelink}}{{compliance}}' + }, + elements:{ + messagelink: ` + + `, + }, + content:{ + message: 'By using our site, you acknowledge that you have read and understand our ', + + cookiePolicyLink: 'Cookie Policy', + cookiePolicyHref: 'https://cookie.com', + + privacyPolicyLink: 'Privacy Policy', + privacyPolicyHref: 'https://privacy.com', + + tosLink: 'Terms of Service', + tosHref: 'https://tos.com', + } +}; + + +@NgModule({ + declarations: [AppComponent, ...], + imports: [NgcCookieConsentModule.forRoot(cookieConfig), ...], + bootstrap: [AppComponent] +}) +export class AppModule { +} +``` + +## Credits + +`ngx-cookieconsent` is built upon [Cookie Consent](https://www.osano.com/cookieconsent/), by [Osano](https://osano.com) + +## License + +Copyright (c) 2018-2021 Tine Kondo. Licensed under the MIT License (MIT) + diff --git a/ngx-cookieconsent/angular.json b/ngx-cookieconsent/angular.json new file mode 100644 index 0000000..c22f608 --- /dev/null +++ b/ngx-cookieconsent/angular.json @@ -0,0 +1,251 @@ +{ + "version": 1, + "cli": { + "defaultCollection": "@nrwl/angular" + }, + "defaultProject": "ngx-cookieconsent-demo", + "schematics": { + "@nrwl/angular": { + "application": { + "linter": "eslint" + }, + "library": { + "linter": "eslint" + }, + "storybook-configuration": { + "linter": "eslint" + } + }, + "@nrwl/angular:application": { + "style": "scss", + "linter": "eslint", + "unitTestRunner": "jest", + "e2eTestRunner": "cypress" + }, + "@nrwl/angular:library": { + "style": "scss", + "linter": "eslint", + "unitTestRunner": "jest" + }, + "@nrwl/angular:component": { + "style": "scss" + } + }, + "projects": { + "ngx-cookieconsent-demo": { + "projectType": "application", + "root": "apps/ngx-cookieconsent-demo", + "sourceRoot": "apps/ngx-cookieconsent-demo/src", + "prefix": "ngx-cookieconsent", + "architect": { + "build": { + "builder": "@angular-devkit/build-angular:browser", + "options": { + "outputPath": "dist/ngx-cookieconsent-demo/browser", + "index": "apps/ngx-cookieconsent-demo/src/index.html", + "main": "apps/ngx-cookieconsent-demo/src/main.ts", + "polyfills": "apps/ngx-cookieconsent-demo/src/polyfills.ts", + "tsConfig": "apps/ngx-cookieconsent-demo/tsconfig.app.json", + "inlineStyleLanguage": "scss", + "assets": [ + "apps/ngx-cookieconsent-demo/src/favicon.ico", + "apps/ngx-cookieconsent-demo/src/assets" + ], + "styles": ["apps/ngx-cookieconsent-demo/src/styles.scss"], + "scripts": ["node_modules/cookieconsent/build/cookieconsent.min.js"] + }, + "configurations": { + "production": { + "budgets": [ + { + "type": "initial", + "maximumWarning": "500kb", + "maximumError": "1mb" + }, + { + "type": "anyComponentStyle", + "maximumWarning": "2kb", + "maximumError": "4kb" + } + ], + "fileReplacements": [ + { + "replace": "apps/ngx-cookieconsent-demo/src/environments/environment.ts", + "with": "apps/ngx-cookieconsent-demo/src/environments/environment.prod.ts" + } + ], + "outputHashing": "all" + }, + "development": { + "buildOptimizer": false, + "optimization": false, + "vendorChunk": true, + "extractLicenses": false, + "sourceMap": true, + "namedChunks": true + } + }, + "defaultConfiguration": "production" + }, + "serve": { + "builder": "@angular-devkit/build-angular:dev-server", + "configurations": { + "production": { + "browserTarget": "ngx-cookieconsent-demo:build:production" + }, + "development": { + "browserTarget": "ngx-cookieconsent-demo:build:development" + } + }, + "defaultConfiguration": "development" + }, + "extract-i18n": { + "builder": "@angular-devkit/build-angular:extract-i18n", + "options": { + "browserTarget": "ngx-cookieconsent-demo:build" + } + }, + "lint": { + "builder": "@nrwl/linter:eslint", + "options": { + "lintFilePatterns": [ + "apps/ngx-cookieconsent-demo/src/**/*.ts", + "apps/ngx-cookieconsent-demo/src/**/*.html" + ] + } + }, + "test": { + "builder": "@nrwl/jest:jest", + "outputs": ["coverage/apps/ngx-cookieconsent-demo"], + "options": { + "jestConfig": "apps/ngx-cookieconsent-demo/jest.config.js", + "passWithNoTests": true + } + }, + "server": { + "builder": "@angular-devkit/build-angular:server", + "options": { + "outputPath": "dist/ngx-cookieconsent-demo/server", + "main": "apps/ngx-cookieconsent-demo/server.ts", + "tsConfig": "apps/ngx-cookieconsent-demo/tsconfig.server.json", + "inlineStyleLanguage": "scss" + }, + "configurations": { + "production": { + "outputHashing": "media", + "fileReplacements": [ + { + "replace": "apps/ngx-cookieconsent-demo/src/environments/environment.ts", + "with": "apps/ngx-cookieconsent-demo/src/environments/environment.prod.ts" + } + ] + }, + "development": { + "optimization": false, + "sourceMap": true, + "extractLicenses": false + } + }, + "defaultConfiguration": "production" + }, + "serve-ssr": { + "builder": "@nguniversal/builders:ssr-dev-server", + "configurations": { + "development": { + "browserTarget": "ngx-cookieconsent-demo:build:development", + "serverTarget": "ngx-cookieconsent-demo:server:development" + }, + "production": { + "browserTarget": "ngx-cookieconsent-demo:build:production", + "serverTarget": "ngx-cookieconsent-demo:server:production" + } + }, + "defaultConfiguration": "development" + }, + "prerender": { + "builder": "@nguniversal/builders:prerender", + "options": { + "routes": [ + "/" + ] + }, + "configurations": { + "production": { + "browserTarget": "ngx-cookieconsent-demo:build:production" + }, + "development": { + "browserTarget": "ngx-cookieconsent-demo:build:development" + } + }, + "defaultConfiguration": "production" + } + } + }, + "ngx-cookieconsent-demo-e2e": { + "root": "apps/ngx-cookieconsent-demo-e2e", + "sourceRoot": "apps/ngx-cookieconsent-demo-e2e/src", + "projectType": "application", + "architect": { + "e2e": { + "builder": "@nrwl/cypress:cypress", + "options": { + "cypressConfig": "apps/ngx-cookieconsent-demo-e2e/cypress.json", + "tsConfig": "apps/ngx-cookieconsent-demo-e2e/tsconfig.e2e.json", + "devServerTarget": "ngx-cookieconsent-demo:serve:development" + }, + "configurations": { + "production": { + "devServerTarget": "ngx-cookieconsent-demo:serve:production" + } + } + }, + "lint": { + "builder": "@nrwl/linter:eslint", + "options": { + "lintFilePatterns": ["apps/ngx-cookieconsent-demo-e2e/**/*.{js,ts}"] + } + } + } + }, + "ngx-cookieconsent": { + "projectType": "library", + "root": "libs/ngx-cookieconsent", + "sourceRoot": "libs/ngx-cookieconsent/src", + "prefix": "ngx-cookieconsent", + "architect": { + "build": { + "builder": "@nrwl/angular:package", + "options": { + "project": "libs/ngx-cookieconsent/ng-package.json" + }, + "configurations": { + "production": { + "tsConfig": "libs/ngx-cookieconsent/tsconfig.lib.prod.json" + }, + "development": { + "tsConfig": "libs/ngx-cookieconsent/tsconfig.lib.json" + } + }, + "defaultConfiguration": "production" + }, + "test": { + "builder": "@nrwl/jest:jest", + "outputs": ["coverage/libs/ngx-cookieconsent"], + "options": { + "jestConfig": "libs/ngx-cookieconsent/jest.config.js", + "passWithNoTests": true + } + }, + "lint": { + "builder": "@nrwl/linter:eslint", + "options": { + "lintFilePatterns": [ + "libs/ngx-cookieconsent/src/**/*.ts", + "libs/ngx-cookieconsent/src/**/*.html" + ] + } + } + } + } + } +} diff --git a/ngx-cookieconsent/apps/.gitkeep b/ngx-cookieconsent/apps/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/ngx-cookieconsent/apps/ngx-cookieconsent-demo-e2e/.eslintrc.json b/ngx-cookieconsent/apps/ngx-cookieconsent-demo-e2e/.eslintrc.json new file mode 100644 index 0000000..ff98cb5 --- /dev/null +++ b/ngx-cookieconsent/apps/ngx-cookieconsent-demo-e2e/.eslintrc.json @@ -0,0 +1,20 @@ +{ + "extends": ["plugin:cypress/recommended", "../../.eslintrc.json"], + "ignorePatterns": ["!**/*"], + "overrides": [ + { + "files": ["*.ts", "*.tsx", "*.js", "*.jsx"], + "parserOptions": { + "project": "apps/ngx-cookieconsent-demo-e2e/tsconfig.*?.json" + }, + "rules": {} + }, + { + "files": ["src/plugins/index.js"], + "rules": { + "@typescript-eslint/no-var-requires": "off", + "no-undef": "off" + } + } + ] +} diff --git a/ngx-cookieconsent/apps/ngx-cookieconsent-demo-e2e/cypress.json b/ngx-cookieconsent/apps/ngx-cookieconsent-demo-e2e/cypress.json new file mode 100644 index 0000000..caaea0c --- /dev/null +++ b/ngx-cookieconsent/apps/ngx-cookieconsent-demo-e2e/cypress.json @@ -0,0 +1,12 @@ +{ + "fileServerFolder": ".", + "fixturesFolder": "./src/fixtures", + "integrationFolder": "./src/integration", + "modifyObstructiveCode": false, + "pluginsFile": "./src/plugins/index", + "supportFile": "./src/support/index.ts", + "video": true, + "videosFolder": "../../dist/cypress/apps/ngx-cookieconsent-demo-e2e/videos", + "screenshotsFolder": "../../dist/cypress/apps/ngx-cookieconsent-demo-e2e/screenshots", + "chromeWebSecurity": false +} diff --git a/ngx-cookieconsent/apps/ngx-cookieconsent-demo-e2e/src/fixtures/example.json b/ngx-cookieconsent/apps/ngx-cookieconsent-demo-e2e/src/fixtures/example.json new file mode 100644 index 0000000..294cbed --- /dev/null +++ b/ngx-cookieconsent/apps/ngx-cookieconsent-demo-e2e/src/fixtures/example.json @@ -0,0 +1,4 @@ +{ + "name": "Using fixtures to represent data", + "email": "hello@cypress.io" +} diff --git a/ngx-cookieconsent/apps/ngx-cookieconsent-demo-e2e/src/integration/app.spec.ts b/ngx-cookieconsent/apps/ngx-cookieconsent-demo-e2e/src/integration/app.spec.ts new file mode 100644 index 0000000..3558716 --- /dev/null +++ b/ngx-cookieconsent/apps/ngx-cookieconsent-demo-e2e/src/integration/app.spec.ts @@ -0,0 +1,13 @@ +import { getGreeting } from '../support/app.po'; + +describe('ngx-cookieconsent-demo', () => { + beforeEach(() => cy.visit('/')); + + it('should display welcome message', () => { + // Custom command example, see `../support/commands.ts` file + cy.login('my-email@something.com', 'myPassword'); + + // Function helper example, see `../support/app.po.ts` file + getGreeting().contains('Welcome to ngx-cookieconsent-demo!'); + }); +}); diff --git a/ngx-cookieconsent/apps/ngx-cookieconsent-demo-e2e/src/plugins/index.js b/ngx-cookieconsent/apps/ngx-cookieconsent-demo-e2e/src/plugins/index.js new file mode 100644 index 0000000..9067e75 --- /dev/null +++ b/ngx-cookieconsent/apps/ngx-cookieconsent-demo-e2e/src/plugins/index.js @@ -0,0 +1,22 @@ +// *********************************************************** +// This example plugins/index.js can be used to load plugins +// +// You can change the location of this file or turn off loading +// the plugins file with the 'pluginsFile' configuration option. +// +// You can read more here: +// https://on.cypress.io/plugins-guide +// *********************************************************** + +// This function is called when a project is opened or re-opened (e.g. due to +// the project's config changing) + +const { preprocessTypescript } = require('@nrwl/cypress/plugins/preprocessor'); + +module.exports = (on, config) => { + // `on` is used to hook into various events Cypress emits + // `config` is the resolved Cypress config + + // Preprocess Typescript file using Nx helper + on('file:preprocessor', preprocessTypescript(config)); +}; diff --git a/ngx-cookieconsent/apps/ngx-cookieconsent-demo-e2e/src/support/app.po.ts b/ngx-cookieconsent/apps/ngx-cookieconsent-demo-e2e/src/support/app.po.ts new file mode 100644 index 0000000..3293424 --- /dev/null +++ b/ngx-cookieconsent/apps/ngx-cookieconsent-demo-e2e/src/support/app.po.ts @@ -0,0 +1 @@ +export const getGreeting = () => cy.get('h1'); diff --git a/ngx-cookieconsent/apps/ngx-cookieconsent-demo-e2e/src/support/commands.ts b/ngx-cookieconsent/apps/ngx-cookieconsent-demo-e2e/src/support/commands.ts new file mode 100644 index 0000000..310f1fa --- /dev/null +++ b/ngx-cookieconsent/apps/ngx-cookieconsent-demo-e2e/src/support/commands.ts @@ -0,0 +1,33 @@ +// *********************************************** +// This example commands.js shows you how to +// create various custom commands and overwrite +// existing commands. +// +// For more comprehensive examples of custom +// commands please read more here: +// https://on.cypress.io/custom-commands +// *********************************************** + +// eslint-disable-next-line @typescript-eslint/no-namespace +declare namespace Cypress { + // eslint-disable-next-line @typescript-eslint/no-unused-vars + interface ChainableInstall above dependencies via npm. In particular for Cookie Consent
:
+npm install --save cookieconsent
Now install ngx-cookieconsent
via:
+npm install --save ngx-cookieconsent
++Note: If you are using
+angular-cli
to build your app, make sure thatcookieconsent
is properly listed as a global library, and as global style.
To do so, edit your angular-cli.json
as such:
+"scripts":"../node_modules/cookieconsent/build/cookieconsent.min.js""styles":"../node_modules/cookieconsent/build/cookieconsent.min.css"
++Note:If you are using
+SystemJS
, you should adjust your configuration to point to the UMD bundle. +In your systemjs config file,map
needs to tell the System loader where to look forngx-cookieconsent
:
+map:'ngx-cookieconsent': 'node_modules/ngx-cookieconsent/bundles/ngx-cookieconsent.umd.js'
In your systemjs config file, meta
needs to tell the System loader how to load cookieconsent
:
+meta:'./node_modules/cookieconsent/build/cookieconsent.min.js':format: 'amd'
In your index.html file, add script and link tags to load cookieconsent
globally:
+<!-- 1 Configure SystemJS --><script src="system.config.js"></script><!-- 2 Add cookieconsent dependency--><link rel="stylesheet" type="text/css" href="node_modules/cookieconsent/build/cookieconsent.min.css"/><script src="node_modules/cookieconsent/build/cookieconsent.min.js"></script>
Once installed you need to import the main module:
++;
The only remaining part is to list the imported module in your application module. The exact method will be slightly
+different for the root (top-level) module for which you should end up with the code similar to (notice NgcCookieConsentModule.forRoot()
):
+;const cookieConfig:NgcCookieConsentConfig =cookie:domain: 'localhost' // or 'your.domain.com' // it is mandatory to set a domain, for cookies to work properly (see https://goo.gl/S2Hy2A)palette:popup:background: '#000'button:background: '#f1d600'theme: 'edgeless'type: 'opt-out';@
Other modules in your application can simply import NgcCookieConsentModule
:
+;@
Once the module is imported, you can use the NgcCookieContentService
in your component (i.e. AppComponent
) to subscribe to main events fired by Cookie Consent and do stuff like disabling cookies or other.
Here is how it works:
++;;;@implements OnInit OnDestroy//keep refs to subscriptions to be able to unsubscribe laterprivate popupOpenSubscription: Subscription;private popupCloseSubscription: Subscription;private initializeSubscription: Subscription;private statusChangeSubscription: Subscription;private revokeChoiceSubscription: Subscription;private noCookieLawSubscription: Subscription;{{ '{' }}}{{ '{' }}// subscribe to cookieconsent observables to react to main eventsthispopupOpenSubscription = thisccServicepopupOpen$;thispopupCloseSubscription = thisccServicepopupClose$;thisinitializeSubscription = thisccServiceinitialize$;thisstatusChangeSubscription = thisccServicestatusChange$;thisrevokeChoiceSubscription = thisccServicerevokeChoice$;thisnoCookieLawSubscription = thisccServicenoCookieLaw$;}{{ '{' }}// unsubscribe to cookieconsent observables to prevent memory leaksthispopupOpenSubscription;thispopupCloseSubscription;thisinitializeSubscription;thisstatusChangeSubscription;thisrevokeChoiceSubscription;thisnoCookieLawSubscription;}
See Cookie Consent Documentation to see more about how to customize the UI or interact with user interactions.
+Messages displayed in the Cookie Consent Bar can easily be translated, using libraries like ngx-translate. +Basically this involved the following steps (using ngx-translate + Anglar CLI):
+Provide the translation JSON files in src/assets/
, for e.g: en.json
, fr.json
, ...
+"cookie":"header": "Cookies used on the website!""message": "This website uses cookies to ensure you get the best experience on our website.""dismiss": "Got it!""allow": "Allow cookies""deny": "Decline""link": "Learn more""policy": "Cookie Policy"
++Note: see content-options.ts for complete list of messages that can be translated.
+
AppComponent
+;;@{{ '{' }}}{{ '{' }}// Support for translated cookies messagesthistranslateService;thistranslateService;const browserLang = thistranslateService;thistranslateService;thistranslateService//;}
ngx-cookieconsent
is built upon Cookie Consent, created by Insites
Copyright (c) 2018 Tine Kondo. Licensed under the MIT License (MIT)
+ +{{ options | json }}+ +
+ For help and additional options see the official documentation. +
\ No newline at end of file diff --git a/ngx-cookieconsent/apps/ngx-cookieconsent-demo/src/app/home/playground/playground.component.scss b/ngx-cookieconsent/apps/ngx-cookieconsent-demo/src/app/home/playground/playground.component.scss new file mode 100644 index 0000000..e69de29 diff --git a/ngx-cookieconsent/apps/ngx-cookieconsent-demo/src/app/home/playground/playground.component.spec.ts b/ngx-cookieconsent/apps/ngx-cookieconsent-demo/src/app/home/playground/playground.component.spec.ts new file mode 100644 index 0000000..6cfd719 --- /dev/null +++ b/ngx-cookieconsent/apps/ngx-cookieconsent-demo/src/app/home/playground/playground.component.spec.ts @@ -0,0 +1,25 @@ +import { async, ComponentFixture, TestBed } from '@angular/core/testing'; + +import { PlaygroundComponent } from './playground.component'; + +describe('PlaygroundComponent', () => { + let component: PlaygroundComponent; + let fixture: ComponentFixture