From d7d29e3654be2c00c483b18813097dfc7080ea18 Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Bellet Date: Mon, 14 Mar 2022 17:25:51 +0100 Subject: [PATCH] Create a new controller for new products page Controller is constrained by FeatureToggle - new_products_page - and available on '/new_products' Add simple view for new products page and a product Add new products page as a new entry in the menu --- app/controllers/admin/products_controller.rb | 7 +++++++ app/views/admin/products/_product.html.haml | 14 ++++++++++++++ app/views/admin/products/index.html.haml | 13 +++++++++++++ .../spree/admin/shared/_product_sub_menu.html.haml | 2 ++ config/routes/admin.rb | 4 ++++ 5 files changed, 40 insertions(+) create mode 100644 app/controllers/admin/products_controller.rb create mode 100644 app/views/admin/products/_product.html.haml create mode 100644 app/views/admin/products/index.html.haml diff --git a/app/controllers/admin/products_controller.rb b/app/controllers/admin/products_controller.rb new file mode 100644 index 0000000000..123aea7531 --- /dev/null +++ b/app/controllers/admin/products_controller.rb @@ -0,0 +1,7 @@ +# frozen_string_literal: true + +module Admin + class ProductsController < Spree::Admin::BaseController + def index; end + end +end diff --git a/app/views/admin/products/_product.html.haml b/app/views/admin/products/_product.html.haml new file mode 100644 index 0000000000..d7be7958bb --- /dev/null +++ b/app/views/admin/products/_product.html.haml @@ -0,0 +1,14 @@ +%div.product + = if product.images[0] + %div.image + %img{src: product.images[0].attachment.url(:mini, false) } + %div.title + = product.name + %div.unit + = product.unit_value + = product.variant_unit + %div.price + = product.price + +%pre + = product.to_json diff --git a/app/views/admin/products/index.html.haml b/app/views/admin/products/index.html.haml new file mode 100644 index 0000000000..55aea2617f --- /dev/null +++ b/app/views/admin/products/index.html.haml @@ -0,0 +1,13 @@ +- content_for :page_title do + New Products Page + += render partial: 'spree/admin/shared/product_sub_menu' + + +%div + %input.search{type: 'text', placeholder: 'Search', id: 'search_query'} + %button.btn.btn-primary{type: 'submit'} + Filter results + +#new_products + = render partial: "product", collection: @products diff --git a/app/views/spree/admin/shared/_product_sub_menu.html.haml b/app/views/spree/admin/shared/_product_sub_menu.html.haml index 66859dec69..41a3f5b3b7 100644 --- a/app/views/spree/admin/shared/_product_sub_menu.html.haml +++ b/app/views/spree/admin/shared/_product_sub_menu.html.haml @@ -4,3 +4,5 @@ = tab :properties = tab :variant_overrides, url: main_app.admin_inventory_path, match_path: '/inventory' = tab :import, url: main_app.admin_product_import_path, match_path: '/product_import' + - if feature?(:new_products_page, spree_current_user) + = tab :new_products, url: main_app.admin_new_products_path, match_path: '/new_products' diff --git a/config/routes/admin.rb b/config/routes/admin.rb index a7e900dce7..8bd8cf7620 100644 --- a/config/routes/admin.rb +++ b/config/routes/admin.rb @@ -67,6 +67,10 @@ Openfoodnetwork::Application.routes.draw do post '/product_import/save_data', to: 'product_import#save_data', as: 'product_import_save_async' post '/product_import/reset_absent', to: 'product_import#reset_absent_products', as: 'product_import_reset_async' + constraints FeatureToggleConstraint.new(:new_products_page) do + get '/new_products', to: 'products#index' + end + resources :variant_overrides do post :bulk_update, on: :collection post :bulk_reset, on: :collection