Browse Source

Read file

pull/84/head
baarkerlounger 4 years ago
parent
commit
cb0462a404
  1. 2
      Gemfile
  2. 4
      Gemfile.lock
  3. 8
      app/controllers/bulk_upload_controller.rb
  4. 15
      app/views/case_logs/bulk_upload.html.erb
  5. 3
      config/routes.rb

2
Gemfile

@ -29,6 +29,8 @@ gem "discard"
gem "activeadmin"
# Admin charts
gem "chartkick"
# Spreadsheet parsing
gem "roo"
group :development, :test do
# Call 'byebug' anywhere in the code to stop execution and get a debugger console

4
Gemfile.lock

@ -292,6 +292,9 @@ GEM
actionpack (>= 5.0)
railties (>= 5.0)
rexml (3.2.5)
roo (2.8.3)
nokogiri (~> 1)
rubyzip (>= 1.3.0, < 3.0.0)
rubocop (1.21.0)
parallel (~> 1.10)
parser (>= 3.0.0.0)
@ -405,6 +408,7 @@ DEPENDENCIES
puma (~> 5.0)
rack-mini-profiler (~> 2.0)
rails (~> 6.1.4)
roo
rspec-core!
rspec-expectations!
rspec-mocks!

8
app/controllers/bulk_upload_controller.rb

@ -1,5 +1,13 @@
class BulkUploadController < ApplicationController
XLS = "application/vnd.ms-excel".freeze
def show
render "case_logs/bulk_upload"
end
def process_bulk_upload
if params["case_log_bulk_upload"].content_type == XLS
xlsx = Roo::Spreadsheet.open(params["case_log_bulk_upload"].tempfile, extension: :xlsx)
end
end
end

15
app/views/case_logs/bulk_upload.html.erb

@ -1,10 +1,9 @@
<h1 class="govuk-heading-xl">
Bulk Upload
</h1>
<div class="govuk-form-group">
<label class="govuk-label" for="file-upload-1">
Upload a file
</label>
<input class="govuk-file-upload" id="file-upload-1" name="file-upload-1" type="file">
<%= form_with url: "/case_logs/bulk_upload", method: "post", builder: GOVUKDesignSystemFormBuilder::FormBuilder do |f| %>
<%= f.govuk_file_field :case_log_bulk_upload,
label: { text: "Bulk Upload", size: "l" },
hint: { text: "Upload a spreadsheet using the template" }
%>
<%= f.govuk_submit "Upload" %>
<% end %>
</div>

3
config/routes.rb

@ -4,7 +4,8 @@ Rails.application.routes.draw do
root to: "test#index"
get "about", to: "about#index"
post "/case_logs/:id", to: "case_logs#submit_form"
post "/case_logs/:id", to: "case_logs#submit_form", constraints: { id: /\d/ }
post "/case_logs/bulk_upload", to: "bulk_upload#process_bulk_upload"
get "/case_logs/bulk_upload", to: "bulk_upload#show"
form_handler = FormHandler.instance

Loading…
Cancel
Save