mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2024-12-24 08:43:13 +08:00
Implement hide all repository reminders button [SCI-6505] (#3940)
This commit is contained in:
parent
ae97bd64f7
commit
36fbfcab2f
7 changed files with 76 additions and 1 deletions
|
@ -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
|
||||
|
|
|
@ -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,
|
||||
|
|
23
app/jobs/hide_repository_reminders_job.rb
Normal file
23
app/jobs/hide_repository_reminders_job.rb
Normal 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
|
|
@ -3,4 +3,6 @@
|
|||
class HiddenRepositoryCellReminder < ApplicationRecord
|
||||
belongs_to :repository_cell
|
||||
belongs_to :user
|
||||
|
||||
validates :user, uniqueness: { scope: :repository_cell }
|
||||
end
|
||||
|
|
|
@ -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>
|
||||
|
|
|
@ -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"
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue