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
$(this).find('.btn-save').enable()
$(this).find('.loading-gif').hide()
$('.update-notifications').on 'ajax:complete', ->
$(this).find('.btn-save').enable()
$('.update-notifications').on 'ajax:success', (e, data) ->
if data.saved
new Flash("Notification settings saved", "notice")
else
new Flash("Failed to save new settings", "alert")
@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
end
def update
type = params[:notification_type]
@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"
else
flash[:alert] = "Failed to save new settings"
end
redirect_back_or_default(default: profile_notifications_path)
end
format.js
if current_user.update_attributes(user_params)
flash[:notice] = "Notification settings saved"
else
flash[:alert] = "Failed to save new settings"
end
redirect_back_or_default(default: profile_notifications_path)
end
def user_params
......
......@@ -6,12 +6,8 @@
= notification_icon(setting.level)
%span.str-truncated
- if setting.source.kind_of? Project
= link_to_project(setting.source)
- else
= link_to setting.source.name, group_path(setting.source)
= link_to group.name, group_path(group)
.pull-right
= form_tag profile_notifications_path, method: :put, remote: true, class: 'update-notifications' do
= hidden_field_tag :notification_id, setting.id
= 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'
= form_for [group, setting], remote: true, html: { class: 'update-notifications' } do |f|
= f.select :level, NotificationSetting.levels.keys, {}, 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"
- 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|
-if @user.errors.any?
%div
- if @user.errors.any?
%div.alert.alert-danger
%ul
- @user.errors.full_messages.each do |msg|
......@@ -20,48 +20,50 @@
.col-lg-9
%h5
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
= f.label :notification_level, value: :mention do
= f.radio_button :notification_level, :mention
.level-title
On Mention
%p You will receive notifications only for comments in which you were @mentioned
= form_for @user, url: profile_notifications_path, method: :put, html: { class: 'update-notifications prepend-top-default' } do |f|
.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
= f.label :notification_level, value: :participating do
= f.radio_button :notification_level, :participating
.level-title
Participating
%p You will only receive notifications from related resources (e.g. from your commits or assigned issues)
.radio
= f.label :notification_level, value: :mention do
= f.radio_button :notification_level, :mention
.level-title
On Mention
%p You will receive notifications only for comments in which you were @mentioned
.radio
= f.label :notification_level, value: :watch do
= f.radio_button :notification_level, :watch
.level-title
Watch
%p You will receive notifications for any activity
.radio
= f.label :notification_level, value: :participating do
= f.radio_button :notification_level, :participating
.level-title
Participating
%p You will only receive notifications from related resources (e.g. from your commits or assigned issues)
.prepend-top-default
= f.submit 'Update settings', class: "btn btn-create"
.radio
= 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
%h5
Groups (#{@group_notifications.count})
%div
%ul.bordered-list
- @group_notifications.each do |setting|
= render 'settings', setting: setting
= render 'group_settings', setting: setting, group: setting.source
%h5
Projects (#{@project_notifications.count})
%p.account-well
......@@ -69,4 +71,4 @@
.append-bottom-default
%ul.bordered-list
- @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
resource :avatar, only: [:destroy]
resources :milestones, constraints: { id: /[^\/]+/ }, only: [:index, :show, :update, :new, :create]
resources :notification_settings, only: [:update]
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