change as Kun's comments

This commit is contained in:
xiahaoshawn 2016-06-06 15:39:17 +08:00
parent 7def2ad824
commit 21f0633d6d
8 changed files with 56 additions and 30 deletions

View File

@ -0,0 +1,37 @@
(function() {
'use strict';
angular
.module('harbor.summary')
.constant('projectStatistics', projectStatistics)
.factory('getStatisticsName', getStatisticsName);
function projectStatistics() {
return [
{'name': 'projects', 'payloadName': 'my_project_count'},
{'name': 'repositories', 'payloadName': 'my_repo_count'},
{'name': 'public_projects', 'payloadName': 'public_project_count'},
{'name': 'public_repositories', 'payloadName': 'public_repo_count'},
{'name': 'total_projects', 'payloadName': 'total_project_count'},
{'name': 'total_repositories', 'payloadName': 'total_repo_count'},
];
}
getStatisticsName.$inject = ['projectStatistics'];
function getStatisticsName(projectStatistics) {
var r = projectStatistics();
return get;
function get(query) {
for(var i = 0; i < r.length; i++) {
var StatisticsName = r[i];
if(query.key === 'payloadName' && StatisticsName.payloadName === query.value
|| query.key === 'name' && StatisticsName.name === query.value) {
return StatisticsName;
}
}
}
}
})();

View File

@ -1,15 +1,4 @@
<h4 class="page-header title-color underlined">// 'summary' | tr //</h4> <h4 class="page-header title-color underlined">// 'summary' | tr //</h4>
<dl class="page-content dl-horizontal" ng-if="vm.isAdmin"> <dl class="page-content dl-horizontal" ng-repeat="(key, value) in vm.statProjects">
<dt>// 'projects' | tr //:</dt><dd>//vm.statProjects['my_project_count']//</dd> <dt>// vm.getSummaryName(key) | tr //:</dt><dd>//value//</dd>
<dt>// 'public_projects' | tr //:</dt><dd>//vm.statProjects['public_project_count']//</dd>
<dt>// 'total_projects' | tr //:</dt><dd>//vm.statProjects['total_project_count']//</dd>
<dt>// 'repositories' | tr //:</dt><dd>//vm.statProjects['my_repo_count']//</dd>
<dt>// 'public_repositories' | tr //:</dt><dd>//vm.statProjects['public_repo_count']//</dd>
<dt>// 'total_repositories' | tr //:</dt><dd>//vm.statProjects['total_repo_count']//</dd>
</dl>
<dl class="page-content dl-horizontal" ng-if="!vm.isAdmin">
<dt>// 'projects' | tr //:</dt><dd>//vm.statProjects['my_project_count']//</dd>
<dt>// 'public_projects' | tr //:</dt><dd>//vm.statProjects['public_project_count']//</dd>
<dt>// 'repositories' | tr //:</dt><dd>//vm.statProjects['my_repo_count']//</dd>
<dt>// 'public_repositories' | tr //:</dt><dd>//vm.statProjects['public_repo_count']//</dd>
</dl> </dl>

View File

