Module: CsvTemplateGenerator
- Defined in:
- backend/app/lib/csv_template_generator.rb
Defined Under Namespace
Classes: CsvTemplateError, Template, TemplateSpec
Class Method Summary collapse
-
.csv_for_top_container_generation(resource_id) ⇒ Object
Module-level methods here are primarily what’s called by consumers at the controller level.
-
.q(*args) ⇒ Object
Class Method Details
.csv_for_top_container_generation(resource_id) ⇒ Object
Module-level methods here are primarily what’s called by consumers at the controller level. Generally they will consist of 1. instantiate a template definition 2. fetch a a dataset 3. return an enumerator over CSV lines for streaming to frontend/direct download
174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 |
# File 'backend/app/lib/csv_template_generator.rb', line 174 def csv_for_top_container_generation(resource_id) tmpl = Template.new( TemplateSpec.new( sheet_description: "Archival Object Top Container Generation Template", field_name_text: "ArchivesSpace field code (please don't edit this row)", title_text: "Field Name", group_text: "Maps to ASpace Type", columns: { # For reference archival_object_id: {title: "Archival Object ID", group: "Archival Object"}, ref_id: {title: "Ref ID", group: "Archival Object"}, component_id: {title: "Component ID", group: "Archival Object"}, archival_object_title: {title: "Title", group: "Archival Object"}, resource_title: {title: "Resource Title", group: "Resource"}, ead_id: {title: "EAD ID", group: "Resource"}, identifier: {title: "Identifier", group: "Resource", formatter: ->(value) { JSON.parse(value).compact.join(" ") }}, # Editable instance_type: {title: "Instance Type", group: "Instance", blank: true}, top_container_id: {title: "Top Container ID (existing top container, leave blank if creating new container)", group: "Container", blank: true}, top_container_type: {title: "Top Container Type", blank: true, group: "Top Container"}, top_container_indicator: {title: "Top Container Indicator", group: "Top Container", blank: true}, top_container_barcode: {title: "Top container barcode", group: "Top Container", blank: true}, container_profile_id: {title: "Container Profile ID", group: "Top Container", blank: true}, child_type: {title: "Child Type", group: "Sub Container", blank: true}, child_indicator: {title: "Child Indicator", group: "Sub Container", blank: true}, child_barcode: {title: "Child Barcode", group: "Sub Container", blank: true}, location_id: {title: "Location ID", group: "Location", blank: true} } ) ) dataset = DB.open do |ds| ds[:resource]. inner_join(:archival_object, :root_record_id => :id). where(q(:resource, :id) => resource_id). select( q(:archival_object, :id).as(:archival_object_id), q(:archival_object, :ref_id), q(:archival_object, :component_id), q(:archival_object, :title).as(:archival_object_title), q(:resource, :title).as(:resource_title), q(:resource, :ead_id), q(:resource, :identifier) ). order(q(:archival_object, :id)) end tmpl.each(dataset) end |
.q(*args) ⇒ Object
164 165 166 167 |
# File 'backend/app/lib/csv_template_generator.rb', line 164 def q(*args) # Convenience method to get qualified names without having to type 14 chars Sequel.qualify(*args) end |