Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow different templates for secondary literature #1043

Draft
wants to merge 6 commits into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
98 changes: 62 additions & 36 deletions app/admin/publication.rb
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
ActiveAdmin.register Publication do
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Having these changes in this patch makes it difficult to review this change.

Copy link
Contributor Author

@fjorba fjorba Dec 15, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I understand, but Emacs strips those extra spaces for me. In fact, there are so many in Muscat that it is difficult for me to stop Emacs to strip them everywhere else. Shouldn't be a policy in Muscat, like in other projects, to strip them before commiting upstream? I know that there are git hooks for that.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On the other hand, I have just seen that from the Github web interface it is possible to hide whitespace changes, using the icon in the middle of the Review changes button line.


include MergeControllerActions

collection_action :autocomplete_publication_name, :method => :get

menu :parent => "indexes_menu", :label => proc {I18n.t(:menu_publications)}

# Remove mass-delete action
batch_action :destroy, false

# Remove all action items
config.clear_action_items!
config.per_page = [10, 30, 50, 100]
Expand All @@ -22,30 +22,30 @@
#
# temporarily allow all parameters
controller do

after_destroy :check_model_errors

before_create do |item|
item.user = current_user
end
autocomplete :publication, [:name, :author, :description], :display_value => :autocomplete_label , :extra_data => [:author, :date, :description]


def check_model_errors(object)
return unless object.errors.any?
flash[:error] ||= []
flash[:error].concat(object.errors.full_messages)
end

def action_methods
return super - ['new', 'edit', 'destroy'] if is_selection_mode?
super
end

def permitted_params
params.permit!
end

def show
begin
@item = @publication = Publication.find(params[:id])
Expand All @@ -54,11 +54,23 @@ def show
return
end

@editor_profile = EditorConfiguration.get_show_layout @publication
@prev_item, @next_item, @prev_page, @next_page = Publication.near_items_as_ransack(params, @publication)
# Try to load the MARC object.
begin
@item.marc.load_source true
rescue ActiveRecord::RecordNotFound
# If resolving the remote objects fails, it means
# Something went wrong saving the source, like a DB falure
# continue to show the page so the user does not panic, and
# show an error message. Also send a mail to the administrators
flash[:error] = I18n.t(:unloadable_record)
AdminNotifications.notify("Publication #{@item.id} seems unloadable, please check", @item).deliver_now
end

@editor_profile = EditorConfiguration.get_show_layout @item
@prev_item, @next_item, @prev_page, @next_page = Publication.near_items_as_ransack(params, @item)

@jobs = @publication.delayed_jobs

respond_to do |format|
format.html
format.xml { render :xml => @item.marc.to_xml(@item.updated_at, @item.versions) }
Expand All @@ -84,8 +96,14 @@ def index
end

def new
flash.now[:error] = I18n.t(params[:validation_error], term: params[:validation_term]) if params[:validation_error]
@publication = Publication.new
@template_name = ""

if (!params[:existing_title] || params[:existing_title].empty?) && (!params[:new_record_type] || params[:new_record_type].empty?)
redirect_to action: :select_new_template
return
end

if params[:existing_title] and !params[:existing_title].empty?
# Check that the record does exist...
begin
Expand All @@ -94,7 +112,7 @@ def new
redirect_to admin_root_path, :flash => { :error => "#{I18n.t(:error_not_found)} (Publication #{params[:id]})" }
return
end

new_marc = MarcPublication.new(base_item.marc.marc_source)
new_marc.reset_to_new
@publication.marc = new_marc
Expand All @@ -109,25 +127,29 @@ def new
end

end

# Include the MARC extensions
include MarcControllerActions

member_action :reindex, method: :get do
job = Delayed::Job.enqueue(ReindexItemsJob.new(params[:id], Publication, :referring_sources))
redirect_to resource_path(params[:id]), notice: "Reindex Job started #{job.id}"
end

member_action :duplicate, method: :get do
redirect_to action: :new, :existing_title => params[:id]
return
end


collection_action :select_new_template, :method => :get do
@page_title = "#{I18n.t(:select_template)}"
end


###########
## Index ##
###########
###########