@ -6,10 +6,11 @@
.module('harbor.summary') .module('harbor.summary')
.directive('projectSummary', projectSummary); .directive('projectSummary', projectSummary);
ProjectSummaryController.$inject = ['StatProjectService']; ProjectSummaryController.$inject = ['StatProjectService', 'getStatisticsName'];
function ProjectSummaryController(StatProjectService) { function ProjectSummaryController(StatProjectService, getStatisticsName) {
var vm = this; var vm = this;
vm.getSummaryName = getSummaryName;
StatProjectService() StatProjectService()
.success(statProjectSuccess) .success(statProjectSuccess)
@ -17,16 +18,16 @@
function statProjectSuccess(data, status) { function statProjectSuccess(data, status) {
vm.statProjects = data; vm.statProjects = data;
if(vm.statProjects.hasOwnProperty("total_project_count")) {
vm.isAdmin = true;
}else {
vm.isAdmin = false;
}
} }
function statProjectFailed(status) { function statProjectFailed(status) {
console.log('Failed stat project:' + status); console.log('Failed stat project:' + status);
} }
function getSummaryName(payloadName) {
var statisticsName = getStatisticsName({'key': 'payloadName', 'value': payloadName});
return statisticsName.name;
}
} }
function projectSummary() { function projectSummary() {

View File

@ -22,6 +22,7 @@
vm.togglePublicity = togglePublicity; vm.togglePublicity = togglePublicity;
vm.user = currentUser.get(); vm.user = currentUser.get();
vm.retrieve(); vm.retrieve();
vm.getProjectRole = getProjectRole;
function retrieve() { function retrieve() {
@ -31,13 +32,12 @@
} }
function listProjectSuccess(data, status) { function listProjectSuccess(data, status) {
data.forEach(function(data){
var currentRole = getRole({'key': 'roleId', 'value': data.role_id});
data.role_name = currentRole.name;
});
vm.projects = data || []; vm.projects = data || [];
}
function getProjectRole(roleId) {
var role = getRole({'key': 'roleId', 'value': roleId});
return role.name;
} }
function listProjectFailed(e) { function listProjectFailed(e) {

View File

@ -45,7 +45,6 @@ var locale_messages = {
'comments': 'Comments', 'comments': 'Comments',
'comment_is_too_long': 'Comment is too long. (maximum 20 characters)', 'comment_is_too_long': 'Comment is too long. (maximum 20 characters)',
'forgot_password_description': 'Please input the Email used when you signed up, a reset password Email will be sent to you.', 'forgot_password_description': 'Please input the Email used when you signed up, a reset password Email will be sent to you.',
'email_does_not_exist': 'Email does not exist',
'reset_password': 'Reset Password', 'reset_password': 'Reset Password',
'summary': 'Summary', 'summary': 'Summary',
'projects': 'Projects', 'projects': 'Projects',

View File

@ -45,7 +45,6 @@ var locale_messages = {
'comments': '备注', 'comments': '备注',
'comment_is_too_long' : '备注长度超出限制。最长为20个字符', 'comment_is_too_long' : '备注长度超出限制。最长为20个字符',
'forgot_password_description': '重置邮件将发送到此邮箱。', 'forgot_password_description': '重置邮件将发送到此邮箱。',
'email_does_not_exist': '邮箱不存在。',
'reset_password': '重置密码', 'reset_password': '重置密码',
'summary': '摘要', 'summary': '摘要',
'projects': '项目', 'projects': '项目',

View File

@ -36,7 +36,7 @@
<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><a href="/ng/repository#/repositories?project_id=//p.ProjectId//&is_public=//p.Public//">//p.Name//</a></td> <td><a href="/ng/repository#/repositories?project_id=//p.ProjectId//&is_public=//p.Public//">//p.Name//</a></td>
<td>//p.repo_count//</td> <td>//p.repo_count//</td>
<td>//p.role_name//</td> <td>//vm.getProjectRole(p.role_id)//</td>
<td>//p.CreationTime | dateL : 'YYYY-MM-DD HH:mm:ss'//</td> <td>//p.CreationTime | dateL : 'YYYY-MM-DD HH:mm:ss'//</td>
<td><publicity-button is-public="p.Public" owned="p.OwnerId == vm.user.UserId" project-id="p.ProjectId"></publicity-button></td> <td><publicity-button is-public="p.Public" owned="p.OwnerId == vm.user.UserId" project-id="p.ProjectId"></publicity-button></td>
</tr> </tr>

View File

@ -200,3 +200,4 @@
<script src="/static/ng/resources/js/components/summary/summary.module.js"></script> <script src="/static/ng/resources/js/components/summary/summary.module.js"></script>
<script src="/static/ng/resources/js/components/summary/summary.directive.js"></script> <script src="/static/ng/resources/js/components/summary/summary.directive.js"></script>
<script src="/static/ng/resources/js/components/summary/summary.config.js"></script>