Merge pull request #868 from wknet123/master

Update for loading projects with pagination of UI.
This commit is contained in:
Daniel Jiang 2016-10-13 17:57:19 +08:00 committed by GitHub
commit 421cfc48b7
3 changed files with 73 additions and 39 deletions

View File

@ -33,24 +33,25 @@
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 = Number(getParameterByName('page', $location.absUrl()) || DEFAULT_PAGE);
vm.pageSize = Number(getParameterByName('page_size', $location.absUrl()) || DEFAULT_PAGE_SIZE); vm.projects = [];
vm.retrieve = retrieve; vm.retrieve = retrieve;
vm.filterInput = ''; vm.filterInput = '';
vm.selectItem = selectItem; vm.selectItem = selectItem;
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)
.success(getProjectSuccess) .then(getProjectSuccess, getProjectFailed);
.error(getProjectFailed);
} }
$scope.$watch('vm.page', function(current) {
vm.retrieve(); if(current) {
vm.retrieve();
}
});
$scope.$watch('vm.isPublic', function(current) { $scope.$watch('vm.isPublic', function(current) {
vm.projectType = vm.isPublic === 0 ? 'my_project_count' : 'public_project_count'; vm.projectType = vm.isPublic === 0 ? 'my_project_count' : 'public_project_count';
@ -62,33 +63,68 @@
} }
}); });
function getProjectSuccess(data, status) { function parseNextLink(link) {
vm.projects = data || []; if(link === '') {
if(vm.projects.length == 0 && vm.isPublic === 0){ return false;
$window.location.href = '/project';
} }
if(getParameterByName('project_id', $location.absUrl())){ var parts = link.split(",");
for(var i in vm.projects) { for(var i in parts) {
var project = vm.projects[i]; var groups = /^\<(.*)\>;\srel=\"(\w+)\"$/.exec($.trim(parts[i]));
if(project['project_id'] == getParameterByName('project_id', $location.absUrl())) { if(groups && groups.length > 2){
vm.selectedProject = project; var url = groups[1];
break; var rel = groups[2];
if(rel === 'next') {
return {
'page': getParameterByName('page', url),
'rel' : rel
};
} }
} }
} }
return false;
$location.search('project_id', vm.selectedProject.project_id);
vm.checkProjectMember(vm.selectedProject.project_id);
vm.resultCount = vm.projects.length;
$scope.$watch('vm.filterInput', function(current, origin) {
vm.resultCount = $filter('name')(vm.projects, vm.filterInput, 'name').length;
});
} }
function getProjectFailed(data) {
function getProjectSuccess(response) {
var partialProjects = response.data || [];
for(var i in partialProjects) {
vm.projects.push(partialProjects[i]);
}
var nextLink = parseNextLink(response.headers("Link") || '');
if(nextLink) {
vm.page = parseInt(nextLink.page);
} else {
if(vm.projects.length == 0 && vm.isPublic === 0){
$window.location.href = '/project';
}
if(getParameterByName('project_id', $location.absUrl())){
for(var i in vm.projects) {
var project = vm.projects[i];
if(project['project_id'] == getParameterByName('project_id', $location.absUrl())) {
vm.selectedProject = project;
break;
}
}
}
$location.search('project_id', vm.selectedProject.project_id);
vm.checkProjectMember(vm.selectedProject.project_id);
vm.resultCount = vm.projects.length;
$scope.$watch('vm.filterInput', function(current, origin) {
vm.resultCount = $filter('name')(vm.projects, vm.filterInput, 'name').length;
});
}
}
function getProjectFailed(response) {
$scope.$emit('modalTitle', $filter('tr')('error')); $scope.$emit('modalTitle', $filter('tr')('error'));
$scope.$emit('modalMessage', $filter('tr')('failed_to_get_project')); $scope.$emit('modalMessage', $filter('tr')('failed_to_get_project'));
$scope.$emit('raiseError', true); $scope.$emit('raiseError', true);

View File

@ -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
} }
}); });

View File

@ -59,7 +59,7 @@
<td colspan="5" height="320px" class="empty-hint" ng-if="vm.projects.length === 0"><h4 class="text-muted">// 'no_projects_add_new_project' | tr //</h4></td> <td colspan="5" height="320px" class="empty-hint" ng-if="vm.projects.length === 0"><h4 class="text-muted">// 'no_projects_add_new_project' | tr //</h4></td>
</tr> </tr>
<tr ng-if="vm.projects.length > 0" ng-repeat="p in vm.projects"> <tr ng-if="vm.projects.length > 0" ng-repeat="p in vm.projects">
<td width="20%"><a href="/repository#/repositories?page=//vm.page//&page_size=//vm.pageSize//&project_id=//p.project_id//&is_public=//p.public//">//p.name//</a></td> <td width="20%"><a href="/repository#/repositories?project_id=//p.project_id//&is_public=//vm.isPublic//">//p.name//</a></td>
<td width="15%">//p.repo_count//</td> <td width="15%">//p.repo_count//</td>
<td width="15%" ng-if="vm.isPublic === 0">//vm.getProjectRole(p.current_user_role_id) | tr//</td> <td width="15%" ng-if="vm.isPublic === 0">//vm.getProjectRole(p.current_user_role_id) | tr//</td>
<td width="20%">//p.creation_time | dateL : 'YYYY-MM-DD HH:mm:ss'//</td> <td width="20%">//p.creation_time | dateL : 'YYYY-MM-DD HH:mm:ss'//</td>