diff --git a/app/assets/javascripts/admin/order_cycles/controllers/order_cycle_exchanges_controller.js.coffee b/app/assets/javascripts/admin/order_cycles/controllers/order_cycle_exchanges_controller.js.coffee index 1953754cbf..9e966575d5 100644 --- a/app/assets/javascripts/admin/order_cycles/controllers/order_cycle_exchanges_controller.js.coffee +++ b/app/assets/javascripts/admin/order_cycles/controllers/order_cycle_exchanges_controller.js.coffee @@ -38,15 +38,16 @@ angular.module('admin.orderCycles') $scope.loadExchangeProducts = (exchange, page = 1) -> enterprise = $scope.enterprises[exchange.enterprise_id] + enterprise.supplied_products ?= [] return if enterprise.last_page_loaded? && enterprise.last_page_loaded >= page enterprise.last_page_loaded = page incoming = true if $scope.view == 'incoming' params = { exchange_id: exchange.id, enterprise_id: exchange.enterprise_id, order_cycle_id: $scope.order_cycle.id, incoming: incoming, page: page} - ExchangeProduct.index params, (products, last_page) -> - enterprise.last_page = last_page - enterprise.supplied_products = [] unless enterprise.supplied_products? + ExchangeProduct.index params, (products, num_of_pages, num_of_products) -> + enterprise.num_of_pages = num_of_pages + enterprise.num_of_products = num_of_products enterprise.supplied_products.push products... $scope.loadMoreExchangeProducts = -> @@ -54,7 +55,7 @@ angular.module('admin.orderCycles') $scope.loadAllExchangeProducts = -> enterprise = $scope.enterprises[this.exchange.enterprise_id] - for page_to_load in [(enterprise.last_page_loaded + 1)..enterprise.last_page] + for page_to_load in [(enterprise.last_page_loaded + 1)..enterprise.num_of_pages] $scope.loadExchangeProducts(this.exchange, page_to_load) # initialize exchange products panel if not yet done diff --git a/app/assets/javascripts/admin/order_cycles/services/exchange_product.js.coffee b/app/assets/javascripts/admin/order_cycles/services/exchange_product.js.coffee index 92df8f8e84..1a80c637d5 100644 --- a/app/assets/javascripts/admin/order_cycles/services/exchange_product.js.coffee +++ b/app/assets/javascripts/admin/order_cycles/services/exchange_product.js.coffee @@ -10,7 +10,7 @@ angular.module('admin.orderCycles').factory('ExchangeProduct', ($resource) -> index: (params={}, callback=null) -> ExchangeProductResource.index params, (data) => @loaded = true - (callback || angular.noop)(data.products, data.pagination.pages) + (callback || angular.noop)(data.products, data.pagination.pages, data.pagination.results) countVariants: (params={}, callback=null) -> ExchangeProductResource.variant_count params, (data) => diff --git a/app/assets/javascripts/templates/admin/panels/exchange_distributed_products.html.haml b/app/assets/javascripts/templates/admin/panels/exchange_distributed_products.html.haml index 45650d94db..d92e5e1fe5 100644 --- a/app/assets/javascripts/templates/admin/panels/exchange_distributed_products.html.haml +++ b/app/assets/javascripts/templates/admin/panels/exchange_distributed_products.html.haml @@ -1,5 +1,11 @@ .row.exchange-distributed-products{'ng-init' => 'initializeExchangeProductsPanel(exchange)'} .sixteen.columns.alpha.omega + .exchange-load-all-variants + %div + {{ 'js.admin.panels.exchange_products.products_loaded' | t:{ num_of_products_loaded: enterprises[exchange.enterprise_id].supplied_products.length, total_number_of_products: enterprises[exchange.enterprise_id].num_of_products } }} + %a{ 'ng-click' => 'loadAllExchangeProducts()' } + {{ 'js.admin.panels.exchange_products.load_all_products' | t }} + .exchange-select-all-variants %label %input{ type: 'checkbox', name: 'order_cycle_outgoing_exchange_{{ $parent.$index }}_select_all_variants', @@ -7,7 +13,7 @@ 'ng-model' => 'exchange.select_all_variants', 'ng-change' => 'setExchangeVariants(exchange, incomingExchangeVariantsFor(exchange.enterprise_id), exchange.select_all_variants)', 'id' => 'order_cycle_outgoing_exchange_{{ $parent.$index }}_select_all_variants' } - {{ 'admin.select_all' | t }} + {{ 'js.admin.panels.exchange_products.select_all_products' | t:{ total_number_of_products: enterprises[exchange.enterprise_id].num_of_products } }} .exchange-products -# Scope product list based on permissions the current user has to view variants in this exchange diff --git a/app/assets/javascripts/templates/admin/panels/exchange_supplied_products.html.haml b/app/assets/javascripts/templates/admin/panels/exchange_supplied_products.html.haml index c2dc200772..cac2c373ce 100644 --- a/app/assets/javascripts/templates/admin/panels/exchange_supplied_products.html.haml +++ b/app/assets/javascripts/templates/admin/panels/exchange_supplied_products.html.haml @@ -1,5 +1,11 @@ .row.exchange-supplied-products{'ng-init' => 'initializeExchangeProductsPanel(exchange)'} .sixteen.columns.alpha.omega + .exchange-load-all-variants + %div + {{ 'js.admin.panels.exchange_products.products_loaded' | t:{ num_of_products_loaded: enterprises[exchange.enterprise_id].supplied_products.length, total_number_of_products: enterprises[exchange.enterprise_id].num_of_products } }} + %a{ 'ng-click' => 'loadAllExchangeProducts()' } + {{ 'js.admin.panels.exchange_products.load_all_products' | t }} + .exchange-select-all-variants %label %input{ type: 'checkbox', name: 'order_cycle_incoming_exchange_{{ $index }}_select_all_variants', @@ -7,7 +13,7 @@ 'ng-model' => 'exchange.select_all_variants', 'ng-change' => 'setExchangeVariants(exchange, suppliedVariants(exchange.enterprise_id), exchange.select_all_variants)', 'id' => 'order_cycle_incoming_exchange_{{ $index }}_select_all_variants' } - {{ 'admin.select_all' | t }} + {{ 'js.admin.panels.exchange_products.select_all_products' | t:{ total_number_of_products: enterprises[exchange.enterprise_id].num_of_products } }} .exchange-products -# No need to scope product list based on permissions, because if an incoming exchange is visible, diff --git a/app/assets/stylesheets/admin/openfoodnetwork.css.scss b/app/assets/stylesheets/admin/openfoodnetwork.css.scss index 8cdc6c3e87..f26fbc992f 100644 --- a/app/assets/stylesheets/admin/openfoodnetwork.css.scss +++ b/app/assets/stylesheets/admin/openfoodnetwork.css.scss @@ -104,9 +104,13 @@ form.order_cycle { width: 20px; } + .exchange-load-all-variants { + margin: 0px 5px 20px 5px; + } + .exchange-select-all-variants { clear: both; - margin: 5px; + margin: 15px 5px 25px 5px; } .exchange-products { diff --git a/config/locales/en.yml b/config/locales/en.yml index b07869f3a1..8bb7d33cd1 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -2563,6 +2563,8 @@ See the %{link} to find out more about %{sitename}'s features and to start using exchange_products: load_more_products: "Load More Products" load_all_products: "Load All Products" + select_all_products: "Select All %{total_number_of_products} Products" + products_loaded: "%{num_of_products_loaded} of %{total_number_of_products} Products Loaded" tag_rules: shipping_method_tagged_top: "Shipping methods tagged" shipping_method_tagged_bottom: "are:"