From 33af09cae5488c1c357ba233fe84a1c2f51e4f38 Mon Sep 17 00:00:00 2001 From: Mathieu Magnin Date: Thu, 22 Jun 2017 16:45:57 +0200 Subject: [PATCH] Account menu on header --- app/assets/images/icons/account-circle.svg | 1 + app/assets/images/icons/sign-out.svg | 1 + app/assets/javascripts/new_design/header.js | 10 +++ .../stylesheets/new_design/_placeholders.scss | 5 ++ .../stylesheets/new_design/animations.scss | 18 ++++++ .../stylesheets/new_design/new_header.scss | 64 ++++++++++++++++++- app/helpers/application_helper.rb | 6 ++ app/views/layouts/_new_header.haml | 11 ++++ 8 files changed, 115 insertions(+), 1 deletion(-) create mode 100644 app/assets/images/icons/account-circle.svg create mode 100644 app/assets/images/icons/sign-out.svg create mode 100644 app/assets/javascripts/new_design/header.js create mode 100644 app/assets/stylesheets/new_design/animations.scss diff --git a/app/assets/images/icons/account-circle.svg b/app/assets/images/icons/account-circle.svg new file mode 100644 index 000000000..ec478f66c --- /dev/null +++ b/app/assets/images/icons/account-circle.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/app/assets/images/icons/sign-out.svg b/app/assets/images/icons/sign-out.svg new file mode 100644 index 000000000..30022a12b --- /dev/null +++ b/app/assets/images/icons/sign-out.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/app/assets/javascripts/new_design/header.js b/app/assets/javascripts/new_design/header.js new file mode 100644 index 000000000..903b0ff96 --- /dev/null +++ b/app/assets/javascripts/new_design/header.js @@ -0,0 +1,10 @@ +window.TPS = window.TPS || {}; + +$(document).on("click", "body", function () { + $(".header-menu").removeClass("open fade-in-down"); +}); + +TPS.toggleHeaderMenu = function(event) { + event.stopPropagation(); + $(".header-menu").toggleClass("open fade-in-down"); +} diff --git a/app/assets/stylesheets/new_design/_placeholders.scss b/app/assets/stylesheets/new_design/_placeholders.scss index fbb5bf9d5..086e5ecfe 100644 --- a/app/assets/stylesheets/new_design/_placeholders.scss +++ b/app/assets/stylesheets/new_design/_placeholders.scss @@ -19,3 +19,8 @@ max-width: $page-width + 2 * $default-padding; margin: 0 auto; } + +%animation { + animation-fill-mode: forwards; + animation-duration: 0.3s; +} diff --git a/app/assets/stylesheets/new_design/animations.scss b/app/assets/stylesheets/new_design/animations.scss new file mode 100644 index 000000000..c9df122d2 --- /dev/null +++ b/app/assets/stylesheets/new_design/animations.scss @@ -0,0 +1,18 @@ +@import "placeholders"; + +@keyframes fade-in-down { + 0% { + opacity: 0; + margin-top: -10px; + } + + 100% { + opacity: 1; + margin-top: 0; + } +} + +.fade-in-down { + @extend %animation; + animation-name: fade-in-down; +} diff --git a/app/assets/stylesheets/new_design/new_header.scss b/app/assets/stylesheets/new_design/new_header.scss index 2584e62b1..fbb063aa2 100644 --- a/app/assets/stylesheets/new_design/new_header.scss +++ b/app/assets/stylesheets/new_design/new_header.scss @@ -28,7 +28,7 @@ align-items: center; height: 100%; - li { + > li { @include horizontal-padding(8px); &:last-child { @@ -54,6 +54,68 @@ cursor: pointer; position: absolute; right: 0; + + &:hover { + opacity: 0.8; + } + } +} + +.header-menu-opener { + position: relative; + + img { + cursor: pointer; + + &:hover { + opacity: 0.8; + } + } +} + +.header-menu { + display: none; + position: absolute; + right: 0; + top: 34px; + font-size: 14px; + background: #FFFFFF; + box-shadow: 0 4px 16px rgba(0, 0, 0, 0.1); + border: 1px solid $border-grey; + min-width: 270px; + max-width: 340px; + + &.open { + display: block; + } + + li { + border-bottom: 1px solid $border-grey; + + &:last-child { + border-bottom: none; + } + + .menu-item { + align-items: center; + padding: 14px; + color: $grey; + overflow: hidden; + text-overflow: ellipsis; + + img { + margin-right: 14px; + } + } + + .menu-link { + display: flex; + color: $black; + + &:hover { + background: $light-grey; + } + } } } diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 8aed47dc2..f5572c1d9 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -5,4 +5,10 @@ module ApplicationHelper when "alert" then "alert-danger" end end + + def current_email + current_user.try(:email) || + current_gestionnaire.try(:email) || + current_administrateur.try(:email) + end end diff --git a/app/views/layouts/_new_header.haml b/app/views/layouts/_new_header.haml index 6e3e1c545..29df740c7 100644 --- a/app/views/layouts/_new_header.haml +++ b/app/views/layouts/_new_header.haml @@ -11,6 +11,17 @@ = text_field_tag "q", "#{@search_terms unless @search_terms.nil?}", placeholder: "Rechercher" %button{ title: "Rechercher" } = image_tag "icons/search-blue.svg" + %li + .header-menu-opener + = image_tag "icons/account-circle.svg", onclick: "javascript:TPS.toggleHeaderMenu(event);", title: "Mon compte" + %ul.header-menu + %li + .menu-item{ title: current_email } + = current_email + %li + = link_to destroy_user_session_path, method: :delete, class: "menu-item menu-link" do + = image_tag "icons/sign-out.svg" + Se déconnecter - elsif request.path != new_user_session_path %li