diff options
author | Douwe Maan <douwe@gitlab.com> | 2015-09-20 18:28:14 +0200 |
---|---|---|
committer | Douwe Maan <douwe@gitlab.com> | 2015-09-20 19:09:43 +0200 |
commit | 47e926bec0a9da28daaca7dc92415b25f2301daf (patch) | |
tree | 1af109baecd783f4db5d8e618275791ccfd2da79 /app | |
parent | 23f9a64566ec0da50c9ee842ba749a8f33eacb8e (diff) | |
download | gitlab-ce-47e926bec0a9da28daaca7dc92415b25f2301daf.tar.gz |
Minor code cleanupnotification-levels
Diffstat (limited to 'app')
-rw-r--r-- | app/controllers/projects_controller.rb | 5 | ||||
-rw-r--r-- | app/helpers/notifications_helper.rb | 15 | ||||
-rw-r--r-- | app/views/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) |