Improve producers performance

This commit is contained in:
Matt-Yorkley
2019-05-09 20:27:41 +01:00
parent 45d65baf8e
commit ed97400a23
6 changed files with 58 additions and 19 deletions

View File

@@ -1,6 +1,32 @@
Darkswarm.controller "ProducerNodeCtrl", ($scope, HashNavigation, $anchorScroll) ->
$scope.toggle = ->
HashNavigation.toggle $scope.producer.hash
Darkswarm.controller "ProducerNodeCtrl", ($scope, HashNavigation, $anchorScroll, $http) ->
$scope.shopfront_loading = false
$scope.enterprise_details = []
# Toggles shopfront tabs open/closed. Fetches enterprise details from the api, diplays them and adds them
# to $scope.enterprise_details, or simply displays the details again if previously fetched
$scope.toggle = (event) ->
if $scope.open()
$scope.toggle_tab(event)
return
if $scope.enterprise_details[$scope.producer.id]
$scope.producer = $scope.enterprise_details[$scope.producer.id]
$scope.toggle_tab(event)
return
$scope.shopfront_loading = true
$scope.toggle_tab(event)
$http.get("/api/enterprises/" + $scope.producer.id + "/shopfront")
.success (data) ->
$scope.shopfront_loading = false
$scope.producer = data
$scope.enterprise_details[$scope.producer.id] = $scope.producer
.error (data) ->
console.error(data)
$scope.toggle_tab = (event) ->
HashNavigation.toggle $scope.producer.hash if !angular.element(event.target).inheritedData('is-link')
$scope.open = ->
HashNavigation.active($scope.producer.hash)