From c74e30ae7a0194d969c9f15964981b601de4b503 Mon Sep 17 00:00:00 2001 From: jambun Date: Tue, 2 Aug 2016 12:01:56 +1000 Subject: [PATCH 1/3] longer labels for indicators, and a bit of ocd --- backend/model/do_report.rb | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/backend/model/do_report.rb b/backend/model/do_report.rb index 39d91bf..1a24c10 100644 --- a/backend/model/do_report.rb +++ b/backend/model/do_report.rb @@ -6,30 +6,30 @@ class DOReport attr_reader :items BASE_COLUMNS = [ - {:header => "Resource ID", :proc => Proc.new {|resource, item| resource_id(resource)}}, - {:header => "Ref ID", :proc => Proc.new {|resource, item| ref_id(item)}}, - {:header => "URI", :proc => Proc.new {|resource, item| record_uri(item)}}, - {:header => "Indicator 1", :proc => Proc.new {|resource, item, dates, box| indicator_1(box)}}, - {:header => "Indicator 2", :proc => Proc.new {|resource, item, dates, box| indicator_2(box)}}, - {:header => "Indicator 3", :proc => Proc.new {|resource, item, dates, box| indicator_3(box)}}, - {:header => "Title", :proc => Proc.new {|resource, item| record_title(item)}}, - {:header => "Component ID", :proc => Proc.new {|resource, item| component_id(item)}}, + {:header => "Resource ID", :proc => Proc.new {|resource, item| resource_id(resource)}}, + {:header => "Ref ID", :proc => Proc.new {|resource, item| ref_id(item)}}, + {:header => "URI", :proc => Proc.new {|resource, item| record_uri(item)}}, + {:header => "Container Indicator 1", :proc => Proc.new {|resource, item, dates, box| indicator_1(box)}}, + {:header => "Container Indicator 2", :proc => Proc.new {|resource, item, dates, box| indicator_2(box)}}, + {:header => "Container Indicator 3", :proc => Proc.new {|resource, item, dates, box| indicator_3(box)}}, + {:header => "Title", :proc => Proc.new {|resource, item| record_title(item)}}, + {:header => "Component ID", :proc => Proc.new {|resource, item| component_id(item)}}, ] SERIES_COLUMNS = [ - {:header => "Series", :proc => Proc.new { |resource, item, dates, box, series| record_title(series) }} + {:header => "Series", :proc => Proc.new { |resource, item, dates, box, series| record_title(series) }} ] SUBSERIES_COLUMNS = [ - {:header => "Sub-Series", :proc => Proc.new { |resource, item, dates, box, series, subseries| record_title(subseries) }} + {:header => "Sub-Series", :proc => Proc.new { |resource, item, dates, box, series, subseries| record_title(subseries) }} ] BARCODE_COLUMNS = [ - {:header => "Barcode", :proc => Proc.new {|resource, item, dates, box| barcode(box)}} + {:header => "Barcode", :proc => Proc.new {|resource, item, dates, box| barcode(box)}} ] DATES_COLUMNS = [ - {:header => "Dates", :proc => Proc.new {|resource, item, dates| date_string(dates)}} + {:header => "Dates", :proc => Proc.new {|resource, item, dates| date_string(dates)}} ] From 186fab218e0a1b9097ec4b4b0068d82b3684348e Mon Sep 17 00:00:00 2001 From: jambun Date: Tue, 2 Aug 2016 12:53:32 +1000 Subject: [PATCH 2/3] handle many boxes with aplomb --- backend/model/do_report.rb | 23 +++++++++++------------ backend/model/trees_mixin.rb | 4 ++-- 2 files changed, 13 insertions(+), 14 deletions(-) diff --git a/backend/model/do_report.rb b/backend/model/do_report.rb index 1a24c10..52db926 100644 --- a/backend/model/do_report.rb +++ b/backend/model/do_report.rb @@ -240,31 +240,30 @@ def self.ref_id(item) end - def self.indicator_1(box) + def self.box_concat(box, &block) return '' unless box - if box[:top_container] - box[:top_container][:indicator] - end + out = box.map { |b| block.call(b) } + out.compact.join(', ') + end + + + def self.indicator_1(box) + box_concat(box) { |b| b[:top_container][:indicator] if b[:top_container] } end def self.barcode(box) - return '' unless box - if box[:top_container] - box[:top_container][:barcode] - end + box_concat(box) { |b| b[:top_container][:barcode] if b[:top_container] } end def self.indicator_2(box) - return '' unless box - box[:sub_container][:indicator_2] + box_concat(box) { |b| b[:sub_container][:indicator_2] } end def self.indicator_3(box) - return '' unless box - box[:sub_container][:indicator_3] + box_concat(box) { |b| b[:sub_container][:indicator_3] } end diff --git a/backend/model/trees_mixin.rb b/backend/model/trees_mixin.rb index 3a2f619..b5688f1 100644 --- a/backend/model/trees_mixin.rb +++ b/backend/model/trees_mixin.rb @@ -71,8 +71,8 @@ def quick_containers :type_3 => row[:sub_container_type_3], :indicator_3 => row[:sub_container_indicator_3], } - result[row[:archival_object_id]] = fields - + result[row[:archival_object_id]] ||= [] + result[row[:archival_object_id]] << fields end result end From 2578b49e249c06edd619d5b51164f3f12b1fbab8 Mon Sep 17 00:00:00 2001 From: jambun Date: Tue, 2 Aug 2016 13:23:03 +1000 Subject: [PATCH 3/3] don't forget top containers lacking types. they matter too --- backend/model/trees_mixin.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/backend/model/trees_mixin.rb b/backend/model/trees_mixin.rb index b5688f1..9f58b3e 100644 --- a/backend/model/trees_mixin.rb +++ b/backend/model/trees_mixin.rb @@ -83,7 +83,7 @@ def quick_containers def containers_ds TopContainer.linked_instance_ds .join(:archival_object, :id => :instance__archival_object_id) - .join(:enumeration_value___top_container_type, :id => :top_container__type_id) + .left_join(:enumeration_value___top_container_type, :id => :top_container__type_id) .left_join(:enumeration_value___sub_container_type_2, :id => :sub_container__type_2_id) .left_join(:enumeration_value___sub_container_type_3, :id => :sub_container__type_3_id) .filter(:archival_object__root_record_id => self.id)