Commit 01cc2037 authored by Patricio Cano's avatar Patricio Cano

Notification dropdown now shows currently active level, and also shows what...

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.
parent 8a6fb46d
......@@ -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
......@@ -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
- 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
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment