mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-03-02 02:11:33 +00:00
BPUR: add supplier name to product model to allow searching
This commit is contained in:
@@ -87,8 +87,6 @@ productsApp.directive('ngToggleVariants',function(){
|
||||
});
|
||||
|
||||
productsApp.controller('AdminBulkProductsCtrl', function($scope, $timeout, $http, dataFetcher) {
|
||||
$scope.dirtyProducts = {};
|
||||
|
||||
$scope.updateStatusMessage = {
|
||||
text: "",
|
||||
style: {}
|
||||
@@ -102,14 +100,30 @@ productsApp.controller('AdminBulkProductsCtrl', function($scope, $timeout, $http
|
||||
|
||||
$scope.refreshProducts = function(){
|
||||
dataFetcher('/admin/products/bulk_index.json').then(function(data){
|
||||
$scope.products = data;
|
||||
$scope.displayProperties = {};
|
||||
angular.forEach($scope.products,function(product){
|
||||
$scope.displayProperties[product.id] = { showVariants: false }
|
||||
});
|
||||
$scope.resetProducts(data);
|
||||
});
|
||||
};
|
||||
|
||||
$scope.resetProducts = function(data){
|
||||
$scope.products = data;
|
||||
$scope.dirtyProducts = {};
|
||||
$scope.displayProperties = $scope.displayProperties || {};
|
||||
angular.forEach($scope.products,function(product){
|
||||
$scope.displayProperties[product.id] = $scope.displayProperties[product.id] || { showVariants: false };
|
||||
$scope.matchSupplier(product);
|
||||
});
|
||||
}
|
||||
|
||||
$scope.matchSupplier = function(product){
|
||||
for (i in $scope.suppliers){
|
||||
var supplier = $scope.suppliers[i];
|
||||
if (angular.equals(supplier,product.supplier)){
|
||||
product.supplier = supplier;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$scope.updateOnHand = function(product){
|
||||
product.on_hand = onHand(product);
|
||||
}
|
||||
@@ -174,8 +188,7 @@ productsApp.controller('AdminBulkProductsCtrl', function($scope, $timeout, $http
|
||||
})
|
||||
.success(function(data){
|
||||
if (angular.toJson($scope.products) == angular.toJson(data)){
|
||||
$scope.products = data;
|
||||
$scope.dirtyProducts = {};
|
||||
$scope.resetProducts(data);
|
||||
$scope.displaySuccess();
|
||||
}
|
||||
else{
|
||||
@@ -273,7 +286,7 @@ function filterSubmitProducts(productsToFilter){
|
||||
var hasUpdatableProperty = false;
|
||||
filteredProduct.id = product.id;
|
||||
if (product.hasOwnProperty("name")) { filteredProduct.name = product.name; hasUpdatableProperty = true; }
|
||||
if (product.hasOwnProperty("supplier_id")) { filteredProduct.supplier_id = product.supplier_id; hasUpdatableProperty = true; }
|
||||
if (product.hasOwnProperty("supplier")) { filteredProduct.supplier_id = product.supplier.id; hasUpdatableProperty = true; }
|
||||
if (product.hasOwnProperty("price")) { filteredProduct.price = product.price; hasUpdatableProperty = true; }
|
||||
if (product.hasOwnProperty("on_hand") && filteredVariants.length == 0) { filteredProduct.on_hand = product.on_hand; hasUpdatableProperty = true; } //only update if no variants present
|
||||
if (product.hasOwnProperty("available_on")) { filteredProduct.available_on = product.available_on; hasUpdatableProperty = true; }
|
||||
|
||||
@@ -34,7 +34,7 @@
|
||||
%td.firstcol
|
||||
%input{ 'ng-model' => "product.name", :name => 'product_name', 'ng-track-product' => 'name', :type => 'text' }
|
||||
%td
|
||||
%select.select2{ 'ng-model' => 'product.supplier_id', :name => 'supplier_id', 'ng-track-product' => 'supplier_id', 'ng-options' => 's.id as s.name for s in suppliers' }
|
||||
%select.select2{ 'ng-model' => 'product.supplier', :name => 'supplier', 'ng-track-product' => 'supplier', 'ng-options' => 's.name for s in suppliers' }
|
||||
%td
|
||||
%input{ 'ng-model' => 'product.price', 'ng-decimal' => :true, :name => 'price', 'ng-track-product' => 'price', :type => 'text' }
|
||||
%td
|
||||
|
||||
@@ -1,7 +1,10 @@
|
||||
r.list_of :products, @collection.sort_by(&:id) do
|
||||
r.element :id
|
||||
r.element :name
|
||||
r.element :supplier_id
|
||||
r.element :supplier do
|
||||
r.element :id
|
||||
r.element :name
|
||||
end
|
||||
r.element :available_on, Proc.new{ |product| product.available_on.strftime("%F %T") }
|
||||
r.element :price
|
||||
r.element :on_hand
|
||||
|
||||
@@ -30,7 +30,10 @@ describe Spree::Admin::ProductsController do
|
||||
p1r = {
|
||||
"id" => p1.id,
|
||||
"name" => p1.name,
|
||||
"supplier_id" => p1.supplier_id,
|
||||
"supplier" => {
|
||||
"id" => p1.supplier_id,
|
||||
"name" => p1.supplier.name
|
||||
},
|
||||
"available_on" => p1.available_on.strftime("%F %T"),
|
||||
"price" => p1.price.to_s,
|
||||
"on_hand" => ( v11.on_hand + v12.on_hand + v13.on_hand ),
|
||||
@@ -44,7 +47,10 @@ describe Spree::Admin::ProductsController do
|
||||
p2r = {
|
||||
"id" => p2.id,
|
||||
"name" => p2.name,
|
||||
"supplier_id" => p2.supplier_id,
|
||||
"supplier" => {
|
||||
"id" => p2.supplier_id,
|
||||
"name" => p2.supplier.name
|
||||
},
|
||||
"available_on" => p2.available_on.strftime("%F %T"),
|
||||
"price" => p2.price.to_s,
|
||||
"on_hand" => v21.on_hand,
|
||||
|
||||
@@ -40,8 +40,8 @@ feature %q{
|
||||
|
||||
visit '/admin/products/bulk_edit'
|
||||
|
||||
page.should have_select "supplier_id", with_options: [s1.name,s2.name,s3.name], selected: s2.name
|
||||
page.should have_select "supplier_id", with_options: [s1.name,s2.name,s3.name], selected: s3.name
|
||||
page.should have_select "supplier", with_options: [s1.name,s2.name,s3.name], selected: s2.name
|
||||
page.should have_select "supplier", with_options: [s1.name,s2.name,s3.name], selected: s3.name
|
||||
end
|
||||
|
||||
it "displays a date input for available_on for each product, formatted to yyyy-mm-dd hh:mm:ss" do
|
||||
@@ -183,13 +183,13 @@ feature %q{
|
||||
visit '/admin/products/bulk_edit'
|
||||
|
||||
page.should have_field "product_name", with: p.name
|
||||
page.should have_select "supplier_id", selected: s1.name
|
||||
page.should have_select "supplier", selected: s1.name
|
||||
page.should have_field "available_on", with: p.available_on.strftime("%F %T")
|
||||
page.should have_field "price", with: "10.0"
|
||||
page.should have_field "on_hand", with: "6"
|
||||
|
||||
fill_in "product_name", with: "Big Bag Of Potatoes"
|
||||
select(s2.name, :from => 'supplier_id')
|
||||
select(s2.name, :from => 'supplier')
|
||||
fill_in "available_on", with: (Date.today-3).strftime("%F %T")
|
||||
fill_in "price", with: "20"
|
||||
fill_in "on_hand", with: "18"
|
||||
@@ -200,7 +200,7 @@ feature %q{
|
||||
visit '/admin/products/bulk_edit'
|
||||
|
||||
page.should have_field "product_name", with: "Big Bag Of Potatoes"
|
||||
page.should have_select "supplier_id", selected: s2.name
|
||||
page.should have_select "supplier", selected: s2.name
|
||||
page.should have_field "available_on", with: (Date.today-3).strftime("%F %T")
|
||||
page.should have_field "price", with: "20.0"
|
||||
page.should have_field "on_hand", with: "18"
|
||||
|
||||
@@ -114,6 +114,7 @@ describe("filtering products", function(){
|
||||
updated_at: null,
|
||||
count_on_hand: 0,
|
||||
supplier_id: 5,
|
||||
supplier: { id: 5, name: "Supplier 1" },
|
||||
group_buy: null,
|
||||
group_buy_unit_size: null,
|
||||
on_demand: false,
|
||||
@@ -323,6 +324,7 @@ describe("AdminBulkProductsCtrl", function(){
|
||||
it("deletes products with a http delete request to /admin/products/(permalink).js", function(){
|
||||
spyOn(window, "confirm").andReturn(true);
|
||||
scope.products = [ { id: 9, permalink_live: "apples" }, { id: 13, permalink_live: "oranges" } ];
|
||||
scope.dirtyProducts = {};
|
||||
httpBackend.expectDELETE('/admin/products/oranges.js').respond(200, "data");
|
||||
scope.deleteProduct(scope.products[1]);
|
||||
httpBackend.flush();
|
||||
|
||||
Reference in New Issue
Block a user