Skip to content

Commit

Permalink
Merge pull request #16 from hudmol/v2.0-dev
Browse files Browse the repository at this point in the history
V2.0 dev
  • Loading branch information
jambun authored May 10, 2017
2 parents facc19e + 34a46bc commit 809f9fa
Show file tree
Hide file tree
Showing 11 changed files with 869 additions and 100 deletions.
25 changes: 25 additions & 0 deletions backend/controllers/report.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,29 @@ class ArchivesSpaceService < Sinatra::Base
]
end


Endpoint.post('/plugins/digitization_work_order/repositories/:repo_id/ladybird')
.description("Return Excel formatted export for record uris")
.params(["repo_id", :repo_id],
["uri", [String], "The uris of the records to include in the report"],
["resource_uri", String, "The resource URI"])
.permissions([:view_repository])
.returns([200, "report"]) \
do
[
200,
{
"Content-Type" => "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
"Content-Disposition" => "attachment; filename=\"#{ladybird_export_filename(JSONModel.parse_reference(params[:resource_uri]).fetch(:id))}\""
},
LadybirdExport.new(params[:uri], params[:resource_uri]).to_stream
]
end

private

def ladybird_export_filename(resource_id)
"digitization_work_order_report.#{Resource.id_to_identifier(resource_id).gsub(' ', '_')}.xlsx"
end

end
693 changes: 693 additions & 0 deletions backend/model/ladybird_export.rb

Large diffs are not rendered by default.

39 changes: 23 additions & 16 deletions frontend/assets/work_order.js
Original file line number Diff line number Diff line change
@@ -1,26 +1,33 @@
var WorkOrderToolbarAction = function() {
this.setupButton();
};


WorkOrderToolbarAction.prototype.setupButton = function() {
this.$button = $(AS.renderTemplate("workOrderButtonTemplate"));
/* The past. Eventually this (and the conditional below) can go away. */
var setupButtonASpace15 = function() {
$workOrder = $(AS.renderTemplate("workOrderButtonTemplate"));

/* ArchivesSpace 1.5.x */
$workOrder.addClass("btn btn-xs btn-default");
var $btnGroup = $("<div>").addClass("btn-group");

this.$button.appendTo($btnGroup);
$workOrder.appendTo($btnGroup);
$btnGroup.appendTo($("#archives_tree_toolbar .btn-toolbar"));
}
};

/* The future! */
var setupButtonASpace2x = function() {
$workOrder = $(AS.renderTemplate("workOrderButtonTemplate"));
/* ArchivesSpace 2.x */
$('#other-dropdown .dropdown-menu').append($('<li />').append($workOrder));
$('#other-dropdown').show();
};


