From cfe3f72d0e9c1034167210e8d04b330638494de0 Mon Sep 17 00:00:00 2001 From: luisramos0 Date: Tue, 19 Nov 2019 16:28:00 +0000 Subject: [PATCH] Add load more button to list of exchange products --- .../order_cycle_exchanges_controller.js.coffee | 16 +++++++++++----- .../exchange_distributed_products.html.haml | 3 +++ .../panels/exchange_supplied_products.html.haml | 3 +++ .../admin/order_cycles/_exchange_form.html.haml | 4 ++-- config/locales/en.yml | 2 ++ 5 files changed, 21 insertions(+), 7 deletions(-) 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 066bcaf25c..bd233106ee 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 @@ -36,14 +36,20 @@ angular.module('admin.orderCycles') $scope.removeDistributionOfVariant = (variant_id) -> OrderCycle.removeDistributionOfVariant(variant_id) - $scope.loadExchangeProducts = (exchange) -> - return if $scope.enterprises[exchange.enterprise_id].supplied_products_fetched? - $scope.enterprises[exchange.enterprise_id].supplied_products_fetched = true + $scope.loadExchangeProducts = (exchange, page = 1) -> + enterprise = $scope.enterprises[exchange.enterprise_id] + + 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} + 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) -> - $scope.enterprises[exchange.enterprise_id].supplied_products = products + enterprise.supplied_products = [] unless enterprise.supplied_products? + enterprise.supplied_products.push products... + + $scope.loadMoreExchangeProducts = -> + $scope.loadExchangeProducts(this.exchange, this.enterprises[this.exchange.enterprise_id].last_page_loaded + 1) # initialize exchange products panel if not yet done $scope.exchangeProdutsPanelInitialized = [] 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 4dad8310ce..5cfb64526c 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 @@ -26,3 +26,6 @@ 'id' => 'order_cycle_outgoing_exchange_{{ $parent.$parent.$index }}_variants_{{ variant.id }}', 'ng-disabled' => '!order_cycle.editable_variants_for_outgoing_exchanges.hasOwnProperty(exchange.enterprise_id) || order_cycle.editable_variants_for_outgoing_exchanges[exchange.enterprise_id].indexOf(variant.id) < 0' } {{ variant.label }} + .pagination + .button{ 'ng-click' => 'loadMoreExchangeProducts()' } + {{ 'js.admin.panels.exchange_products.load_more_products' | t }} 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 e6c80e973a..a1930bc9ad 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 @@ -27,3 +27,6 @@ 'id' => 'order_cycle_incoming_exchange_{{ $parent.$parent.$index }}_variants_{{ variant.id }}', 'ng-disabled' => '!order_cycle.editable_variants_for_incoming_exchanges.hasOwnProperty(exchange.enterprise_id) || order_cycle.editable_variants_for_incoming_exchanges[exchange.enterprise_id].indexOf(variant.id) < 0' } {{ variant.label }} + .pagination + .button{ 'ng-click' => 'loadMoreExchangeProducts()' } + {{ 'js.admin.panels.exchange_products.load_more_products' | t }} diff --git a/app/views/admin/order_cycles/_exchange_form.html.haml b/app/views/admin/order_cycles/_exchange_form.html.haml index 63a44e9a3b..19c0172165 100644 --- a/app/views/admin/order_cycles/_exchange_form.html.haml +++ b/app/views/admin/order_cycles/_exchange_form.html.haml @@ -35,10 +35,10 @@ - if type == 'supplier' %tr.panel-row{ object: "exchange", panels: "{products: 'exchange_supplied_products'}", - locals: "$index,order_cycle,exchange,enterprises,setExchangeVariants,suppliedVariants,removeDistributionOfVariant,initializeExchangeProductsPanel", + locals: "$index,order_cycle,exchange,enterprises,setExchangeVariants,suppliedVariants,removeDistributionOfVariant,initializeExchangeProductsPanel,loadMoreExchangeProducts", colspan: 4 } - if type == 'distributor' %tr.panel-row{ object: "exchange", panels: "{products: 'exchange_distributed_products', tags: 'exchange_tags'}", - locals: "$index,order_cycle,exchange,enterprises,setExchangeVariants,incomingExchangeVariantsFor,variantSuppliedToOrderCycle,initializeExchangeProductsPanel", + locals: "$index,order_cycle,exchange,enterprises,setExchangeVariants,incomingExchangeVariantsFor,variantSuppliedToOrderCycle,initializeExchangeProductsPanel,loadMoreExchangeProducts", colspan: 5 } diff --git a/config/locales/en.yml b/config/locales/en.yml index f1945520a0..7ca682af94 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -2560,6 +2560,8 @@ See the %{link} to find out more about %{sitename}'s features and to start using severity: Severity description: Description resolve: Resolve + exchange_products: + load_more_products: "Load More Products" tag_rules: shipping_method_tagged_top: "Shipping methods tagged" shipping_method_tagged_bottom: "are:"