Commit 5583197e authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets

Create NotificationSettings object only when user change value in dropdown

Signed-off-by: default avatarDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
parent f8f68d6b
...@@ -38,12 +38,19 @@ class @Project ...@@ -38,12 +38,19 @@ class @Project
e.preventDefault() e.preventDefault()
notification_level = $(@).data 'notification-level' notification_level = $(@).data 'notification-level'
label = $(@).data 'notification-title' label = $(@).data 'notification-title'
$('#notification_level').val(notification_level) $('#notification_setting_level').val(notification_level)
$('#notification-form').submit() $('#notification-form').submit()
$('#notifications-button').empty().append("<i class='fa fa-bell'></i>" + label + "<i class='fa fa-angle-down'></i>") $('#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' $(@).parents('ul').find('li.active').removeClass 'active'
$(@).parent().addClass '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()
projectSelectDropdown: -> projectSelectDropdown: ->
......
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
...@@ -102,7 +102,8 @@ class ProjectsController < Projects::ApplicationController ...@@ -102,7 +102,8 @@ class ProjectsController < Projects::ApplicationController
@membership = @project.team.find_member(current_user.id) @membership = @project.team.find_member(current_user.id)
if @membership 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
end end
......
- if @notification_setting - if @notification_setting
= form_tag profile_notifications_path, method: :put, remote: true, class: 'inline', id: 'notification-form' do = form_for [@project.namespace.becomes(Namespace), @project, @notification_setting], remote: true, html: { class: 'inline', id: 'notification-form' } do |f|
= hidden_field_tag :notification_id, @notification_setting.id = f.hidden_field :level
= hidden_field_tag :notification_level, @notification_setting.level
%span.dropdown %span.dropdown
%a.dropdown-new.btn.notifications-btn#notifications-button{href: '#', "data-toggle" => "dropdown"} %a.dropdown-new.btn.notifications-btn#notifications-button{href: '#', "data-toggle" => "dropdown"}
= icon('bell') = icon('bell')
......
...@@ -606,6 +606,7 @@ Rails.application.routes.draw do ...@@ -606,6 +606,7 @@ Rails.application.routes.draw do
resources :forks, only: [:index, :new, :create] resources :forks, only: [:index, :new, :create]
resource :import, only: [:new, :create, :show] resource :import, only: [:new, :create, :show]
resources :notification_settings, only: [:create, :update]
resources :refs, only: [] do resources :refs, only: [] do
collection do collection do
......
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