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.
This commit is contained in:
parent
8a6fb46dff
commit
01cc20378b
|
@ -30,3 +30,5 @@ class @Project
|
|||
level = $(this).data('notification-level')
|
||||
$('#notification_level').val(level)
|
||||
$('#notification-form').submit()
|
||||
$(this).parents('ul').find('li.active').removeClass('active')
|
||||
$(this).parent().addClass('active')
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
= notification_list_item(level, @membership)
|
Loading…
Reference in New Issue