Skip to content

Commit

Permalink
added cookies banner (with link to cookie policy page) and accept coo…
Browse files Browse the repository at this point in the history
…kies button
  • Loading branch information
luisramos0 committed Jun 28, 2018
1 parent 1962bb0 commit 9b45b42
Show file tree
Hide file tree
Showing 11 changed files with 160 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -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}}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Darkswarm.controller "CookiesBannerCtrl", ($scope, CookiesBannerService, $http)->

$scope.acceptCookies = ->
$http.get('/cookie_consent')
CookiesBannerService.close()
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Darkswarm.directive 'cookiesBanner', (CookiesBannerService) ->
restrict: 'A'
link: (scope, elm, attr)->
CookiesBannerService.setActive()
CookiesBannerService.open()
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Darkswarm.factory "CookiesPolicyModalService", (Navigation, $modal, $location)->
Darkswarm.factory "CookiesPolicyModalService", (Navigation, $modal, $location, CookiesBannerService)->

new class CookiesPolicyModalService
defaultPath: "/policies/cookies"
Expand All @@ -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() )
43 changes: 43 additions & 0 deletions app/assets/stylesheets/darkswarm/cookies_banner.css.scss
Original file line number Diff line number Diff line change
@@ -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;
// }
//}
28 changes: 28 additions & 0 deletions app/controllers/api/cookies_consent_controller.rb
Original file line number Diff line number Diff line change
@@ -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
17 changes: 17 additions & 0 deletions app/controllers/home_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion app/views/shared/_footer.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 7 additions & 0 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 4 additions & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 9b45b42

Please sign in to comment.