Skip to content

Commit

Permalink
Group all helper methods together
Browse files Browse the repository at this point in the history
  • Loading branch information
kdp-cloud committed May 29, 2024
1 parent 66a9e6a commit 12935e0
Showing 1 changed file with 17 additions and 18 deletions.
35 changes: 17 additions & 18 deletions app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ class ApplicationController < ActionController::Base
include FairSignposting

helper :all
helper_method %i[current_person is_condensed_view page_and_sort_params controller_model
displaying_single_page? display_isa_graph? safe_class_lookup]

layout Seek::Config.main_layout

Expand All @@ -54,7 +56,6 @@ def with_current_user
def current_person
current_user.try(:person)
end
helper_method :current_person

def partially_registered?
redirect_to register_people_path if current_user && !current_user.registration_complete?
Expand Down Expand Up @@ -119,7 +120,7 @@ def page_and_sort_params
params.permit(:page, :sort, :order, :view, :table_cols, permitted_filter_params)
end

helper_method :page_and_sort_params


def controller_model
begin
Expand All @@ -128,7 +129,6 @@ def controller_model
end
end

helper_method :controller_model

def self.api_actions(*actions)
@api_actions ||= []
Expand Down Expand Up @@ -234,7 +234,8 @@ def find_and_authorize_requested_item
case privilege
when :publish, :manage, :edit, :download, :delete
if current_user.nil?
flash[:error] = "You are not authorized to #{privilege} this #{name.humanize}, you may need to login first."
flash[:error] =
"You are not authorized to #{privilege} this #{name.humanize}, you may need to login first."
else
flash[:error] = "You are not authorized to #{privilege} this #{name.humanize}."
end
Expand Down Expand Up @@ -290,14 +291,16 @@ def render_not_found_error(e)

def render_unknown_attribute_error(e)
respond_to do |format|
format.json { render json: { errors: [{ title: 'Unknown attribute', details: e.message }] }, status: :unprocessable_entity }
format.json {
render json: { errors: [{ title: 'Unknown attribute', details: e.message }] }, status: :unprocessable_entity }
format.all { render plain: e.message, status: :unprocessable_entity }
end
end

def render_not_implemented_error(e)
respond_to do |format|
format.json { render json: { errors: [{ title: 'Not implemented', details: e.message }] }, status: :not_implemented }
format.json {
render json: { errors: [{ title: 'Not implemented', details: e.message }] }, status: :not_implemented }
format.all { render plain: e.message, status: :not_implemented }
end
end
Expand All @@ -319,8 +322,6 @@ def is_condensed_view?
(!params.has_key?(:view) && session.has_key?(:view) && !session[:view].nil? && session[:view]!="default")
end

helper_method :is_condensed_view


def log_event
# FIXME: why is needed to wrap in this block when the around filter already does ?
Expand Down Expand Up @@ -383,7 +384,8 @@ def log_event
user_agent: user_agent,
data: activity_loggable.title)
end
when *Seek::Util.authorized_types.map { |t| t.name.underscore.pluralize.split('/').last } + ["sample_types"] # TODO: Find a nicer way of doing this...
when *Seek::Util.authorized_types.map { |t|
t.name.underscore.pluralize.split('/').last } + ["sample_types"] # TODO: Find a nicer way of doing this...
action = 'create' if action == 'create_metadata' || action == 'create_from_template'
action = 'update' if action == 'create_version'
action = 'inline_view' if action == 'explore'
Expand Down Expand Up @@ -531,7 +533,8 @@ def rdf_enabled?
return unless request.format.rdf?
unless Seek::Util.rdf_capable_types.include?(controller_model)
respond_to do |format|
format.rdf { render plain: 'This resource does not support RDF', status: :not_acceptable, content_type: 'text/plain' }
format.rdf {
render plain: 'This resource does not support RDF', status: :not_acceptable, content_type: 'text/plain' }
end
end
end
Expand Down Expand Up @@ -607,9 +610,11 @@ def relationify_collection(collection)
def determine_extended_metadata_keys(asset = nil)
keys = []
if asset
type_id = params.dig(controller_name.singularize.to_sym, asset, :extended_metadata_attributes, :extended_metadata_type_id)
type_id = params.dig(controller_name.singularize.to_sym, asset, :extended_metadata_attributes,
:extended_metadata_type_id)
else
type_id = params.dig(controller_name.singularize.to_sym, :extended_metadata_attributes, :extended_metadata_type_id)
type_id = params.dig(controller_name.singularize.to_sym, :extended_metadata_attributes,
:extended_metadata_type_id)
end
if type_id.present?
metadata_type = ExtendedMetadataType.find(type_id)
Expand Down Expand Up @@ -651,14 +656,10 @@ def displaying_single_page?
@single_page || false
end

helper_method :displaying_single_page?

def display_isa_graph?
!displaying_single_page?
end

helper_method :display_isa_graph?


def creator_related_params
[:other_creators,
Expand All @@ -678,6 +679,4 @@ def creator_related_params
def safe_class_lookup(class_name, raise: true)
Seek::Util.lookup_class(class_name, raise: raise)
end

helper_method :safe_class_lookup
end

0 comments on commit 12935e0

Please sign in to comment.