diff --git a/Gemfile b/Gemfile index 2b6743c..c2df4f0 100644 --- a/Gemfile +++ b/Gemfile @@ -15,6 +15,7 @@ gem "graphql-client", github: "rmosolgo/graphql-client", ref: "27ef61f" gem "haml" gem "importmap-rails" gem "jbuilder" +gem "kaminari" gem "pry-rails" gem "redcarpet" gem "redis" diff --git a/Gemfile.lock b/Gemfile.lock index 0441dcf..3649d14 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -169,6 +169,18 @@ GEM activesupport (>= 5.0.0) jmespath (1.6.2) json (2.7.1) + kaminari (1.2.2) + activesupport (>= 4.1.0) + kaminari-actionview (= 1.2.2) + kaminari-activerecord (= 1.2.2) + kaminari-core (= 1.2.2) + kaminari-actionview (1.2.2) + actionview + kaminari-core (= 1.2.2) + kaminari-activerecord (1.2.2) + activerecord + kaminari-core (= 1.2.2) + kaminari-core (1.2.2) language_server-protocol (3.17.0.3) lint_roller (1.1.0) loofah (2.22.0) @@ -382,6 +394,7 @@ DEPENDENCIES haml importmap-rails jbuilder + kaminari pg pry-rails puma diff --git a/app/controllers/admin/csv_uploads_controller.rb b/app/controllers/admin/csv_uploads_controller.rb index 1c06b6b..af4e2cf 100644 --- a/app/controllers/admin/csv_uploads_controller.rb +++ b/app/controllers/admin/csv_uploads_controller.rb @@ -1,5 +1,6 @@ class Admin::CsvUploadsController < ApplicationController expose(:csv_upload) + expose(:csv_uploads) { CsvUpload.order(created_at: :desc).page params[:page] } def create if csv_upload.save diff --git a/app/views/admin/csv_uploads/index.html.haml b/app/views/admin/csv_uploads/index.html.haml new file mode 100644 index 0000000..570efce --- /dev/null +++ b/app/views/admin/csv_uploads/index.html.haml @@ -0,0 +1,20 @@ +%h1 CSV Uploads + +%p= link_to "New CSV Upload", new_admin_csv_upload_path + +%table + %thead + %tr + %th ID + %th Parser Class Name + %th Original Filename + %th.text-right Created At + %tbody + - csv_uploads.each do |csv_upload| + %tr + %td= link_to csv_upload.id, admin_csv_upload_path(csv_upload.id) + %td= csv_upload.parser_class_name + %td= csv_upload.original_filename + %td.text-right= csv_upload.created_at.to_formatted_s(:long) + += paginate csv_uploads diff --git a/app/views/admin/csv_uploads/new.html.haml b/app/views/admin/csv_uploads/new.html.haml index fc11f18..c2bef4a 100644 --- a/app/views/admin/csv_uploads/new.html.haml +++ b/app/views/admin/csv_uploads/new.html.haml @@ -1,5 +1,7 @@ %h1 New CSV Upload +%p= link_to "CSV Upload List", admin_csv_uploads_path + = form_with model: [:admin, csv_upload], multipart: true do |form| %select#csv_upload_parser_class_name(name="csv_upload[parser_class_name]" required="true") %option(value="" disabled="true" selected hidden) pick parser diff --git a/app/views/admin/csv_uploads/show.html.haml b/app/views/admin/csv_uploads/show.html.haml index 562ed6c..909690d 100644 --- a/app/views/admin/csv_uploads/show.html.haml +++ b/app/views/admin/csv_uploads/show.html.haml @@ -1,5 +1,7 @@ %h1 CSV Upload #{csv_upload.id} +%p= link_to "CSV Upload List", admin_csv_uploads_path + = render partial: "attrs_table", locals: { attrs: csv_upload.table_attrs } %h2 Data diff --git a/config/routes.rb b/config/routes.rb index 47800ac..c0dd83c 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -26,7 +26,7 @@ namespace :admin do resources :books, only: %i[create edit new update] - resources :csv_uploads, only: %i[create new show] + resources :csv_uploads, only: %i[create index new show] resources :gift_ideas resources :hooks, only: %i[create edit index] resources :post_bin_requests, only: %i[index show] diff --git a/spec/system/csv_uploads/admin_views_csv_uploads_spec.rb b/spec/system/csv_uploads/admin_views_csv_uploads_spec.rb new file mode 100644 index 0000000..d781e1a --- /dev/null +++ b/spec/system/csv_uploads/admin_views_csv_uploads_spec.rb @@ -0,0 +1,12 @@ +require "rails_helper" + +describe "Admin views CsvUploads" do + include_context "admin password matches" + + scenario "views CsvUploads" do + FactoryBot.create_list(:csv_upload, 26) + visit "/admin/csv_uploads" + expect(page).to have_css "a", text: "New CSV Upload" + expect(page.all("tbody tr").count).to eq 25 + end +end