From aa10d7b1edc16be6c0bd7e0ae69f9d95e45349a9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=81lex=20Hermida?= Date: Wed, 16 May 2018 13:34:25 +0200 Subject: [PATCH] Add user terms directive --- app/coffee/app.coffee | 2 +- app/coffee/modules/auth.coffee | 13 +++- app/index.jade | 1 + .../terms-announcement.directive.coffee | 66 +++++++++++++++++ .../terms-announcement.jade | 12 +++ .../terms-announcement.scss | 73 +++++++++++++++++++ .../terms-announcement.service.coffee | 31 ++++++++ 7 files changed, 195 insertions(+), 3 deletions(-) create mode 100644 app/modules/components/terms-announcement/terms-announcement.directive.coffee create mode 100644 app/modules/components/terms-announcement/terms-announcement.jade create mode 100644 app/modules/components/terms-announcement/terms-announcement.scss create mode 100644 app/modules/components/terms-announcement/terms-announcement.service.coffee diff --git a/app/coffee/app.coffee b/app/coffee/app.coffee index 8a4cb88d..652f1cf7 100644 --- a/app/coffee/app.coffee +++ b/app/coffee/app.coffee @@ -792,7 +792,7 @@ init = ($log, $rootscope, $auth, $events, $analytics, $translate, $location, $na # Load user if $auth.isAuthenticated() user = $auth.getUser() - + $auth.showTerms() # Analytics $analytics.initialize() diff --git a/app/coffee/modules/auth.coffee b/app/coffee/modules/auth.coffee index 82fa1876..3290952b 100644 --- a/app/coffee/modules/auth.coffee +++ b/app/coffee/modules/auth.coffee @@ -68,10 +68,11 @@ class AuthService extends taiga.Service "$translate", "tgCurrentUserService", "tgThemeService", - "$tgAnalytics"] + "$tgAnalytics", + "tgTermsAnnouncementService"] constructor: (@rootscope, @storage, @model, @rs, @http, @urls, @config, @translate, @currentUserService, - @themeService, @analytics) -> + @themeService, @analytics, @termsAnnouncementService) -> super() userModel = @.getUser() @@ -238,6 +239,12 @@ class AuthService extends taiga.Service url = @urls.resolve("users-export") return @http.post(url) + showTerms: (data) -> + user = @.getUser() + if not user or user.read_new_terms + return + @termsAnnouncementService.show('GDPR', 'General Data Protection Regulation - Read more!') + module.service("$tgAuth", AuthService) @@ -290,6 +297,8 @@ LoginDirective = ($auth, $confirm, $location, $config, $routeParams, $navUrls, $ $events.setupConnection() $analytics.trackEvent("auth", "login", "user login", 1) + $auth.showTerms() + if $scope.nextUrl.indexOf('http') == 0 $window.location.href = $scope.nextUrl else diff --git a/app/index.jade b/app/index.jade index c1dc3b96..438ba307 100644 --- a/app/index.jade +++ b/app/index.jade @@ -45,6 +45,7 @@ html(lang="en") div(tg-joy-ride) div(tg-live-announcement) + div(tg-terms-announcement) script(src="/#{v}/js/libs.js") script(src="/#{v}/js/templates.js") diff --git a/app/modules/components/terms-announcement/terms-announcement.directive.coffee b/app/modules/components/terms-announcement/terms-announcement.directive.coffee new file mode 100644 index 00000000..6d3db730 --- /dev/null +++ b/app/modules/components/terms-announcement/terms-announcement.directive.coffee @@ -0,0 +1,66 @@ +### +# Copyright (C) 2014-2015 Andrey Antukh +# Copyright (C) 2014-2015 Jesús Espino Garcia +# Copyright (C) 2014-2015 David Barragán Merino +# Copyright (C) 2014-2017 Alejandro Alonso +# Copyright (C) 2014-2017 Juan Francisco Alcántara +# Copyright (C) 2014-2017 Xavi Julian +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . +# +# File: terms-announcement.directive.coffee +### + + +TermsAnnouncementDirective = (TermsAnnouncementService, $repo, $auth) -> + link = (scope, el, attrs) -> + + return { + restrict: "AE", + scope: {}, + controllerAs: 'vm', + controller: () -> + this.close = () -> + TermsAnnouncementService.open = false + user = $auth.getUser() + + onSuccess = (data) => + $auth.setUser(data) + + user.read_new_terms = true + $repo.save(user).then(onSuccess) + + Object.defineProperties(this, { + open: { + get: () -> return TermsAnnouncementService.open + }, + title: { + get: () -> return TermsAnnouncementService.title + }, + desc: { + get: () -> return TermsAnnouncementService.desc + } + }) + link: link, + templateUrl: "components/terms-announcement/terms-announcement.html" + } + +TermsAnnouncementDirective.$inject = [ + "tgTermsAnnouncementService", + "$tgRepo", + "$tgAuth" +] + +angular.module("taigaComponents") + .directive("tgTermsAnnouncement", TermsAnnouncementDirective) diff --git a/app/modules/components/terms-announcement/terms-announcement.jade b/app/modules/components/terms-announcement/terms-announcement.jade new file mode 100644 index 00000000..6736dc43 --- /dev/null +++ b/app/modules/components/terms-announcement/terms-announcement.jade @@ -0,0 +1,12 @@ +.terms-announcement(ng-class="{visible: vm.open}") + .terms-announcement-inner + img.anouncement-decoration(src="/#{v}/images/notification-decoration.png", alt="Loading...") + .text + h2.title {{vm.title}} + p.warning(ng-bind-html="vm.desc") + a.close( + ng-click="vm.close()" + href="" + ng-title="COMMON.CLOSE | translate" + ) + tg-svg(svg-icon="icon-close") diff --git a/app/modules/components/terms-announcement/terms-announcement.scss b/app/modules/components/terms-announcement/terms-announcement.scss new file mode 100644 index 00000000..ce76d3db --- /dev/null +++ b/app/modules/components/terms-announcement/terms-announcement.scss @@ -0,0 +1,73 @@ +.terms-announcement { + $animation-steps-duration: .5s; + align-content: center; + background: $tribe-primary; + display: flex; + height: 0; + justify-content: center; + overflow: hidden; + pointer-events: none; + position: fixed; + top: 0; + transition: width $animation-steps-duration, height $animation-steps-duration; + transition-delay: $animation-steps-duration; + width: 0; + z-index: 99; + .terms-announcement-inner { + opacity: 0; + transition: opacity $animation-steps-duration; + width: 100%; + } + &.visible { + height: 146px; + pointer-events: auto; + transition-delay: 0s; + width: 100%; + .terms-announcement-inner { + opacity: 1; + transition: opacity $animation-steps-duration $animation-steps-duration; + } + } +} + +.terms-announcement-inner { + display: flex; + max-width: 1200px; + .announcement-decoration { + align-self: flex-end; + margin-right: 1rem; + } + .text { + padding: 1.25rem 3rem 1.25rem 2rem; + position: relative; + width: 100%; + } + .title { + @include font-type(bold); + @include font-size(larger); + color: $tribe-secondary; + margin-bottom: .5rem; + } + .warning { + color: $tribe-secondary; + a { + @include font-type(bold); + color: $tribe-secondary; + } + } + .close { + display: block; + position: absolute; + right: 0; + top: 1rem; + svg { + @include svg-size(2rem); + fill: lighten($tribe-secondary, 15%); + pointer-events: none; + transition: fill .2s; + &:hover { + fill: $tribe-secondary; + } + } + } +} diff --git a/app/modules/components/terms-announcement/terms-announcement.service.coffee b/app/modules/components/terms-announcement/terms-announcement.service.coffee new file mode 100644 index 00000000..55cf87f6 --- /dev/null +++ b/app/modules/components/terms-announcement/terms-announcement.service.coffee @@ -0,0 +1,31 @@ +### +# Copyright (C) 2014-2015 Taiga Agile LLC +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . +# +# File: notification.service.coffee +### + +class TermsAnnouncementService extends taiga.Service + constructor: () -> + @.open = false + @.title = "" + @.desc = "" + + show: (title, desc) -> + @.open = true + @.title = title + @.desc = desc + +angular.module("taigaComponents").service("tgTermsAnnouncementService", TermsAnnouncementService)