diff options
-rw-r--r-- | CHANGELOG | 1 | ||||
-rw-r--r-- | app/assets/javascripts/project.js.coffee | 16 | ||||
-rw-r--r-- | app/assets/stylesheets/pages/projects.scss | 4 | ||||
-rw-r--r-- | app/controllers/projects_controller.rb | 4 | ||||
-rw-r--r-- | app/helpers/notifications_helper.rb | 45 | ||||
-rw-r--r-- | app/models/notification.rb | 21 | ||||
-rw-r--r-- | app/views/profiles/notifications/show.html.haml | 2 | ||||
-rw-r--r-- | app/views/projects/_home_panel.html.haml | 2 | ||||
-rw-r--r-- | app/views/projects/buttons/_notifications.html.haml | 14 | ||||
-rw-r--r-- | features/project/project.feature | 6 | ||||
-rw-r--r-- | features/steps/project/project.rb | 14 |
11 files changed, 126 insertions, 3 deletions
diff --git a/CHANGELOG b/CHANGELOG index 94ce0f50d35..31b2a759d40 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -51,6 +51,7 @@ v 8.0.0 (unreleased) - Add support for Crowd - Global Labels that are available to all projects - Fix highlighting of deleted lines in diffs. + - Project notification level can be set on the project page itself - Added service API endpoint to retrieve service parameters (Petheő Bence) - Add FogBugz project import (Jared Szechy) - Sort users autocomplete lists by user (Allister Antosik) diff --git a/app/assets/javascripts/project.js.coffee b/app/assets/javascripts/project.js.coffee index 39a433dfc91..0ea8fffce07 100644 --- a/app/assets/javascripts/project.js.coffee +++ b/app/assets/javascripts/project.js.coffee @@ -24,3 +24,19 @@ class @Project $.cookie('hide_no_password_message', 'false', { path: path }) $(@).parents('.no-password-message').remove() e.preventDefault() + + $('.update-notification').on 'click', (e) -> + e.preventDefault() + notification_level = $(@).data 'notification-level' + $('#notification_level').val(notification_level) + $('#notification-form').submit() + label = null + switch notification_level + when 0 then label = ' Disabled ' + when 1 then label = ' Participating ' + when 2 then label = ' Watching ' + when 3 then label = ' Global ' + when 4 then label = ' On Mention ' + $('#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'
\ No newline at end of file diff --git a/app/assets/stylesheets/pages/projects.scss b/app/assets/stylesheets/pages/projects.scss index 53004fca350..a986fafff07 100644 --- a/app/assets/stylesheets/pages/projects.scss +++ b/app/assets/stylesheets/pages/projects.scss @@ -329,3 +329,7 @@ pre.light-well { margin-top: -1px; } } + +.inline-form { + display: inline-block; +} diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb index f4d1a828aab..213c2a7173b 100644 --- a/app/controllers/projects_controller.rb +++ b/app/controllers/projects_controller.rb @@ -86,6 +86,10 @@ class ProjectsController < ApplicationController if @project.empty_repo? render 'projects/empty' else + if current_user + @membership = @project.project_member_by_id(current_user.id) + end + render :show end else diff --git a/app/helpers/notifications_helper.rb b/app/helpers/notifications_helper.rb index 2f8e64c375f..cf11f8e5320 100644 --- a/app/helpers/notifications_helper.rb +++ b/app/helpers/notifications_helper.rb @@ -12,4 +12,49 @@ module NotificationsHelper icon('circle-o', class: 'ns-default') end end + + def notification_list_item(notification_level, user_membership) + case notification_level + when Notification::N_DISABLED + content_tag(:li, class: active_level_for(user_membership, Notification::N_DISABLED)) do + link_to '#', class: 'update-notification', data: { notification_level: Notification::N_DISABLED } do + icon('microphone-slash fw', text: 'Disabled') + end + end + when Notification::N_PARTICIPATING + content_tag(:li, class: active_level_for(user_membership, Notification::N_PARTICIPATING)) do + link_to '#', class: 'update-notification', data: { notification_level: Notification::N_PARTICIPATING } do + icon('volume-up fw', text: 'Participate') + end + end + when Notification::N_WATCH + content_tag(:li, class: active_level_for(user_membership, Notification::N_WATCH)) do + link_to '#', class: 'update-notification', data: { notification_level: Notification::N_WATCH } do + icon('eye fw', text: 'Watch') + end + end + when Notification::N_MENTION + content_tag(:li, class: active_level_for(user_membership, Notification::N_MENTION)) do + link_to '#', class: 'update-notification', data: { notification_level: Notification::N_MENTION } do + icon('at fw', text: 'On mention') + end + end + when Notification::N_GLOBAL + content_tag(:li, class: active_level_for(user_membership, Notification::N_GLOBAL)) do + link_to '#', class: 'update-notification', data: { notification_level: Notification::N_GLOBAL } do + icon('globe fw', text: 'Global') + end + end + else + # do nothing + end + end + + def notification_label(user_membership) + Notification.new(user_membership).to_s + end + + def active_level_for(user_membership, level) + 'active' if user_membership.notification_level == level + end end diff --git a/app/models/notification.rb b/app/models/notification.rb index 1395274173d..171b8df45c2 100644 --- a/app/models/notification.rb +++ b/app/models/notification.rb @@ -12,7 +12,7 @@ class Notification class << self def notification_levels - [N_DISABLED, N_PARTICIPATING, N_WATCH, N_MENTION] + [N_DISABLED, N_MENTION, N_PARTICIPATING, N_WATCH] end def options_with_labels @@ -26,7 +26,7 @@ class Notification end def project_notification_levels - [N_DISABLED, N_PARTICIPATING, N_WATCH, N_GLOBAL, N_MENTION] + [N_DISABLED, N_MENTION, N_PARTICIPATING, N_WATCH, N_GLOBAL] end end @@ -57,4 +57,21 @@ class Notification def level target.notification_level end + + def to_s + case level + when N_DISABLED + 'Disabled' + when N_PARTICIPATING + 'Participating' + when N_WATCH + 'Watching' + when N_MENTION + 'On mention' + when N_GLOBAL + 'Global' + else + # do nothing + end + end end diff --git a/app/views/profiles/notifications/show.html.haml b/app/views/profiles/notifications/show.html.haml index ea4e5f3e182..8eebd96b674 100644 --- a/app/views/profiles/notifications/show.html.haml +++ b/app/views/profiles/notifications/show.html.haml @@ -33,7 +33,7 @@ = f.label :notification_level, value: Notification::N_MENTION do = f.radio_button :notification_level, Notification::N_MENTION .level-title - Mention + On Mention %p You will receive notifications only for comments in which you were @mentioned .radio diff --git a/app/views/projects/_home_panel.html.haml b/app/views/projects/_home_panel.html.haml index b347846c932..c1d5428f676 100644 --- a/app/views/projects/_home_panel.html.haml +++ b/app/views/projects/_home_panel.html.haml @@ -26,6 +26,8 @@ = icon('download fw') Download + = render 'projects/buttons/notifications' + = render 'projects/buttons/dropdown' - if @project.gitlab_ci? diff --git a/app/views/projects/buttons/_notifications.html.haml b/app/views/projects/buttons/_notifications.html.haml new file mode 100644 index 00000000000..57f764178d5 --- /dev/null +++ b/app/views/projects/buttons/_notifications.html.haml @@ -0,0 +1,14 @@ +- return unless @membership + += form_tag profile_notifications_path, method: :put, remote: true, class: 'inline-form', id: 'notification-form' do + = hidden_field_tag :notification_type, 'project' + = hidden_field_tag :notification_id, @membership.id + = hidden_field_tag :notification_level + %span.dropdown + %a.dropdown-toggle.btn.btn-new#notifications-button{href: '#', "data-toggle" => "dropdown"} + = icon('bell') + = notification_label(@membership) + = icon('angle-down') + %ul.dropdown-menu.dropdown-menu-right.project-home-dropdown + - Notification.project_notification_levels.each do |level| + = notification_list_item(level, @membership) diff --git a/features/project/project.feature b/features/project/project.feature index 089ffcba14a..b3fb0794547 100644 --- a/features/project/project.feature +++ b/features/project/project.feature @@ -74,3 +74,9 @@ Feature: Project Given I disable snippets in project When I visit project "Shop" page Then I should not see "Snippets" button + + @javascript + Scenario: I edit Project Notifications + Given I click notifications drop down button + When I choose Mention setting + Then I should see Notification saved message diff --git a/features/steps/project/project.rb b/features/steps/project/project.rb index 079a190e356..15f77734cb2 100644 --- a/features/steps/project/project.rb +++ b/features/steps/project/project.rb @@ -130,4 +130,18 @@ class Spinach::Features::Project < Spinach::FeatureSteps step 'I should see back to group button' do expect(page).to have_content 'Back to group' end + + step 'I click notifications drop down button' do + click_link 'notifications-button' + end + + step 'I choose Mention setting' do + click_link 'On mention' + end + + step 'I should see Notification saved message' do + page.within '.flash-container' do + expect(page).to have_content 'Notification settings saved' + end + end end |