From 9b45b4290f651e9d8f3fe83a4904f14f34a38296 Mon Sep 17 00:00:00 2001 From: luisramos0 Date: Thu, 28 Jun 2018 01:52:09 +0100 Subject: [PATCH] added cookies banner (with link to cookie policy page) and accept cookies button --- .../cookies_banner/cookies_banner.html.haml | 15 +++++++ .../cookies_banner_controller.js.coffee | 5 +++ .../cookies_banner_directive.js.coffee | 5 +++ .../cookies_banner_service.js.coffee | 20 +++++++++ .../cookies_policy_modal_service.js.coffee | 16 ++++++- .../darkswarm/cookies_banner.css.scss | 43 +++++++++++++++++++ .../api/cookies_consent_controller.rb | 28 ++++++++++++ app/controllers/home_controller.rb | 17 ++++++++ app/views/shared/_footer.html.haml | 2 +- config/locales/en.yml | 7 +++ config/routes.rb | 4 ++ 11 files changed, 160 insertions(+), 2 deletions(-) create mode 100644 app/assets/javascripts/darkswarm/cookies_banner/cookies_banner.html.haml create mode 100644 app/assets/javascripts/darkswarm/cookies_banner/cookies_banner_controller.js.coffee create mode 100644 app/assets/javascripts/darkswarm/cookies_banner/cookies_banner_directive.js.coffee create mode 100644 app/assets/javascripts/darkswarm/cookies_banner/cookies_banner_service.js.coffee create mode 100644 app/assets/stylesheets/darkswarm/cookies_banner.css.scss create mode 100644 app/controllers/api/cookies_consent_controller.rb diff --git a/app/assets/javascripts/darkswarm/cookies_banner/cookies_banner.html.haml b/app/assets/javascripts/darkswarm/cookies_banner/cookies_banner.html.haml new file mode 100644 index 000000000000..2343051cd79e --- /dev/null +++ b/app/assets/javascripts/darkswarm/cookies_banner/cookies_banner.html.haml @@ -0,0 +1,15 @@ +.row + .large-9.columns + %p + {{ 'legal.cookies_banner.cookies_usage' | t}} + %p + {{ 'legal.cookies_banner.cookies_desc' | t}} + %p + {{ 'legal.cookies_banner.cookies_policy_link_desc' | t}} + -# + %a{ 'cookies-policy-modal'=> true} + {{ 'legal.cookies_banner.cookies_policy_link' | t}} + + .large-3.columns + %button{ng: { controller:"CookiesBannerCtrl", click: "acceptCookies()" }} + {{ 'legal.cookies_banner.cookies_accept_button' | t}} diff --git a/app/assets/javascripts/darkswarm/cookies_banner/cookies_banner_controller.js.coffee b/app/assets/javascripts/darkswarm/cookies_banner/cookies_banner_controller.js.coffee new file mode 100644 index 000000000000..7ea13a29e9ac --- /dev/null +++ b/app/assets/javascripts/darkswarm/cookies_banner/cookies_banner_controller.js.coffee @@ -0,0 +1,5 @@ +Darkswarm.controller "CookiesBannerCtrl", ($scope, CookiesBannerService, $http)-> + + $scope.acceptCookies = -> + $http.get('/cookie_consent') + CookiesBannerService.close() diff --git a/app/assets/javascripts/darkswarm/cookies_banner/cookies_banner_directive.js.coffee b/app/assets/javascripts/darkswarm/cookies_banner/cookies_banner_directive.js.coffee new file mode 100644 index 000000000000..f3553018a2b5 --- /dev/null +++ b/app/assets/javascripts/darkswarm/cookies_banner/cookies_banner_directive.js.coffee @@ -0,0 +1,5 @@ +Darkswarm.directive 'cookiesBanner', (CookiesBannerService) -> + restrict: 'A' + link: (scope, elm, attr)-> + CookiesBannerService.setActive() + CookiesBannerService.open() diff --git a/app/assets/javascripts/darkswarm/cookies_banner/cookies_banner_service.js.coffee b/app/assets/javascripts/darkswarm/cookies_banner/cookies_banner_service.js.coffee new file mode 100644 index 000000000000..8d8a9e496092 --- /dev/null +++ b/app/assets/javascripts/darkswarm/cookies_banner/cookies_banner_service.js.coffee @@ -0,0 +1,20 @@ +Darkswarm.factory "CookiesBannerService", (Navigation, $modal, $location, Redirections, Loading)-> + + new class CookiesBannerService + modalMessage: null + isActive: false + + open: (path, template = 'darkswarm/cookies_banner/cookies_banner.html') => + return unless @isActive + @modalInstance = $modal.open + templateUrl: template + windowClass: "cookies-banner full" + backdrop: 'static' + keyboard: false + + close: => + return unless @isActive + @modalInstance.close() + + setActive: => + @isActive = true diff --git a/app/assets/javascripts/darkswarm/cookies_policy/cookies_policy_modal_service.js.coffee b/app/assets/javascripts/darkswarm/cookies_policy/cookies_policy_modal_service.js.coffee index 43576d80b94d..882c36d9c38c 100644 --- a/app/assets/javascripts/darkswarm/cookies_policy/cookies_policy_modal_service.js.coffee +++ b/app/assets/javascripts/darkswarm/cookies_policy/cookies_policy_modal_service.js.coffee @@ -1,4 +1,4 @@ -Darkswarm.factory "CookiesPolicyModalService", (Navigation, $modal, $location)-> +Darkswarm.factory "CookiesPolicyModalService", (Navigation, $modal, $location, CookiesBannerService)-> new class CookiesPolicyModalService defaultPath: "/policies/cookies" @@ -12,5 +12,19 @@ Darkswarm.factory "CookiesPolicyModalService", (Navigation, $modal, $location)-> @modalInstance = $modal.open templateUrl: template windowClass: "cookies-policy-modal medium" + + @closeCookiesBanner() + @onCloseReOpenCookiesBanner() + selectedPath = path || @defaultPath Navigation.navigate selectedPath + + closeCookiesBanner: => + setTimeout -> + CookiesBannerService.close() + , 200 + + onCloseReOpenCookiesBanner: => + @modalInstance.result.then( + -> CookiesBannerService.open(), + -> CookiesBannerService.open() ) diff --git a/app/assets/stylesheets/darkswarm/cookies_banner.css.scss b/app/assets/stylesheets/darkswarm/cookies_banner.css.scss new file mode 100644 index 000000000000..310a58e120c1 --- /dev/null +++ b/app/assets/stylesheets/darkswarm/cookies_banner.css.scss @@ -0,0 +1,43 @@ +.cookies-banner { + background: #3b3b3b; + position: fixed; + bottom: 0; + z-index: 100000; + top: 20vh !important; + + @media only screen and (min-width: 640px) { + top: 20vh !important; + } + + @media only screen and (min-width: 800px) { + top: 40vh !important; + } + + @media only screen and (min-width: 1024px) { + top: 60vh !important; + } +} + +.cookies-banner button { + background-color: green; +} + +.cookies-banner p { + color: white; + font-size: 0.75rem; +} + +// The following styles may be useful to change the banner's reveal-modal behaviour (it will have to be done on the controller to activate and deactivate styles on open/close ) + +// makes the main page body actionable +//.reveal-modal-bg { +// display: none !important; +//} + +// Makes the main page body scrollable on large screens +// body { +// overflow: auto !important; +// @media only screen and (max-width: 400px) { +// overflow: hidden !important; +// } +//} diff --git a/app/controllers/api/cookies_consent_controller.rb b/app/controllers/api/cookies_consent_controller.rb new file mode 100644 index 000000000000..6c792894604b --- /dev/null +++ b/app/controllers/api/cookies_consent_controller.rb @@ -0,0 +1,28 @@ +module Api + class CookiesConsentController < BaseController + respond_to :json + + def initialize + super + @cookie_name = 'cookies_consent' + end + + def show + render json: {cookie_consent: cookies[@cookie_name] != nil} + end + + def create + cookies[@cookie_name] = { + :value => @cookie_name, + :expires => 1.year.from_now, + :domain => request.host + } + show + end + + def destroy + cookies.delete(@cookie_name, :domain => request.host) + show + end + end +end diff --git a/app/controllers/home_controller.rb b/app/controllers/home_controller.rb index 55b6b827e1f7..0c57364686be 100644 --- a/app/controllers/home_controller.rb +++ b/app/controllers/home_controller.rb @@ -3,7 +3,24 @@ class HomeController < BaseController before_filter :enable_embedded_shopfront + def initialize + super + @cookie_name = 'cookies_consent' + @cookie_domain = '0.0.0.0' + end + + def cookie_consent + cookies[@cookie_name] = { + :value => @cookie_name, + :expires => 1.year.from_now, + :domain => @cookie_domain + } + render :nothing => true + end + def index + @show_cookies_banner = request.cookies[@cookie_name] == nil + if ContentConfig.home_show_stats @num_distributors = Enterprise.is_distributor.activated.visible.count @num_producers = Enterprise.is_primary_producer.activated.visible.count diff --git a/app/views/shared/_footer.html.haml b/app/views/shared/_footer.html.haml index 89318b39f7b8..4a82069adb4b 100644 --- a/app/views/shared/_footer.html.haml +++ b/app/views/shared/_footer.html.haml @@ -143,7 +143,7 @@ %div = t :footer_legal_data_text = t :footer_legal_data_call - %a{'cookies-policy-modal'=> true} + %a{'cookies-policy-modal'=> true, 'cookies-banner'=> @show_cookies_banner} = t :footer_legal_data_cookies_policy .medium-2.columns.text-center diff --git a/config/locales/en.yml b/config/locales/en.yml index 048f7e3a9aac..f99e3c2ba4b5 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -1297,6 +1297,13 @@ en: disabling_cookies_ie_link: "http://windows.microsoft.com/es-xl/internet-explorer/delete-manage-cookies#ie=ie-10" disabling_cookies_safari_link: "https://www.apple.com/legal/privacy/en-ww/cookies/" disabling_cookies_note: "But be aware that if you delete or modify the essential cookies used by Open Food Network, the website won’t work, you will not be able to add anything to your cart neither to checkout for instance." + cookies_banner: + cookies_usage: "This site uses cookies in order to make your navigation frictionless and secure, and to help us understand how you use it in order to improve the features we offer." + cookies_definition: "Cookies are very small text files that are stored on your computer when you visit some websites." + cookies_desc: "We use only the cookies that are necessary for delivering you the service of selling/buying food online. We don’t sell any of your data. We use cookies mainly to remember who you are if you ‘log in’ to the service, or to be able to remember the items you put in your cart even if you are not logged in. If you keep navigating on the website without clicking on “Accept cookies”, we assume you are giving us consent to store the cookies that are essential for the functioning of the website." + cookies_policy_link_desc: "If you want to learn more, check our" + cookies_policy_link: "cookies policy" + cookies_accept_button: "Accept Cookies" home_shop: Shop Now diff --git a/config/routes.rb b/config/routes.rb index 53356e2f521e..c1cd7d87d945 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -217,6 +217,10 @@ get :job_queue end + scope '/cookies' do + resource :consent, only: [:show, :create, :destroy], :controller => "CookiesConsent" + end + post '/product_images/:product_id', to: 'product_images#update_product_image' end