summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPatricio Cano <suprnova32@gmail.com>2015-09-14 20:33:24 -0500
committerPatricio Cano <suprnova32@gmail.com>2015-09-14 20:33:24 -0500
commit01cc20378be1b77bd2a40a6af257e2cf116ce26a (patch)
tree043a3d8fc24f1cea2f530ffb1122e5ad00d12a96
parent8a6fb46dff970d599860b06a6c9105c503cbb89c (diff)
downloadgitlab-ce-01cc20378be1b77bd2a40a6af257e2cf116ce26a.tar.gz
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.
-rw-r--r--app/assets/javascripts/project.js.coffee4
-rw-r--r--app/controllers/projects_controller.rb4
-rw-r--r--app/helpers/notifications_helper.rb19
-rw-r--r--app/views/projects/buttons/_notifications.html.haml6
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