Skip to content

Commit

Permalink
Bulk Actions: delete thumbnails
Browse files Browse the repository at this point in the history
  • Loading branch information
ewlarson committed May 2, 2024
1 parent 5c1f155 commit 026ef56
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 1 deletion.
19 changes: 19 additions & 0 deletions app/javascript/controllers/results_controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,25 @@ export default class extends Controller {
form.submit();
}

deleteThumbnails(event) {
var el = document.querySelector('#bulk_action_field_name');
el.setAttribute('value', "Delete Thumbnails");

// Set field value
var el = document.querySelector('#bulk_action_field_value');
el.setAttribute(
'value',
event.currentTarget.innerHTML.toLowerCase().trim()
);

// Set scope value
this.setPubState(event);

// Submit form
var form = document.querySelector('#result-action-form');
form.submit();
}

bulkActionDelete(event) {
event.preventDefault();

Expand Down
2 changes: 2 additions & 0 deletions app/jobs/bulk_action_run_document_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ def perform(action, doc, field_name, field_value)
update_delete(doc, field_value)
when :harvest_thumbnails
GeoblacklightAdmin::StoreImageJob.perform_later(doc.friendlier_id)
when :delete_thumbnails
GeoblacklightAdmin::DeleteThumbnailJob.perform_later(doc.friendlier_id)
# @TODO: Field Level changes
else
logger.debug("@TODO - #{field_name} => #{field_value}")
Expand Down
3 changes: 3 additions & 0 deletions app/jobs/bulk_action_run_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ def perform(bulk_action)
when "Harvest Thumbnails"
logger.debug("BulkAction: Harvest Thumbnails")
:harvest_thumbnails
when "Delete Thumbnails"
logger.debug("BulkAction: Delete Thumbnails")
:delete_thumbnails
else
:update_field_value
end
Expand Down
14 changes: 14 additions & 0 deletions app/jobs/geoblacklight_admin/delete_thumbnail_job.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# frozen_string_literal: true

module GeoblacklightAdmin
class DeleteThumbnailJob < ApplicationJob
queue_as :default

def perform(solr_document_id)
document = Document.find_by_friendlier_id(solr_document_id)
if document.thumbnail.present?
document.thumbnail.destroy!
end
end
end
end
5 changes: 5 additions & 0 deletions app/models/bulk_actions/change_publication_state.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,9 @@ class DraftDocument < BulkAction
class HarvestThumbnails < BulkAction
# Add specific methods and validations for HarvestThumbnails here
end

# Subclass for DeleteThumbnails
class DeleteThumbnails < BulkAction
# Add specific methods and validations for DeleteThumbnails here
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
<div class="dropdown-divider"></div>
<h6 class="dropdown-header">Imagery</h6>
<a class="dropdown-item" data-action="click->results#harvestThumbnails" href="javascript:void(0);">Harvest Thumbnails</a>
<a class="dropdown-item" data-action="click->results#deleteThumbnails" href="javascript:void(0);">Delete Thumbnails</a>
</div>
</span>

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@geoblacklight/admin",
"type": "module",
"version": "0.4.2",
"version": "0.4.3",
"license": "Apache-2.0",
"publishConfig": {
"access": "public"
Expand Down

0 comments on commit 026ef56

Please sign in to comment.