Skip to content

Commit

Permalink
Merge branch 'develop' into feature/decouple-references
Browse files Browse the repository at this point in the history
  • Loading branch information
ewlarson committed Nov 5, 2024
2 parents e26c411 + 602951a commit 5e793ba
Show file tree
Hide file tree
Showing 13 changed files with 90 additions and 25 deletions.
2 changes: 1 addition & 1 deletion app/controllers/admin/assets_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ def set_asset

# Only allow a list of trusted parameters through.
def asset_params
params.require(:asset).permit(:parent_id)
params.require(:asset).permit(:parent_id, :thumbnail)
end

# Checks if a value can be converted to a date.
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/admin/document_assets_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ def set_document_asset
#
# Returns a list of permitted parameters for document asset update.
def document_asset_params
params.require(:asset).permit(:title, :label, :dct_references_uri_key)
params.require(:asset).permit(:title, :label, :dct_references_uri_key, :thumbnail)
end
end
end
30 changes: 30 additions & 0 deletions app/helpers/geoblacklight_admin_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -205,4 +205,34 @@ def link_to_gbl_import(label, import, state = false)
def assets_dct_references_options
escape_javascript(options_for_select(I18n.t("activemodel.enum_values.document/reference.category").invert.sort.insert(0, ["Choose Reference Type", nil]))).to_s
end

# Determines if a document's thumbnail should be rendered.
#
# @param document [Object] the document object
# @return [Boolean] true if the thumbnail should be rendered, false otherwise
def thumb_to_render?(document)
if document&.thumbnail&.file_url&.present? && document&.thumbnail&.file_derivatives&.present?
true
elsif document&.document_assets&.any?
document.document_assets.any? do |asset|
asset.file_derivatives&.key?(:thumb_standard_2X)
end
else
false
end
end

# Returns the URL of the thumbnail to render for a document.
#
# @param document [Object] the document object
# @return [String] the URL of the thumbnail to render
def thumbnail_to_render(document)
if document&.thumbnail&.file_url&.present? && document&.thumbnail&.file_derivatives&.present?
document.thumbnail.file_url(:thumb_standard_2X)
elsif document&.document_assets&.any?
document.document_assets.find do |asset|
asset.file_derivatives&.key?(:thumb_standard_2X)
end&.file_url(:thumb_standard_2X)
end
end
end
1 change: 1 addition & 0 deletions app/javascript/controllers/results_controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { Controller } from "stimulus"
export default class extends Controller {

connect() {
console.log("GBL Admin - ResultsController connected");
}

checkedState(checked, selector='input[type=checkbox]') {
Expand Down
8 changes: 0 additions & 8 deletions app/javascript/entrypoints/engine.js

This file was deleted.

7 changes: 5 additions & 2 deletions app/javascript/index.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
console.log('Vite ⚡️ Rails - GBL Admin')

// Stimulus
// Import Stimulus and controllers
import { Application } from '@hotwired/stimulus'
import ResultsController from "./controllers/results_controller"

// Initialize Stimulus
window.Stimulus = Application.start()
Stimulus.register("results", ResultsController)

// Register controllers
Stimulus.register("results", ResultsController)
4 changes: 1 addition & 3 deletions app/models/document.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,7 @@ def item_viewer
# @TODO: Redundant? Kithe also includes a members association
def document_assets
scope = Kithe::Asset
scope = scope.where(parent_id: id)

# scope = scope.page(params[:page]).per(20).order(created_at: :desc)
scope = scope.where(parent_id: id).order(position: :asc)
scope.includes(:parent)
end

Expand Down
2 changes: 1 addition & 1 deletion app/views/admin/bulk_actions/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
<% if @bulk_action.state_machine.current_state == 'created' %>
<%= form_tag run_admin_bulk_action_path(@bulk_action), method: :patch do -%>
<%= hidden_field_tag :run, true -%>
<%= submit_tag 'Run Bulk Action' -%>
<%= submit_tag '+ Run Bulk Action', class: 'btn btn-primary btn-block' -%>
<%- end -%>
<% else %>
<%= @bulk_action.state_machine.current_state %>
Expand Down
4 changes: 1 addition & 3 deletions app/views/admin/documents/_document.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@
<% @document = Document.find_by(friendlier_id: document.friendlier_id) %>
<% if thumb_to_render?(@document) %>
<%= link_to edit_admin_document_path(document.friendlier_id) do %>
<% if @document.thumbnail.file_derivatives[:thumb_standard_2X].exists? %>
<%= image_tag(@document.thumbnail.file_url(:thumb_standard_2X), class: "thumbnail") %>
<% end %>
<%= image_tag(thumbnail_to_render(@document), class: "thumbnail") %>
<% end %>
<% end %>
</div>
Expand Down
6 changes: 2 additions & 4 deletions app/views/admin/documents/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,9 @@
<h1 class="h5">
<% if @document.persisted? %>
<div class="row">
<% if @document.thumbnail.present? %>
<% if thumb_to_render?(@document) %>
<div class="thumbnail col-2">
<% unless @document&.thumbnail&.file_url(:thumb_mini).nil? %>
<%= image_tag @document&.thumbnail&.file_url(:thumb_mini) %>
<% end %>
<%= image_tag thumbnail_to_render(@document), class: "thumbnail" %>
</div>
<% end %>
<div class="col">
Expand Down
10 changes: 9 additions & 1 deletion docs/development.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,12 @@ standardrb --fix
### Test App
```bash
bundle exec rake ci
```
```

### Build Node Module
Bump the package version in `package.json` and run the following commands to build and publish the node module.

```bash
bundle exec vite build
npm publish
```
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.5",
"version": "0.4.12",
"license": "Apache-2.0",
"publishConfig": {
"access": "public"
Expand Down
37 changes: 37 additions & 0 deletions test/helpers/geoblacklight_admin_helper_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,31 @@
require "test_helper"

class GeoblacklightAdminHelperTest < ActionView::TestCase
include GeoblacklightAdminHelper
attr_reader :current_user

setup do
@current_user = users(:user_001)

@document_with_thumbnail = OpenStruct.new(
thumbnail: OpenStruct.new(
file_url: "http://example.com/thumbnail.jpg",
file_derivatives: {thumb_standard_2X: "http://example.com/thumbnail_2x.jpg"}
),
document_assets: []
)

@document_with_assets = OpenStruct.new(
thumbnail: nil,
document_assets: [
OpenStruct.new(file_derivatives: {thumb_standard_2X: "http://example.com/asset_thumbnail_2x.jpg"})
]
)

@document_without_thumbnail = OpenStruct.new(
thumbnail: nil,
document_assets: []
)
end

test "diff_class" do
Expand Down Expand Up @@ -72,4 +93,20 @@ class GeoblacklightAdminHelperTest < ActionView::TestCase
test "params_as_hidden_fields" do
assert_equal "<input type=\"hidden\" name=\"q\" value=\"foo\" autocomplete=\"off\" />", params_as_hidden_fields({"q" => "foo"})
end

test "thumb_to_render_with_thumbnail" do
assert thumb_to_render?(@document_with_thumbnail)
end

test "thumb_to_render_with_assets" do
assert thumb_to_render?(@document_with_assets)
end

test "thumb_to_render_without_thumbnail_or_assets" do
refute thumb_to_render?(@document_without_thumbnail)
end

test "thumbnail_to_render_without_thumbnail_or_assets" do
assert_nil thumbnail_to_render(@document_without_thumbnail)
end
end

0 comments on commit 5e793ba

Please sign in to comment.