github.com/justinjmoses/evergreen@v0.0.0-20170530173719-1d50e381ff0d/service/static/js/patches.js (about) 1 mciModule.controller('PatchesController', function($scope, $http, $window, 2 $location, $rootScope) { 3 $scope.userTz = $window.userTz; 4 5 $scope.loading = true; 6 7 $scope.patchesForUsername = $window.patchesForUsername; 8 var endpoint = $scope.patchesForUsername ? 9 '/json/patches/user/' + encodeURIComponent($window.patchesForUsername) : 10 '/json/patches/project/' + encodeURIComponent($scope.project); 11 12 $scope.previousPage = function() { 13 $location.search('page', Math.max(0, $scope.currentPage - 1)); 14 }; 15 16 $scope.nextPage = function() { 17 $location.search('page', $scope.currentPage + 1); 18 }; 19 20 $scope.loadCurrentPage = function() { 21 $scope.loading = true; 22 $scope.uiPatches = []; 23 $scope.patchesError = null; 24 25 var params = { params: { page: $scope.currentPage } }; 26 $http.get(endpoint, params). 27 success(function(data) { 28 $scope.loading = false; 29 $scope.versionsMap = data['VersionsMap']; 30 $scope.uiPatches = data['UIPatches']; 31 32 _.each($scope.versionsMap, function(version) { 33 _.each(version.Builds, function(build) { 34 build.taskResults = []; 35 _.each(build.Tasks, function(task) { 36 build.taskResults.push({ 37 link: '/task/' + task.Task.id, 38 tooltip: task.Task.display_name, 39 'class': task.Task.status 40 }); 41 }); 42 }); 43 }); 44 }). 45 error(function(err) { 46 $scope.loading = false; 47 $scope.patchesError = err; 48 }); 49 }; 50 51 $rootScope.$on('$locationChangeStart', function() { 52 var page = $location.search()['page']; 53 if (page) { 54 page = parseInt(page, 10); 55 } else { 56 page = 0; 57 } 58 if (page !== $scope.currentPage) { 59 $scope.currentPage = page; 60 $scope.loadCurrentPage(); 61 } 62 }); 63 64 $scope.currentPage = $location.search()['page'] || 0; 65 $scope.loadCurrentPage(); 66 });