Skip to content

Commit

Permalink
support for new container model in RDE
Browse files Browse the repository at this point in the history
  • Loading branch information
jambun authored and payten committed May 17, 2017
1 parent 14b7f63 commit 8a788b8
Show file tree
Hide file tree
Showing 12 changed files with 151 additions and 34 deletions.
2 changes: 1 addition & 1 deletion backend/app/model/mixins/resource_trees.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module ResourceTrees

def build_node_query
node_query = super
node_query.eager(:instance => :container)
node_query.eager(:instance => :sub_container)
end


Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
Sequel.migration do

up do
alter_table(:top_container) do
add_column(:created_for_collection, String, :null => true)
end
end


down do
# no going back
end

end

2 changes: 2 additions & 0 deletions common/schemas/top_container.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
"readonly" => "true"
},

"created_for_collection" => {"type" => "string", "maxLength" => 255, "required" => false},

"active_restrictions" => {
"type" => "array",
"readonly" => "true",
Expand Down
9 changes: 9 additions & 0 deletions frontend/app/assets/javascripts/rde.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
//= require jquery.kiketable.colsizable-1.1
//= require jquery.columnmanager.min
//= require bootstrap-multiselect
//= require linker

$(function() {

Expand All @@ -14,6 +15,8 @@ $(function() {
return;
}

$(".linker:not(.initialised)").linker();

// Cookie Names
var COOKIE_NAME_VISIBLE_COLUMN = "rde."+$rde_form.data("cookie-prefix")+".visible";
var COOKIE_NAME_STICKY_COLUMN = "rde."+$rde_form.data("cookie-prefix")+".sticky";
Expand Down Expand Up @@ -81,6 +84,8 @@ $(function() {

$(":input:visible:first", $row).focus();

$(".linker:not(.initialised)").linker();

validateRows($row);
});

Expand Down Expand Up @@ -128,6 +133,9 @@ $(function() {
} else {
$target.removeAttr("checked");
}
} else if ($source.is(":hidden") && $source.parents().closest("div").hasClass("linker-wrapper")) {
// a linker!
$target.attr("data-selected", $source.val());
} else {
$target.val($source.val());
}
Expand Down Expand Up @@ -227,6 +235,7 @@ $(function() {
});

var renderInlineErrors = function($rows, exception_data) {
$(".linker:not(.initialised)").linker();
$rows.each(function(i, row) {
var $row = $(row);
var row_result = exception_data[i];
Expand Down
25 changes: 23 additions & 2 deletions frontend/app/controllers/top_containers_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,13 @@ def index
def new
@top_container = JSONModel(:top_container).new._always_valid!

render_aspace_partial :partial => "top_containers/new" if inline?
if inline?
render_aspace_partial(:partial => "top_containers/new",
:locals => {
:small => params[:small],
:created_for_collection => params[:created_for_collection]
})
end
end


Expand Down Expand Up @@ -216,8 +222,23 @@ def barcode_length_range
def search_filter_for(uri)
return {} if uri.blank?

# filter for containers in this collection
# or that were created for this collection
# if they are currently not associated with any collection
# this is helpful in situations like RDE
# where the top_container is created and should be linkable
# to other records in the collection before any of them are saved

created_for_query = AdvancedQueryBuilder.new
created_for_query.and('created_for_collection_u_sstr', uri, 'text', true)
created_for_query.and('collection_uri_u_sstr', '*', 'text', true, true)

top_or_query = AdvancedQueryBuilder.new
top_or_query.or('collection_uri_u_sstr', uri, 'text', true)
top_or_query.or(created_for_query)

return {
'filter' => AdvancedQueryBuilder.new.and('collection_uri_u_sstr', uri, 'text', true).build.to_json
'filter' => AdvancedQueryBuilder.new.and(top_or_query).build.to_json
}
end

Expand Down
40 changes: 13 additions & 27 deletions frontend/app/views/archival_objects/_rde_templates.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,7 @@
<th id="colEDimensions" class="fieldset-label sticky" data-section="extent"><%= I18n.t("extent.dimensions") %></th>

<th id="colIType" class="fieldset-label sticky" data-section="instance"><%= I18n.t("rde.instance_type") %></th>
<th id="colCType1" class="fieldset-label sticky" data-section="instance"><%= I18n.t("top_container.type") %></th>
<th id="colCInd1" class="fieldset-label sticky" data-section="instance"><%= I18n.t("top_container.indicator") %></th>
<th id="colCBarc1" class="fieldset-label sticky" data-section="instance"><%= I18n.t("top_container.barcode") %></th>
<th id="colCTop" class="fieldset-label sticky" data-section="instance"><%= I18n.t("top_container._singular") %></th>
<th id="colCType2" class="fieldset-label" data-section="instance"><%= I18n.t("sub_container.type_2") %></th>
<th id="colCInd2" class="fieldset-label" data-section="instance"><%= I18n.t("sub_container.indicator_2") %></th>
<th id="colCType3" class="fieldset-label" data-section="instance"><%= I18n.t("sub_container.type_3") %></th>
Expand Down Expand Up @@ -174,54 +172,42 @@
<%= form.select "instance_type", jsonmodel_definition(:instance).options_for(form, 'instance_type', true).reject{|option_arr| option_arr[1] === 'digital_object'} %>
<% end %>
</td>
<td data-col="colCType1" class="form-group">
<td data-col="colCTop" class="form-group">
<% form.push(form.set_index("instances[]", 0), begin archival_object["instances"][0] || {} rescue {} end) do %>
<% form.push(form.set_index("container", 0), form["container"] || {}) do %>
<%= form.select "type_1", jsonmodel_definition(:container).options_for(form, 'type_1', true) %>
<% form.push(form.set_index("sub_container", 0), form["sub_container"] || {}) do %>
<% form.push("top_container", form.obj["top_container"] || {}) do %>
<%= render_aspace_partial :partial => "top_containers/rde_linker", :locals => {:form => form} %>
<% end %>
<% end %>
<% form.push(form.set_index("container", 0), []) do %>
<% form.push(form.set_index("sub_container", 0), []) do %>
<span id="<%= form.id_for(nil) %>"></span>
<% end %>
<% end %>
</td>
<td data-col="colCInd1" class="form-group">
<% form.push(form.set_index("instances[]", 0), begin archival_object["instances"][0] || {} rescue {} end) do %>
<% form.push(form.set_index("container", 0), form["container"] || {}) do %>
<%= form.textfield "indicator_1" %>
<% end %>
<% end %>
</td>
<td data-col="colCBarc1" class="form-group">
<% form.push(form.set_index("instances[]", 0), begin archival_object["instances"][0] || {} rescue {} end) do %>
<% form.push(form.set_index("container", 0), form["container"] || {}) do %>
<%= form.textfield "barcode_1" %>
<% end %>
<% end %>
</td>
<td data-col="colCType2" class="form-group">
<% form.push(form.set_index("instances[]", 0), begin archival_object["instances"][0] || {} rescue {} end) do %>
<% form.push(form.set_index("container", 0), form["container"] || {}) do %>
<%= form.select "type_2", jsonmodel_definition(:container).options_for(form, 'type_2', true) %>
<% form.push(form.set_index("sub_container", 0), form["sub_container"] || {}) do %>
<%= form.select "type_2", jsonmodel_definition(:sub_container).options_for(form, 'type_2', true) %>
<% end %>
<% end %>
</td>
<td data-col="colCInd2" class="form-group">
<% form.push(form.set_index("instances[]", 0), begin archival_object["instances"][0] || {} rescue {} end) do %>
<% form.push(form.set_index("container", 0), form["container"] || {}) do %>
<% form.push(form.set_index("sub_container", 0), form["sub_container"] || {}) do %>
<%= form.textfield "indicator_2" %>
<% end %>
<% end %>
</td>
<td data-col="colCType3" class="form-group">
<% form.push(form.set_index("instances[]", 0), begin archival_object["instances"][0] || {} rescue {} end) do %>
<% form.push(form.set_index("container", 0), form["container"] || {}) do %>
<%= form.select "type_3", jsonmodel_definition(:container).options_for(form, 'type_3', true) %>
<% form.push(form.set_index("sub_container", 0), form["sub_container"] || {}) do %>
<%= form.select "type_3", jsonmodel_definition(:sub_container).options_for(form, 'type_3', true) %>
<% end %>
<% end %>
</td>
<td data-col="colCInd3" class="form-group">
<% form.push(form.set_index("instances[]", 0), begin archival_object["instances"][0] || {} rescue {} end) do %>
<% form.push(form.set_index("container", 0), form["container"] || {}) do %>
<% form.push(form.set_index("sub_container", 0), form["sub_container"] || {}) do %>
<%= form.textfield "indicator_3" %>
<% end %>
<% end %>
Expand Down
1 change: 1 addition & 0 deletions frontend/app/views/top_containers/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
<%= form.hidden_input("ils_item_id") %>
<%= form.label_and_readonly("exported_to_ils", I18n.t("top_container.not_exported")) %>
<%= form.hidden_input("exported_to_ils") %>
<%= form.hidden_input("created_for_collection", created_for_collection) %>

<div class="subrecord-form-container">
<%= render_aspace_partial :partial => "shared/subrecord_form", :locals => {:form => form, :name => "container_locations"} %>
Expand Down
11 changes: 11 additions & 0 deletions frontend/app/views/top_containers/_form_small.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<%= render_aspace_partial :partial => "shared/form_messages", :locals => {:object => @top_container, :form => form} %>
<% define_template("top_container", jsonmodel_definition(:top_container)) do |form| %>
<%= form.label_and_select "type", form.possible_options_for('type', true) %>
<%= form.label_and_textfield("indicator") %>
<%= form.label_and_textfield("barcode") %>
<%= form.hidden_input("created_for_collection", created_for_collection) %>
<% end %>
<% form.emit_template("top_container") %>
10 changes: 7 additions & 3 deletions frontend/app/views/top_containers/_linker.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

linkable_types = ["top_container"]

build_typeahead_url = proc {
find_scope_uri = proc {
record = [:"@accession", :"@archival_object", :"@resource"].map {|instvar| self.instance_variable_get(instvar)}.compact.first
# If a new record resource or accession, uri will be nil and the typeahead will search
# within the repository.
Expand All @@ -27,7 +27,11 @@
uri = record["resource"]["ref"]
end

url_for :controller => :top_containers, :action => :typeahead, :format => :json, :uri => uri
uri
}

build_typeahead_url = proc {
url_for :controller => :top_containers, :action => :typeahead, :format => :json, :uri => find_scope_uri.call
}

%>
Expand Down Expand Up @@ -70,7 +74,7 @@
<li><a href="javascript:void(0);" class="linker-browse-btn"><%= I18n.t("actions.browse") %></a></li>
<% if allow_create && user_can?('update_container_record') %>
<li>
<a data-target="<%= url_for :controller => :top_containers, :action => :new, :inline => true %>" class="linker-create-btn"><%= I18n.t("actions.create") %></a>
<a data-target="<%= url_for :controller => :top_containers, :action => :new, :inline => true, :created_for_collection => find_scope_uri.call %>" class="linker-create-btn"><%= I18n.t("actions.create") %></a>
</li>
<% end %>
</ul>
Expand Down
5 changes: 4 additions & 1 deletion frontend/app/views/top_containers/_new.html.erb
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
<%= form_for @top_container, :as => "top_container", :url => {:action => :create}, :html => {:class => 'form-horizontal aspace-record-form', :id => "new_top_container"} do |f| %>
<%= form_context :top_container, @top_container do |form| %>
<%= hidden_field "inline", "true" %>
<%= render_aspace_partial :partial => "form", :locals => {:form => form} %>
<%= render_aspace_partial :partial => "form#{small ? '_small' : ''}",
:locals => {:form => form, :created_for_collection => created_for_collection} %>
<% end %>
<% end %>

Expand Down
63 changes: 63 additions & 0 deletions frontend/app/views/top_containers/_rde_linker.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
<%
if form.obj['ref'].blank?
selected_json = "{}"
else
selected_json = form.obj['_resolved'].to_json
end

exclude_ids = [] if exclude_ids.blank?

allow_create = true if allow_create.nil?

required = true if required.nil?

linkable_types = ["top_container"]

build_typeahead_url = proc {
uri = self.instance_variable_get(:"@resource_uri")

url_for :controller => :top_containers, :action => :typeahead, :format => :json, :uri => uri
}

%>
<div class="form-group <% if required %>required<% end %>">
<div class="controls col-sm-10">
<div class="input-group linker-wrapper">
<input type="text" class="linker"
id="<%= form.id_for("ref") %>"
data-label="<%= I18n.t("top_container._singular") %>"
data-label_plural="<%= I18n.t("top_container._plural") %>"
data-name="ref"
data-path="<%= form.path %>"
data-url="<%= build_typeahead_url.call %>"
data-browse-url="<%= url_for :controller => :top_containers, :action => :bulk_operations_browse %>"
data-selected="<%= selected_json %>"
data-multiplicity="one"
data-types='<%= linkable_types.to_json %>'
data-exclude='<%= exclude_ids.to_json %>'
/>

<% if form.obj.has_key?('_resolved') %>

<input type="text"
class='prelinker'
name="<%= form.path %>[_resolved]"
value="<%= selected_json %>" />

<input type="text"
class='prelinker'
name="<%= form.path %>[ref]"
value="<%= form.obj["ref"] %>" />

<% end %>
<% if allow_create && user_can?('update_container_record') %>

<div class="input-group-btn">
<a data-target="<%= url_for :controller => :top_containers, :action => :new, :small => true, :inline => true, :created_for_collection => self.instance_variable_get(:"@resource_uri") %>" class="btn btn-default linker-create-btn"><%= I18n.t("actions.create") %></a>
</div>

<% end %>
</div>
</div>
</div>
2 changes: 2 additions & 0 deletions indexer/app/lib/indexer_common.rb
Original file line number Diff line number Diff line change
Expand Up @@ -528,6 +528,8 @@ def configure_doc_rules

doc['typeahead_sort_key_u_sort'] = record['record']['indicator'].to_s.rjust(255, '#')
doc['barcode_u_sstr'] = record['record']['barcode']

doc['created_for_collection_u_sstr'] = record['record']['created_for_collection']
end
}

Expand Down

0 comments on commit 8a788b8

Please sign in to comment.