# Solr search all fields: "_equal"
filter :name_equals, :label => proc {I18n.t(:any_field_contains)}, :as => :string
filter :"100a_or_700a_contains", :label => proc {I18n.t(:filter_author_or_editor)}, :as => :string
Expand All @@ -143,14 +165,14 @@ def new
# This filter passes the value to the with() function in seach
# see config/initializers/ransack.rb
# Use it to filter sources by folder
filter :id_with_integer, :label => proc {I18n.t(:is_in_folder)}, as: :select,
filter :id_with_integer, :label => proc {I18n.t(:is_in_folder)}, as: :select,
collection: proc{Folder.where(folder_type: "Publication").collect {|c| [c.name, "folder_id:#{c.id}"]}}

index :download_links => false do
selectable_column if !is_selection_mode?
column (I18n.t :filter_wf_stage) {|cat| status_tag(cat.wf_stage,
label: I18n.t('status_codes.' + (cat.wf_stage != nil ? cat.wf_stage : ""), locale: :en))}
column (I18n.t :filter_id), :id
label: I18n.t('status_codes.' + (cat.wf_stage != nil ? cat.wf_stage : ""), locale: :en))}
column (I18n.t :filter_id), :id
column (I18n.t :filter_title_short), :name
column (I18n.t :filter_title), :description
column (I18n.t :filter_author), :author
Expand All @@ -160,19 +182,19 @@ def new
end
active_admin_muscat_actions( self )
end

sidebar :actions, :only => :index do
render :partial => "activeadmin/filter_workaround"
render :partial => "activeadmin/section_sidebar_index"
end

# Include the folder actions
include FolderControllerActions

##########
## Show ##
##########

show :title => proc{ active_admin_publication_show_title( @item.author, @item.description.truncate(60), @item.id) } do
# @item retrived by from the controller is not available there. We need to get it from the @arbre_context
active_admin_navigation_bar( self )
Expand All @@ -183,7 +205,7 @@ def new
else
render :partial => "marc/show"
end

## Source box. Use the standard helper so it is the same everywhere
active_admin_embedded_source_list(self, publication, !is_selection_mode? )

Expand All @@ -201,7 +223,7 @@ def new
end
end
end

# Box for institutions referring to this publication
active_admin_embedded_link_list(self, publication, Institution) do |context|
context.table_for(context.collection) do |cr|
Expand All @@ -216,10 +238,10 @@ def new
end
end
end

if !resource.get_items.empty?
panel I18n.t :filter_series_items do
search=Publication.solr_search do
search=Publication.solr_search do
fulltext(params[:id], :fields=>['7600'])
paginate :page => params[:items_list_page], :per_page=>15
order_by(:date_order)
Expand All @@ -239,19 +261,23 @@ def new
active_admin_navigation_bar( self )
active_admin_comments if !is_selection_mode?
end

sidebar :actions, :only => :show do
render :partial => "activeadmin/section_sidebar_show", :locals => { :item => publication }
end

##########
## Edit ##
##########

sidebar :sections, :only => [:edit, :new, :update] do
render("editor/section_sidebar") # Calls a partial
end


sidebar :help, :only => [:select_new_template] do
render :partial => "template_help"
end

form :partial => "editor/edit_wide"

end
3 changes: 3 additions & 0 deletions config/locales/de.yml
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,9 @@ de:
individual_entry_threatise_printed: "Theoreticum, gedruckt - Teileintrag der Sammlung"
single_threatise_printed: "Theoreticum, gedruckt - Individualeintrag"

legacy_templates: "LEGACY TEMPLATES"
Copy link
Contributor

@ahankinson ahankinson Dec 15, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We are trying to not put "placeholders" in the language files, so every new entry should be translated into its appropriate language before being added.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just followed @xhero advice: #1017 (comment)

So, which is the preferred way now?

legacy_publication: "SECONDARY LITERATURE UNIFIED TEMPLATE"

