Updates for matching page number in link, remove default page size for retrieving project on UI.

This commit is contained in:
kunw 2016-10-12 14:59:40 +08:00
parent 1c52a9e0a6
commit cc2893ea9d
2 changed files with 33 additions and 19 deletions

View File

@ -33,10 +33,8 @@
vm.isPublic = Number(getParameterByName('is_public', $location.absUrl()));
var DEFAULT_PAGE = 1;
var DEFAULT_PAGE_SIZE = 15;
vm.page = DEFAULT_PAGE;
vm.pageSize = DEFAULT_PAGE_SIZE;
vm.projects = [];
vm.retrieve = retrieve;
@ -45,9 +43,8 @@
vm.checkProjectMember = checkProjectMember;
function retrieve() {
ListProjectService(vm.projectName, vm.isPublic, vm.page, vm.pageSize)
ListProjectService(vm.projectName, vm.isPublic, vm.page)
.then(getProjectSuccess, getProjectFailed);
}
$scope.$watch('vm.page', function(current) {
@ -66,6 +63,29 @@
}
});
function parseNextLink(link) {
if(link === '') {
return false;
}
var parts = link.split(",");
for(var i in parts) {
var groups = /^\<(.*)\>;\srel=\"(\w+)\"$/.exec($.trim(parts[i]));
if(groups && groups.length > 2){
var url = groups[1];
var rel = groups[2];
if(rel === 'next') {
return {
'page': getParameterByName('page', url),
'rel' : rel
};
}
}
}
return false;
}
function getProjectSuccess(response) {
var partialProjects = response.data || [];
@ -73,14 +93,10 @@
vm.projects.push(partialProjects[i]);
}
var link = response.headers("Link") || '';
var pattern = /^<\/api\/projects\?is_public=(\d+)&page\=(\d+)&page_size=(\d+)\&project_name=>; rel=\"(\w+)\"$/;
var groups = pattern.exec(link);
var nextLink = parseNextLink(response.headers("Link") || '');
if(groups && groups[4] === 'next') {
vm.isPublic = parseInt(groups[1]);
vm.page = parseInt(groups[2]);
vm.pageSize = parseInt(groups[3]);
if(nextLink) {
vm.page = parseInt(nextLink.page);
} else {
if(vm.projects.length == 0 && vm.isPublic === 0){

View File

@ -27,15 +27,13 @@
function ListProject(projectName, isPublic, page, pageSize) {
$log.info('list project projectName:' + projectName, ', isPublic:' + isPublic);
var urlParams = '';
if(angular.isDefined(page, pageSize)) {
urlParams = '?page=' + page + '&page_size=' + pageSize;
}
return $http
.get('/api/projects' + urlParams, {
.get('/api/projects', {
'params' : {
'is_public': isPublic,
'project_name': projectName
'project_name': projectName,
'page': page,
'page_size': pageSize
}
});