Skip to content

Commit

Permalink
perf(page): remove resolve from state
Browse files Browse the repository at this point in the history
remove resolve from state and query /boxes on activate function in map controller
  • Loading branch information
mpfeil committed Feb 11, 2018
1 parent a236068 commit 49bf93f
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 31 deletions.
18 changes: 1 addition & 17 deletions app/scripts/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,23 +44,7 @@ angular
url: '',
controller: 'MapController',
controllerAs: 'map',
templateUrl: 'views/explore2.map.html',
resolve: { /* @ngInject */
boxes: function (ngProgressFactory, OpenSenseMapAPI) {
var progressbar = ngProgressFactory.createInstance();
progressbar.setColor('#4EAF47');
progressbar.start();
return OpenSenseMapAPI.getBoxes({params: {classify: true}})
.then(function (data) {
progressbar.complete();
return data;
})
.catch(function (error) {
progressbar.complete();
return new Error('Could not resolve getBoxes() on explore.map.');
});
}
}
templateUrl: 'views/explore2.map.html'
})
.state('explore.map.sidebar', {
url: 'explore',
Expand Down
47 changes: 33 additions & 14 deletions app/scripts/controllers/map.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
.module('openSenseMapApp')
.controller('MapController', MapController);

MapController.$inject = ['$scope', '$state', '$timeout', '$document', '$templateRequest', '$compile', 'boxes', 'OpenSenseMapData', 'osemMapData', 'isMobile'];
MapController.$inject = ['$scope', '$state', '$timeout', '$document', '$templateRequest', '$compile', 'ngProgressFactory', 'OpenSenseMapData', 'osemMapData', 'isMobile', 'OpenSenseMapAPI'];

function MapController ($scope, $state, $timeout, $document, $templateRequest, $compile, boxes, OpenSenseMapData, osemMapData, isMobile) {
function MapController ($scope, $state, $timeout, $document, $templateRequest, $compile, ngProgressFactory, OpenSenseMapData, osemMapData, isMobile, OpenSenseMapAPI) {
var vm = this;
vm.showAllMarkers = true;
vm.showClustering = true;
Expand Down Expand Up @@ -37,18 +37,37 @@
////

function activate () {
if (boxes instanceof Error) {
$state.go('explore.map.sidebar.error');
return;
}

OpenSenseMapData.setMarkers(boxes)
.then(function (response) {
vm.mapMarkers = response;
})
.catch(function (error) {
console.error(error);
});
var progressbar = ngProgressFactory.createInstance();
progressbar.setColor('#4EAF47');
progressbar.start();
return OpenSenseMapAPI.getBoxes({params: {classify: true}})
.then(function (data) {
return OpenSenseMapData.setMarkers(data)
.then(function (response) {
vm.mapMarkers = response;
progressbar.complete();
})
.catch(function (error) {
progressbar.complete();
console.error(error);
});
})
.catch(function (error) {
progressbar.complete();
return new Error('Could not resolve getBoxes() on explore.map.');
});
// if (boxes instanceof Error) {
// $state.go('explore.map.sidebar.error');
// return;
// }

// return OpenSenseMapData.setMarkers(boxes)
// .then(function (response) {
// vm.mapMarkers = response;
// })
// .catch(function (error) {
// console.error(error);
// });
}

function createLegendFromTemplate (templateURI, clickHandler) {
Expand Down

0 comments on commit 49bf93f

Please sign in to comment.