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,29 +6,13 @@ class Profiles::NotificationsController < Profiles::ApplicationController ...@@ -6,29 +6,13 @@ class Profiles::NotificationsController < Profiles::ApplicationController
end end
def update def update
type = params[:notification_type] if current_user.update_attributes(user_params)
flash[:notice] = "Notification settings saved"
@saved = if type == 'global' else
current_user.update_attributes(user_params) flash[:alert] = "Failed to save new settings"
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"
else
flash[:alert] = "Failed to save new settings"
end
redirect_back_or_default(default: profile_notifications_path)
end
format.js
end end
redirect_back_or_default(default: profile_notifications_path)
end end
def user_params def user_params
......
...@@ -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,48 +20,50 @@ ...@@ -20,48 +20,50 @@
.col-lg-9 .col-lg-9
%h5 %h5
Global notification settings Global notification settings
.form-group
= f.label :notification_email, class: "label-light"
= f.select :notification_email, @user.all_emails, { include_blank: false }, class: "select2"
.form-group
= f.label :notification_level, class: 'label-light'
.radio
= f.label :notification_level, value: :disabled do
= f.radio_button :notification_level, :disabled
.level-title
Disabled
%p You will not get any notifications via email
.radio = form_for @user, url: profile_notifications_path, method: :put, html: { class: 'update-notifications prepend-top-default' } do |f|
= f.label :notification_level, value: :mention do .form-group
= f.radio_button :notification_level, :mention = f.label :notification_email, class: "label-light"
.level-title = f.select :notification_email, @user.all_emails, { include_blank: false }, class: "select2"
On Mention .form-group
%p You will receive notifications only for comments in which you were @mentioned = f.label :notification_level, class: 'label-light'
.radio
= f.label :notification_level, value: :disabled do
= f.radio_button :notification_level, :disabled
.level-title
Disabled
%p You will not get any notifications via email
.radio .radio
= f.label :notification_level, value: :participating do = f.label :notification_level, value: :mention do
= f.radio_button :notification_level, :participating = f.radio_button :notification_level, :mention
.level-title .level-title
Participating On Mention
%p You will only receive notifications from related resources (e.g. from your commits or assigned issues) %p You will receive notifications only for comments in which you were @mentioned
.radio .radio
= f.label :notification_level, value: :watch do = f.label :notification_level, value: :participating do
= f.radio_button :notification_level, :watch = f.radio_button :notification_level, :participating
.level-title .level-title
Watch Participating
%p You will receive notifications for any activity %p You will only receive notifications from related resources (e.g. from your commits or assigned issues)
.prepend-top-default .radio
= f.submit 'Update settings', class: "btn btn-create" = f.label :notification_level, value: :watch do
= f.radio_button :notification_level, :watch
.level-title
Watch
%p You will receive notifications for any activity
.prepend-top-default
= f.submit 'Update settings', class: "btn btn-create"
%hr %hr
%h5 %h5
Groups (#{@group_notifications.count}) Groups (#{@group_notifications.count})
%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