Improve EnterpriseFee loading

Request is only send if there isn't another currently running, and also
ensure that filtered enterprise fees are loaded only when not other
request is running.
This commit is contained in:
Gaetan Craig-Riou
2026-03-20 14:38:49 +11:00
parent c7de67a14f
commit 8defb2f4c8
2 changed files with 16 additions and 1 deletions

View File

@@ -3,7 +3,18 @@ angular.module('admin.orderCycles').controller 'AdminOrderCycleIncomingCtrl', ($
$scope.view = 'incoming'
# NB: weirdly at this next line $scope.order_cycle.id comes out undefined so we use $scope.order_cycle_id instead
$scope.enterprise_fees = EnterpriseFee.index(order_cycle_id: $scope.order_cycle_id, per_item: true)
$scope.enterprise_fees = null
$scope.enterprise_fees = EnterpriseFee.index(order_cycle_id: $scope.order_cycle_id, per_item: true) unless EnterpriseFee.loading
# We want to make sure to load the filtered EnterpriseFee when any previous request is finished
# otherwise the enterprise_fees migh get overriden by non filtered ones.
$scope.$watch () ->
EnterpriseFee.loading
, (isLoading) =>
return if $scope.enterprise_fees
$scope.enterprise_fees = EnterpriseFee.index(order_cycle_id: $scope.order_cycle_id, per_item: true) isLoading == false
$scope.exchangeTotalVariants = (exchange) ->
return unless $scope.enterprises? && $scope.enterprises[exchange.enterprise_id]?

View File

@@ -14,10 +14,14 @@ angular.module('admin.orderCycles').factory('EnterpriseFee', ($resource) ->
EnterpriseFee: EnterpriseFee
enterprise_fees: {}
loaded: false
loading: false
index: (params={}) ->
return if @loading == true
@loading = true
EnterpriseFee.index params, (data) =>
@enterprise_fees = data
@loading = false
@loaded = true
forEnterprise: (enterprise_id) ->