From ad2441324b5a2c26da4274cc26f44c11e41f838d Mon Sep 17 00:00:00 2001 From: Aaron Elkiss Date: Mon, 13 Oct 2025 12:12:18 -0400 Subject: [PATCH] ETT-298: Additional column for full download * additional custom ransacker for full download * remove custom ransacker for pages --- app/controllers/ht_downloads_controller.rb | 6 ++++-- app/models/ht_download.rb | 10 +++++----- app/presenters/ht_download_presenter.rb | 13 ++++--------- config/locales/en.yml | 1 + config/locales/ja.yml | 1 + spec/lib/otis/log_importer_spec.rb | 2 +- spec/models/ht_download_spec.rb | 14 ++++++++++---- test/controllers/ht_downloads_controller_test.rb | 4 ++-- test/presenters/ht_download_presenter_test.rb | 10 ++++++++++ 9 files changed, 38 insertions(+), 23 deletions(-) diff --git a/app/controllers/ht_downloads_controller.rb b/app/controllers/ht_downloads_controller.rb index 19bb747..a91c2c8 100644 --- a/app/controllers/ht_downloads_controller.rb +++ b/app/controllers/ht_downloads_controller.rb @@ -40,7 +40,8 @@ class HTDownloadsController < ApplicationController "rights_code" => :ht_hathifile_rights_code_eq, "rights_date_used" => :ht_hathifile_rights_date_used_eq, "title" => :ht_hathifile_title_i_cont, - "pages" => :pages_eq + "pages" => :pages_eq, + "full_download" => :full_download_eq } # Translation table from params[:sortName] to a form Ransack can understand. @@ -59,7 +60,8 @@ class HTDownloadsController < ApplicationController "rights_code" => :ht_hathifile_rights_code, "rights_date_used" => :ht_hathifile_rights_date_used, "title" => :ht_hathifile_title, - "pages" => :pages + "pages" => :pages, + "full_download" => :full_download } def index diff --git a/app/models/ht_download.rb b/app/models/ht_download.rb index b009185..7789991 100644 --- a/app/models/ht_download.rb +++ b/app/models/ht_download.rb @@ -14,7 +14,7 @@ class HTDownload < ApplicationRecord scope :for_role, ->(role) { where(role: role) } def self.ransackable_attributes(auth_object = nil) - ["role", "datetime", "email", "htid", "id", "in_copyright", "inst_code", "is_partial", "sha", "yyyy", "yyyymm", "pages"] + ["role", "datetime", "email", "htid", "id", "in_copyright", "inst_code", "sha", "yyyy", "yyyymm", "full_download", "pages"] end def self.ransackable_associations(auth_object = nil) @@ -33,16 +33,16 @@ def hf ht_hathifile end - def partial? - is_partial + def full_download + !is_partial end ransacker :datetime do Arel.sql("DATE(#{table_name}.datetime)") end - ransacker :pages do - Arel.sql("COALESCE(#{table_name}.pages, CASE WHEN #{table_name}.is_partial = '0' THEN 'all' ELSE 'unknown' END)") + ransacker :full_download do + Arel.sql("(CASE WHEN #{table_name}.is_partial = '0' THEN 'yes' WHEN #{table_name}.is_partial = '1' THEN 'no' END)") end def sha diff --git a/app/presenters/ht_download_presenter.rb b/app/presenters/ht_download_presenter.rb index 736a1bd..207bd9f 100644 --- a/app/presenters/ht_download_presenter.rb +++ b/app/presenters/ht_download_presenter.rb @@ -17,6 +17,7 @@ class HTDownloadPresenter < ApplicationPresenter imprint author rights_date_used + full_download pages ].freeze @@ -36,6 +37,7 @@ class HTDownloadPresenter < ApplicationPresenter imprint: :input, author: :input, rights_date_used: :select, + full_download: :select, pages: :select }.freeze @@ -118,14 +120,7 @@ def show_institution_name link_to institution_name, ht_institution_path(inst_code) end - def show_pages - if pages - pages - elsif !partial? - "all" - else - # partial download but no page count recorded - "unknown" - end + def show_full_download + full_download ? "yes" : "no" end end diff --git a/config/locales/en.yml b/config/locales/en.yml index 86bd4d8..3fd135c 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -30,6 +30,7 @@ en: datetime: Time digitization_agent_code: Digitization Agent email: E-mail + full_download: Full Download htid: HTID imprint: Imprint inst_code: Institution Code diff --git a/config/locales/ja.yml b/config/locales/ja.yml index 9f4c062..f3396b7 100644 --- a/config/locales/ja.yml +++ b/config/locales/ja.yml @@ -30,6 +30,7 @@ ja: datetime: 時間 digitization_agent_code: デジタル化エージェント email: Eメール + full_download: フルダウンロード htid: HTID imprint: 奥付 inst_code: 機関コード diff --git a/spec/lib/otis/log_importer_spec.rb b/spec/lib/otis/log_importer_spec.rb index d8c8b46..dab3a27 100644 --- a/spec/lib/otis/log_importer_spec.rb +++ b/spec/lib/otis/log_importer_spec.rb @@ -52,7 +52,7 @@ # Both the qualifying ssdproxy records in the fixtures are partial downloads with # 42 pages download = HTDownload.where(role: "ssdproxy").first - expect(download.partial?).to be true + expect(download.is_partial).to be true expect(download.pages).to eq 42 end diff --git a/spec/models/ht_download_spec.rb b/spec/models/ht_download_spec.rb index 8fea5a4..9fbe409 100644 --- a/spec/models/ht_download_spec.rb +++ b/spec/models/ht_download_spec.rb @@ -68,10 +68,16 @@ end end - describe "#partial?" do - it "responds to partial?" do |download| - build(:ht_download, is_partial: 1) do |download| - expect(download.partial?).to be(true) + describe "#full_download" do + it "is false when is_partial is true" do |download| + build(:ht_download, is_partial: true) do |download| + expect(download.full_download).to be(false) + end + end + + it "is true when is_partial is false" do |download| + build(:ht_download, is_partial: false) do |download| + expect(download.full_download).to be(true) end end end diff --git a/test/controllers/ht_downloads_controller_test.rb b/test/controllers/ht_downloads_controller_test.rb index dc23fc2..37c9b3b 100644 --- a/test/controllers/ht_downloads_controller_test.rb +++ b/test/controllers/ht_downloads_controller_test.rb @@ -39,9 +39,9 @@ def setup assert_equal 10, json_body["rows"].length end - test "export list of pages=all reports as JSON" do + test "export list of full_download=yes reports as JSON" do sign_in! - get ht_downloads_url(format: :json, filter: "{\"pages\":\"all\"}") + get ht_downloads_url(format: :json, filter: "{\"full_download\":\"yes\"}") json_body = JSON.parse(@response.body) assert_kind_of Hash, json_body diff --git a/test/presenters/ht_download_presenter_test.rb b/test/presenters/ht_download_presenter_test.rb index 1cd6785..2289d76 100644 --- a/test/presenters/ht_download_presenter_test.rb +++ b/test/presenters/ht_download_presenter_test.rb @@ -51,6 +51,16 @@ class HTDownloadPresenterTest < ActiveSupport::TestCase assert_match "Resource Sharing", report.field_value(:role) end + test "show full download - is_partial: false" do + report = HTDownloadPresenter.new(create(:ht_download, is_partial: false), action: :index) + assert_equal "yes", report.field_value(:full_download) + end + + test "show full download - is_partial: true" do + report = HTDownloadPresenter.new(create(:ht_download, is_partial: true), action: :index) + assert_equal "no", report.field_value(:full_download) + end + test "show institution name" do create(:ht_download) do |rep| create(:ht_institution) do |inst|