From 63e15c1fa3f8681e802b615a5e690fab9588cf4a Mon Sep 17 00:00:00 2001 From: James Bullen Date: Wed, 19 Jun 2019 10:08:44 +1000 Subject: [PATCH] fdid 66 should show the resource's dates - not each archival object's --- backend/model/ladybird_export.rb | 57 ++++++++++++++++++++++++++++---- 1 file changed, 51 insertions(+), 6 deletions(-) diff --git a/backend/model/ladybird_export.rb b/backend/model/ladybird_export.rb index 8516a25..29e325e 100644 --- a/backend/model/ladybird_export.rb +++ b/backend/model/ladybird_export.rb @@ -40,7 +40,7 @@ def column_definitions # Host, Title {fdid=63} {:header => "{fdid=63}", :proc => Proc.new {|row| host_title(row)}}, # Dates Inclusive/Bulk {fdid=66} - {:header => "{fdid=66}", :proc => Proc.new {|row| creation_years(row)}}, + {:header => "{fdid=66}", :proc => Proc.new {|row| collection_creation_years(row)}}, # Host, note {fdid=68} {:header => "{fdid=68}", :proc => Proc.new {|row| host_note(row)}}, # Creator {fdid=69} @@ -147,6 +147,10 @@ def creators_for_archival_object(id) @creators.fetch(id, []) end + def creation_dates_for_resource(id) + @resource_creation_dates.fetch(id, []) + end + def creation_dates_for_archival_object(id) @creation_dates.fetch(id, []) end @@ -251,7 +255,8 @@ def dataset ds = ds.select_append(Sequel.as(:sub_container__indicator_2, :sub_container_indicator)) ds = ds.select_append(Sequel.as(:type_enum__value, :sub_container_type)) - prepare_creation_dates + prepare_resource_creation_dates + prepare_ao_creation_dates prepare_related_agents prepare_extents prepare_notes @@ -273,7 +278,46 @@ def extract_ids }.compact end - def prepare_creation_dates + def prepare_resource_creation_dates + @all_resource_dates = {} + @resource_creation_dates = {} + + creation_enum_id = EnumerationValue + .filter(:enumeration_id => Enumeration.filter(:name => 'date_label').select(:id)) + .filter(:value => 'creation') + .select(:id) + .first[:id] + + bulk_type_enum_id = EnumerationValue + .filter(:enumeration_id => Enumeration.filter(:name => 'date_type').select(:id)) + .filter(:value => 'bulk') + .select(:id) + .first[:id] + + ASDate + .filter(:date__resource_id => @resource_id) + .select(:resource_id, + :expression, + :begin, + :end, + Sequel.as(:date__date_type_id, :date_type_id), + Sequel.as(:date__label_id, :label_id)) + .each do |row| + @all_resource_dates[row[:resource_id]] ||= [] + @all_resource_dates[row[:resource_id]] << row + + if row[:label_id] == creation_enum_id + if row[:date_type_id] == bulk_type_enum_id + row[:bulk] = true + end + + @resource_creation_dates[row[:resource_id]] ||= [] + @resource_creation_dates[row[:resource_id]] << row + end + end + end + + def prepare_ao_creation_dates @all_dates = {} @creation_dates = {} @@ -763,8 +807,9 @@ def all_years(row, mode = :range) # There are cases where there is more than one inclusive/single creation date object for an item (ex. Nov 3 1892 and April 8 1893). # In cases like these, we would like each date object separated with a semi-color (so we would get "Nov 3 1892; April 8 1893"). # HM: assuming only zero or none bulk creation dates (i.e. only looking at the first). - def creation_years(row) - dates = creation_dates_for_archival_object(row[:archival_object_id]) + # New requirement: 66 should be the collection date (if it exists) + def collection_creation_years(row) + dates = creation_dates_for_resource(@resource_id) return if dates.empty? @@ -772,7 +817,7 @@ def creation_years(row) bulk = dates.select{|d| d[:bulk]}.first def fmt_date(date) - date[:expression] || [(date[:begin] || '').sub(/-.*/, ''), (date[:end] || '').sub(/-.*/, '')].select{|d| !d.empty?}.compact.join('-') + date[:expression] || [(date[:begin] || '').sub(/-.*/, ''), (date[:end] || '').sub(/-.*/, '')].select{|d| !d.empty?}.compact.uniq.join('-') end out = non_bulk.map{|d| fmt_date(d)}.join('; ')