From adcae6ebd597c731b22a748b882b668e6301763f Mon Sep 17 00:00:00 2001 From: Patricio Cano Date: Mon, 14 Sep 2015 19:27:54 -0500 Subject: [PATCH] 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 +- .../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 -- GitLab