diff --git a/app/assets/javascripts/repositories/repository_datatable.js b/app/assets/javascripts/repositories/repository_datatable.js index d4b366660..92d7670b2 100644 --- a/app/assets/javascripts/repositories/repository_datatable.js +++ b/app/assets/javascripts/repositories/repository_datatable.js @@ -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 diff --git a/app/controllers/repositories_controller.rb b/app/controllers/repositories_controller.rb index 1e07adc7a..7128631e6 100644 --- a/app/controllers/repositories_controller.rb +++ b/app/controllers/repositories_controller.rb @@ -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, diff --git a/app/jobs/hide_repository_reminders_job.rb b/app/jobs/hide_repository_reminders_job.rb new file mode 100644 index 000000000..b72a6b2e8 --- /dev/null +++ b/app/jobs/hide_repository_reminders_job.rb @@ -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 diff --git a/app/models/hidden_repository_cell_reminder.rb b/app/models/hidden_repository_cell_reminder.rb index 27a87462f..59835c974 100644 --- a/app/models/hidden_repository_cell_reminder.rb +++ b/app/models/hidden_repository_cell_reminder.rb @@ -3,4 +3,6 @@ class HiddenRepositoryCellReminder < ApplicationRecord belongs_to :repository_cell belongs_to :user + + validates :user, uniqueness: { scope: :repository_cell } end diff --git a/app/views/repositories/_toolbar_buttons.html.erb b/app/views/repositories/_toolbar_buttons.html.erb index aee2048e7..ed756a4b1 100644 --- a/app/views/repositories/_toolbar_buttons.html.erb +++ b/app/views/repositories/_toolbar_buttons.html.erb @@ -23,6 +23,16 @@ <% end %> <%= render partial: 'repositories/toolbar/row_actions' %> + <% if @repository.repository_rows.with_active_reminders(current_user).any? %> + + <% end %> <% end %>