diff options
-rw-r--r-- | app/assets/javascripts/project.js.coffee | 9 | ||||
-rw-r--r-- | app/controllers/projects/notification_settings_controller.rb | 22 | ||||
-rw-r--r-- | app/controllers/projects_controller.rb | 3 | ||||
-rw-r--r-- | app/views/projects/buttons/_notifications.html.haml | 5 | ||||
-rw-r--r-- | config/routes.rb | 1 |
5 files changed, 35 insertions, 5 deletions
diff --git a/app/assets/javascripts/project.js.coffee b/app/assets/javascripts/project.js.coffee index f171442d05a..07be85a32a5 100644 --- a/app/assets/javascripts/project.js.coffee +++ b/app/assets/javascripts/project.js.coffee @@ -38,12 +38,19 @@ class @Project e.preventDefault() notification_level = $(@).data 'notification-level' label = $(@).data 'notification-title' - $('#notification_level').val(notification_level) + $('#notification_setting_level').val(notification_level) $('#notification-form').submit() $('#notifications-button').empty().append("<i class='fa fa-bell'></i>" + label + "<i class='fa fa-angle-down'></i>") $(@).parents('ul').find('li.active').removeClass 'active' $(@).parent().addClass 'active' + $('#notification-form').on 'ajax:success', (e, data) -> + if data.saved + new Flash("Notification settings saved", "notice") + else + new Flash("Failed to save new settings", "alert") + + @projectSelectDropdown() projectSelectDropdown: -> diff --git a/app/controllers/projects/notification_settings_controller.rb b/app/controllers/projects/notification_settings_controller.rb new file mode 100644 index 00000000000..3ecf63d107f --- /dev/null +++ b/app/controllers/projects/notification_settings_controller.rb @@ -0,0 +1,22 @@ +class Projects::NotificationSettingsController < Projects::ApplicationController + def create + notification_setting = project.notification_settings.new(notification_setting_params) + notification_setting.user = current_user + saved = notification_setting.save + + render json: { saved: saved } + end + + def update + notification_setting = project.notification_settings.where(user_id: current_user).find(params[:id]) + saved = notification_setting.update_attributes(notification_setting_params) + + render json: { saved: saved } + end + + private + + def notification_setting_params + params.require(:notification_setting).permit(:level) + end +end diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb index e2dc6309d26..ec5318f2d2c 100644 --- a/app/controllers/projects_controller.rb +++ b/app/controllers/projects_controller.rb @@ -102,7 +102,8 @@ class ProjectsController < Projects::ApplicationController @membership = @project.team.find_member(current_user.id) if @membership - @notification_setting = current_user.notification_settings.find_or_create_for(@project) + @notification_setting = current_user.notification_settings.find_or_initialize_by(source: @project) + @notification_setting.set_defaults unless @notification_setting.persisted? end end diff --git a/app/views/projects/buttons/_notifications.html.haml b/app/views/projects/buttons/_notifications.html.haml index 4b8a10f0819..2b9d8f2ac81 100644 --- a/app/views/projects/buttons/_notifications.html.haml +++ b/app/views/projects/buttons/_notifications.html.haml @@ -1,7 +1,6 @@ - if @notification_setting - = form_tag profile_notifications_path, method: :put, remote: true, class: 'inline', id: 'notification-form' do - = hidden_field_tag :notification_id, @notification_setting.id - = hidden_field_tag :notification_level, @notification_setting.level + = form_for [@project.namespace.becomes(Namespace), @project, @notification_setting], remote: true, html: { class: 'inline', id: 'notification-form' } do |f| + = f.hidden_field :level %span.dropdown %a.dropdown-new.btn.notifications-btn#notifications-button{href: '#', "data-toggle" => "dropdown"} = icon('bell') diff --git a/config/routes.rb b/config/routes.rb index 6bf22fb4456..c665cefbb57 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -606,6 +606,7 @@ Rails.application.routes.draw do resources :forks, only: [:index, :new, :create] resource :import, only: [:new, :create, :show] + resources :notification_settings, only: [:create, :update] resources :refs, only: [] do collection do |