From 0fd219f53736a0b2537077f5342fad84ebbd0e79 Mon Sep 17 00:00:00 2001 From: Ferran Jorba Date: Tue, 15 Dec 2020 09:00:45 +0100 Subject: [PATCH 1/2] Allow different templates for secondary literature This patch is the second version of the first step towards having different templates for secondary literature. It synchronises some code and configuration files from sources so now, when creating a new record, appears a menu with a single choice, the legacy template. This version takes into account the catalogues to publications rename and it adds the locale entries compatible with the i18n reorganisation. There are yet no new fields (like record type) or tag changes. --- app/admin/publication.rb | 98 ++++++++++++------- config/locales/de.yml | 3 + config/locales/en.yml | 6 +- config/locales/es.yml | 3 + config/locales/fr.yml | 5 +- config/locales/it.yml | 3 + config/locales/pl.yml | 3 + config/locales/pt.yml | 3 + .../publication/template_configuration.yml | 7 ++ lib/editor_configuration.rb | 12 +++ 10 files changed, 105 insertions(+), 38 deletions(-) create mode 100644 config/marc/default/publication/template_configuration.yml diff --git a/app/admin/publication.rb b/app/admin/publication.rb index d7a0220d7..d178b27d5 100644 --- a/app/admin/publication.rb +++ b/app/admin/publication.rb @@ -1,14 +1,14 @@ ActiveAdmin.register Publication do - + 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] @@ -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]) @@ -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) } @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 ) @@ -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? ) @@ -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| @@ -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) @@ -239,7 +261,7 @@ 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 @@ -247,11 +269,15 @@ def new ########## ## 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 diff --git a/config/locales/de.yml b/config/locales/de.yml index 52b41c685..ed663c0e7 100644 --- a/config/locales/de.yml +++ b/config/locales/de.yml @@ -246,6 +246,9 @@ de: individual_entry_threatise_printed: "Theoreticum, gedruckt - Teileintrag der Sammlung" single_threatise_printed: "Theoreticum, gedruckt - Individualeintrag" + legacy_templates: "LEGACY TEMPLATES" + legacy_publication: "SECONDARY LITERATURE UNIFIED TEMPLATE" + #################### MENUS menu_home: "Home" menu_sources: "Quellen" diff --git a/config/locales/en.yml b/config/locales/en.yml index db2cb8773..1623548da 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -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]" @@ -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" diff --git a/config/locales/es.yml b/config/locales/es.yml index 9cd9f12d3..8502cdffd 100644 --- a/config/locales/es.yml +++ b/config/locales/es.yml @@ -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" diff --git a/config/locales/fr.yml b/config/locales/fr.yml index 8c9b56d2e..ac3d868de 100644 --- a/config/locales/fr.yml +++ b/config/locales/fr.yml @@ -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" diff --git a/config/locales/it.yml b/config/locales/it.yml index b3185d97f..f2efa0e5a 100644 --- a/config/locales/it.yml +++ b/config/locales/it.yml @@ -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" diff --git a/config/locales/pl.yml b/config/locales/pl.yml index ba1f2300c..32e70140c 100644 --- a/config/locales/pl.yml +++ b/config/locales/pl.yml @@ -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 diff --git a/config/locales/pt.yml b/config/locales/pt.yml index 133a5d185..dfe65dd87 100644 --- a/config/locales/pt.yml +++ b/config/locales/pt.yml @@ -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" diff --git a/config/marc/default/publication/template_configuration.yml b/config/marc/default/publication/template_configuration.yml new file mode 100644 index 000000000..c75c5f10a --- /dev/null +++ b/config/marc/default/publication/template_configuration.yml @@ -0,0 +1,7 @@ +display: + legacy_templates: + legacy_publication: + record_type: default_publication + +default_mapping: + legacy_publication: "default" diff --git a/lib/editor_configuration.rb b/lib/editor_configuration.rb index a7c425642..180afe600 100644 --- a/lib/editor_configuration.rb +++ b/lib/editor_configuration.rb @@ -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 From d863c01c3708517becd6509a7406afd629d33cd4 Mon Sep 17 00:00:00 2001 From: Ferran Jorba Date: Thu, 14 Dec 2023 17:56:21 +0100 Subject: [PATCH 2/2] Rename "legacy" templates to "generic" Generic is more... generic, and doesn't imply obsolescence. --- config/locales/ca.yml | 3 +++ config/locales/de.yml | 4 ++-- config/locales/en.yml | 4 ++-- config/locales/es.yml | 4 ++-- config/locales/fr.yml | 4 ++-- config/locales/it.yml | 4 ++-- config/locales/pl.yml | 4 ++-- config/locales/pt.yml | 4 ++-- config/marc/default/publication/template_configuration.yml | 6 +++--- 9 files changed, 20 insertions(+), 17 deletions(-) diff --git a/config/locales/ca.yml b/config/locales/ca.yml index 96bc0c04f..62b507193 100644 --- a/config/locales/ca.yml +++ b/config/locales/ca.yml @@ -252,6 +252,9 @@ ca: individual_entry_threatise_printed: "Entrada individual en una col·lecció de tractats impresos" single_threatise_printed: "Tractat imprès individual" + generic_publication_templates: "Plantilles genèriques" + generic_publication_template: "Plantilla genèrica de literatura secundària" + #################### MENUS menu_home: "Pagina d'inici" menu_sources: "Fonts" diff --git a/config/locales/de.yml b/config/locales/de.yml index cd634dc94..9ce77b64f 100644 --- a/config/locales/de.yml +++ b/config/locales/de.yml @@ -252,8 +252,8 @@ de: individual_entry_threatise_printed: "Theoreticum, gedruckt - Teileintrag der Sammlung" single_threatise_printed: "Theoreticum, gedruckt - Individualeintrag" - legacy_templates: "LEGACY TEMPLATES" - legacy_publication: "SECONDARY LITERATURE UNIFIED TEMPLATE" + generic_publication_templates: "GENERIC TEMPLATES" + generic_publication_template: "SECONDARY LITERATURE GENERIC TEMPLATE" #################### MENUS menu_home: "Home" diff --git a/config/locales/en.yml b/config/locales/en.yml index 6a9b1aa39..980d5fec3 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -253,8 +253,8 @@ en: 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" + generic_publication_templates: "Generic templates" + generic_publication_template: "Secondary literature generic template" #################### MENUS menu_home: "Home page" diff --git a/config/locales/es.yml b/config/locales/es.yml index 3dba131e2..e06587ea3 100644 --- a/config/locales/es.yml +++ b/config/locales/es.yml @@ -253,8 +253,8 @@ 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" + generic_publication_templates: "Plantillas genéricas" + generic_publication_template: "Plantilla genérica para literatura secundaria" #################### MENUS menu_home: "Página principal" diff --git a/config/locales/fr.yml b/config/locales/fr.yml index 34b90a9fc..bf0654d04 100644 --- a/config/locales/fr.yml +++ b/config/locales/fr.yml @@ -252,8 +252,8 @@ fr: individual_entry_threatise_printed: "Entrée dans une collection de traités imprimés" single_threatise_printed: "Traité imprimé individuel" - legacy_templates: "LEGACY TEMPLATES" - legacy_publication: "SECONDARY LITERATURE UNIFIED TEMPLATE" + generic_publication_templates: "GENERIC TEMPLATES" + generic_publication_template: "SECONDARY LITERATURE GENERIC TEMPLATE" #################### MENUS menu_home: "Home" diff --git a/config/locales/it.yml b/config/locales/it.yml index 7db2cd95b..c21f5bb77 100644 --- a/config/locales/it.yml +++ b/config/locales/it.yml @@ -257,8 +257,8 @@ 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" + generic_publication_templates: "GENERIC TEMPLATES" + generic_publication_template: "SECONDARY LITERATURE GENERIC TEMPLATE" #################### MENUS menu_home: "Home" diff --git a/config/locales/pl.yml b/config/locales/pl.yml index a643f9c9e..58857f3f2 100644 --- a/config/locales/pl.yml +++ b/config/locales/pl.yml @@ -253,8 +253,8 @@ 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" + generic_publication_templates: "GENERIC TEMPLATES" + generic_publication_template: "SECONDARY LITERATURE GENERIC TEMPLATE" #################### MENUS menu_home: Strona główna diff --git a/config/locales/pt.yml b/config/locales/pt.yml index aac996324..6ee276e75 100644 --- a/config/locales/pt.yml +++ b/config/locales/pt.yml @@ -249,8 +249,8 @@ 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" + generic_publication_templates: "GENERIC TEMPLATES" + generic_publication_template: "SECONDARY LITERATURE GENERIC TEMPLATE" #################### MENUS menu_home: "Início" diff --git a/config/marc/default/publication/template_configuration.yml b/config/marc/default/publication/template_configuration.yml index c75c5f10a..ed621173d 100644 --- a/config/marc/default/publication/template_configuration.yml +++ b/config/marc/default/publication/template_configuration.yml @@ -1,7 +1,7 @@ display: - legacy_templates: - legacy_publication: + generic_publication_templates: + generic_publication_template: record_type: default_publication default_mapping: - legacy_publication: "default" + generic_publication: "default"