github.com/justinjmoses/evergreen@v0.0.0-20170530173719-1d50e381ff0d/public/static/js/patches.js (about) 1 mciModule.controller('PatchesController', function($scope, $filter, $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 = { 26 params: { 27 page: $scope.currentPage 28 } 29 }; 30 $http.get(endpoint, params). 31 success(function(data) { 32 $scope.loading = false; 33 $scope.versionsMap = data['VersionsMap']; 34 $scope.uiPatches = data['UIPatches']; 35 36 _.each($scope.uiPatches, function(patch) { 37 patch.canEdit = ($window.user.Id === patch.Patch.Author ) || $window.isSuperUser 38 }); 39 40 _.each($scope.versionsMap, function(version) { 41 _.each(version.Builds, function(build) { 42 build.taskResults = []; 43 _.each(build.Tasks, function(task) { 44 build.taskResults.push({ 45 link: '/task/' + task.Task.id, 46 tooltip: task.Task.display_name, 47 'class': $filter('statusFilter')(task.Task), 48 }); 49 }); 50 }); 51 }); 52 }). 53 error(function(err) { 54 $scope.loading = false; 55 $scope.patchesError = err; 56 }); 57 }; 58 59 $rootScope.$on('$locationChangeStart', function() { 60 var page = $location.search()['page']; 61 if (page) { 62 page = parseInt(page, 10); 63 } else { 64 page = 0; 65 } 66 if (page !== $scope.currentPage) { 67 $scope.currentPage = page; 68 $scope.loadCurrentPage(); 69 } 70 }); 71 72 $scope.currentPage = $location.search()['page'] || 0; 73 $scope.loadCurrentPage(); 74 });