Skip to content

Commit

Permalink
Correct path to generate file size and change row count
Browse files Browse the repository at this point in the history
This also displays a humanized number instead showing the
plain byte count.

Also include the number of works in the detail page
  • Loading branch information
little9 committed Oct 2, 2019
1 parent b5b685c commit 5b2715c
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 19 deletions.
25 changes: 14 additions & 11 deletions app/importers/modular_importer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def import
csv_import_detail.batch_id = @csv_import.id
csv_import_detail.deduplication_field = DEDUPLICATION_FIELD
csv_import_detail.update_actor_stack = @csv_import.update_actor_stack
csv_import_detail.save!
csv_import_detail.save

attrs = {
csv_import_detail: csv_import_detail
Expand All @@ -34,18 +34,21 @@ def import
Rails.logger.info "[zizia] event: start_import, batch_id: #{@csv_import.id}, collection_id: #{@collection_id}, user: #{@user_email}"
importer = Zizia::Importer.new(parser: Zizia::CsvParser.new(file: file), record_importer: Zizia::HyraxRecordImporter.new(attributes: attrs))

importer.records.each do |record|
importer.records.each_with_index do |record, index|
pre_ingest_work = Zizia::PreIngestWork.new(csv_import_detail_id: csv_import_detail.id)
@row += 1

pre_ingest_file = Zizia::PreIngestFile.new(row_number: @row,
pre_ingest_work: pre_ingest_work,
filename: record.mapper.files.first,
size: File.join(ENV['IMPORT_PATH'], record.mapper.files.first).size)
pre_ingest_work.save!
pre_ingest_file.save!

record.mapper.files.each do |child_file|
full_path = Dir.glob("#{ENV['IMPORT_PATH']}/**/#{child_file}").first
pre_ingest_file = Zizia::PreIngestFile.new(row_number: index + 1,
pre_ingest_work: pre_ingest_work,
filename: child_file,
size: File.size(full_path))
pre_ingest_file.save
end
pre_ingest_work.save
end
csv_import_detail.save!

csv_import_detail.save
importer.import
file.close
end
Expand Down
8 changes: 6 additions & 2 deletions app/views/zizia/csv_import_details/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
<th>ID</th>
<th>Associated User</th>
<th>CSV File</th>
<th>Total Size in Bytes</th>
<th>Number of Works</th>
<th>Total Size</th>
</tr>
<% @csv_import_details.each do |csv_import_detail| %>
<tr>
Expand All @@ -18,7 +19,10 @@
<%= csv_import_detail.csv_import.manifest %>
</td>
<td>
<%= csv_import_detail.total_size %>
<%= csv_import_detail.pre_import_works.count %>
</td>
<td>
<%= number_to_human_size(csv_import_detail.total_size) %>
</td>
</tr>
<% end %>
Expand Down
5 changes: 2 additions & 3 deletions app/views/zizia/csv_import_details/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<li>Import created by: <%= User.find(@csv_import_detail.csv_import.user_id) %>
</li>
<li>CSV File: <%= @csv_import_detail.csv_import.manifest %></li>
<li>Total Size in Bytes: <%= @csv_import_detail.total_size %></li>
<li>Total Size: <%= number_to_human_size(@csv_import_detail.total_size) %></li>
</ul>

<h3>Files</h3>
Expand All @@ -21,10 +21,9 @@
<%= pre_ingest_file.filename %>
</td>
<td>
<%= pre_ingest_file.size %>
<%= number_to_human_size(pre_ingest_file.size) %>
</td>
<td>
Row number:
<%= pre_ingest_file.row_number %>
</td>
</tr>
Expand Down
2 changes: 1 addition & 1 deletion lib/zizia/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# frozen_string_literal: true

module Zizia
VERSION = '4.4.1.alpha.01'
VERSION = '4.5.0.alpha.01'
end
2 changes: 1 addition & 1 deletion spec/dummy/spec/system/csv_import_details_page_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@
visit ('/csv_import_details/index')
expect(page).to have_content('CSV Imports ID')
click_on '1'
expect(page).to have_content('Total Size in Bytes')
expect(page).to have_content('Total Size')
end
end
3 changes: 2 additions & 1 deletion spec/dummy/spec/system/import_from_csv_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -241,9 +241,10 @@

# Viewing additional details after an import
visit "/csv_import_details/index"
expect(page).to have_content('Total Size in Bytes')
expect(page).to have_content('Total Size')
find(:xpath, '//*[@id="content-wrapper"]/table/tbody/tr[2]/td[1]/a').click
expect(page).to have_content('dog.jpg')
expect(page).to have_content('5.74 MB')
end
end
end

0 comments on commit 5b2715c

Please sign in to comment.