Implement hide all repository reminders button [SCI-6505] (#3940)

This commit is contained in:
artoscinote 2022-03-30 10:54:55 +02:00 committed by GitHub
parent ae97bd64f7
commit 36fbfcab2f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 76 additions and 1 deletions

View file

@ -772,6 +772,24 @@ var RepositoryDatatable = (function(global) {
})
.on('click', '#deleteRepositoryRecords', function() {
$('#deleteRepositoryRecord').modal('show');
})
.on('click', '#hideRepositoryReminders', function() {
var visibleReminderRepositoryRowIds = $('.row-reminders-dropdown').map(
function() { return $(this).closest('[role=row]').attr('id'); }
).toArray();
$.ajax({
type: 'POST',
url: $(this).data('hideRemindersUrl'),
dataType: 'json',
data: {
visible_reminder_repository_row_ids: visibleReminderRepositoryRowIds
},
success: function() {
$('#hideRepositoryReminders').remove();
TABLE.ajax.reload();
}
});
});
// Handle enter key

View file

@ -99,6 +99,26 @@ class RepositoriesController < ApplicationController
end
end
def hide_reminders
# synchronously hide currently visible reminders
if params[:visible_reminder_repository_row_ids].present?
repository_cell_ids =
RepositoryCell.joins(:repository_row)
.where(repository_rows: { id: params[:visible_reminder_repository_row_ids] })
.where.not(id: current_user.hidden_repository_cell_reminders.select(:repository_cell_id))
.with_active_reminder(current_user).pluck(:id)
HiddenRepositoryCellReminder.import(
repository_cell_ids.map { |id| { repository_cell_id: id, user_id: current_user.id } }
)
end
# offload the rest to background job
HideRepositoryRemindersJob.perform_later(@repository, current_user)
render json: { status: :ok }, status: :accepted
end
def create
@repository = Repository.new(
team: current_team,

View file

@ -0,0 +1,23 @@
# frozen_string_literal: true
class HideRepositoryRemindersJob < ApplicationJob
queue_as :high_priority
def perform(repository, user)
hidden_reminder_repository_cell_ids =
HiddenRepositoryCellReminder.joins(repository_cell: { repository_row: :repository })
.where(user: user)
.where(repositories: { id: repository.id })
.select(:id)
repository_cell_ids =
RepositoryCell.joins(repository_row: :repository)
.where.not(id: hidden_reminder_repository_cell_ids)
.with_active_reminder(user).where(repositories: { id: repository.id })
.pluck(:id)
HiddenRepositoryCellReminder.import(
repository_cell_ids.map { |rid| { repository_cell_id: rid, user_id: user.id } }
)
end
end

View file

@ -3,4 +3,6 @@
class HiddenRepositoryCellReminder < ApplicationRecord
belongs_to :repository_cell
belongs_to :user
validates :user, uniqueness: { scope: :repository_cell }
end

View file

@ -23,6 +23,16 @@
</button>
<% end %>
<%= render partial: 'repositories/toolbar/row_actions' %>
<% if @repository.repository_rows.with_active_reminders(current_user).any? %>
<button type="button" title="<%= t("repositories.hide_reminders") %>"
class="btn btn-light auto-shrink-button"
id="hideRepositoryReminders"
data-view-mode="active"
data-hide-reminders-url="<%= team_repository_hide_reminders_url(@current_team, @repository) %>">
<span class="fas fa-bell-slash"></span>
<span class="button-text"><%= t("repositories.hide_reminders") %></span>
</button>
<% end %>
<% end %>
<div class="archived-label" data-view-mode="archived">
<%= render partial: 'repositories/toolbar/archive_label' %>
@ -44,4 +54,4 @@
</div>
<% end %>
</div>
</template>
</template>

View file

@ -1628,6 +1628,7 @@ en:
restore_record: "Restore"
save_record: "Save"
cancel_save: "Cancel"
hide_reminders: "Clear all reminders"
assign_records_to_module: "Assign to task"
update_records_to_module: "Update task"
unassign_records_from_module: "Unassign"

View file

@ -186,6 +186,7 @@ Rails.application.routes.draw do
post 'copy', to: 'repositories#copy',
defaults: { format: 'json' }
get :share_modal
post 'hide_reminders', to: 'repositories#hide_reminders'
resources :team_repositories, only: %i(destroy) do
collection do