#################### MENUS
menu_home: "Home"
menu_sources: "Quellen"
Expand Down
6 changes: 5 additions & 1 deletion config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,7 @@ en:
select_template: "Select new template"
available_templates: "Available templates"
from_existing_source: "Create from existing source"
from_existing_publication: "Create from existing secondary literature"
create_from_existing: "Create"
record_types:
unspecified: "[Unknown template]"
Expand Down Expand Up @@ -245,7 +246,10 @@ en:
collection_record_threatise_printed: "Collection record for printed treatises"
individual_entry_threatise_printed: "Individual entry in a printed treatise collection"
single_threatise_printed: "Single printed treatise"


legacy_templates: "Legacy templates for compatibility"
legacy_publication: "Secondary literature unified template"

#################### MENUS
menu_home: "Home page"
menu_sources: "Sources"
Expand Down
3 changes: 3 additions & 0 deletions config/locales/es.yml
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,9 @@ es:
individual_entry_threatise_printed: "Entrada individual en una colección de tratados impresos"
single_threatise_printed: "Tratado impreso individual"

legacy_templates: "Plantillas antiguas, de compatibilidad"
legacy_publication: "Plantilla unificada para la literatura secundaria"

#################### MENUS
menu_home: "Página principal"
menu_sources: "Fuentes"
Expand Down
5 changes: 4 additions & 1 deletion config/locales/fr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,10 @@ fr:
threatise_printed: "Traités imprimés"
collection_record_threatise_printed: "Collection de traités imprimés"
individual_entry_threatise_printed: "Entrée dans une collection de traités imprimés"
single_threatise_printed: Traité imprimé individuel"
single_threatise_printed: "Traité imprimé individuel"

legacy_templates: "LEGACY TEMPLATES"
legacy_publication: "SECONDARY LITERATURE UNIFIED TEMPLATE"

#################### MENUS
menu_home: "Home"
Expand Down
3 changes: 3 additions & 0 deletions config/locales/it.yml
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,9 @@ it:
individual_entry_threatise_printed: "Singolo elemento in una collezione di trattati a stampa"
single_threatise_printed: "Trattato a stampa singolo"

legacy_templates: "LEGACY TEMPLATES"
legacy_publication: "SECONDARY LITERATURE UNIFIED TEMPLATE"

#################### MENUS
menu_home: "Home"
menu_sources: "Fonti"
Expand Down
3 changes: 3 additions & 0 deletions config/locales/pl.yml
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,9 @@ pl:
individual_entry_threatise_printed: Indywidualny wpis w kolekcji traktatów drukowanych
single_threatise_printed: Pojedynczy traktat drukowany

legacy_templates: "LEGACY TEMPLATES"
legacy_publication: "SECONDARY LITERATURE UNIFIED TEMPLATE"

#################### MENUS
menu_home: Strona główna
menu_sources: Źródła
Expand Down
3 changes: 3 additions & 0 deletions config/locales/pt.yml
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,9 @@ pt:
individual_entry_threatise_printed: "Tratado impresso, registro individual em coletânea"
single_threatise_printed: "Tratado impresso único"

legacy_templates: "LEGACY TEMPLATES"
legacy_publication: "SECONDARY LITERATURE UNIFIED TEMPLATE"

#################### MENUS
menu_home: "Início"
menu_sources: "Fontes"
Expand Down
7 changes: 7 additions & 0 deletions config/marc/default/publication/template_configuration.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
display:
legacy_templates:
legacy_publication:
record_type: default_publication

default_mapping:
legacy_publication: "default"
12 changes: 12 additions & 0 deletions lib/editor_configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -462,4 +462,16 @@ def self.get_source_default_file(record_type)
conf["default_mapping"][record_type.to_s]
end

def self.get_publication_templates
conf = YAML::load(IO.read(ConfigFilePath.get_marc_editor_profile_path("#{Rails.root}/config/marc/#{RISM::MARC}/publication/template_configuration.yml")))
return {} if !conf.has_key? "display"
conf["display"]
end

def self.get_publication_default_file(record_type)
conf = YAML::load(IO.read(ConfigFilePath.get_marc_editor_profile_path("#{Rails.root}/config/marc/#{RISM::MARC}/publication/template_configuration.yml")))
return nil if !conf.has_key? "default_mapping"
conf["default_mapping"][record_type.to_s]
end

end