// if a resource tree page, setup the work order toolbar action
// setup the work order toolbar action
$(document).on("loadedrecordform.aspace", function(event, $container) {
// are we dealing with a record with a tree?
if ($(".archives-tree").data("read-only") || $container.is("#archives_tree_toolbar")) {
// is the tree a resource tree?
if (AS._tree && AS._tree.get_json()[0].type == "resource") {
// hurray! add the button.
new WorkOrderToolbarAction();
if (typeof(tree) === 'undefined') {
if (window.location.pathname.indexOf("/resources/") >= 0) {
setupButtonASpace15();
}
} else {
if (tree && tree.current().data('jsonmodel_type') == 'resource') {
setupButtonASpace2x();
}
}
});
35 changes: 24 additions & 11 deletions frontend/controllers/work_order_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,31 +2,46 @@

class WorkOrderController < ApplicationController

set_access_control "view_repository" => [:index, :generate_report]
set_access_control "view_repository" => [:index, :generate_report, :generate_ladybird_export]

def index
@uri = params[:resource]
@tree = escape_xml_characters(load_tree)
end


def generate_ladybird_export
uri = "/plugins/digitization_work_order/repositories/#{session[:repo_id]}/ladybird"
args = {'uri[]' => JSON.parse(params[:selected]), 'resource_uri' => params[:resource]}

generate_response(uri, args)
end


def generate_report
uris = JSON.parse(params[:selected])
uri = "/plugins/digitization_work_order/repositories/#{session[:repo_id]}/report"
args = {
'uri[]' => JSON.parse(params[:selected]),
'extras[]' => JSON.parse(params[:extras]),
'generate_ids' => params[:report_type] == 'downloadWorkOrder'
}

generate_response(uri, args)
end

extras = JSON.parse(params[:extras])

generate_ids = params[:report_type] == 'downloadWorkOrder'
private


def generate_response(uri, args)
queue = Queue.new

backend_session = JSONModel::HTTP::current_backend_session

Thread.new do
JSONModel::HTTP::current_backend_session = backend_session
begin
post_with_stream_response("/plugins/digitization_work_order/repositories/#{session[:repo_id]}/report",
"uri[]" => uris,
"extras[]" => extras,
"generate_ids" => generate_ids) do |report_response|
post_with_stream_response(uri, args) do |report_response|
response.headers['Content-Disposition'] = report_response['Content-Disposition']
response.headers['Content-Type'] = report_response['Content-Type']
response.headers['Last-Modified'] = Time.now.to_s
Expand Down Expand Up @@ -71,10 +86,8 @@ def self.each(&block)
end

self.response_body.queue = queue
end


private
end


def escape_xml_characters(tree)
Expand Down
1 change: 1 addition & 0 deletions frontend/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ en:
loading: Loading...
show_work_order_modal_button: Download Work Order ...
download_report_button: Download Report
download_ladybird_export_button: Download Ladybird Export
cancel_button: Cancel
resource: Resource
records_selected: Records selected
Expand Down
10 changes: 8 additions & 2 deletions frontend/plugin_init.rb
Original file line number Diff line number Diff line change
@@ -1,2 +1,8 @@
my_routes = [File.join(File.dirname(__FILE__), "routes.rb")]
ArchivesSpace::Application.config.paths['config/routes'].concat(my_routes)
if ArchivesSpace::Application.respond_to?(:extend_aspace_routes)
# > v2.0 way of defining routes
ArchivesSpace::Application.extend_aspace_routes(File.join(File.dirname(__FILE__), "routes.rb"))
else
# < v2.0 way of defining routes
my_routes = [File.join(File.dirname(__FILE__), "routes.rb")]
ArchivesSpace::Application.config.paths['config/routes'].concat(my_routes)
end
1 change: 1 addition & 0 deletions frontend/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

scope prefix do
match('/plugins/work_order/generate_report' => 'work_order#generate_report', :via => [:post])
match('/plugins/work_order/generate_ladybird_export' => 'work_order#generate_ladybird_export', :via => [:post])
match('/plugins/work_order' => 'work_order#index', :via => [:get])
end
end
Expand Down
22 changes: 12 additions & 10 deletions frontend/views/layout_head.html.erb
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
<%= stylesheet_link_tag "#{AppConfig[:frontend_prefix]}assets/work_order.css" %>
<%= javascript_include_tag "#{AppConfig[:frontend_prefix]}assets/work_order.js" %>
<script type="text/template" id="workOrderButtonTemplate">
<%= link_to I18n.t("plugins.digitization_work_order.toolbar_button"), {:controller => :work_order, :action => :index, :resource => @resource ? @resource.uri : nil}, {:class => "btn btn-xs btn-default"} %>
</script>
<script type="text/template" id="workOrderLoadingTemplate">
<div class="modal-body" id="workOrderForm">
<%= I18n.t("plugins.digitization_work_order.loading") %>
</div>
</script>
<% if @resource && controller_name == 'resources' && action_name == 'show' %>
<%= stylesheet_link_tag "#{AppConfig[:frontend_prefix]}assets/work_order.css" %>
<%= javascript_include_tag "#{AppConfig[:frontend_prefix]}assets/work_order.js" %>
<script type="text/template" id="workOrderButtonTemplate">
<%= link_to I18n.t("plugins.digitization_work_order.toolbar_button"), {:controller => :work_order, :action => :index, :resource => @resource.uri} %>
</script>
<script type="text/template" id="workOrderLoadingTemplate">
<div class="modal-body" id="workOrderForm">
<%= I18n.t("plugins.digitization_work_order.loading") %>
</div>
</script>
<% end %>
62 changes: 62 additions & 0 deletions frontend/views/work_order/_do_report.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
<div id='work_order_buttons'>
<div class="form-group">
<form class="form-inline">
<fieldset class="form-group additional-options">
<legend><%= I18n.t("plugins.digitization_work_order.additional_options") %></legend>
<label class="checkbox-inline" for="series"><input type="checkbox" id="series" name="series">
<%= I18n.t("plugins.digitization_work_order.series_title") %>
</label>
<label class="checkbox-inline" for="subseries"><input type="checkbox" id="subseries" name="subseries">
<%= I18n.t("plugins.digitization_work_order.subseries_title") %>
</label>
<label class="checkbox-inline" for="barcode"><input type="checkbox" id="barcode" name="barcode">
<%= I18n.t("plugins.digitization_work_order.barcode") %>
</label>
<label class="checkbox-inline" for="dates"><input type="checkbox" id="dates" name="dates">
<%= I18n.t("plugins.digitization_work_order.dates") %>
</label>
</fieldset>
</form>
</div>


<p class="alert alert-info" role="alert">If you would like a report of metadata for these items without generating component unique identifiers (CUIDs) , select <strong>Download Report</strong>. If you would like to create a work order and generate CUIDs for archival objects currently lacking them, select <strong>Download Work Order</strong>.</p>

<div class="form-group">
<button id="generateReport" class="btn btn-primary submit-btn" disabled>
<%= I18n.t("plugins.digitization_work_order.download_report_button") %>
</button>
<button id="showWorkOrderModal" class="btn btn-primary submit-btn" disabled>
<%= I18n.t("plugins.digitization_work_order.show_work_order_modal_button") %>
</button>
<%= link_to I18n.t("plugins.digitization_work_order.cancel_button"),:back, :class => "btn btn-default" %>
</div>

<%= form_tag({:controller => :work_order, :action => :generate_report}, {:method => 'post', :id => "work_order_form"}) do |form| %>
<%= hidden_field_tag "resource", @uri %>
<div class="report-fields"></div>

<div class="modal_overlay"></div>

<div class="work_order_modal">
<h3><%= I18n.t("plugins.digitization_work_order.modal.title") %></h3>
<hr/>
<p><strong><%= I18n.t("plugins.digitization_work_order.resource") %>:
</strong> <%= @tree['title'] %> (<%= @tree['identifier'] %>)
</p>
<p><strong><%= I18n.t("plugins.digitization_work_order.records_selected") %>:
</strong> <span id="selectedCountInModal"></span>
</p>
<hr/>
<p><%= I18n.t("plugins.digitization_work_order.modal.message") %></p>
<p><strong><%= I18n.t("plugins.digitization_work_order.modal.warning") %></strong></p>
<hr/>
<button id="downloadWorkOrder" class="btn btn-primary submit-btn">
<%= I18n.t("plugins.digitization_work_order.modal.download_button") %>
</button>
<button id="cancelWorkOrder" class="btn btn-default">
<%= I18n.t("plugins.digitization_work_order.cancel_button") %>
</button>
</div>

<% end %>
14 changes: 14 additions & 0 deletions frontend/views/work_order/_ladybird_export.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@

<div class="form-group">
<button id="generateLadybirdExport" class="btn btn-primary submit-btn" disabled>
<%= I18n.t("plugins.digitization_work_order.download_ladybird_export_button") %>
</button>
<%= link_to I18n.t("plugins.digitization_work_order.cancel_button"),:back, :class => "btn btn-default" %>
</div>

<%= form_tag({:controller => :work_order, :action => :generate_ladybird_export}, {:method => 'post', :id => "work_order_form"}) do |form| %>
<%= hidden_field_tag "resource", @uri %>
<div class="report-fields"></div>

<% end %>

67 changes: 6 additions & 61 deletions frontend/views/work_order/index.erb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
<%= stylesheet_link_tag "#{AppConfig[:frontend_prefix]}assets/work_order.css" %>
<%= stylesheet_link_tag "#{AppConfig[:frontend_prefix]}assets/fattable.css" %>
<%= javascript_include_tag "#{AppConfig[:frontend_prefix]}assets/fattable.js" %>

Expand All @@ -22,70 +23,14 @@

<div id='work_order_table'></div>

<div id='work_order_buttons'>
<div class="form-group">
<form class="form-inline">
<fieldset class="form-group additional-options">
<legend><%= I18n.t("plugins.digitization_work_order.additional_options") %></legend>
<label class="checkbox-inline" for="series"><input type="checkbox" id="series" name="series">
<%= I18n.t("plugins.digitization_work_order.series_title") %>
</label>
<label class="checkbox-inline" for="subseries"><input type="checkbox" id="subseries" name="subseries">
<%= I18n.t("plugins.digitization_work_order.subseries_title") %>
</label>
<label class="checkbox-inline" for="barcode"><input type="checkbox" id="barcode" name="barcode">
<%= I18n.t("plugins.digitization_work_order.barcode") %>
</label>
<label class="checkbox-inline" for="dates"><input type="checkbox" id="dates" name="dates">
<%= I18n.t("plugins.digitization_work_order.dates") %>
</label>
</fieldset>
</form>
</div>

<p class="alert alert-info" role="alert">If you would like a report of metadata for these items without generating component unique identifiers (CUIDs) , select <strong>Download Report</strong>. If you would like to create a work order and generate CUIDs for archival objects currently lacking them, select <strong>Download Work Order</strong>.</p>
<% if AppConfig.has_key?(:digitization_work_order_ladybird) && AppConfig[:digitization_work_order_ladybird] %>
<%= render_aspace_partial :partial => "ladybird_export" %>
<% else %>
<%= render_aspace_partial :partial => "do_report" %>
<% end %>

<div class="form-group">
<button id="generateReport" class="btn btn-primary submit-btn" disabled>
<%= I18n.t("plugins.digitization_work_order.download_report_button") %>
</button>
<button id="showWorkOrderModal" class="btn btn-primary submit-btn" disabled>
<%= I18n.t("plugins.digitization_work_order.show_work_order_modal_button") %>
</button>
<%= link_to I18n.t("plugins.digitization_work_order.cancel_button"),:back, :class => "btn btn-default" %>
</div>
</div>
</div>

<%= form_tag({:controller => :work_order, :action => :generate_report}, {:method => 'post', :id => "work_order_form"}) do |form| %>
<%= hidden_field_tag "resource", @uri %>
<div class="report-fields"></div>

<div class="modal_overlay"></div>

<div class="work_order_modal">
<h3><%= I18n.t("plugins.digitization_work_order.modal.title") %></h3>
<hr/>
<p><strong><%= I18n.t("plugins.digitization_work_order.resource") %>:
</strong> <%= @tree['title'] %> (<%= @tree['identifier'] %>)
</p>
<p><strong><%= I18n.t("plugins.digitization_work_order.records_selected") %>:
</strong> <span id="selectedCountInModal"></span>
</p>
<hr/>
<p><%= I18n.t("plugins.digitization_work_order.modal.message") %></p>
<p><strong><%= I18n.t("plugins.digitization_work_order.modal.warning") %></strong></p>
<hr/>
<button id="downloadWorkOrder" class="btn btn-primary submit-btn">
<%= I18n.t("plugins.digitization_work_order.modal.download_button") %>
</button>
<button id="cancelWorkOrder" class="btn btn-default">
<%= I18n.t("plugins.digitization_work_order.cancel_button") %>
</button>
</div>

<% end %>

<%= javascript_include_tag "#{AppConfig[:frontend_prefix]}assets/work_order_table.js" %>
<script>
initWorkOrderTable(<%= ASUtils.to_json(@tree).html_safe %>);
Expand Down

0 comments on commit 809f9fa

Please sign in to comment.