mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-27 01:43:22 +00:00
Bulk product update rewrite: basic integration test passing
This commit is contained in:
@@ -1,3 +1,9 @@
|
||||
var productsApp = angular.module('bulk_product_update', [])
|
||||
|
||||
productsApp.config(["$httpProvider", function(provider) {
|
||||
provider.defaults.headers.common['X-CSRF-Token'] = $('meta[name=csrf-token]').attr('content');
|
||||
}]);
|
||||
|
||||
function AdminBulkProductsCtrl($scope, $timeout, $http) {
|
||||
$scope.refreshSuppliers = function(){
|
||||
$http.get('/enterprises/suppliers.json').success(function(data) {
|
||||
@@ -24,8 +30,7 @@ function AdminBulkProductsCtrl($scope, $timeout, $http) {
|
||||
$http({
|
||||
method: 'POST',
|
||||
url: '/admin/products/bulk_update',
|
||||
data: productsToSubmit,
|
||||
headers: {'Content-Type': 'application/json', 'Accept': 'application/json'}
|
||||
data: productsToSubmit
|
||||
})
|
||||
.success(function(data){
|
||||
if (angular.toJson($scope.products) == angular.toJson(data)){
|
||||
@@ -67,8 +72,6 @@ function AdminBulkProductsCtrl($scope, $timeout, $http) {
|
||||
}
|
||||
}
|
||||
|
||||
var productsApp = angular.module('bulk_product_update', [])
|
||||
|
||||
function sortByID(array){
|
||||
var sortedArray = [];
|
||||
for (var i in array){
|
||||
|
||||
@@ -10,6 +10,18 @@ Spree::Admin::ProductsController.class_eval do
|
||||
end
|
||||
end
|
||||
|
||||
def bulk_update
|
||||
@collection_hash = Hash[params[:_json].each_with_index.map { |p,i| [i,p] }]
|
||||
@collection_attributes = { :collection_attributes => @collection_hash }
|
||||
@product_set = Spree::ProductSet.new(@collection_attributes)
|
||||
|
||||
if @product_set.save
|
||||
redirect_to bulk_index_admin_products_url :format => :json
|
||||
else
|
||||
render :nothing => true
|
||||
end
|
||||
end
|
||||
|
||||
protected
|
||||
def location_after_save
|
||||
if URI(request.referer).path == '/admin/products/bulk_index'
|
||||
|
||||
@@ -35,6 +35,7 @@ Spree::Core::Engine.routes.prepend do
|
||||
namespace :admin do
|
||||
resources :products do
|
||||
get :bulk_index, :on => :collection, :as => :bulk_index
|
||||
post :bulk_update, :on => :collection, :as => :bulk_update
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -64,7 +64,7 @@ feature %q{
|
||||
|
||||
fill_in "product_name", with: "Big Bag Of Potatoes"
|
||||
click_button 'Update'
|
||||
page.find("div#update-status-message").should have_content "Updating complete"
|
||||
page.find("span#update-status-message").should have_content "Update complete"
|
||||
click_link 'Bulk Product Edit'
|
||||
|
||||
page.should have_field "product_name", with: "Big Bag Of Potatoes"
|
||||
|
||||
Reference in New Issue
Block a user