Skip to content
Snippets Groups Projects
Commit 2051ea16 authored by Kapil Patel's avatar Kapil Patel
Browse files

Improve performance for CrcDataset show page

parent 496097fa
No related branches found
No related tags found
2 merge requests!115Tombstone not available for dataset,!930.3 release
Pipeline #5842 failed
Showing
with 187 additions and 10 deletions
......@@ -178,13 +178,14 @@ module Hyrax
def generate_target_object_key(repository_file, file_set)
prefix = case file_set.for_complex_type
when 'ComplexSubject'
"#{file_set.for_complex_identifier}/#{repository_file.id}"
complex_subject = ComplexSubject.find_by(source_identifier: file_set.for_complex_identifier)
"#{complex_subject.subject_title}/#{repository_file.id}"
when 'ComplexSession'
complex_session = ComplexSession.find_by(source_identifier: file_set.for_complex_identifier)
"#{complex_session.complex_subject.source_identifier}/#{complex_session.source_identifier}/#{repository_file.id}"
"#{complex_session.complex_subject.subject_title}/#{complex_session.session_title}/#{repository_file.id}"
when 'ComplexModality'
complex_modality = ComplexModality.find_by(source_identifier: file_set.for_complex_identifier)
"#{complex_modality.complex_subject.source_identifier}/#{complex_modality.complex_session.source_identifier}/#{complex_modality.source_identifier}/#{repository_file.id}"
"#{complex_modality.complex_subject.subject_title}/#{complex_modality.complex_session.session_title}/#{complex_modality.modality_title}/#{repository_file.id}"
else
repository_file.id
end
......
# frozen_string_literal: true
module Hyrax
module Dashboard
## Shows a list of all collections to the admins
class CollectionMembersController < Hyrax::My::CollectionsController
before_action :filter_docs_with_read_access!
include Hyrax::Collections::AcceptsBatches
load_resource only: :update_members,
instance_name: :collection,
class: Hyrax.config.collection_model
def after_update
respond_to do |format|
format.html { redirect_to success_return_path, notice: t('hyrax.dashboard.my.action.collection_update_success') }
format.json { render json: @collection, status: :updated, location: dashboard_collection_path(@collection) }
end
end
def after_update_error(err_msg)
respond_to do |format|
format.html { redirect_to err_return_path, alert: err_msg }
format.json { render json: @collection.errors, status: :unprocessable_entity }
end
end
def update_members # rubocop:disable Metrics/MethodLength
err_msg = validate
after_update_error(err_msg) if err_msg.present?
return if err_msg.present?
begin
template = Hyrax::PermissionTemplate.find_by!(source_id: @collection.id)
@collection.reindex_extent = Hyrax::Adapters::NestingIndexAdapter::LIMITED_REINDEX
terminator_actor = Hyrax::Actors::Terminator.new
membership_actor = Hyrax::Actors::CollectionsMembershipActor.new(terminator_actor)
member_collection_hash = {member_of_collections_attributes: {'0': {id: @collection.id}}}
batch_ids.each do |work_id|
work = CrcDataset.find(work_id)
env = Hyrax::Actors::Environment.new(work, current_user.ability, member_collection_hash)
membership_actor.create(env)
Hyrax::PermissionTemplateApplicator.apply(template).to(model: work)
work.save
end
after_update
rescue Hyrax::SingleMembershipError => err
messages = JSON.parse(err.message)
if messages.size == batch_ids.size
after_update_error(messages.uniq.join(', '))
elsif messages.present?
flash[:error] = messages.uniq.join(', ')
after_update
end
end
end
private
def validate
return t('hyrax.dashboard.my.action.members_no_access') if
batch_ids.blank?
return t('hyrax.dashboard.my.action.collection_deny_add_members') unless
current_ability.can?(:deposit, @collection)
return t('hyrax.dashboard.my.action.add_to_collection_only') unless
member_action == "add" # should never happen
end
def success_return_path
dashboard_collection_path(collection_id)
end
def err_return_path
dashboard_collections_path
end
def collection_id
params[:id]
end
def batch_ids
params[:batch_document_ids]
end
def member_action
params[:collection][:members]
end
end
end
end
\ No newline at end of file
......@@ -3,7 +3,7 @@
module Bulkrax
class CrcFolderComplexModalityEntry < CsvEntry
def build
complex_modality = ComplexModality.new(modality: self.raw_metadata['modality'])
complex_modality = ComplexModality.new(modality_title: raw_metadata['title'], modality: self.raw_metadata['modality'])
complex_modality.source_identifier = identifier
complex_modality.parent_source_identifier = self.raw_metadata['for_complex_identifier']
if complex_modality.save
......
......@@ -4,6 +4,7 @@ module Bulkrax
class CrcFolderComplexSubjectEntry < CsvEntry
def build
complex_subject = ComplexSubject.new(self.raw_metadata.slice('subject_identifier', 'subject_species', 'subject_type', 'subject_sex', 'subject_age'))
complex_subject.subject_title = raw_metadata['title']
complex_subject.source_identifier = identifier
complex_subject.parent_source_identifier = self.raw_metadata['for_complex_identifier']
if complex_subject.save
......
......@@ -31,6 +31,6 @@ class ComplexModality < ActiveRecord::Base
s3.init_client
bucket_name = s3.sanitise_name(crc_dataset.id)
s3.create_bucket(bucket_name) unless s3.bucket_exists?(bucket_name)
s3.add_content(bucket_name, "#{complex_subject.source_identifier}/#{complex_session.source_identifier}/#{source_identifier}/metadata.json", to_json)
s3.add_content(bucket_name, "#{complex_subject.subject_title}/#{complex_session.session_title}/#{modality_title}/metadata.json", to_json)
end
end
......@@ -35,6 +35,6 @@ class ComplexSession < ActiveRecord::Base
s3.init_client
bucket_name = s3.sanitise_name(crc_dataset.id)
s3.create_bucket(bucket_name) unless s3.bucket_exists?(bucket_name)
s3.add_content(bucket_name, "#{complex_subject.source_identifier}/#{source_identifier}/metadata.json", to_json)
s3.add_content(bucket_name, "#{complex_subject.subject_title}/#{session_title}/metadata.json", to_json)
end
end
......@@ -33,6 +33,6 @@ class ComplexSubject < ActiveRecord::Base
s3.init_client
bucket_name = s3.sanitise_name(crc_dataset.id)
s3.create_bucket(bucket_name) unless s3.bucket_exists?(bucket_name)
s3.add_content(bucket_name, "#{source_identifier}/metadata.json", to_json)
s3.add_content(bucket_name, "#{subject_title}/metadata.json", to_json)
end
end
<% if Flipflop.assign_admin_set? %>
<%= f.input :admin_set_id, as: :select,
include_blank: false,
collection: admin_set_options,
input_html: { class: 'form-control' } %>
<% end %>
<%= render 'form_in_works', f: f %>
<%= render 'form_member_of_collections', f: f %>
<% if f.object.persisted? %>
<h2 class="h3 mt-4"><%= t("hyrax.works.form.in_this_work") %></h2>
<% if f.object.class.name == "Hyrax::CrcDatasetForm" %>
<%= render 'hyrax/crc_datasets/crc_form_child_work_relationships', f: f %>
<% else %>
<%= render 'form_child_work_relationships', f: f %>
<% end %>
<% end %>
\ No newline at end of file
......@@ -8,4 +8,4 @@
<% render 'items', presenter: @presenter %>
<% end %>
<%= render 'shared/pagination', response: Kaminari.paginate_array(member_ids).page(params[:page] || 1).per(params[:per_page] || 5), route_set: main_app %>
\ No newline at end of file
<%= render 'shared/pagination', response: Kaminari.paginate_array(member_ids).page(params[:page] || 1).per(params[:per_page] || 10), route_set: main_app %>
\ No newline at end of file
<%# Form UI behavior code and details;
Code:
app/assets/javascripts/hyrax/relationships
CSS:
[data-behavior="remove-relationship"] : Button to remove its parent TR from the table
[data-behavior="add-relationship"] : Button to clone its parent TR and inject a new row into the table
.message.has-warning : Used to display UI errors related to input values and server errors
HTML Properties:
table:
[data-behavior="child-relationships"] : allows the javascript to be initialized
data-param-key : the parameter key value for this model type %>
<div class="form-group" data-behavior="child-relationships" data-param-key="<%= f.object.model_name.param_key %>" data-members="">
<div class="form-inline">
<%= f.label :find_child_work %>
<%= f.input_field :find_child_work,
prompt: :translate,
autocomplete: 'off',
data: {
autocomplete: 'work',
'autocomplete-url' => Rails.application.routes.url_helpers.qa_path + '/search/find_works',
'exclude-work': f.object.model.id.to_s # exclude this item from the result set.
} %>
<a href="#" onclick="return false;" class="btn btn-secondary ml-2" data-behavior="add-relationship"><%= t('.add') %></a>
</div>
<div class="message has-warning"></div>
<div class="my-4">
<%= link_to t('.attach_new_work'), polymorphic_path([main_app, :new, :hyrax, :parent, curation_concern.model_name.singular.to_sym], parent_id: curation_concern.id), target: "_blank", class: 'btn btn-primary' %>
</div>
<table class="table table-striped">
<caption><%= t('.caption') %></caption>
<thead>
<tr>
<th><%= t('.header.title') %></th>
<th><%= t('.header.actions') %></th>
</tr>
</thead>
<tbody>
</tbody>
</table>
</div>
<script type="text/x-tmpl" id="tmpl-child-work">
<tr>
<td>{%= o.title %}</td>
<td><button class="btn btn-danger" data-behavior="remove-relationship" data-confirm-text="<%= t('.confirm.text') %>" data-confirm-cancel="<%= t('.confirm.cancel') %>" data-confirm-remove="<%= t('.confirm.remove') %>"><%= t('.actions.remove') %></button></td>
</tr>
</script>
\ No newline at end of file
......@@ -17,6 +17,5 @@
<% f.object.secondary_terms_by_work_type(work_type=work_type).each do |term| %>
<%= render_edit_field_partial(term, f: f) %>
<% end %>
<%= render 'form_media', f: f %>
</div>
<% end %>
......@@ -68,9 +68,24 @@ namespace :rdms do
end
def collection_parent_work_children(parent_record, child_work_ids)
template = Hyrax::PermissionTemplate.find_by!(source_id: parent_record.id)
user = User.find_by(email: 'admin@hyrax')
parent_record.reindex_extent = Hyrax::Adapters::NestingIndexAdapter::LIMITED_REINDEX
terminator_actor = Hyrax::Actors::Terminator.new
membership_actor = Hyrax::Actors::CollectionsMembershipActor.new(terminator_actor)
member_collection_hash = {member_of_collections_attributes: {'0': {id: parent_record.id}}}
child_work_ids.each do |work_id|
work = CrcDataset.find(work_id)
env = Hyrax::Actors::Environment.new(work, Ability.new(user), member_collection_hash)
parent_record.add_member_objects(child_work_ids)
membership_actor.create(env)
Hyrax::PermissionTemplateApplicator.apply(template).to(model: work)
work.save
end
end
def work_parent_work_children(parent_record, child_record_ids)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment