Commit 26631f99 authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets

Change how notification settings in profile are rendered and updated

Signed-off-by: default avatarDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
parent 729fe42b
...@@ -18,8 +18,11 @@ class @Profile ...@@ -18,8 +18,11 @@ class @Profile
$(this).find('.btn-save').enable() $(this).find('.btn-save').enable()
$(this).find('.loading-gif').hide() $(this).find('.loading-gif').hide()
$('.update-notifications').on 'ajax:complete', -> $('.update-notifications').on 'ajax:success', (e, data) ->
$(this).find('.btn-save').enable() if data.saved
new Flash("Notification settings saved", "notice")
else
new Flash("Failed to save new settings", "alert")
@bindEvents() @bindEvents()
......
class Groups::NotificationSettingsController < Groups::ApplicationController
def update
notification_setting = group.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
...@@ -6,19 +6,7 @@ class Profiles::NotificationsController < Profiles::ApplicationController ...@@ -6,19 +6,7 @@ class Profiles::NotificationsController < Profiles::ApplicationController
end end
def update def update
type = params[:notification_type] if current_user.update_attributes(user_params)
@saved = if type == 'global'
current_user.update_attributes(user_params)
else
notification_setting = current_user.notification_settings.find(params[:notification_id])
notification_setting.level = params[:notification_level]
notification_setting.save
end
respond_to do |format|
format.html do
if @saved
flash[:notice] = "Notification settings saved" flash[:notice] = "Notification settings saved"
else else
flash[:alert] = "Failed to save new settings" flash[:alert] = "Failed to save new settings"
...@@ -27,10 +15,6 @@ class Profiles::NotificationsController < Profiles::ApplicationController ...@@ -27,10 +15,6 @@ class Profiles::NotificationsController < Profiles::ApplicationController
redirect_back_or_default(default: profile_notifications_path) redirect_back_or_default(default: profile_notifications_path)
end end
format.js
end
end
def user_params def user_params
params.require(:user).permit(:notification_email, :notification_level) params.require(:user).permit(:notification_email, :notification_level)
end end
......
...@@ -6,12 +6,8 @@ ...@@ -6,12 +6,8 @@
= notification_icon(setting.level) = notification_icon(setting.level)
%span.str-truncated %span.str-truncated
- if setting.source.kind_of? Project = link_to group.name, group_path(group)
= link_to_project(setting.source)
- else
= link_to setting.source.name, group_path(setting.source)
.pull-right .pull-right
= form_tag profile_notifications_path, method: :put, remote: true, class: 'update-notifications' do = form_for [group, setting], remote: true, html: { class: 'update-notifications' } do |f|
= hidden_field_tag :notification_id, setting.id = f.select :level, NotificationSetting.levels.keys, {}, class: 'form-control trigger-submit'
= hidden_field_tag :notification_level, setting.level
= select_tag :notification_level, options_for_select(User.notification_levels.keys, setting.level), class: 'form-control trigger-submit'
%li.notification-list-item
%span.notification.fa.fa-holder.append-right-5
- if setting.global?
= notification_icon(current_user.notification_level)
- else
= notification_icon(setting.level)
%span.str-truncated
= link_to_project(project)
.pull-right
= form_for [project.namespace.becomes(Namespace), project, setting], remote: true, html: { class: 'update-notifications' } do |f|
= f.select :level, NotificationSetting.levels.keys, {}, class: 'form-control trigger-submit'
- page_title "Notifications" - page_title "Notifications"
- header_title page_title, profile_notifications_path - header_title page_title, profile_notifications_path
= form_for @user, url: profile_notifications_path, method: :put, html: { class: 'update-notifications prepend-top-default' } do |f| %div
-if @user.errors.any? - if @user.errors.any?
%div.alert.alert-danger %div.alert.alert-danger
%ul %ul
- @user.errors.full_messages.each do |msg| - @user.errors.full_messages.each do |msg|
...@@ -20,6 +20,8 @@ ...@@ -20,6 +20,8 @@
.col-lg-9 .col-lg-9
%h5 %h5
Global notification settings Global notification settings
= form_for @user, url: profile_notifications_path, method: :put, html: { class: 'update-notifications prepend-top-default' } do |f|
.form-group .form-group
= f.label :notification_email, class: "label-light" = f.label :notification_email, class: "label-light"
= f.select :notification_email, @user.all_emails, { include_blank: false }, class: "select2" = f.select :notification_email, @user.all_emails, { include_blank: false }, class: "select2"
...@@ -61,7 +63,7 @@ ...@@ -61,7 +63,7 @@
%div %div
%ul.bordered-list %ul.bordered-list
- @group_notifications.each do |setting| - @group_notifications.each do |setting|
= render 'settings', setting: setting = render 'group_settings', setting: setting, group: setting.source
%h5 %h5
Projects (#{@project_notifications.count}) Projects (#{@project_notifications.count})
%p.account-well %p.account-well
...@@ -69,4 +71,4 @@ ...@@ -69,4 +71,4 @@
.append-bottom-default .append-bottom-default
%ul.bordered-list %ul.bordered-list
- @project_notifications.each do |setting| - @project_notifications.each do |setting|
= render 'settings', setting: setting = render 'project_settings', setting: setting, project: setting.source
- if @saved
:plain
new Flash("Notification settings saved", "notice")
- else
:plain
new Flash("Failed to save new settings", "alert")
...@@ -406,6 +406,7 @@ Rails.application.routes.draw do ...@@ -406,6 +406,7 @@ Rails.application.routes.draw do
resource :avatar, only: [:destroy] resource :avatar, only: [:destroy]
resources :milestones, constraints: { id: /[^\/]+/ }, only: [:index, :show, :update, :new, :create] resources :milestones, constraints: { id: /[^\/]+/ }, only: [:index, :show, :update, :new, :create]
resources :notification_settings, only: [:update]
end end
end end
......
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