From f344b7893de991921df288bac361e4c39939fa56 Mon Sep 17 00:00:00 2001 From: Matt-Yorkley <9029026+Matt-Yorkley@users.noreply.github.com> Date: Sun, 15 Jul 2018 20:48:12 +0100 Subject: [PATCH 1/5] Remove Product Import guide page --- .../admin/product_import_controller.rb | 6 -- .../admin/product_import/guide.html.haml | 69 ------------ .../product_import/guide/_columns.html.haml | 100 ------------------ .../product_import/guide/_units.html.haml | 54 ---------- .../product_import/guide/_variants.html.haml | 54 ---------- .../admin/product_import/index.html.haml | 6 -- config/routes.rb | 1 - 7 files changed, 290 deletions(-) delete mode 100644 app/views/admin/product_import/guide.html.haml delete mode 100644 app/views/admin/product_import/guide/_columns.html.haml delete mode 100644 app/views/admin/product_import/guide/_units.html.haml delete mode 100644 app/views/admin/product_import/guide/_variants.html.haml diff --git a/app/controllers/admin/product_import_controller.rb b/app/controllers/admin/product_import_controller.rb index 4037bcd85b..f2b1972a9c 100644 --- a/app/controllers/admin/product_import_controller.rb +++ b/app/controllers/admin/product_import_controller.rb @@ -4,12 +4,6 @@ module Admin class ProductImportController < Spree::Admin::BaseController before_filter :validate_upload_presence, except: %i[index guide validate_data] - def guide - @product_categories = Spree::Taxon.order('name ASC').pluck(:name).uniq - @tax_categories = Spree::TaxCategory.order('name ASC').pluck(:name) - @shipping_categories = Spree::ShippingCategory.order('name ASC').pluck(:name) - end - def import # Save uploaded file to tmp directory @filepath = save_uploaded_file(params[:file]) diff --git a/app/views/admin/product_import/guide.html.haml b/app/views/admin/product_import/guide.html.haml deleted file mode 100644 index aab0350606..0000000000 --- a/app/views/admin/product_import/guide.html.haml +++ /dev/null @@ -1,69 +0,0 @@ -- content_for :page_title do - Product Import Guide - -- content_for :page_actions do - %div.toolbar{ 'data-hook' => "toolbar" } - %ul.actions.header-action-links.inline-menu - %li - = button_link_to 'Back to Import', main_app.admin_product_import_path - -= render partial: 'spree/admin/shared/product_sub_menu' - -.product-import-introduction - - %h5 Spreadsheet Columns - - = render 'admin/product_import/guide/columns' - - %h5 Weight, volume, or single items - - %p - When creating a product you can specify a number of options. If the product is measured - by weight, unit_value should be set to a number and unit_type should be set to either - g for grams, Kg for kilograms, or T for tonnes. - - %p - For items such as liquids, the unit_type can be ml for millilitres, L for litres or - Kl for kilolitres. - - %p - For other items that are sold in different units such as "a bunch of carrots", you can - enter 1 for units, leave unit_type blank, and enter a name in the variant_unit_name - column such as "loaf" or "bunch". - - %h6 Example spreadsheet data: - - = render 'admin/product_import/guide/units' - - - %h5 Product Variants - - %p - Variants are distinguished by the units and display_name fields and grouped by product name. - The example below shows a salad that comes in 500g and 750g variants, and a cake that comes in - multiple flavours. - - %h6 Example spreadsheet data: - - = render 'admin/product_import/guide/variants' - - - %h5 Category Values - - %p - Listed below are the available Product categories, as well as Tax and Shipping categories. - - %h6 Product Categories - - - @product_categories.each do |pc| - %span.category= pc - - %h6 Tax Categories - - - @tax_categories.each do |tc| - %span.category= tc - - %h6 Shipping Categories - - - @shipping_categories.each do |sc| - %span.category= sc diff --git a/app/views/admin/product_import/guide/_columns.html.haml b/app/views/admin/product_import/guide/_columns.html.haml deleted file mode 100644 index c79a881162..0000000000 --- a/app/views/admin/product_import/guide/_columns.html.haml +++ /dev/null @@ -1,100 +0,0 @@ -%table.product-import-columns - %thead - %tr - %th Column Title - %th Required - %th Examples - %th Description - %th Notes - %tbody - %tr - %td - %strong name - %td Yes - %td Potatoes - %td The name of the product - %td - %tr - %td - %strong supplier - %td Yes - %td Pennylane Farm - %td The name of the product's supplier - %td - %tr - %td - %strong category - %td Yes - %td Vegetables - %td The product category - %td See below for a list of available categories - %tr - %td - %strong on_hand - %td Yes - %td 15 - %td The amount currently in stock - %td - %tr - %td - %strong price - %td Yes - %td 2.50 - %td The price of the product - %td - %tr - %td - %strong units - %td Yes - %td 750 - %td The weight or volume value. - %td - %tr - %td - %strong unit_type - %td Yes - %td g - %td The unit type, i.e. g for grams, Kg for Kilograms, ml for millilitres. Can be blank (see notes). - %td If unit_type is left blank, a variant_unit_name must be given. - %tr - %td - %strong variant_unit_name - %td Maybe - %td bunch - %td If the product is sold as an item such as "bunch", "loaf" or "case", that goes here. - %td Used for products that don't use a unit_type for weight or volume. - %tr - %td - %strong display_name - %td No - %td Orange - %td Used to name product variants, if they have a distinct name. - %td - %tr - %td - %strong on_demand - %td No - %td 1 - %td Flag the product as "made on demand". The product will not use stock levels. - %td 1 for active, 0 for disabled, or leave blank to ignore. - %tr - %td - %strong tax_category - %td No - %td (Various, see notes) - %td Sets the product tax category - %td See below for a list of available categories - %tr - %td - %strong shipping_category - %td No - %td (Various, see notes) - %td Sets the product shipping category - %td See below for a list of available categories - %tr - %td - %strong available_on - %td No - %td 2018-05-21 - %td Sets the date from which the product will be available - %td Date format is: YYYY-MM-DD diff --git a/app/views/admin/product_import/guide/_units.html.haml b/app/views/admin/product_import/guide/_units.html.haml deleted file mode 100644 index 07161bdb1c..0000000000 --- a/app/views/admin/product_import/guide/_units.html.haml +++ /dev/null @@ -1,54 +0,0 @@ -%table - %thead - %tr - %th - %th name - %th category - %th supplier - %th on_hand - %th price - %th units - %th unit_type - %th variant_unit_name - %tbody - %tr - %td 1 - %td Salad Bag - %td Salads - %td Sue's Salads - %td 26 - %td 3.50 - %td 500 - %td g - %td - %tr - %td 2 - %td Fruit Juice - %td Drinks - %td Country Juices - %td 12 - %td 3.50 - %td 300 - %td ml - %td - %tr - %td 3 - %td Potatoes - %td Vegetables - %td Fernwell Farm - %td 67 - %td 4.20 - %td 1 - %td kg - %td - - %tr - %td 3 - %td Wholemeal Bread - %td Baked goods - %td Tim's Bakery - %td 66 - %td 3.00 - %td 1 - %td - %td loaf diff --git a/app/views/admin/product_import/guide/_variants.html.haml b/app/views/admin/product_import/guide/_variants.html.haml deleted file mode 100644 index dfd95879c1..0000000000 --- a/app/views/admin/product_import/guide/_variants.html.haml +++ /dev/null @@ -1,54 +0,0 @@ -%table - %thead - %tr - %th - %th name - %th category - %th supplier - %th on_hand - %th price - %th units - %th unit_type - %th display_name - %tbody - %tr - %td 1 - %td Salad Bag - %td Salads - %td Sue's Salads - %td 26 - %td 3.50 - %td 500 - %td g - %td - %tr - %td 2 - %td Salad Bag - %td Salads - %td Sue's Salads - %td 44 - %td 5.50 - %td 750 - %td g - %td - %tr - %td 3 - %td Cake - %td Baked goods - %td Tim's Cakes - %td 10 - %td 4 - %td 500 - %td g - %td Banana and Walnut - %tr - %td 4 - %td Cake - %td Baked goods - %td Tim's Cakes - %td 18 - %td 4 - %td 500 - %td g - %td Carrot - diff --git a/app/views/admin/product_import/index.html.haml b/app/views/admin/product_import/index.html.haml index f2e8e5208b..fd17684ef0 100644 --- a/app/views/admin/product_import/index.html.haml +++ b/app/views/admin/product_import/index.html.haml @@ -1,12 +1,6 @@ - content_for :page_title do #{t('admin.product_import.title')} -- content_for :page_actions do - %div.toolbar{ 'data-hook' => "toolbar" } - %ul.actions.header-action-links.inline-menu - %li - = button_link_to 'View Guide', main_app.admin_product_import_guide_path - = render partial: 'spree/admin/shared/product_sub_menu' = render 'upload_form' diff --git a/config/routes.rb b/config/routes.rb index 7e2bc47a32..229b26e331 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -133,7 +133,6 @@ Openfoodnetwork::Application.routes.draw do get '/inventory', to: 'variant_overrides#index' get '/product_import', to: 'product_import#index' - get '/product_import/guide', to: 'product_import#guide', as: 'product_import_guide' post '/product_import', to: 'product_import#import' post '/product_import/validate_data', to: 'product_import#validate_data', as: 'product_import_process_async' post '/product_import/save_data', to: 'product_import#save_data', as: 'product_import_save_async' From 632b991952c14b810eb3d594bdefa71315682a9f Mon Sep 17 00:00:00 2001 From: Matt-Yorkley <9029026+Matt-Yorkley@users.noreply.github.com> Date: Sun, 15 Jul 2018 21:25:42 +0100 Subject: [PATCH 2/5] Add downloadable templates --- public/inventory_template.csv | 1 + public/product_list_template.csv | 1 + 2 files changed, 2 insertions(+) create mode 100644 public/inventory_template.csv create mode 100644 public/product_list_template.csv diff --git a/public/inventory_template.csv b/public/inventory_template.csv new file mode 100644 index 0000000000..68e0fce918 --- /dev/null +++ b/public/inventory_template.csv @@ -0,0 +1 @@ +producer,supplier,name,display_name,units,price,on_hand diff --git a/public/product_list_template.csv b/public/product_list_template.csv new file mode 100644 index 0000000000..f97e4f80d7 --- /dev/null +++ b/public/product_list_template.csv @@ -0,0 +1 @@ +supplier,sku,name,display_name,category,units,unit_type,variant_unit_name,price,on_hand,available_on,on_demand,shipping_category,tax_category From c4af50e95c12262aca65b78b84a0876ed4213d67 Mon Sep 17 00:00:00 2001 From: Matt-Yorkley <9029026+Matt-Yorkley@users.noreply.github.com> Date: Sun, 15 Jul 2018 21:26:17 +0100 Subject: [PATCH 3/5] Add sidebar to Import index page --- .../stylesheets/admin/product_import.css.scss | 65 +++++++++---------- .../admin/product_import_controller.rb | 6 ++ .../product_import/_upload_sidebar.html.haml | 30 +++++++++ .../admin/product_import/index.html.haml | 2 + config/locales/en.yml | 7 ++ 5 files changed, 75 insertions(+), 35 deletions(-) create mode 100644 app/views/admin/product_import/_upload_sidebar.html.haml diff --git a/app/assets/stylesheets/admin/product_import.css.scss b/app/assets/stylesheets/admin/product_import.css.scss index 4210439b78..79265c9231 100644 --- a/app/assets/stylesheets/admin/product_import.css.scss +++ b/app/assets/stylesheets/admin/product_import.css.scss @@ -1,38 +1,3 @@ -.product-import-introduction { - - h1, h2, h3, h4, h5, h6 { - margin: 1.5em 0 1em; - } - - h6 { - font-size: 1em; - } - - p { - margin-bottom: 1em; - } - - span.category { - display: inline-block; - background-color: #f3f3f3; - padding: 0.4em 0.8em; - margin: 0 0.4em 0.5em 0; - } - - table { - - &.product-import-columns tr:hover td { - background-color: transparent; - } - - thead th { - text-transform: none; - font-size: 100%; - text-align: left; - } - } -} - div.panel-section { .neutral { @@ -315,3 +280,33 @@ div.progress-bar { transition: width 0.5s ease-in-out; } } + +#upload-sidebar { + float: right; + background-color: lighten(#eff5fc, 2.5%); + border: 1px solid lighten(#cee1f4, 2.5%); + width: 50%; + padding: 0 1.5em 1.5em; + + h4, h5, h6, p { + margin: 1.25em 0 1em; + } + + a.download { + display: block; + font-size: 1.05em; + margin-bottom: 0.5em; + + i { + margin-right: 0.25em; + } + } + + span.category { + display: inline-block; + background-color: lighten(#5498da, 10%); + color: white; + padding: 0.3em 0.6em; + margin: 0 0.4em 0.5em 0; + } +} diff --git a/app/controllers/admin/product_import_controller.rb b/app/controllers/admin/product_import_controller.rb index f2b1972a9c..88d9623b3a 100644 --- a/app/controllers/admin/product_import_controller.rb +++ b/app/controllers/admin/product_import_controller.rb @@ -4,6 +4,12 @@ module Admin class ProductImportController < Spree::Admin::BaseController before_filter :validate_upload_presence, except: %i[index guide validate_data] + def index + @product_categories = Spree::Taxon.order('name ASC').pluck(:name).uniq + @tax_categories = Spree::TaxCategory.order('name ASC').pluck(:name) + @shipping_categories = Spree::ShippingCategory.order('name ASC').pluck(:name) + end + def import # Save uploaded file to tmp directory @filepath = save_uploaded_file(params[:file]) diff --git a/app/views/admin/product_import/_upload_sidebar.html.haml b/app/views/admin/product_import/_upload_sidebar.html.haml new file mode 100644 index 0000000000..54c5829b29 --- /dev/null +++ b/app/views/admin/product_import/_upload_sidebar.html.haml @@ -0,0 +1,30 @@ +#upload-sidebar + %h5= t('admin.product_import.index.csv_templates') + + %a.download{href: '/product_list_template.csv'} + %i.icon-external-link + = t('admin.product_import.index.product_list_template') + + %a.download{href: '/inventory_template.csv'} + %i.icon-external-link + = t('admin.product_import.index.inventory_template') + + %h5= t('admin.product_import.index.category_values') + + %p + %strong= t('admin.product_import.index.product_categories') + + - @product_categories.each do |pc| + %span.category= pc + + %p + %strong= t('admin.product_import.index.tax_categories') + + - @tax_categories.each do |tc| + %span.category= tc + + %p + %strong= t('admin.product_import.index.shipping_categories') + + - @shipping_categories.each do |sc| + %span.category= sc \ No newline at end of file diff --git a/app/views/admin/product_import/index.html.haml b/app/views/admin/product_import/index.html.haml index fd17684ef0..3ff03f08c1 100644 --- a/app/views/admin/product_import/index.html.haml +++ b/app/views/admin/product_import/index.html.haml @@ -3,4 +3,6 @@ = render partial: 'spree/admin/shared/product_sub_menu' += render 'upload_sidebar' + = render 'upload_form' diff --git a/config/locales/en.yml b/config/locales/en.yml index 67c8d17fd3..c9f944a7d2 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -470,6 +470,13 @@ en: inventories: Inventories import: Import upload: Upload + csv_templates: CSV Templates + product_list_template: Download Product List template + inventory_template: Download Inventory template + category_values: Available Category Values + product_categories: Product Categories + tax_categories: Tax Categories + shipping_categories: Shipping Categories import: review: Review proceed: Proceed From c7deae42538b920b999e255e86a4710e841c9271 Mon Sep 17 00:00:00 2001 From: Matt-Yorkley <9029026+Matt-Yorkley@users.noreply.github.com> Date: Wed, 18 Jul 2018 12:49:20 +0100 Subject: [PATCH 4/5] Remove category field from inventory specs --- spec/models/product_importer_spec.rb | 32 ++++++++++++++-------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/spec/models/product_importer_spec.rb b/spec/models/product_importer_spec.rb index 465b9809b0..73c7423cc3 100644 --- a/spec/models/product_importer_spec.rb +++ b/spec/models/product_importer_spec.rb @@ -296,10 +296,10 @@ describe ProductImport::ProductImporter do describe "importing items into inventory" do before do csv_data = CSV.generate do |csv| - csv << ["name", "supplier", "producer", "category", "on_hand", "price", "units"] - csv << ["Beans", "Another Enterprise", "User Enterprise", "Vegetables", "5", "3.20", "500"] - csv << ["Sprouts", "Another Enterprise", "User Enterprise", "Vegetables", "6", "6.50", "500"] - csv << ["Cabbage", "Another Enterprise", "User Enterprise", "Vegetables", "2001", "1.50", "500"] + csv << ["name", "supplier", "producer", "on_hand", "price", "units", "unit_type"] + csv << ["Beans", "Another Enterprise", "User Enterprise", "5", "3.20", "500", "g"] + csv << ["Sprouts", "Another Enterprise", "User Enterprise", "6", "6.50", "500", "g"] + csv << ["Cabbage", "Another Enterprise", "User Enterprise", "2001", "1.50", "500", "g"] end File.write('/tmp/test-m.csv', csv_data) file = File.new('/tmp/test-m.csv') @@ -422,8 +422,8 @@ describe ProductImport::ProductImporter do it "allows creating inventories for producers that a user's hub has permission for" do csv_data = CSV.generate do |csv| - csv << ["name", "producer", "supplier", "category", "on_hand", "price", "units"] - csv << ["Beans", "User Enterprise", "Another Enterprise", "Vegetables", "777", "3.20", "500"] + csv << ["name", "producer", "supplier", "on_hand", "price", "units", "unit_type"] + csv << ["Beans", "User Enterprise", "Another Enterprise", "777", "3.20", "500", "g"] end File.write('/tmp/test-m.csv', csv_data) file = File.new('/tmp/test-m.csv') @@ -449,9 +449,9 @@ describe ProductImport::ProductImporter do it "does not allow creating inventories for producers that a user's hubs don't have permission for" do csv_data = CSV.generate do |csv| - csv << ["name", "supplier", "category", "on_hand", "price", "units"] - csv << ["Beans", "User Enterprise", "Vegetables", "5", "3.20", "500"] - csv << ["Sprouts", "User Enterprise", "Vegetables", "6", "6.50", "500"] + csv << ["name", "supplier", "on_hand", "price", "units", "unit_type"] + csv << ["Beans", "User Enterprise", "5", "3.20", "500", "g"] + csv << ["Sprouts", "User Enterprise", "6", "6.50", "500", "g"] end File.write('/tmp/test-m.csv', csv_data) file = File.new('/tmp/test-m.csv') @@ -515,9 +515,9 @@ describe ProductImport::ProductImporter do it "can reset all inventory items for an enterprise that are not present in the uploaded file to zero stock" do csv_data = CSV.generate do |csv| - csv << ["name", "supplier", "producer", "category", "on_hand", "price", "units"] - csv << ["Beans", "Another Enterprise", "User Enterprise", "Vegetables", "6", "3.20", "500"] - csv << ["Sprouts", "Another Enterprise", "User Enterprise", "Vegetables", "7", "6.50", "500"] + csv << ["name", "supplier", "producer", "on_hand", "price", "units", "unit_type"] + csv << ["Beans", "Another Enterprise", "User Enterprise", "6", "3.20", "500", "g"] + csv << ["Sprouts", "Another Enterprise", "User Enterprise", "7", "6.50", "500", "g"] end File.write('/tmp/test-m.csv', csv_data) file = File.new('/tmp/test-m.csv') @@ -617,10 +617,10 @@ describe ProductImport::ProductImporter do it "can overwrite fields with selected defaults when importing to inventory" do csv_data = CSV.generate do |csv| - csv << ["name", "producer", "supplier", "category", "on_hand", "price", "units"] - csv << ["Beans", "User Enterprise", "Another Enterprise", "Vegetables", "", "3.20", "500"] - csv << ["Sprouts", "User Enterprise", "Another Enterprise", "Vegetables", "7", "6.50", "500"] - csv << ["Cabbage", "User Enterprise", "Another Enterprise", "Vegetables", "", "1.50", "500"] + csv << ["name", "producer", "supplier", "on_hand", "price", "units", "unit_type"] + csv << ["Beans", "User Enterprise", "Another Enterprise", "", "3.20", "500", "g"] + csv << ["Sprouts", "User Enterprise", "Another Enterprise", "7", "6.50", "500", "g"] + csv << ["Cabbage", "User Enterprise", "Another Enterprise", "", "1.50", "500", "g"] end File.write('/tmp/test-m.csv', csv_data) file = File.new('/tmp/test-m.csv') From 5737c9803d116f24e7dc833778463169fb860226 Mon Sep 17 00:00:00 2001 From: Matt-Yorkley <9029026+Matt-Yorkley@users.noreply.github.com> Date: Wed, 18 Jul 2018 12:59:52 +0100 Subject: [PATCH 5/5] Add unit_type field to inventory template --- public/inventory_template.csv | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/public/inventory_template.csv b/public/inventory_template.csv index 68e0fce918..dd7329a89c 100644 --- a/public/inventory_template.csv +++ b/public/inventory_template.csv @@ -1 +1 @@ -producer,supplier,name,display_name,units,price,on_hand +producer,supplier,name,display_name,units,unit_type,price,on_hand