Skip to content

Commit

Permalink
Drop digitization_work_order plugin requirement by including all the …
Browse files Browse the repository at this point in the history
…bits we need
  • Loading branch information
payten committed May 3, 2022
1 parent b7de20e commit 2350cef
Show file tree
Hide file tree
Showing 12 changed files with 1,654 additions and 24 deletions.
4 changes: 3 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
# Placeholder
ASpaceGems.setup if defined? ASpaceGems

gem "write_xlsx", "1.01.0"
14 changes: 10 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,16 +78,22 @@ existing note, a new note will be created.

## Prerequisites

This plugin relies on the `digitization_work_order` plugin being enabled,
available here:

https://github.com/hudmol/digitization_work_order.
### MySQL

A MySQL database is also required. For instructions on how to setup MySQL and
ArchivesSpace please see:

https://archivesspace.github.io/tech-docs/provisioning/mysql.html

### `v1.4.x` and under: `digitization_work_order` plugin

**This prerequisite was dropped as of release `v1.5.0`.**

For all releases up to and and including `v1.4.x`, this plugin relies on the
`digitization_work_order` plugin being enabled, available here:

https://github.com/hudmol/digitization_work_order.

## Installation

Download the latest release from the Releases tab in Github:
Expand Down
10 changes: 10 additions & 0 deletions backend/controllers/spreadsheet_bulk_updater.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,14 @@ class ArchivesSpaceService < Sinatra::Base
]
end

Endpoint.get('/plugins/spreadsheet_bulk_updater/repositories/:repo_id/resources/:id/small_tree')
.description("Generate the archival object tree for a resource")
.params(["repo_id", :repo_id],
["id", :id])
.permissions([:view_repository])
.returns([200, ""]) \
do
json_response(BulkUpdaterSmallTree.for_resource(params[:id]))
end

end
7 changes: 7 additions & 0 deletions backend/model/bulk_updater_small_tree.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
class BulkUpdaterSmallTree

def self.for_resource(resource_id)
Resource.get_or_die(resource_id).bulk_updater_quick_tree
end

end
99 changes: 99 additions & 0 deletions backend/model/trees_mixin.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
module Trees
def bulk_updater_quick_tree
links = {}
properties = {}

root_type = self.class.root_type
node_type = self.class.node_type

top_nodes = []

container_info = bulk_updater_fetch_container_info

query = build_node_query

offset = 0
loop do
nodes = query.limit(NODE_PAGE_SIZE, offset)

nodes.each do |node|
if node.parent_id
links[node.parent_id] ||= []
links[node.parent_id] << [node.position, node.id]
else
top_nodes << [node.position, node.id]
end

properties[node.id] = {
:title => node.display_string,
:uri => self.class.uri_for(node_type, node.id),
:ref_id => node[:ref_id],
:component_id => node[:component_id],
:container => container_info.fetch(node.id, nil),
}

# Drop out nils to keep the object size as small as possible
properties[node.id].keys.each do |key|
properties[node.id].delete(key) if properties[node.id][key].nil?
end
end

if nodes.empty?
break
else
offset += NODE_PAGE_SIZE
end
end

result = {
:title => self.title,
:identifier => Identifiers.format(Identifiers.parse(self.identifier)),
:children => top_nodes.sort_by(&:first).map {|_, node| self.class.assemble_tree(node, links, properties)},
:uri => self.class.uri_for(root_type, self.id)
}

result
end


private

def bulk_updater_containers_ds
TopContainer.linked_instance_ds
.join(:archival_object, :id => :instance__archival_object_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)
.select(Sequel.as(:archival_object__id, :archival_object_id),
Sequel.as(:top_container__barcode, :top_container_barcode),
Sequel.as(:top_container_type__value, :top_container_type),
Sequel.as(:top_container__indicator, :top_container_indicator),
Sequel.as(:sub_container_type_2__value, :sub_container_type_2),
Sequel.as(:sub_container__indicator_2, :sub_container_indicator_2),
Sequel.as(:sub_container_type_3__value, :sub_container_type_3),
Sequel.as(:sub_container__indicator_3, :sub_container_indicator_3))
end


def bulk_updater_fetch_container_info
result = {}

bulk_updater_containers_ds.each do |row|
result[row[:archival_object_id]] = [
# BoxType Indicator [Barcode]
[row[:top_container_type],
row[:top_container_indicator],
row[:top_container_barcode] ? ('[' + row[:top_container_barcode] + ']') : nil].compact.join(': '),

# BoxType_2 Indicator_2
[row[:sub_container_type_2], row[:sub_container_indicator_2]].compact.join(': '),

# BoxType_3 Indicator_3
[row[:sub_container_type_3], row[:sub_container_indicator_3]].compact.join(': '),
].reject(&:empty?).join(', ')
end

result
end
end
10 changes: 0 additions & 10 deletions backend/plugin_init.rb
Original file line number Diff line number Diff line change
@@ -1,13 +1,3 @@
unless AppConfig[:plugins].include?('digitization_work_order')
msg = [
"Hi there, thanks for trying out this great plugin!",
"Currently it relies on the digitization_work_order plugin, which you can download here: https://github.com/hudmol/digitization_work_order.",
"Thanks again!",
]
Log.error("\n\nWe hit an error while starting as_spreadsheet_bulk_updater:\n\n" + msg.join("\n") + "\n\n")
raise msg.join(' ')
end

if ASpaceEnvironment.demo_db?
msg = [
"Hi there, thanks for trying out this great plugin!",
Expand Down
74 changes: 74 additions & 0 deletions frontend/assets/bulk_updater.css
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,77 @@
.bulk-update-column-selector td.label-cell label, .bulk-update-column-selector td.label-cell input[type=checkbox] {
margin: 0;
}

#bulk_updater_table {
white-space: nowrap;
}

#bulk_updater_table > .fattable-body-container > div > div {
padding: 6px 0 0 10px;
}

#bulk_updater_table .work-order-spaces {
float: left;
height: 200%;
margin-top: -10px;
}

#bulk_updater_table .work-order-space {
display: inline-block;
width: 15px;
border-left: 1px dotted #DDD;
height: 100%;
margin-left: 10px;
}
#bulk_updater_table .work-order-label {
}
#bulk_updater_table .work-order-checkbox-label {
width: 100%;
text-align: center;
}
#bulk_updater_table .work-order-has-children .work-order-label {
font-weight: bold;
}

#bulk_updater_table .metadata-field-label {
font-weight: bold;
color: #888;
}

#bulk_updater_table .metadata-field-label:after {
content: ':';
margin-right: 4px;
}

#bulk_updater_table .metadata-field-value {
margin-right: 8px;
}

#bulk_updater_buttons .additional-options legend {
padding-top: 10px;
margin-bottom: 0;
}

.bulk_updater_modal {
display: none;
position: fixed;
top: 80px;
background: #FFF;
width: 50%;
border: 2px solid #DDD;
margin: auto;
padding: 20px;
}

.modal_overlay {
display: none;
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
background: #000;
opacity: 0.5;
filter: alpha(opacity=50);
}

Loading

0 comments on commit 2350cef

Please sign in to comment.