BigW Consortium Gitlab

Commit 5583197e by Dmitriy Zaporozhets

Create NotificationSettings object only when user change value in dropdown

parent f8f68d6b
......@@ -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: ->
......
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
@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
......
- 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')
......
......@@ -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
......
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