mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-13 23:37:47 +00:00
WIP: Bulk Product Update Rewrite: initial acceptance testing
This commit is contained in:
10
app/assets/javascripts/admin/bulk_product_update.js
Normal file
10
app/assets/javascripts/admin/bulk_product_update.js
Normal file
@@ -0,0 +1,10 @@
|
||||
function AdminProductsBulkCtrl($scope, $http) {
|
||||
$scope.refreshData = function(){
|
||||
$http({ method: 'GET', url:'/admin/products/bulk_index.json' }).success(function(data) {
|
||||
$scope.products = data;
|
||||
});
|
||||
}
|
||||
$scope.refreshData();
|
||||
}
|
||||
|
||||
var productsApp = angular.module('bulk_product_update', [])
|
||||
26
app/controllers/spree/admin/products_controller_decorator.rb
Normal file
26
app/controllers/spree/admin/products_controller_decorator.rb
Normal file
@@ -0,0 +1,26 @@
|
||||
Spree::Admin::ProductsController.class_eval do
|
||||
before_filter :load_product_set, :only => :bulk_index
|
||||
|
||||
alias_method :location_after_save_original, :location_after_save
|
||||
|
||||
def bulk_index
|
||||
respond_to do |format|
|
||||
format.html
|
||||
format.json
|
||||
end
|
||||
end
|
||||
|
||||
protected
|
||||
def location_after_save
|
||||
if URI(request.referer).path == '/admin/products/bulk_index'
|
||||
bulk_index_admin_products_url
|
||||
else
|
||||
location_after_save_original
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
def load_product_set
|
||||
@product_set = Spree::ProductSet.new :collection => collection
|
||||
end
|
||||
end
|
||||
7
app/models/spree/product_set.rb
Normal file
7
app/models/spree/product_set.rb
Normal file
@@ -0,0 +1,7 @@
|
||||
class Spree::ProductSet < ModelSet
|
||||
def initialize(attributes={})
|
||||
super(Spree::Product, Spree::Product.all,
|
||||
proc { |attrs| attrs[:product_id].blank? },
|
||||
attributes)
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,4 @@
|
||||
Deface::Override.new(:virtual_path => "spree/admin/shared/_product_sub_menu",
|
||||
:name => "add_bulk_index_tab_to_products_admin_sub_menu",
|
||||
:insert_bottom => "[data-hook='admin_product_sub_tabs']",
|
||||
:text => "<%= tab('Bulk Product Edit', :url => bulk_index_admin_products_path) %>")
|
||||
22
app/views/spree/admin/products/bulk_index.html.haml
Normal file
22
app/views/spree/admin/products/bulk_index.html.haml
Normal file
@@ -0,0 +1,22 @@
|
||||
- content_for :page_title do
|
||||
= "Bulk Edit Products"
|
||||
|
||||
- content_for :page_actions do
|
||||
%div{ :class => "toolbar", 'data-hook' => "toolbar" }
|
||||
%ul{ :class => "actions header-action-links inline-menu" }
|
||||
%li#new_product_link
|
||||
= button_link_to t(:new_product), new_object_url, { :remote => true, :icon => 'icon-plus', :id => 'admin_new_product' }
|
||||
|
||||
= render :partial => 'spree/admin/shared/product_sub_menu'
|
||||
|
||||
%div#new_product(data-hook)
|
||||
|
||||
%div{ 'ng-app' => 'bulk_product_update', 'ng-controller' => 'AdminProductsBulkCtrl' }
|
||||
%table.index#listing_products
|
||||
%thead
|
||||
%tr
|
||||
%th Name
|
||||
%tbody{ 'ng-repeat' => 'product in products | filter:query' }
|
||||
%tr
|
||||
%td
|
||||
%input{ 'ng-model' => "product.name", :type => 'text' }
|
||||
4
app/views/spree/admin/products/bulk_index.rep
Normal file
4
app/views/spree/admin/products/bulk_index.rep
Normal file
@@ -0,0 +1,4 @@
|
||||
r.list_of :products, @collection do
|
||||
r.element :id
|
||||
r.element :name
|
||||
end
|
||||
@@ -32,6 +32,12 @@ Spree::Core::Engine.routes.prepend do
|
||||
match '/admin/reports/payments' => 'admin/reports#payments', :as => "payments_admin_reports", :via => [:get, :post]
|
||||
match '/admin/reports/order_cycles' => 'admin/reports#order_cycles', :as => "order_cycles_admin_reports", :via => [:get, :post]
|
||||
|
||||
namespace :admin do
|
||||
resources :products do
|
||||
get :bulk_index, :on => :collection, :as => :bulk_index
|
||||
end
|
||||
end
|
||||
|
||||
resources :orders do
|
||||
get :select_distributor, :on => :member
|
||||
get :deselect_distributor, :on => :collection
|
||||
|
||||
67
spec/features/admin/bulk_product_update_spec.rb
Normal file
67
spec/features/admin/bulk_product_update_spec.rb
Normal file
@@ -0,0 +1,67 @@
|
||||
require 'spec_helper'
|
||||
|
||||
feature %q{
|
||||
As an Administrator
|
||||
I want to be able to manage products in bulk
|
||||
} , js: true do
|
||||
|
||||
include AuthenticationWorkflow
|
||||
include WebHelper
|
||||
|
||||
before :all do
|
||||
@default_wait_time = Capybara.default_wait_time
|
||||
Capybara.default_wait_time = 5
|
||||
end
|
||||
|
||||
after :all do
|
||||
Capybara.default_wait_time = @default_wait_time
|
||||
end
|
||||
|
||||
scenario "listing products" do
|
||||
p = FactoryGirl.create(:product)
|
||||
|
||||
login_to_admin_section
|
||||
click_link 'Products'
|
||||
click_link 'Bulk Product Edit'
|
||||
|
||||
page.first('input').value.should == p.name
|
||||
end
|
||||
|
||||
scenario "create a new product" do
|
||||
s = FactoryGirl.create(:supplier_enterprise)
|
||||
d = FactoryGirl.create(:distributor_enterprise)
|
||||
|
||||
login_to_admin_section
|
||||
click_link 'Products'
|
||||
click_link 'Bulk Product Edit'
|
||||
|
||||
click_link 'New Product'
|
||||
|
||||
page.should have_content 'NEW PRODUCT'
|
||||
|
||||
fill_in 'product_name', :with => 'Big Bag Of Apples'
|
||||
select(s.name, :from => 'product_supplier_id')
|
||||
choose('product_group_buy_0')
|
||||
fill_in 'product_price', :with => '10.00'
|
||||
fill_in 'product_available_on', :with => Date.today.strftime("%Y/%m/%d")
|
||||
check('product_product_distributions_attributes_0__destroy')
|
||||
click_button 'Create'
|
||||
|
||||
URI.parse(current_url).path.should == '/admin/products/bulk_index'
|
||||
flash_message.should == 'Product "Big Bag Of Apples" has been successfully created!'
|
||||
page.should have_content 'Big Bag Of Apples'
|
||||
end
|
||||
|
||||
scenario "updating a product" do
|
||||
p = FactoryGirl.create(:product)
|
||||
s1 = FactoryGirl.create(:supplier_enterprise)
|
||||
s2 = FactoryGirl.create(:supplier_enterprise)
|
||||
p.supplier = s1
|
||||
|
||||
login_to_admin_section
|
||||
click_link 'Products'
|
||||
click_link 'Bulk Product Edit'
|
||||
|
||||
page.first(:css, "td select", :text => s1.name).select(s2.name)
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user