mirror of
https://github.com/goharbor/harbor.git
synced 2024-12-30 12:38:17 +01:00
Updates for matching page number in link, remove default page size for retrieving project on UI.
This commit is contained in:
parent
1c52a9e0a6
commit
cc2893ea9d
@ -33,10 +33,8 @@
|
|||||||
vm.isPublic = Number(getParameterByName('is_public', $location.absUrl()));
|
vm.isPublic = Number(getParameterByName('is_public', $location.absUrl()));
|
||||||
|
|
||||||
var DEFAULT_PAGE = 1;
|
var DEFAULT_PAGE = 1;
|
||||||
var DEFAULT_PAGE_SIZE = 15;
|
|
||||||
|
|
||||||
vm.page = DEFAULT_PAGE;
|
vm.page = DEFAULT_PAGE;
|
||||||
vm.pageSize = DEFAULT_PAGE_SIZE;
|
|
||||||
|
|
||||||
vm.projects = [];
|
vm.projects = [];
|
||||||
vm.retrieve = retrieve;
|
vm.retrieve = retrieve;
|
||||||
@ -45,9 +43,8 @@
|
|||||||
vm.checkProjectMember = checkProjectMember;
|
vm.checkProjectMember = checkProjectMember;
|
||||||
|
|
||||||
function retrieve() {
|
function retrieve() {
|
||||||
ListProjectService(vm.projectName, vm.isPublic, vm.page, vm.pageSize)
|
ListProjectService(vm.projectName, vm.isPublic, vm.page)
|
||||||
.then(getProjectSuccess, getProjectFailed);
|
.then(getProjectSuccess, getProjectFailed);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$scope.$watch('vm.page', function(current) {
|
$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) {
|
function getProjectSuccess(response) {
|
||||||
|
|
||||||
var partialProjects = response.data || [];
|
var partialProjects = response.data || [];
|
||||||
@ -73,14 +93,10 @@
|
|||||||
vm.projects.push(partialProjects[i]);
|
vm.projects.push(partialProjects[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
var link = response.headers("Link") || '';
|
var nextLink = parseNextLink(response.headers("Link") || '');
|
||||||
var pattern = /^<\/api\/projects\?is_public=(\d+)&page\=(\d+)&page_size=(\d+)\&project_name=>; rel=\"(\w+)\"$/;
|
|
||||||
var groups = pattern.exec(link);
|
|
||||||
|
|
||||||
if(groups && groups[4] === 'next') {
|
if(nextLink) {
|
||||||
vm.isPublic = parseInt(groups[1]);
|
vm.page = parseInt(nextLink.page);
|
||||||
vm.page = parseInt(groups[2]);
|
|
||||||
vm.pageSize = parseInt(groups[3]);
|
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
if(vm.projects.length == 0 && vm.isPublic === 0){
|
if(vm.projects.length == 0 && vm.isPublic === 0){
|
||||||
|
@ -27,15 +27,13 @@
|
|||||||
|
|
||||||
function ListProject(projectName, isPublic, page, pageSize) {
|
function ListProject(projectName, isPublic, page, pageSize) {
|
||||||
$log.info('list project projectName:' + projectName, ', isPublic:' + isPublic);
|
$log.info('list project projectName:' + projectName, ', isPublic:' + isPublic);
|
||||||
var urlParams = '';
|
|
||||||
if(angular.isDefined(page, pageSize)) {
|
|
||||||
urlParams = '?page=' + page + '&page_size=' + pageSize;
|
|
||||||
}
|
|
||||||
return $http
|
return $http
|
||||||
.get('/api/projects' + urlParams, {
|
.get('/api/projects', {
|
||||||
'params' : {
|
'params' : {
|
||||||
'is_public': isPublic,
|
'is_public': isPublic,
|
||||||
'project_name': projectName
|
'project_name': projectName,
|
||||||
|
'page': page,
|
||||||
|
'page_size': pageSize
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user