add project and repo statistics data to dashboad

This commit is contained in:
xiahaoshawn 2016-05-26 12:29:49 +08:00
parent a48e3298f7
commit 55d1b075f3
4 changed files with 53 additions and 36 deletions

View File

@ -1,5 +1,13 @@
package ng package ng
import (
"net/http"
"github.com/vmware/harbor/dao"
"github.com/vmware/harbor/models"
"github.com/vmware/harbor/utils/log"
)
// DashboardController handles requests to /ng/dashboard // DashboardController handles requests to /ng/dashboard
type DashboardController struct { type DashboardController struct {
BaseController BaseController
@ -7,5 +15,24 @@ type DashboardController struct {
// Get renders the dashboard page // Get renders the dashboard page
func (dc *DashboardController) Get() { func (dc *DashboardController) Get() {
sessionUserID := dc.GetSession("userId")
var isAdmin int
if sessionUserID != nil {
userID := sessionUserID.(int)
u, err := dao.GetUser(models.User{UserID: userID})
if err != nil {
log.Errorf("Error occurred in GetUser, error: %v", err)
dc.CustomAbort(http.StatusInternalServerError, "Internal error.")
}
if u == nil {
log.Warningf("User was deleted already, user id: %d, canceling request.", userID)
dc.CustomAbort(http.StatusUnauthorized, "")
}
isAdmin = u.HasAdminRole
}
dc.Data["IsAdmin"] = isAdmin
dc.Forward("Dashboard", "dashboard.htm") dc.Forward("Dashboard", "dashboard.htm")
} }

View File

@ -20,12 +20,12 @@
ListIntegratedLogService() ListIntegratedLogService()
.then(listIntegratedLogSuccess, listIntegratedLogFailed); .then(listIntegratedLogSuccess, listIntegratedLogFailed);
function statProjectSuccess(data) { function statProjectSuccess(response) {
vm.statProjects = data; vm.statProjects = response.data;
} }
function statProjectFailed(data) { function statProjectFailed(response) {
console.log('Failed stat project:' + data); console.log('Failed stat project:' + response.data);
} }
function listTop10RepositorySuccess(data) { function listTop10RepositorySuccess(data) {

View File

@ -6,33 +6,16 @@
.module('harbor.services.project') .module('harbor.services.project')
.factory('StatProjectService', StatProjectService); .factory('StatProjectService', StatProjectService);
StatProjectService.$inject = ['$http', '$q', '$timeout']; StatProjectService.$inject = ['$http', '$log'];
function StatProjectService($http, $q, $timeout) { function StatProjectService($http, $log) {
var mockData = { return StatProject;
'projects': 30,
'public_projects': 50,
'total_projects': 120,
'repositories': 50,
'public_repositories': 40,
'total_repositories': 110
};
function async() { function StatProject() {
var deferred = $q.defer(); $log.info('statistics projects and repositories');
return $http
$timeout(function() { .get('/api/statistics');
deferred.resolve(mockData);
}, 500);
return deferred.promise;
}
return statProject;
function statProject() {
return async();
} }
} }

View File

@ -6,12 +6,19 @@
<div class="up-section"> <div class="up-section">
<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"> <dl class="page-content dl-horizontal">
<dt>// 'projects' | tr //:</dt><dd>//vm.statProjects['projects']//</dd> {{ if eq .IsAdmin 1 }}
<dt>// 'public_projects' | tr //:</dt><dd>//vm.statProjects['public_projects']//</dd> <dt>// 'projects' | tr //:</dt><dd>//vm.statProjects['my_project_count']//</dd>
<dt>// 'total_projects' | tr //:</dt><dd>//vm.statProjects['total_projects']//</dd> <dt>// 'public_projects' | tr //:</dt><dd>//vm.statProjects['public_project_count']//</dd>
<dt>// 'repositories' | tr //:</dt><dd>//vm.statProjects['repositories']//</dd> <dt>// 'total_projects' | tr //:</dt><dd>//vm.statProjects['total_project_count']//</dd>
<dt>// 'public_repositories' | tr //:</dt><dd>//vm.statProjects['public_repositories']//</dd> <dt>// 'repositories' | tr //:</dt><dd>//vm.statProjects['my_repo_count']//</dd>
<dt>// 'total_repositories' | tr //:</dt><dd>//vm.statProjects['total_repositories']//</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>
{{ else }}
<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>
{{ end }}
</dl> </dl>
</div> </div>
</div> </div>