Skip to content

Commit

Permalink
🚧 Add files from PALs Hyku not in other repos
Browse files Browse the repository at this point in the history
This is a first pass of the PALs work.  There was a lot of head
scratching and copying things into Hyku Prime.  Together this is a
rough process.

Related to:

- scientist-softserv/palni_palci_knapsack@3595d6f
  • Loading branch information
jeremyf committed Apr 5, 2024
1 parent e720484 commit 0ca6d93
Show file tree
Hide file tree
Showing 39 changed files with 2,854 additions and 0 deletions.
Binary file added app/assets/images/loading-progress.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 6 additions & 0 deletions app/assets/javascripts/admin_font_select.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Blacklight.onLoad(function() {
if($("#admin_appearance_body_font").length > 0){
$("#admin_appearance_body_font").fontselect({lookahead: 20});
$("#admin_appearance_headline_font").fontselect({lookahead: 20});
}
});
52 changes: 52 additions & 0 deletions app/controllers/api/sushi_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# frozen_string_literal: true

module API
class SushiController < ApplicationController
private

##
# We have encountered an error in their request, this might be an invalid date or a missing
# required parameter. The end user can adjust the request and try again.
#
# @param [Exception]
def render_sushi_exception(error)
render json: error, status: 422
end
rescue_from Sushi::Error::Exception, with: :render_sushi_exception

public

##
# needs to include the following filters: begin & end date, item ID
#
#
# When given an item_id parameter, filter the results to only that item_id.
#
# @note We should not need to find the record in ActiveFedora; hopefully we have all we need in
# the stats database.
def item_report
@report = Sushi::ItemReport.new(params, account: current_account)
render json: @report
end

def platform_report
@report = Sushi::PlatformReport.new(params, account: current_account)
render json: @report
end

def platform_usage
@report = Sushi::PlatformUsageReport.new(params, account: current_account)
render json: @report
end

def server_status
@status = Sushi::ServerStatus.new(account: current_account).server_status
render json: @status
end

def report_list
@report = Sushi::ReportList.new
render json: @report
end
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# frozen_string_literal: true

# OVERRIDE Hyrax v5.0.0 to sort subcollections by title

module Hyrax
module CollectionsControllerBehaviorDecorator
def load_member_subcollections
super
return if @subcollection_docs.blank?

@subcollection_docs.sort_by! { |doc| doc.title.first&.downcase }
end

def show
params[:sort] ||= Hyrax::Collections::CollectionMemberSearchServiceDecorator::DEFAULT_SORT_FIELD

super
end
end
end

Hyrax::CollectionsControllerBehavior.prepend Hyrax::CollectionsControllerBehaviorDecorator
17 changes: 17 additions & 0 deletions app/controllers/hyrax/admin/workflows_controller_decorator.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# frozen_string_literal: true

# OVERRIDE Hyrax 3.6.0 to redirect back to the review submissions page after approving or rejecting a work
# when the user came from the review submissions page

module Hyrax
module Admin
module WorkflowsControllerDecorator
def index
super
session[:from_admin_workflows] = true if request.fullpath.include?(admin_workflows_path)
end
end
end
end

Hyrax::Admin::WorkflowsController.prepend(Hyrax::Admin::WorkflowsControllerDecorator)
29 changes: 29 additions & 0 deletions app/controllers/hyrax/my/works_controller_decorator.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# frozen_string_literal: true

# OVERRIDE Hyrax 5.0.0 to add custom sort fields while in the dashboard for works

module Hyrax
module My
module WorksControllerDecorator
def configure_facets
configure_blacklight do |config|
# clear facets copied from the CatalogController
config.sort_fields.clear
config.add_sort_field "date_uploaded_dtsi desc", label: "date uploaded \u25BC"
config.add_sort_field "date_uploaded_dtsi asc", label: "date uploaded \u25B2"
config.add_sort_field "date_modified_dtsi desc", label: "date modified \u25BC"
config.add_sort_field "date_modified_dtsi asc", label: "date modified \u25B2"
config.add_sort_field "system_create_dtsi desc", label: "date created \u25BC"
config.add_sort_field "system_create_dtsi asc", label: "date created \u25B2"
config.add_sort_field "depositor_ssi asc, title_ssi asc", label: "depositor (A-Z)"
config.add_sort_field "depositor_ssi desc, title_ssi desc", label: "depositor (Z-A)"
config.add_sort_field "creator_ssi asc, title_ssi asc", label: "creator (A-Z)"
config.add_sort_field "creator_ssi desc, title_ssi desc", label: "creator (Z-A)"
end
end
end
end
end

