diff --git a/.travis.yml b/.travis.yml index 7764342b15..0ba99dc9e1 100644 --- a/.travis.yml +++ b/.travis.yml @@ -36,7 +36,7 @@ before_script: fi script: - - '[ "$KARMA" = "true" ] && bundle exec rake karma:run || echo "Skipping karma run"' + - 'if [ "$KARMA" = "true" ]; then bundle exec rake karma:run; else echo "Skipping karma run"; fi' #- "KNAPSACK_GENERATE_REPORT=true bundle exec rspec spec" - "bundle exec rake knapsack:rspec" diff --git a/app/assets/javascripts/admin/order_cycles/controllers/create.js.coffee b/app/assets/javascripts/admin/order_cycles/controllers/create.js.coffee new file mode 100644 index 0000000000..2c98d60f0e --- /dev/null +++ b/app/assets/javascripts/admin/order_cycles/controllers/create.js.coffee @@ -0,0 +1,83 @@ +angular.module('admin.orderCycles') + .controller 'AdminCreateOrderCycleCtrl', ($scope, $filter, OrderCycle, Enterprise, EnterpriseFee, ocInstance, StatusMessage) -> + $scope.enterprises = Enterprise.index(coordinator_id: ocInstance.coordinator_id) + $scope.supplier_enterprises = Enterprise.producer_enterprises + $scope.distributor_enterprises = Enterprise.hub_enterprises + $scope.supplied_products = Enterprise.supplied_products + $scope.enterprise_fees = EnterpriseFee.index(coordinator_id: ocInstance.coordinator_id) + + $scope.OrderCycle = OrderCycle + $scope.order_cycle = OrderCycle.new({ coordinator_id: ocInstance.coordinator_id}) + + $scope.StatusMessage = StatusMessage + + $scope.loaded = -> + Enterprise.loaded && EnterpriseFee.loaded + + $scope.suppliedVariants = (enterprise_id) -> + Enterprise.suppliedVariants(enterprise_id) + + $scope.exchangeSelectedVariants = (exchange) -> + OrderCycle.exchangeSelectedVariants(exchange) + + $scope.setExchangeVariants = (exchange, variants, selected) -> + OrderCycle.setExchangeVariants(exchange, variants, selected) + + $scope.enterpriseTotalVariants = (enterprise) -> + Enterprise.totalVariants(enterprise) + + $scope.productSuppliedToOrderCycle = (product) -> + OrderCycle.productSuppliedToOrderCycle(product) + + $scope.variantSuppliedToOrderCycle = (variant) -> + OrderCycle.variantSuppliedToOrderCycle(variant) + + $scope.incomingExchangeVariantsFor = (enterprise_id) -> + $filter('filterExchangeVariants')(OrderCycle.incomingExchangesVariants(), $scope.order_cycle.visible_variants_for_outgoing_exchanges[enterprise_id]) + + $scope.exchangeDirection = (exchange) -> + OrderCycle.exchangeDirection(exchange) + + $scope.enterprisesWithFees = -> + $scope.enterprises[id] for id in OrderCycle.participatingEnterpriseIds() when $scope.enterpriseFeesForEnterprise(id).length > 0 + + $scope.toggleProducts = ($event, exchange) -> + $event.preventDefault() + OrderCycle.toggleProducts(exchange) + + $scope.enterpriseFeesForEnterprise = (enterprise_id) -> + EnterpriseFee.forEnterprise(parseInt(enterprise_id)) + + $scope.addSupplier = ($event) -> + $event.preventDefault() + OrderCycle.addSupplier($scope.new_supplier_id) + + $scope.addDistributor = ($event) -> + $event.preventDefault() + OrderCycle.addDistributor($scope.new_distributor_id) + + $scope.removeExchange = ($event, exchange) -> + $event.preventDefault() + OrderCycle.removeExchange(exchange) + + $scope.addCoordinatorFee = ($event) -> + $event.preventDefault() + OrderCycle.addCoordinatorFee() + + $scope.removeCoordinatorFee = ($event, index) -> + $event.preventDefault() + OrderCycle.removeCoordinatorFee(index) + + $scope.addExchangeFee = ($event, exchange) -> + $event.preventDefault() + OrderCycle.addExchangeFee(exchange) + + $scope.removeExchangeFee = ($event, exchange, index) -> + $event.preventDefault() + OrderCycle.removeExchangeFee(exchange, index) + + $scope.removeDistributionOfVariant = (variant_id) -> + OrderCycle.removeDistributionOfVariant(variant_id) + + $scope.submit = (destination) -> + OrderCycle.create(destination) diff --git a/app/assets/javascripts/admin/order_cycles/controllers/edit.js.coffee b/app/assets/javascripts/admin/order_cycles/controllers/edit.js.coffee new file mode 100644 index 0000000000..fd426eb455 --- /dev/null +++ b/app/assets/javascripts/admin/order_cycles/controllers/edit.js.coffee @@ -0,0 +1,84 @@ +angular.module('admin.orderCycles') + .controller 'AdminEditOrderCycleCtrl', ($scope, $filter, $location, OrderCycle, Enterprise, EnterpriseFee, StatusMessage) -> + order_cycle_id = $location.absUrl().match(/\/admin\/order_cycles\/(\d+)/)[1] + $scope.enterprises = Enterprise.index(order_cycle_id: order_cycle_id) + $scope.supplier_enterprises = Enterprise.producer_enterprises + $scope.distributor_enterprises = Enterprise.hub_enterprises + $scope.supplied_products = Enterprise.supplied_products + $scope.enterprise_fees = EnterpriseFee.index(order_cycle_id: order_cycle_id) + + $scope.OrderCycle = OrderCycle + $scope.order_cycle = OrderCycle.load(order_cycle_id) + + $scope.StatusMessage = StatusMessage + + $scope.loaded = -> + Enterprise.loaded && EnterpriseFee.loaded && OrderCycle.loaded + + $scope.suppliedVariants = (enterprise_id) -> + Enterprise.suppliedVariants(enterprise_id) + + $scope.exchangeSelectedVariants = (exchange) -> + OrderCycle.exchangeSelectedVariants(exchange) + + $scope.setExchangeVariants = (exchange, variants, selected) -> + OrderCycle.setExchangeVariants(exchange, variants, selected) + + $scope.enterpriseTotalVariants = (enterprise) -> + Enterprise.totalVariants(enterprise) + + $scope.productSuppliedToOrderCycle = (product) -> + OrderCycle.productSuppliedToOrderCycle(product) + + $scope.variantSuppliedToOrderCycle = (variant) -> + OrderCycle.variantSuppliedToOrderCycle(variant) + + $scope.incomingExchangeVariantsFor = (enterprise_id) -> + $filter('filterExchangeVariants')(OrderCycle.incomingExchangesVariants(), $scope.order_cycle.visible_variants_for_outgoing_exchanges[enterprise_id]) + + $scope.exchangeDirection = (exchange) -> + OrderCycle.exchangeDirection(exchange) + + $scope.enterprisesWithFees = -> + $scope.enterprises[id] for id in OrderCycle.participatingEnterpriseIds() when $scope.enterpriseFeesForEnterprise(id).length > 0 + + $scope.toggleProducts = ($event, exchange) -> + $event.preventDefault() + OrderCycle.toggleProducts(exchange) + + $scope.enterpriseFeesForEnterprise = (enterprise_id) -> + EnterpriseFee.forEnterprise(parseInt(enterprise_id)) + + $scope.addSupplier = ($event) -> + $event.preventDefault() + OrderCycle.addSupplier($scope.new_supplier_id) + + $scope.addDistributor = ($event) -> + $event.preventDefault() + OrderCycle.addDistributor($scope.new_distributor_id) + + $scope.removeExchange = ($event, exchange) -> + $event.preventDefault() + OrderCycle.removeExchange(exchange) + + $scope.addCoordinatorFee = ($event) -> + $event.preventDefault() + OrderCycle.addCoordinatorFee() + + $scope.removeCoordinatorFee = ($event, index) -> + $event.preventDefault() + OrderCycle.removeCoordinatorFee(index) + + $scope.addExchangeFee = ($event, exchange) -> + $event.preventDefault() + OrderCycle.addExchangeFee(exchange) + + $scope.removeExchangeFee = ($event, exchange, index) -> + $event.preventDefault() + OrderCycle.removeExchangeFee(exchange, index) + + $scope.removeDistributionOfVariant = (variant_id) -> + OrderCycle.removeDistributionOfVariant(variant_id) + + $scope.submit = (destination) -> + OrderCycle.update(destination) diff --git a/app/assets/javascripts/admin/order_cycles/controllers/order_cycle_controller.js.coffee b/app/assets/javascripts/admin/order_cycles/controllers/order_cycle_controller.js.coffee deleted file mode 100644 index 40428e1f73..0000000000 --- a/app/assets/javascripts/admin/order_cycles/controllers/order_cycle_controller.js.coffee +++ /dev/null @@ -1,204 +0,0 @@ -angular.module('admin.orderCycles', ['ngResource', 'admin.utils']) - .controller('AdminCreateOrderCycleCtrl', ['$scope', '$filter', 'OrderCycle', 'Enterprise', 'EnterpriseFee', 'ocInstance', 'StatusMessage', ($scope, $filter, OrderCycle, Enterprise, EnterpriseFee, ocInstance, StatusMessage) -> - $scope.enterprises = Enterprise.index(coordinator_id: ocInstance.coordinator_id) - $scope.supplier_enterprises = Enterprise.producer_enterprises - $scope.distributor_enterprises = Enterprise.hub_enterprises - $scope.supplied_products = Enterprise.supplied_products - $scope.enterprise_fees = EnterpriseFee.index(coordinator_id: ocInstance.coordinator_id) - - $scope.OrderCycle = OrderCycle - $scope.order_cycle = OrderCycle.new({ coordinator_id: ocInstance.coordinator_id}) - - $scope.StatusMessage = StatusMessage - - $scope.loaded = -> - Enterprise.loaded && EnterpriseFee.loaded - - $scope.suppliedVariants = (enterprise_id) -> - Enterprise.suppliedVariants(enterprise_id) - - $scope.exchangeSelectedVariants = (exchange) -> - OrderCycle.exchangeSelectedVariants(exchange) - - $scope.setExchangeVariants = (exchange, variants, selected) -> - OrderCycle.setExchangeVariants(exchange, variants, selected) - - $scope.enterpriseTotalVariants = (enterprise) -> - Enterprise.totalVariants(enterprise) - - $scope.productSuppliedToOrderCycle = (product) -> - OrderCycle.productSuppliedToOrderCycle(product) - - $scope.variantSuppliedToOrderCycle = (variant) -> - OrderCycle.variantSuppliedToOrderCycle(variant) - - $scope.incomingExchangeVariantsFor = (enterprise_id) -> - $filter('filterExchangeVariants')(OrderCycle.incomingExchangesVariants(), $scope.order_cycle.visible_variants_for_outgoing_exchanges[enterprise_id]) - - $scope.exchangeDirection = (exchange) -> - OrderCycle.exchangeDirection(exchange) - - $scope.enterprisesWithFees = -> - $scope.enterprises[id] for id in OrderCycle.participatingEnterpriseIds() when $scope.enterpriseFeesForEnterprise(id).length > 0 - - $scope.toggleProducts = ($event, exchange) -> - $event.preventDefault() - OrderCycle.toggleProducts(exchange) - - $scope.enterpriseFeesForEnterprise = (enterprise_id) -> - EnterpriseFee.forEnterprise(parseInt(enterprise_id)) - - $scope.addSupplier = ($event) -> - $event.preventDefault() - OrderCycle.addSupplier($scope.new_supplier_id) - - $scope.addDistributor = ($event) -> - $event.preventDefault() - OrderCycle.addDistributor($scope.new_distributor_id) - - $scope.removeExchange = ($event, exchange) -> - $event.preventDefault() - OrderCycle.removeExchange(exchange) - - $scope.addCoordinatorFee = ($event) -> - $event.preventDefault() - OrderCycle.addCoordinatorFee() - - $scope.removeCoordinatorFee = ($event, index) -> - $event.preventDefault() - OrderCycle.removeCoordinatorFee(index) - - $scope.addExchangeFee = ($event, exchange) -> - $event.preventDefault() - OrderCycle.addExchangeFee(exchange) - - $scope.removeExchangeFee = ($event, exchange, index) -> - $event.preventDefault() - OrderCycle.removeExchangeFee(exchange, index) - - $scope.removeDistributionOfVariant = (variant_id) -> - OrderCycle.removeDistributionOfVariant(variant_id) - - $scope.submit = (destination) -> - OrderCycle.create(destination) - ]) - - .controller('AdminEditOrderCycleCtrl', ['$scope', '$filter', '$location', 'OrderCycle', 'Enterprise', 'EnterpriseFee', 'StatusMessage', ($scope, $filter, $location, OrderCycle, Enterprise, EnterpriseFee, StatusMessage) -> - order_cycle_id = $location.absUrl().match(/\/admin\/order_cycles\/(\d+)/)[1] - $scope.enterprises = Enterprise.index(order_cycle_id: order_cycle_id) - $scope.supplier_enterprises = Enterprise.producer_enterprises - $scope.distributor_enterprises = Enterprise.hub_enterprises - $scope.supplied_products = Enterprise.supplied_products - $scope.enterprise_fees = EnterpriseFee.index(order_cycle_id: order_cycle_id) - - $scope.OrderCycle = OrderCycle - $scope.order_cycle = OrderCycle.load(order_cycle_id) - - $scope.StatusMessage = StatusMessage - - $scope.loaded = -> - Enterprise.loaded && EnterpriseFee.loaded && OrderCycle.loaded - - $scope.suppliedVariants = (enterprise_id) -> - Enterprise.suppliedVariants(enterprise_id) - - $scope.exchangeSelectedVariants = (exchange) -> - OrderCycle.exchangeSelectedVariants(exchange) - - $scope.setExchangeVariants = (exchange, variants, selected) -> - OrderCycle.setExchangeVariants(exchange, variants, selected) - - $scope.enterpriseTotalVariants = (enterprise) -> - Enterprise.totalVariants(enterprise) - - $scope.productSuppliedToOrderCycle = (product) -> - OrderCycle.productSuppliedToOrderCycle(product) - - $scope.variantSuppliedToOrderCycle = (variant) -> - OrderCycle.variantSuppliedToOrderCycle(variant) - - $scope.incomingExchangeVariantsFor = (enterprise_id) -> - $filter('filterExchangeVariants')(OrderCycle.incomingExchangesVariants(), $scope.order_cycle.visible_variants_for_outgoing_exchanges[enterprise_id]) - - $scope.exchangeDirection = (exchange) -> - OrderCycle.exchangeDirection(exchange) - - $scope.enterprisesWithFees = -> - $scope.enterprises[id] for id in OrderCycle.participatingEnterpriseIds() when $scope.enterpriseFeesForEnterprise(id).length > 0 - - $scope.toggleProducts = ($event, exchange) -> - $event.preventDefault() - OrderCycle.toggleProducts(exchange) - - $scope.enterpriseFeesForEnterprise = (enterprise_id) -> - EnterpriseFee.forEnterprise(parseInt(enterprise_id)) - - $scope.addSupplier = ($event) -> - $event.preventDefault() - OrderCycle.addSupplier($scope.new_supplier_id) - - $scope.addDistributor = ($event) -> - $event.preventDefault() - OrderCycle.addDistributor($scope.new_distributor_id) - - $scope.removeExchange = ($event, exchange) -> - $event.preventDefault() - OrderCycle.removeExchange(exchange) - - $scope.addCoordinatorFee = ($event) -> - $event.preventDefault() - OrderCycle.addCoordinatorFee() - - $scope.removeCoordinatorFee = ($event, index) -> - $event.preventDefault() - OrderCycle.removeCoordinatorFee(index) - - $scope.addExchangeFee = ($event, exchange) -> - $event.preventDefault() - OrderCycle.addExchangeFee(exchange) - - $scope.removeExchangeFee = ($event, exchange, index) -> - $event.preventDefault() - OrderCycle.removeExchangeFee(exchange, index) - - $scope.removeDistributionOfVariant = (variant_id) -> - OrderCycle.removeDistributionOfVariant(variant_id) - - $scope.submit = (destination) -> - OrderCycle.update(destination) - ]) - - .config(['$httpProvider', ($httpProvider) -> - $httpProvider.defaults.headers.common['X-CSRF-Token'] = $('meta[name=csrf-token]').attr('content') - ]) - - .directive('datetimepicker', ['$parse', ($parse) -> - (scope, element, attrs) -> - # using $parse instead of scope[attrs.datetimepicker] for cases - # where attrs.datetimepicker is 'foo.bar.lol' - $(element).datetimepicker - dateFormat: 'yy-mm-dd' - timeFormat: 'HH:mm:ss' - showOn: "button" - buttonImage: "<%= asset_path 'datepicker/cal.gif' %>" - buttonImageOnly: true - stepMinute: 15 - onSelect: (dateText, inst) -> - scope.$apply -> - parsed = $parse(attrs.datetimepicker) - parsed.assign(scope, dateText) - ]) - - .directive('ofnOnChange', -> - (scope, element, attrs) -> - element.bind 'change', -> - scope.$apply(attrs.ofnOnChange) - ) - - .directive('ofnSyncDistributions', -> - (scope, element, attrs) -> - element.bind 'change', -> - if !$(this).is(':checked') - scope.$apply -> - scope.removeDistributionOfVariant(attrs.ofnSyncDistributions) - ) diff --git a/app/assets/javascripts/admin/order_cycles/order_cycles.js.coffee b/app/assets/javascripts/admin/order_cycles/order_cycles.js.coffee index 2f97440e71..a75fdad58c 100644 --- a/app/assets/javascripts/admin/order_cycles/order_cycles.js.coffee +++ b/app/assets/javascripts/admin/order_cycles/order_cycles.js.coffee @@ -1 +1,32 @@ -angular.module('admin.orderCycles', ['ngResource', 'admin.indexUtils']) +angular.module('admin.orderCycles', ['ngResource', 'admin.utils', 'admin.indexUtils']) + + .config ($httpProvider) -> + $httpProvider.defaults.headers.common['X-CSRF-Token'] = $('meta[name=csrf-token]').attr('content') + + .directive 'datetimepicker', ($parse) -> + (scope, element, attrs) -> + # using $parse instead of scope[attrs.datetimepicker] for cases + # where attrs.datetimepicker is 'foo.bar.lol' + $(element).datetimepicker + dateFormat: 'yy-mm-dd' + timeFormat: 'HH:mm:ss' + showOn: "button" + buttonImage: "<%= asset_path 'datepicker/cal.gif' %>" + buttonImageOnly: true + stepMinute: 15 + onSelect: (dateText, inst) -> + scope.$apply -> + parsed = $parse(attrs.datetimepicker) + parsed.assign(scope, dateText) + + .directive 'ofnOnChange', -> + (scope, element, attrs) -> + element.bind 'change', -> + scope.$apply(attrs.ofnOnChange) + + .directive 'ofnSyncDistributions', -> + (scope, element, attrs) -> + element.bind 'change', -> + if !$(this).is(':checked') + scope.$apply -> + scope.removeDistributionOfVariant(attrs.ofnSyncDistributions) diff --git a/app/serializers/api/line_item_serializer.rb b/app/serializers/api/line_item_serializer.rb index d791febdfc..35d3f9c540 100644 --- a/app/serializers/api/line_item_serializer.rb +++ b/app/serializers/api/line_item_serializer.rb @@ -1,5 +1,5 @@ class Api::LineItemSerializer < ActiveModel::Serializer - attributes :id, :quantity, :price + attributes :id, :quantity, :max_quantity, :price has_one :variant, serializer: Api::VariantSerializer end diff --git a/app/views/spree/shared/_order_details.html.haml b/app/views/spree/shared/_order_details.html.haml index 25582aac8f..8be8d3cf50 100644 --- a/app/views/spree/shared/_order_details.html.haml +++ b/app/views/spree/shared/_order_details.html.haml @@ -62,7 +62,7 @@ %strong= order.shipping_method.name .pad .text-big - Ready for collection + = t :order_pickup_time %strong #{order.order_cycle.pickup_time_for(order.distributor)} %p.text-small.text-skinny.pre-line %em= order.shipping_method.description.andand.html_safe || "" diff --git a/config/application.rb b/config/application.rb index 8a492f5121..ba75a097ec 100644 --- a/config/application.rb +++ b/config/application.rb @@ -66,6 +66,7 @@ module Openfoodnetwork # The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded. # config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s] config.i18n.default_locale = ENV["LOCALE"] + I18n.locale = config.i18n.locale = config.i18n.default_locale # Setting this to true causes a performance regression in Rails 3.2.17 # When we're on a version with the fix below, we can set it to true diff --git a/config/locales/en.yml b/config/locales/en.yml index 04d350153b..701d758891 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -227,6 +227,7 @@ en: order_delivery_on: Delivery on order_delivery_address: Delivery address order_special_instructions: "Your notes:" + order_pickup_time: Ready for collection order_pickup_instructions: Collection Instructions order_produce: Produce order_total_price: Total diff --git a/config/locales/fr.yml b/config/locales/fr.yml index b0613efff4..7ddd01655a 100644 --- a/config/locales/fr.yml +++ b/config/locales/fr.yml @@ -166,6 +166,7 @@ fr: order_delivery_on: Livraison prévue order_delivery_address: Adresse de livraison order_special_instructions: "Vos commentaires:" + order_pickup_time: Disponible pour retrait order_pickup_instructions: Instructions de retrait order_produce: Produit order_total_price: Total diff --git a/spec/features/consumer/shopping/shopping_spec.rb b/spec/features/consumer/shopping/shopping_spec.rb index 12e9d8323b..e81a792881 100644 --- a/spec/features/consumer/shopping/shopping_spec.rb +++ b/spec/features/consumer/shopping/shopping_spec.rb @@ -187,7 +187,7 @@ feature "As a consumer I want to shop with a distributor", js: true do visit shop_path end - it "should save group buy data to the cart" do + it "should save group buy data to the cart and display it on shopfront reload" do # -- Quantity fill_in "variants[#{variant.id}]", with: 6 page.should have_in_cart product.name @@ -202,6 +202,11 @@ feature "As a consumer I want to shop with a distributor", js: true do li = Spree::Order.order(:created_at).last.line_items.order(:created_at).last li.max_quantity.should == 7 + + # -- Reload + visit shop_path + page.should have_field "variants[#{variant.id}]", with: 6 + page.should have_field "variant_attributes[#{variant.id}][max_quantity]", with: 7 end end end