Skip to content

Commit

Permalink
Merge pull request #1623 from next-l/i1581-xlsx-export
Browse files Browse the repository at this point in the history
Manifestationのxlsxテンプレートファイルを追加
  • Loading branch information
nabeta committed Apr 19, 2022
2 parents 9e90276 + ce200c3 commit 98dcf0d
Show file tree
Hide file tree
Showing 8 changed files with 54 additions and 0 deletions.
2 changes: 2 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,8 @@ gem 'kramdown'
gem 'resque', require: 'resque/server'
gem 'sassc', '~> 2.1.0'
gem 'acts-as-taggable-on'
gem 'caxlsx'
gem 'caxlsx_rails'

group :development, :test do
gem 'annotate'
Expand Down
11 changes: 11 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,14 @@ GEM
rack-test (>= 0.6.3)
regexp_parser (>= 1.5, < 3.0)
xpath (~> 3.2)
caxlsx (3.2.0)
htmlentities (~> 4.3, >= 4.3.4)
marcel (~> 1.0)
nokogiri (~> 1.10, >= 1.10.4)
rubyzip (>= 1.3.0, < 3)
caxlsx_rails (0.6.3)
actionpack (>= 3.1)
caxlsx (>= 3.0)
childprocess (4.1.0)
climate_control (0.2.0)
cocoon (1.2.15)
Expand Down Expand Up @@ -154,6 +162,7 @@ GEM
globalize (>= 5.0.0)
hashdiff (1.0.1)
highline (2.0.3)
htmlentities (4.3.4)
i18n (1.10.0)
concurrent-ruby (~> 1.0)
image_processing (1.12.2)
Expand Down Expand Up @@ -420,6 +429,8 @@ DEPENDENCIES
browser
byebug
capybara (>= 3.26)
caxlsx
caxlsx_rails
cocoon
devise
dotenv-rails
Expand Down
2 changes: 2 additions & 0 deletions app/controllers/manifestations_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,7 @@ def index
format.mods
format.json
format.js
format.xlsx
end
end

Expand Down Expand Up @@ -317,6 +318,7 @@ def show
format.json
format.text
format.js
format.xlsx
format.download {
if @manifestation.attachment.path
if ENV['ENJU_STORAGE'] == 's3'
Expand Down
1 change: 1 addition & 0 deletions app/views/manifestations/_export_detail.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
<ul>
<li><%= link_to 'RDF/XML', manifestation_url(@manifestation, format: :rdf) %></li>
<li><%= link_to 'MODS', manifestation_url(@manifestation, format: :mods) %></li>
<li><%= link_to 'XLSX', manifestation_url(@manifestation, format: :xlsx) %></li>
<li><%= link_to 'TSV', manifestation_url(@manifestation, format: :txt) %></li>
<li><%= link_to 'JSON', manifestation_url(@manifestation, format: :json) %></li>
</ul>
1 change: 1 addition & 0 deletions app/views/manifestations/_export_list.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
<ul>
<li><%= link_to 'RDF/XML', url_for(request.params.merge(format: :rdf, only_path: true)) %>
<li><%= link_to 'MODS', url_for(request.params.merge(format: :mods, only_path: true)) %></li>
<li><%= link_to 'XLSX', url_for(request.params.merge(format: :xlsx, only_path: true)) %></li>
<li><%= link_to 'TSV', url_for(request.params.merge(format: :txt, only_path: true)) %></li>
<li><%= link_to 'JSON', url_for(request.params.merge(format: :json, only_path: true)) %></li>
</ul>
13 changes: 13 additions & 0 deletions app/views/manifestations/index.xlsx.axlsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
wb = xlsx_package.workbook
wb.add_worksheet do |sheet|
sheet.add_row (Manifestation.csv_header(role: current_user_role_name) + Item.csv_header(role: current_user_role_name))
@manifestations.each do |manifestation|
if manifestation.items.empty?
sheet.add_row manifestation.to_hash(role: current_user_role_name).values
else
manifestation.items.each do |item|
sheet.add_row (manifestation.to_hash(role: current_user_role_name).values + item.to_hash(role: current_user_role_name).values)
end
end
end
end
11 changes: 11 additions & 0 deletions app/views/manifestations/show.xlsx.axlsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
wb = xlsx_package.workbook
wb.add_worksheet do |sheet|
sheet.add_row (Manifestation.csv_header(role: current_user_role_name) + Item.csv_header(role: current_user_role_name))
if @manifestation.items.empty?
sheet.add_row @manifestation.to_hash(role: current_user_role_name).values
else
@manifestation.items.each do |item|
sheet.add_row (@manifestation.to_hash(role: current_user_role_name).values + item.to_hash(role: current_user_role_name).values)
end
end
end
13 changes: 13 additions & 0 deletions spec/controllers/manifestations_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,13 @@ def valid_attributes
expect(response).to render_template('manifestations/index')
end

it 'assigns all manifestations as @manifestations in xlsx format' do
get :index, format: :xlsx
expect(response).to be_successful
expect(assigns(:manifestations)).to_not be_nil
expect(response).to render_template('manifestations/index')
end

it 'assigns all manifestations as @manifestations in openurl' do
get :index, params: { api: 'openurl', title: 'ruby' }
expect(assigns(:manifestations)).to_not be_nil
Expand Down Expand Up @@ -321,6 +328,12 @@ def valid_attributes
expect(response).to render_template('manifestations/show')
end

it 'should show manifestation xlsx template' do
get :show, params: { id: 22, format: 'xlsx' }
expect(assigns(:manifestation)).to eq Manifestation.find(22)
expect(response).to render_template('manifestations/show')
end

it 'should show manifestation with holding' do
get :show, params: { id: 1, mode: 'holding' }
expect(response).to be_successful
Expand Down

0 comments on commit 98dcf0d

Please sign in to comment.