Hyrax::My::WorksController.singleton_class.send(:prepend, Hyrax::My::WorksControllerDecorator)
Hyrax::My::WorksController.configure_facets
20 changes: 20 additions & 0 deletions app/controllers/hyrax/workflow_actions_controller_decorator.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# frozen_string_literal: true

# OVERRIDE Hyrax 5.0.0 to redirect back to the review submissions page after approving or rejecting a work
# when the user came from the review submissions page

module Hyrax
module WorkflowActionsControllerDecorator
private

def after_update_response
respond_to do |wants|
redirect_path = session[:from_admin_workflows] ? admin_workflows_path : [main_app, curation_concern]
wants.html { redirect_to redirect_path, notice: "The #{curation_concern.class.human_readable_type} has been updated." }
wants.json { render 'hyrax/base/show', status: :ok, location: polymorphic_path([main_app, curation_concern]) }
end
end
end
end

Hyrax::WorkflowActionsController.prepend(Hyrax::WorkflowActionsControllerDecorator)
17 changes: 17 additions & 0 deletions app/jobs/create_derivatives_job_decorator.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# frozen_string_literal: true

# OVERRIDE Hyrax v3.6.0
# @see CreateLargeDerivativesJob
module CreateDerivativesJobDecorator
# OVERRIDE: Divert audio and video derivative
# creation to CreateLargeDerivativesJob.
def perform(file_set, file_id, filepath = nil)
return super if is_a?(CreateLargeDerivativesJob)
return super unless file_set.video? || file_set.audio?

CreateLargeDerivativesJob.perform_later(*arguments)
true
end
end

CreateDerivativesJob.prepend(CreateDerivativesJobDecorator)
16 changes: 16 additions & 0 deletions app/jobs/create_large_derivatives_job.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# frozen_string_literal: true

# CreateLargeDerivativesJob is intended to be used for resource-intensive derivative
# generation (e.g. video processing). It is functionally similar to CreateDerivativesJob,
# except that it queues jobs in the :auxiliary queue.
#
# The worker responsible for processing jobs in the :auxiliary queue should be
# configured to have more resources dedicated to it, especially CPU. Otherwise, the
# `ffmpeg` commands that this job class eventually triggers could be throttled.
#
# @see CreateDerivativesJobDecorator
# @see Hydra::Derivatives::Processors::Ffmpeg
# @see https://github.com/scientist-softserv/palni-palci/issues/852
class CreateLargeDerivativesJob < CreateDerivativesJob
queue_as :auxiliary
end
5 changes: 5 additions & 0 deletions app/jobs/file_set_index_job.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class FileSetIndexJob < Hyrax::ApplicationJob
def perform(file_set)
file_set&.update_index
end
end
10 changes: 10 additions & 0 deletions app/jobs/prune_stale_guest_users_job.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# frozen_string_literal: true

class PruneStaleGuestUsersJob < ApplicationJob
non_tenant_job
repeat 'every week at 8am' # midnight PST

def perform
RolesService.prune_stale_guest_users
end
end
5 changes: 5 additions & 0 deletions app/jobs/work_index_job.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class WorkIndexJob < Hyrax::ApplicationJob
def perform(work)
work.update_index
end
end
25 changes: 25 additions & 0 deletions app/models/file_download_stat_decorator.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# frozen_string_literal: true

# OVERRIDE Hyrax hyrax-v3.5.0 to require Hyrax::Download so the method below doesn't fail

Hyrax::Download # rubocop:disable Lint/Void

module FileDownloadStatClass
# Hyrax::Download is sent to Hyrax::Analytics.profile as #hyrax__download
# see Legato::ProfileMethods.method_name_from_klass
def ga_statistics(start_date, file)
profile = Hyrax::Analytics.profile
unless profile
Hyrax.logger.error("Google Analytics profile has not been established. Unable to fetch statistics.")
return []
end
# OVERRIDE Hyrax hyrax-v3.5.0
profile.hyrax__download(sort: 'date',
start_date: start_date,
end_date: Date.yesterday,
limit: 10_000)
.for_file(file.id)
end
end

FileDownloadStat.singleton_class.send(:prepend, FileDownloadStatClass)
Loading

0 comments on commit 0ca6d93

Please sign in to comment.