Skip to content

Commit

Permalink
Admin views csv uploads
Browse files Browse the repository at this point in the history
  • Loading branch information
jonallured committed Feb 18, 2024
1 parent 74243d9 commit 8da58eb
Show file tree
Hide file tree
Showing 8 changed files with 52 additions and 1 deletion.
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
13 changes: 13 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -382,6 +394,7 @@ DEPENDENCIES
haml
importmap-rails
jbuilder
kaminari
pg
pry-rails
puma
Expand Down
1 change: 1 addition & 0 deletions app/controllers/admin/csv_uploads_controller.rb
Original file line number Diff line number Diff line change
@@ -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
Expand Down
20 changes: 20 additions & 0 deletions app/views/admin/csv_uploads/index.html.haml
Original file line number Diff line number Diff line change
@@ -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
2 changes: 2 additions & 0 deletions app/views/admin/csv_uploads/new.html.haml
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 2 additions & 0 deletions app/views/admin/csv_uploads/show.html.haml
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
12 changes: 12 additions & 0 deletions spec/system/csv_uploads/admin_views_csv_uploads_spec.rb
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 8da58eb

Please sign in to comment.