Commit 220708fa authored by Felipe Artur's avatar Felipe Artur

Remove schema from branch history

parent 0cf03523
...@@ -75,6 +75,7 @@ class Dispatcher ...@@ -75,6 +75,7 @@ class Dispatcher
when 'projects:show' when 'projects:show'
shortcut_handler = new ShortcutsNavigation() shortcut_handler = new ShortcutsNavigation()
new NotificationsForm()
new TreeView() if $('#tree-slider').length new TreeView() if $('#tree-slider').length
when 'groups:activity' when 'groups:activity'
new Activities() new Activities()
......
class @NotificationsForm
constructor: ->
@form = $('.custom-notifications-form')
@removeEventListeners()
@initEventListeners()
removeEventListeners: ->
$(document).off 'change', '.js-custom-notification-event'
initEventListeners: ->
$(document).on 'change', '.js-custom-notification-event', @toggleCheckbox
toggleCheckbox: (e) =>
$checkbox = $(e.currentTarget)
$parent = $checkbox.closest('.checkbox')
@saveEvent($checkbox, $parent)
showCheckboxLoadingSpinner: ($parent) ->
$parent
.addClass 'is-loading'
.find '.custom-notification-event-loading'
.removeClass 'fa-check'
.addClass 'fa-spin fa-spinner'
.removeClass 'is-done'
saveEvent: ($checkbox, $parent) ->
$.ajax(
url: @form.attr('action')
method: 'patch'
dataType: 'json'
data: @form.serialize()
beforeSend: =>
@showCheckboxLoadingSpinner($parent)
).done (data) ->
$checkbox.enable()
if data.saved
$parent
.find '.custom-notification-event-loading'
.toggleClass 'fa-spin fa-spinner fa-check is-done'
setTimeout(->
$parent
.removeClass 'is-loading'
.find '.custom-notification-event-loading'
.toggleClass 'fa-spin fa-spinner fa-check is-done'
, 2000)
...@@ -34,21 +34,26 @@ class @Project ...@@ -34,21 +34,26 @@ class @Project
$(@).parents('.no-password-message').remove() $(@).parents('.no-password-message').remove()
e.preventDefault() e.preventDefault()
$('.update-notification').on 'click', (e) -> $(document)
e.preventDefault() .off 'click', '.update-notification'
notification_level = $(@).data 'notification-level' .on 'click', '.update-notification', (e) ->
label = $(@).data 'notification-title' e.preventDefault()
$('#notification_setting_level').val(notification_level) notificationLevel = $(@).data 'notification-level'
$('#notification-form').submit() label = $(@).data 'notification-title'
$('#notifications-button').empty().append("<i class='fa fa-bell'></i>" + label + "<i class='fa fa-angle-down'></i>") $('.js-notification-loading').toggleClass 'fa-bell fa-spin fa-spinner'
$(@).parents('ul').find('li.active').removeClass 'active' $('#notification_setting_level').val(notificationLevel)
$(@).parent().addClass 'active' $('#notification-form').submit()
$('#notification-form').on 'ajax:success', (e, data) -> $(document)
if data.saved .off 'ajax:success', '#notification-form'
new Flash("Notification settings saved", "notice") .on 'ajax:success', '#notification-form', (e, data) ->
else if data.saved
new Flash("Failed to save new settings", "alert") new Flash('Notification settings saved', 'notice')
$('.js-notification-toggle-btns')
.closest('.notification-dropdown')
.replaceWith(data.html)
else
new Flash('Failed to save new settings', 'alert')
@projectSelectDropdown() @projectSelectDropdown()
......
...@@ -133,11 +133,6 @@ ...@@ -133,11 +133,6 @@
} }
} }
.btn-group:not(:first-child):not(:last-child) > .btn {
border-top-right-radius: 3px;
border-bottom-right-radius: 3px;
}
form { form {
margin-left: 10px; margin-left: 10px;
} }
...@@ -604,3 +599,20 @@ pre.light-well { ...@@ -604,3 +599,20 @@ pre.light-well {
} }
} }
} }
.custom-notifications-form {
.is-loading {
.custom-notification-event-loading {
display: inline-block;
}
}
}
.custom-notification-event-loading {
display: none;
margin-left: 5px;
&.is-done {
color: $gl-text-green;
}
}
...@@ -2,10 +2,24 @@ class Projects::NotificationSettingsController < Projects::ApplicationController ...@@ -2,10 +2,24 @@ class Projects::NotificationSettingsController < Projects::ApplicationController
before_action :authenticate_user! before_action :authenticate_user!
def update def update
notification_setting = current_user.notification_settings_for(project) @notification_setting = current_user.notification_settings_for(project)
saved = notification_setting.update_attributes(notification_setting_params)
render json: { saved: saved } if params[:custom_events].nil?
saved = @notification_setting.update_attributes(notification_setting_params)
else
events = params[:events] || {}
NotificationSetting::EMAIL_EVENTS.each do |event|
@notification_setting.events[event] = events[event]
end
saved = @notification_setting.save
end
render json: {
html: view_to_html_string("projects/buttons/_notifications", locals: { project: @project, notification_setting: @notification_setting }),
saved: saved,
}
end end
private private
......
...@@ -19,7 +19,7 @@ class NotificationSetting < ActiveRecord::Base ...@@ -19,7 +19,7 @@ class NotificationSetting < ActiveRecord::Base
:new_note, :new_note,
:new_issue, :new_issue,
:reopen_issue, :reopen_issue,
:closed_issue, :close_issue,
:reassign_issue, :reassign_issue,
:new_merge_request, :new_merge_request,
:reopen_merge_request, :reopen_merge_request,
...@@ -42,13 +42,12 @@ class NotificationSetting < ActiveRecord::Base ...@@ -42,13 +42,12 @@ class NotificationSetting < ActiveRecord::Base
setting setting
end end
# Set all event attributes as true when level is not custom # Set all event attributes to false when level is not custom or being initialized
def set_events def set_events
# Level is a ENUM cannot compare to symbol return if self.custom? || self.persisted?
return if level == "custom"
EMAIL_EVENTS.each do |event| EMAIL_EVENTS.each do |event|
self.send("#{event}=", true) events[event] = false
end end
end end
end end
...@@ -29,6 +29,7 @@ class NotificationService ...@@ -29,6 +29,7 @@ class NotificationService
# * issue assignee if their notification level is not Disabled # * issue assignee if their notification level is not Disabled
# * project team members with notification level higher then Participating # * project team members with notification level higher then Participating
# * watchers of the issue's labels # * watchers of the issue's labels
# * users with custom level checked with "new issue"
# #
def new_issue(issue, current_user) def new_issue(issue, current_user)
new_resource_email(issue, issue.project, :new_issue_email) new_resource_email(issue, issue.project, :new_issue_email)
...@@ -39,6 +40,7 @@ class NotificationService ...@@ -39,6 +40,7 @@ class NotificationService
# * issue author if their notification level is not Disabled # * issue author if their notification level is not Disabled
# * issue assignee if their notification level is not Disabled # * issue assignee if their notification level is not Disabled
# * project team members with notification level higher then Participating # * project team members with notification level higher then Participating
# * users with custom level checked with "close issue"
# #
def close_issue(issue, current_user) def close_issue(issue, current_user)
close_resource_email(issue, issue.project, current_user, :closed_issue_email) close_resource_email(issue, issue.project, current_user, :closed_issue_email)
...@@ -48,6 +50,7 @@ class NotificationService ...@@ -48,6 +50,7 @@ class NotificationService
# #
# * issue old assignee if their notification level is not Disabled # * issue old assignee if their notification level is not Disabled
# * issue new assignee if their notification level is not Disabled # * issue new assignee if their notification level is not Disabled
# * users with custom level checked with "reassign issue"
# #
def reassigned_issue(issue, current_user) def reassigned_issue(issue, current_user)
reassign_resource_email(issue, issue.project, current_user, :reassigned_issue_email) reassign_resource_email(issue, issue.project, current_user, :reassigned_issue_email)
...@@ -66,6 +69,7 @@ class NotificationService ...@@ -66,6 +69,7 @@ class NotificationService
# * mr assignee if their notification level is not Disabled # * mr assignee if their notification level is not Disabled
# * project team members with notification level higher then Participating # * project team members with notification level higher then Participating
# * watchers of the mr's labels # * watchers of the mr's labels
# * users with custom level checked with "new merge request"
# #
def new_merge_request(merge_request, current_user) def new_merge_request(merge_request, current_user)
new_resource_email(merge_request, merge_request.target_project, :new_merge_request_email) new_resource_email(merge_request, merge_request.target_project, :new_merge_request_email)
...@@ -75,6 +79,7 @@ class NotificationService ...@@ -75,6 +79,7 @@ class NotificationService
# #
# * merge_request old assignee if their notification level is not Disabled # * merge_request old assignee if their notification level is not Disabled
# * merge_request assignee if their notification level is not Disabled # * merge_request assignee if their notification level is not Disabled
# * users with custom level checked with "reassign merge request"
# #
def reassigned_merge_request(merge_request, current_user) def reassigned_merge_request(merge_request, current_user)
reassign_resource_email(merge_request, merge_request.target_project, current_user, :reassigned_merge_request_email) reassign_resource_email(merge_request, merge_request.target_project, current_user, :reassigned_merge_request_email)
......
- if @notification_setting - if @notification_setting
= form_for @notification_setting, url: namespace_project_notification_setting_path(@project.namespace.becomes(Namespace), @project), method: :patch, remote: true, html: { class: 'inline', id: 'notification-form' } do |f| .dropdown.notification-dropdown.pull-right
= f.hidden_field :level = form_for @notification_setting, url: namespace_project_notification_setting_path(@project.namespace.becomes(Namespace), @project), method: :patch, remote: true, html: { class: "inline", id: "notification-form" } do |f|
.dropdown = f.hidden_field :level
%button.btn.btn-default.notifications-btn#notifications-button{ data: { toggle: "dropdown" }, aria: { haspopup: "true", expanded: "false" } } .js-notification-toggle-btns
= icon('bell') - if @notification_setting.level != "custom"
= notification_title(@notification_setting.level) %button.dropdown-new.btn.btn-default.notifications-btn#notifications-button{ type: "button", data: { toggle: "dropdown", target: ".notification-dropdown" } }
= icon('caret-down') = icon("bell", class: "js-notification-loading")
%ul.dropdown-menu.dropdown-menu-no-wrap.dropdown-menu-align-right.dropdown-menu-selectable.dropdown-menu-large{ role: "menu" } = notification_title(@notification_setting.level)
- NotificationSetting.levels.each do |level| = icon("caret-down")
= notification_list_item(level.first, @notification_setting) - else
.btn-group
%button.dropdown-new.btn.btn-default.notifications-btn#notifications-button{ type: "button", data: { toggle: "modal", target: "#custom-notifications-modal" } }
= icon("bell", class: "js-notification-loading")
= notification_title(@notification_setting.level)
%button.btn.btn-danger.dropdown-toggle{ data: { toggle: "dropdown", target: ".notification-dropdown" } }
%span.caret
.sr-only Toggle dropdown
= render "shared/projects/notification_dropdown"
= content_for :scripts_body do
= render "shared/projects/custom_notifications"
#custom-notifications-modal.modal.fade{ tabindex: "-1", role: "dialog", aria: { labelledby: "custom-notifications-title" } }
.modal-dialog
.modal-content
.modal-header
%button.close{ type: "button", data: { dismiss: "modal" }, aria: { label: "close" } }
%span{ aria: { hidden: "true" } } ×
%h4#custom-notifications-title.modal-title
Custom notification events
.modal-body
.container-fluid
= form_for @notification_setting, url: namespace_project_notification_setting_path(@project.namespace.becomes(Namespace), @project), method: :patch, html: { class: "custom-notifications-form" } do |f|
= hidden_field_tag "custom_events", "true"
= f.hidden_field :level
.row
.col-lg-3
%h4.prepend-top-0
Notification events
.col-lg-9
- NotificationSetting::EMAIL_EVENTS.each do |event, index|
= index
.form-group
.checkbox{ class: ("prepend-top-0" if index == 0) }
%label{ for: "events_#{event}" }
= check_box_tag "events[#{event}]", true, @notification_setting.events[event], id: "events_#{event}", class: "js-custom-notification-event"
%strong
= event.to_s.humanize
= icon("spinner spin", class: "custom-notification-event-loading")
%ul.dropdown-menu.dropdown-menu-no-wrap.dropdown-menu-align-right.dropdown-menu-selectable.dropdown-menu-large{ role: "menu" }
- NotificationSetting.levels.each do |level|
- if level.first != "custom"
= notification_list_item(level.first, @notification_setting)
- if @notification_setting.level != "custom"
%li.divider
%li
%a.update-notification{ href: "#", role: "button", data: { toggle: "modal", target: "#custom-notifications-modal", notification_level: "custom", notification_title: "Custom" } }
Custom
...@@ -126,7 +126,7 @@ class Spinach::Features::Project < Spinach::FeatureSteps ...@@ -126,7 +126,7 @@ class Spinach::Features::Project < Spinach::FeatureSteps
end end
step 'I click notifications drop down button' do step 'I click notifications drop down button' do
find('#notifications-button').click first('.notifications-btn').click
end end
step 'I choose Mention setting' do step 'I choose Mention setting' 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