From 84508c40b7a132b775717d2aeef313d4e370a2b9 Mon Sep 17 00:00:00 2001 From: Darby Date: Mon, 14 Sep 2015 16:37:11 -0700 Subject: PAtrially working notification button --- app/controllers/projects_controller.rb | 1 + app/helpers/notifications_helper.rb | 31 ++++++++++++++++++++++ app/views/projects/_home_panel.html.haml | 2 ++ .../projects/buttons/_notifications.html.haml | 15 +++++++++++ 4 files changed, 49 insertions(+) create mode 100644 app/views/projects/buttons/_notifications.html.haml diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb index dafc11d0707..2c80f237f86 100644 --- a/app/controllers/projects_controller.rb +++ b/app/controllers/projects_controller.rb @@ -82,6 +82,7 @@ class ProjectsController < ApplicationController if @project.empty_repo? render 'projects/empty' else + @membership_id = @project.project_members.where(user_id: current_user.id).first render :show end else diff --git a/app/helpers/notifications_helper.rb b/app/helpers/notifications_helper.rb index 2f8e64c375f..db6fe3b29ed 100644 --- a/app/helpers/notifications_helper.rb +++ b/app/helpers/notifications_helper.rb @@ -12,4 +12,35 @@ module NotificationsHelper icon('circle-o', class: 'ns-default') end end + + def notification_list_item(notification_level) + case notification_level + when Notification::N_DISABLED + content_tag(:li) do + icon('microphone-slash') do + 'Disabled' + end + end + when Notification::N_PARTICIPATING + content_tag(:li) do + icon('volume-up') do + 'Participating' + end + end + when Notification::N_WATCH + content_tag(:li) do + icon('globe') do + 'Watch' + end + end + when Notification::N_MENTION + content_tag(:li) do + icon('at') do + 'Mention' + end + end + else + # do nothing + end + end end diff --git a/app/views/projects/_home_panel.html.haml b/app/views/projects/_home_panel.html.haml index b93036e78e6..67a00b4ebef 100644 --- a/app/views/projects/_home_panel.html.haml +++ b/app/views/projects/_home_panel.html.haml @@ -25,6 +25,8 @@ = icon('download fw') Download + = render 'projects/buttons/notifications' + = render 'projects/buttons/dropdown' = render "shared/clone_panel" diff --git a/app/views/projects/buttons/_notifications.html.haml b/app/views/projects/buttons/_notifications.html.haml new file mode 100644 index 00000000000..fb30868fc6b --- /dev/null +++ b/app/views/projects/buttons/_notifications.html.haml @@ -0,0 +1,15 @@ +- if current_user and !@membership_id.nil? + %span.dropdown + = form_tag profile_notifications_path, method: :put, remote: true do + = hidden_field_tag :notification_type, 'project' + = hidden_field_tag :notification_id, @membership_id + %a.dropdown-toggle.btn.btn-new{href: '#', "data-toggle" => "dropdown"} + = icon('bell') + Notifications + %ul.dropdown-menu.dropdown-menu-right.project-home-dropdown + - Notification.notification_levels.each do | level | + = notification_list_item(level) + + + + -- cgit v1.2.1 From ab56718feb0e155ae889afe900a009594f8acfa1 Mon Sep 17 00:00:00 2001 From: Patricio Cano Date: Mon, 14 Sep 2015 18:40:47 -0500 Subject: Fixed notification level list item helper. --- app/helpers/notifications_helper.rb | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/app/helpers/notifications_helper.rb b/app/helpers/notifications_helper.rb index db6fe3b29ed..3cc59f9ca5b 100644 --- a/app/helpers/notifications_helper.rb +++ b/app/helpers/notifications_helper.rb @@ -17,27 +17,23 @@ module NotificationsHelper case notification_level when Notification::N_DISABLED content_tag(:li) do - icon('microphone-slash') do - 'Disabled' - end + icon('microphone-slash') + 'Disabled' end when Notification::N_PARTICIPATING content_tag(:li) do - icon('volume-up') do - 'Participating' - end + icon('volume-up') + 'Participating' end when Notification::N_WATCH content_tag(:li) do - icon('globe') do - 'Watch' - end + icon('globe') + 'Watch' end when Notification::N_MENTION content_tag(:li) do - icon('at') do - 'Mention' - end + icon('at') + 'Mention' end else # do nothing -- cgit v1.2.1 From adcae6ebd597c731b22a748b882b668e6301763f Mon Sep 17 00:00:00 2001 From: Patricio Cano Date: Mon, 14 Sep 2015 19:27:54 -0500 Subject: Notification level can now be saved from within the project view. --- app/assets/javascripts/project.js.coffee | 6 ++++++ app/assets/stylesheets/pages/projects.scss | 4 ++++ app/controllers/projects_controller.rb | 2 +- app/helpers/notifications_helper.rb | 20 ++++++++++++-------- app/models/notification.rb | 2 +- app/views/projects/buttons/_notifications.html.haml | 19 ++++++++----------- 6 files changed, 32 insertions(+), 21 deletions(-) diff --git a/app/assets/javascripts/project.js.coffee b/app/assets/javascripts/project.js.coffee index 39a433dfc91..94380ccac7b 100644 --- a/app/assets/javascripts/project.js.coffee +++ b/app/assets/javascripts/project.js.coffee @@ -24,3 +24,9 @@ class @Project $.cookie('hide_no_password_message', 'false', { path: path }) $(@).parents('.no-password-message').remove() e.preventDefault() + + $('.update-notification').on 'click', (e) -> + e.preventDefault() + level = $(this).data('notification-level') + $('#notification_level').val(level) + $('#notification-form').submit() \ No newline at end of file diff --git a/app/assets/stylesheets/pages/projects.scss b/app/assets/stylesheets/pages/projects.scss index 361fd63bc79..8021b3bbffa 100644 --- a/app/assets/stylesheets/pages/projects.scss +++ b/app/assets/stylesheets/pages/projects.scss @@ -338,3 +338,7 @@ pre.light-well { margin-top: -1px; } } + +.inline-form { + display: inline-block; +} diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb index 2c80f237f86..fad5a706f49 100644 --- a/app/controllers/projects_controller.rb +++ b/app/controllers/projects_controller.rb @@ -82,7 +82,7 @@ class ProjectsController < ApplicationController if @project.empty_repo? render 'projects/empty' else - @membership_id = @project.project_members.where(user_id: current_user.id).first + @membership_id = @project.project_members.where(user_id: current_user.id).first.id render :show end else diff --git a/app/helpers/notifications_helper.rb b/app/helpers/notifications_helper.rb index 3cc59f9ca5b..4aa9ccedda0 100644 --- a/app/helpers/notifications_helper.rb +++ b/app/helpers/notifications_helper.rb @@ -17,23 +17,27 @@ module NotificationsHelper case notification_level when Notification::N_DISABLED content_tag(:li) do - icon('microphone-slash') - 'Disabled' + link_to '#', class: 'update-notification', data: { notification_level: Notification::N_DISABLED } do + icon('microphone-slash', text: 'Disabled') + end end when Notification::N_PARTICIPATING content_tag(:li) do - icon('volume-up') - 'Participating' + link_to '#', class: 'update-notification', data: { notification_level: Notification::N_PARTICIPATING } do + icon('volume-up', text: 'Participating') + end end when Notification::N_WATCH content_tag(:li) do - icon('globe') - 'Watch' + link_to '#', class: 'update-notification', data: { notification_level: Notification::N_WATCH } do + icon('globe', text: 'Watch') + end end when Notification::N_MENTION content_tag(:li) do - icon('at') - 'Mention' + link_to '#', class: 'update-notification', data: { notification_level: Notification::N_MENTION } do + icon('at', text: 'Mention') + end end else # do nothing diff --git a/app/models/notification.rb b/app/models/notification.rb index 1395274173d..828378655ce 100644 --- a/app/models/notification.rb +++ b/app/models/notification.rb @@ -12,7 +12,7 @@ class Notification class << self def notification_levels - [N_DISABLED, N_PARTICIPATING, N_WATCH, N_MENTION] + [N_DISABLED, N_MENTION, N_PARTICIPATING, N_WATCH] end def options_with_labels diff --git a/app/views/projects/buttons/_notifications.html.haml b/app/views/projects/buttons/_notifications.html.haml index fb30868fc6b..76e462a8986 100644 --- a/app/views/projects/buttons/_notifications.html.haml +++ b/app/views/projects/buttons/_notifications.html.haml @@ -1,15 +1,12 @@ - if current_user and !@membership_id.nil? - %span.dropdown - = form_tag profile_notifications_path, method: :put, remote: true do - = hidden_field_tag :notification_type, 'project' - = hidden_field_tag :notification_id, @membership_id + = form_tag profile_notifications_path, method: :put, remote: true, class: 'inline-form', id: 'notification-form' do + = hidden_field_tag :notification_type, 'project' + = hidden_field_tag :notification_id, @membership_id + = hidden_field_tag :notification_level + %span.dropdown %a.dropdown-toggle.btn.btn-new{href: '#', "data-toggle" => "dropdown"} = icon('bell') Notifications - %ul.dropdown-menu.dropdown-menu-right.project-home-dropdown - - Notification.notification_levels.each do | level | - = notification_list_item(level) - - - - + %ul.dropdown-menu.dropdown-menu-right.project-home-dropdown + - Notification.notification_levels.each do |level| + = notification_list_item(level) \ No newline at end of file -- cgit v1.2.1 From dd2ffafea4c4cd0a2c9ccebe6d52e00afe371535 Mon Sep 17 00:00:00 2001 From: Patricio Cano Date: Mon, 14 Sep 2015 19:30:58 -0500 Subject: Added spacing to icons in Notification drop down --- app/helpers/notifications_helper.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/app/helpers/notifications_helper.rb b/app/helpers/notifications_helper.rb index 4aa9ccedda0..0e4fd039831 100644 --- a/app/helpers/notifications_helper.rb +++ b/app/helpers/notifications_helper.rb @@ -18,25 +18,25 @@ module NotificationsHelper when Notification::N_DISABLED content_tag(:li) do link_to '#', class: 'update-notification', data: { notification_level: Notification::N_DISABLED } do - icon('microphone-slash', text: 'Disabled') + icon('microphone-slash fw', text: 'Disabled') end end when Notification::N_PARTICIPATING content_tag(:li) do link_to '#', class: 'update-notification', data: { notification_level: Notification::N_PARTICIPATING } do - icon('volume-up', text: 'Participating') + icon('volume-up fw', text: 'Participating') end end when Notification::N_WATCH content_tag(:li) do link_to '#', class: 'update-notification', data: { notification_level: Notification::N_WATCH } do - icon('globe', text: 'Watch') + icon('globe fw', text: 'Watch') end end when Notification::N_MENTION content_tag(:li) do link_to '#', class: 'update-notification', data: { notification_level: Notification::N_MENTION } do - icon('at', text: 'Mention') + icon('at fw', text: 'Mention') end end else -- cgit v1.2.1 From 8a6fb46dff970d599860b06a6c9105c503cbb89c Mon Sep 17 00:00:00 2001 From: Patricio Cano Date: Mon, 14 Sep 2015 19:40:45 -0500 Subject: Corrected `case` indentation to conform with Rubocop --- app/helpers/notifications_helper.rb | 44 ++++++++++++++++++------------------- 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/app/helpers/notifications_helper.rb b/app/helpers/notifications_helper.rb index 0e4fd039831..829993fd77f 100644 --- a/app/helpers/notifications_helper.rb +++ b/app/helpers/notifications_helper.rb @@ -15,32 +15,32 @@ module NotificationsHelper def notification_list_item(notification_level) case notification_level - when Notification::N_DISABLED - content_tag(:li) do - link_to '#', class: 'update-notification', data: { notification_level: Notification::N_DISABLED } do - icon('microphone-slash fw', text: 'Disabled') - end + when Notification::N_DISABLED + content_tag(:li) do + link_to '#', class: 'update-notification', data: { notification_level: Notification::N_DISABLED } do + icon('microphone-slash fw', text: 'Disabled') end - when Notification::N_PARTICIPATING - content_tag(:li) do - link_to '#', class: 'update-notification', data: { notification_level: Notification::N_PARTICIPATING } do - icon('volume-up fw', text: 'Participating') - end + end + when Notification::N_PARTICIPATING + content_tag(:li) do + link_to '#', class: 'update-notification', data: { notification_level: Notification::N_PARTICIPATING } do + icon('volume-up fw', text: 'Participating') end - when Notification::N_WATCH - content_tag(:li) do - link_to '#', class: 'update-notification', data: { notification_level: Notification::N_WATCH } do - icon('globe fw', text: 'Watch') - end + end + when Notification::N_WATCH + content_tag(:li) do + link_to '#', class: 'update-notification', data: { notification_level: Notification::N_WATCH } do + icon('globe fw', text: 'Watch') end - when Notification::N_MENTION - content_tag(:li) do - link_to '#', class: 'update-notification', data: { notification_level: Notification::N_MENTION } do - icon('at fw', text: 'Mention') - end + end + when Notification::N_MENTION + content_tag(:li) do + link_to '#', class: 'update-notification', data: { notification_level: Notification::N_MENTION } do + icon('at fw', text: 'Mention') end - else - # do nothing + end + else + # do nothing end end end -- cgit v1.2.1 From 01cc20378be1b77bd2a40a6af257e2cf116ce26a Mon Sep 17 00:00:00 2001 From: Patricio Cano Date: Mon, 14 Sep 2015 20:33:24 -0500 Subject: Notification dropdown now shows currently active level, and also shows what the actual value of `global` is, if the project has the notification level set to global. --- app/assets/javascripts/project.js.coffee | 4 +++- app/controllers/projects_controller.rb | 4 +++- app/helpers/notifications_helper.rb | 19 ++++++++++++++----- app/views/projects/buttons/_notifications.html.haml | 6 +++--- 4 files changed, 23 insertions(+), 10 deletions(-) diff --git a/app/assets/javascripts/project.js.coffee b/app/assets/javascripts/project.js.coffee index 94380ccac7b..f524627e0be 100644 --- a/app/assets/javascripts/project.js.coffee +++ b/app/assets/javascripts/project.js.coffee @@ -29,4 +29,6 @@ class @Project e.preventDefault() level = $(this).data('notification-level') $('#notification_level').val(level) - $('#notification-form').submit() \ No newline at end of file + $('#notification-form').submit() + $(this).parents('ul').find('li.active').removeClass('active') + $(this).parent().addClass('active') \ No newline at end of file diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb index fad5a706f49..14c3a6028c9 100644 --- a/app/controllers/projects_controller.rb +++ b/app/controllers/projects_controller.rb @@ -82,7 +82,9 @@ class ProjectsController < ApplicationController if @project.empty_repo? render 'projects/empty' else - @membership_id = @project.project_members.where(user_id: current_user.id).first.id + unless current_user.nil? + @membership = @project.project_members.where(user_id: current_user.id).first + end render :show end else diff --git a/app/helpers/notifications_helper.rb b/app/helpers/notifications_helper.rb index 829993fd77f..48dc198e4e2 100644 --- a/app/helpers/notifications_helper.rb +++ b/app/helpers/notifications_helper.rb @@ -13,28 +13,28 @@ module NotificationsHelper end end - def notification_list_item(notification_level) + def notification_list_item(notification_level, user_membership) case notification_level when Notification::N_DISABLED - content_tag(:li) do + content_tag(:li, class: active_level_for(user_membership, 'disabled?')) do link_to '#', class: 'update-notification', data: { notification_level: Notification::N_DISABLED } do icon('microphone-slash fw', text: 'Disabled') end end when Notification::N_PARTICIPATING - content_tag(:li) do + content_tag(:li, class: active_level_for(user_membership, 'participating?')) do link_to '#', class: 'update-notification', data: { notification_level: Notification::N_PARTICIPATING } do icon('volume-up fw', text: 'Participating') end end when Notification::N_WATCH - content_tag(:li) do + content_tag(:li, class: active_level_for(user_membership, 'watch?')) do link_to '#', class: 'update-notification', data: { notification_level: Notification::N_WATCH } do icon('globe fw', text: 'Watch') end end when Notification::N_MENTION - content_tag(:li) do + content_tag(:li, class: active_level_for(user_membership, 'mention?')) do link_to '#', class: 'update-notification', data: { notification_level: Notification::N_MENTION } do icon('at fw', text: 'Mention') end @@ -43,4 +43,13 @@ module NotificationsHelper # do nothing end end + + def active_level_for(user_membership, level) + value = Notification.new(user_membership) + if value.global? + return 'active' if current_user.notification.send(level) + elsif value.send(level) + return 'active' + end + end end diff --git a/app/views/projects/buttons/_notifications.html.haml b/app/views/projects/buttons/_notifications.html.haml index 76e462a8986..6d9d48994e1 100644 --- a/app/views/projects/buttons/_notifications.html.haml +++ b/app/views/projects/buttons/_notifications.html.haml @@ -1,7 +1,7 @@ -- if current_user and !@membership_id.nil? +- if current_user and !@membership.nil? = form_tag profile_notifications_path, method: :put, remote: true, class: 'inline-form', id: 'notification-form' do = hidden_field_tag :notification_type, 'project' - = hidden_field_tag :notification_id, @membership_id + = hidden_field_tag :notification_id, @membership.id = hidden_field_tag :notification_level %span.dropdown %a.dropdown-toggle.btn.btn-new{href: '#', "data-toggle" => "dropdown"} @@ -9,4 +9,4 @@ Notifications %ul.dropdown-menu.dropdown-menu-right.project-home-dropdown - Notification.notification_levels.each do |level| - = notification_list_item(level) \ No newline at end of file + = notification_list_item(level, @membership) \ No newline at end of file -- cgit v1.2.1 From fa6df2228e7d8957db4b37a44b687c71aac52449 Mon Sep 17 00:00:00 2001 From: Patricio Cano Date: Mon, 14 Sep 2015 20:50:13 -0500 Subject: Replaced `this` with `@` in the coffee file and added an arrow that clearly marks the Notifications button as a drop down --- app/assets/javascripts/project.js.coffee | 6 +++--- app/views/projects/buttons/_notifications.html.haml | 1 + 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/app/assets/javascripts/project.js.coffee b/app/assets/javascripts/project.js.coffee index f524627e0be..e187ec6ab77 100644 --- a/app/assets/javascripts/project.js.coffee +++ b/app/assets/javascripts/project.js.coffee @@ -27,8 +27,8 @@ class @Project $('.update-notification').on 'click', (e) -> e.preventDefault() - level = $(this).data('notification-level') + level = $(@).data 'notification-level' $('#notification_level').val(level) $('#notification-form').submit() - $(this).parents('ul').find('li.active').removeClass('active') - $(this).parent().addClass('active') \ No newline at end of file + $(@).parents('ul').find('li.active').removeClass 'active' + $(@).parent().addClass 'active' \ No newline at end of file diff --git a/app/views/projects/buttons/_notifications.html.haml b/app/views/projects/buttons/_notifications.html.haml index 6d9d48994e1..e782aeb3616 100644 --- a/app/views/projects/buttons/_notifications.html.haml +++ b/app/views/projects/buttons/_notifications.html.haml @@ -7,6 +7,7 @@ %a.dropdown-toggle.btn.btn-new{href: '#', "data-toggle" => "dropdown"} = icon('bell') Notifications + = icon('angle-down') %ul.dropdown-menu.dropdown-menu-right.project-home-dropdown - Notification.notification_levels.each do |level| = notification_list_item(level, @membership) \ No newline at end of file -- cgit v1.2.1 From de1ffce7391a9e6adf07a8be60cd36bbc95ef2f3 Mon Sep 17 00:00:00 2001 From: Patricio Cano Date: Wed, 16 Sep 2015 18:03:48 -0500 Subject: Added Spinach tests and updated CHANGELOG --- CHANGELOG | 1 + features/project/project.feature | 6 ++++++ features/steps/project/project.rb | 14 ++++++++++++++ 3 files changed, 21 insertions(+) diff --git a/CHANGELOG b/CHANGELOG index 36ee3e69ab3..4e0e5d44be8 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -43,6 +43,7 @@ v 8.0.0 (unreleased) - Add support for Crowd - Global Labels that are available to all projects - Fix highlighting of deleted lines in diffs. + - Project notification level can be set on the project page itself v 7.14.1 - Improve abuse reports management from admin area diff --git a/features/project/project.feature b/features/project/project.feature index 089ffcba14a..b3fb0794547 100644 --- a/features/project/project.feature +++ b/features/project/project.feature @@ -74,3 +74,9 @@ Feature: Project Given I disable snippets in project When I visit project "Shop" page Then I should not see "Snippets" button + + @javascript + Scenario: I edit Project Notifications + Given I click notifications drop down button + When I choose Mention setting + Then I should see Notification saved message diff --git a/features/steps/project/project.rb b/features/steps/project/project.rb index 0404fd5e594..54c026395fc 100644 --- a/features/steps/project/project.rb +++ b/features/steps/project/project.rb @@ -130,4 +130,18 @@ class Spinach::Features::Project < Spinach::FeatureSteps step 'I should see back to group button' do expect(page).to have_content 'Back to Group' end + + step 'I click notifications drop down button' do + click_link 'Notifications' + end + + step 'I choose Mention setting' do + click_link 'Mention' + end + + step 'I should see Notification saved message' do + page.within '.flash-container' do + expect(page).to have_content 'Notification settings saved' + end + end end -- cgit v1.2.1 From 4c98357f16b1acfa793d8a5b28c7147e21f20356 Mon Sep 17 00:00:00 2001 From: Patricio Cano Date: Wed, 16 Sep 2015 19:46:24 -0500 Subject: Added Global to the drop downs and updated the label of the button to show the current level instead of `Notifications` --- app/assets/javascripts/project.js.coffee | 12 ++++++++++-- app/helpers/notifications_helper.rb | 22 +++++++++++++++------- app/models/notification.rb | 19 ++++++++++++++++++- .../projects/buttons/_notifications.html.haml | 6 +++--- features/steps/project/project.rb | 4 ++-- 5 files changed, 48 insertions(+), 15 deletions(-) diff --git a/app/assets/javascripts/project.js.coffee b/app/assets/javascripts/project.js.coffee index e187ec6ab77..0ea8fffce07 100644 --- a/app/assets/javascripts/project.js.coffee +++ b/app/assets/javascripts/project.js.coffee @@ -27,8 +27,16 @@ class @Project $('.update-notification').on 'click', (e) -> e.preventDefault() - level = $(@).data 'notification-level' - $('#notification_level').val(level) + notification_level = $(@).data 'notification-level' + $('#notification_level').val(notification_level) $('#notification-form').submit() + label = null + switch notification_level + when 0 then label = ' Disabled ' + when 1 then label = ' Participating ' + when 2 then label = ' Watching ' + when 3 then label = ' Global ' + when 4 then label = ' On Mention ' + $('#notifications-button').empty().append("" + label + "") $(@).parents('ul').find('li.active').removeClass 'active' $(@).parent().addClass 'active' \ No newline at end of file diff --git a/app/helpers/notifications_helper.rb b/app/helpers/notifications_helper.rb index 48dc198e4e2..4fd06bebc2a 100644 --- a/app/helpers/notifications_helper.rb +++ b/app/helpers/notifications_helper.rb @@ -24,19 +24,25 @@ module NotificationsHelper when Notification::N_PARTICIPATING content_tag(:li, class: active_level_for(user_membership, 'participating?')) do link_to '#', class: 'update-notification', data: { notification_level: Notification::N_PARTICIPATING } do - icon('volume-up fw', text: 'Participating') + icon('volume-up fw', text: 'Participate') end end when Notification::N_WATCH content_tag(:li, class: active_level_for(user_membership, 'watch?')) do link_to '#', class: 'update-notification', data: { notification_level: Notification::N_WATCH } do - icon('globe fw', text: 'Watch') + icon('eye fw', text: 'Watch') end end when Notification::N_MENTION content_tag(:li, class: active_level_for(user_membership, 'mention?')) do link_to '#', class: 'update-notification', data: { notification_level: Notification::N_MENTION } do - icon('at fw', text: 'Mention') + icon('at fw', text: 'On mention') + end + end + when Notification::N_GLOBAL + content_tag(:li, class: active_level_for(user_membership, 'global?')) do + link_to '#', class: 'update-notification', data: { notification_level: Notification::N_GLOBAL } do + icon('globe fw', text: 'Global') end end else @@ -44,12 +50,14 @@ module NotificationsHelper end end + def notification_label(user_membership) + Notification.new(user_membership).to_s + end + def active_level_for(user_membership, level) value = Notification.new(user_membership) - if value.global? - return 'active' if current_user.notification.send(level) - elsif value.send(level) - return 'active' + if value.send(level) + 'active' end end end diff --git a/app/models/notification.rb b/app/models/notification.rb index 828378655ce..171b8df45c2 100644 --- a/app/models/notification.rb +++ b/app/models/notification.rb @@ -26,7 +26,7 @@ class Notification end def project_notification_levels - [N_DISABLED, N_PARTICIPATING, N_WATCH, N_GLOBAL, N_MENTION] + [N_DISABLED, N_MENTION, N_PARTICIPATING, N_WATCH, N_GLOBAL] end end @@ -57,4 +57,21 @@ class Notification def level target.notification_level end + + def to_s + case level + when N_DISABLED + 'Disabled' + when N_PARTICIPATING + 'Participating' + when N_WATCH + 'Watching' + when N_MENTION + 'On mention' + when N_GLOBAL + 'Global' + else + # do nothing + end + end end diff --git a/app/views/projects/buttons/_notifications.html.haml b/app/views/projects/buttons/_notifications.html.haml index e782aeb3616..9bb46157229 100644 --- a/app/views/projects/buttons/_notifications.html.haml +++ b/app/views/projects/buttons/_notifications.html.haml @@ -4,10 +4,10 @@ = hidden_field_tag :notification_id, @membership.id = hidden_field_tag :notification_level %span.dropdown - %a.dropdown-toggle.btn.btn-new{href: '#', "data-toggle" => "dropdown"} + %a.dropdown-toggle.btn.btn-new#notifications-button{href: '#', "data-toggle" => "dropdown"} = icon('bell') - Notifications + = notification_label(@membership) = icon('angle-down') %ul.dropdown-menu.dropdown-menu-right.project-home-dropdown - - Notification.notification_levels.each do |level| + - Notification.project_notification_levels.each do |level| = notification_list_item(level, @membership) \ No newline at end of file diff --git a/features/steps/project/project.rb b/features/steps/project/project.rb index 54c026395fc..390a0ba9703 100644 --- a/features/steps/project/project.rb +++ b/features/steps/project/project.rb @@ -132,11 +132,11 @@ class Spinach::Features::Project < Spinach::FeatureSteps end step 'I click notifications drop down button' do - click_link 'Notifications' + click_link 'notifications-button' end step 'I choose Mention setting' do - click_link 'Mention' + click_link 'On mention' end step 'I should see Notification saved message' do -- cgit v1.2.1 From 825db23f6750c6194932d420fa548ccfa12eddd3 Mon Sep 17 00:00:00 2001 From: Patricio Cano Date: Wed, 16 Sep 2015 20:04:12 -0500 Subject: Updated label from `Mention` to `On Mention`. --- app/views/profiles/notifications/show.html.haml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/profiles/notifications/show.html.haml b/app/views/profiles/notifications/show.html.haml index ea4e5f3e182..8eebd96b674 100644 --- a/app/views/profiles/notifications/show.html.haml +++ b/app/views/profiles/notifications/show.html.haml @@ -33,7 +33,7 @@ = f.label :notification_level, value: Notification::N_MENTION do = f.radio_button :notification_level, Notification::N_MENTION .level-title - Mention + On Mention %p You will receive notifications only for comments in which you were @mentioned .radio -- cgit v1.2.1 From 23f9a64566ec0da50c9ee842ba749a8f33eacb8e Mon Sep 17 00:00:00 2001 From: Patricio Cano Date: Wed, 16 Sep 2015 21:02:40 -0500 Subject: Use the `find_by_user_id` magic finder instead of `where`. --- app/controllers/projects_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb index 009e856d93c..9aed6a19e54 100644 --- a/app/controllers/projects_controller.rb +++ b/app/controllers/projects_controller.rb @@ -87,7 +87,7 @@ class ProjectsController < ApplicationController render 'projects/empty' else unless current_user.nil? - @membership = @project.project_members.where(user_id: current_user.id).first + @membership = @project.project_members.find_by_user_id(current_user.id) end render :show end -- cgit v1.2.1 From 47e926bec0a9da28daaca7dc92415b25f2301daf Mon Sep 17 00:00:00 2001 From: Douwe Maan Date: Sun, 20 Sep 2015 18:28:14 +0200 Subject: Minor code cleanup --- app/controllers/projects_controller.rb | 5 ++-- app/helpers/notifications_helper.rb | 15 +++++------- .../projects/buttons/_notifications.html.haml | 27 +++++++++++----------- 3 files changed, 23 insertions(+), 24 deletions(-) diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb index 9aed6a19e54..213c2a7173b 100644 --- a/app/controllers/projects_controller.rb +++ b/app/controllers/projects_controller.rb @@ -86,9 +86,10 @@ class ProjectsController < ApplicationController if @project.empty_repo? render 'projects/empty' else - unless current_user.nil? - @membership = @project.project_members.find_by_user_id(current_user.id) + if current_user + @membership = @project.project_member_by_id(current_user.id) end + render :show end else diff --git a/app/helpers/notifications_helper.rb b/app/helpers/notifications_helper.rb index 4fd06bebc2a..cf11f8e5320 100644 --- a/app/helpers/notifications_helper.rb +++ b/app/helpers/notifications_helper.rb @@ -16,31 +16,31 @@ module NotificationsHelper def notification_list_item(notification_level, user_membership) case notification_level when Notification::N_DISABLED - content_tag(:li, class: active_level_for(user_membership, 'disabled?')) do + content_tag(:li, class: active_level_for(user_membership, Notification::N_DISABLED)) do link_to '#', class: 'update-notification', data: { notification_level: Notification::N_DISABLED } do icon('microphone-slash fw', text: 'Disabled') end end when Notification::N_PARTICIPATING - content_tag(:li, class: active_level_for(user_membership, 'participating?')) do + content_tag(:li, class: active_level_for(user_membership, Notification::N_PARTICIPATING)) do link_to '#', class: 'update-notification', data: { notification_level: Notification::N_PARTICIPATING } do icon('volume-up fw', text: 'Participate') end end when Notification::N_WATCH - content_tag(:li, class: active_level_for(user_membership, 'watch?')) do + content_tag(:li, class: active_level_for(user_membership, Notification::N_WATCH)) do link_to '#', class: 'update-notification', data: { notification_level: Notification::N_WATCH } do icon('eye fw', text: 'Watch') end end when Notification::N_MENTION - content_tag(:li, class: active_level_for(user_membership, 'mention?')) do + content_tag(:li, class: active_level_for(user_membership, Notification::N_MENTION)) do link_to '#', class: 'update-notification', data: { notification_level: Notification::N_MENTION } do icon('at fw', text: 'On mention') end end when Notification::N_GLOBAL - content_tag(:li, class: active_level_for(user_membership, 'global?')) do + content_tag(:li, class: active_level_for(user_membership, Notification::N_GLOBAL)) do link_to '#', class: 'update-notification', data: { notification_level: Notification::N_GLOBAL } do icon('globe fw', text: 'Global') end @@ -55,9 +55,6 @@ module NotificationsHelper end def active_level_for(user_membership, level) - value = Notification.new(user_membership) - if value.send(level) - 'active' - end + 'active' if user_membership.notification_level == level end end diff --git a/app/views/projects/buttons/_notifications.html.haml b/app/views/projects/buttons/_notifications.html.haml index 9bb46157229..57f764178d5 100644 --- a/app/views/projects/buttons/_notifications.html.haml +++ b/app/views/projects/buttons/_notifications.html.haml @@ -1,13 +1,14 @@ -- if current_user and !@membership.nil? - = form_tag profile_notifications_path, method: :put, remote: true, class: 'inline-form', id: 'notification-form' do - = hidden_field_tag :notification_type, 'project' - = hidden_field_tag :notification_id, @membership.id - = hidden_field_tag :notification_level - %span.dropdown - %a.dropdown-toggle.btn.btn-new#notifications-button{href: '#', "data-toggle" => "dropdown"} - = icon('bell') - = notification_label(@membership) - = icon('angle-down') - %ul.dropdown-menu.dropdown-menu-right.project-home-dropdown - - Notification.project_notification_levels.each do |level| - = notification_list_item(level, @membership) \ No newline at end of file +- return unless @membership + += form_tag profile_notifications_path, method: :put, remote: true, class: 'inline-form', id: 'notification-form' do + = hidden_field_tag :notification_type, 'project' + = hidden_field_tag :notification_id, @membership.id + = hidden_field_tag :notification_level + %span.dropdown + %a.dropdown-toggle.btn.btn-new#notifications-button{href: '#', "data-toggle" => "dropdown"} + = icon('bell') + = notification_label(@membership) + = icon('angle-down') + %ul.dropdown-menu.dropdown-menu-right.project-home-dropdown + - Notification.project_notification_levels.each do |level| + = notification_list_item(level, @membership) -- cgit v1.2.1