Skip to content

Commit

Permalink
Merge pull request #12 from hudmol/boxes-done-better
Browse files Browse the repository at this point in the history
Boxes done better
  • Loading branch information
marktriggs authored Aug 2, 2016
2 parents 1366274 + 2578b49 commit 48c2366
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 27 deletions.
47 changes: 23 additions & 24 deletions backend/model/do_report.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)}}
]


Expand Down Expand Up @@ -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


Expand Down
6 changes: 3 additions & 3 deletions backend/model/trees_mixin.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand Down

0 comments on commit 48c2366

Please sign in to comment.