mirror of
https://github.com/goharbor/harbor
synced 2024-09-21 07:46:39 +00:00
add project and repo statistics data to dashboad
This commit is contained in:
parent
a48e3298f7
commit
55d1b075f3
|
@ -1,5 +1,13 @@
|
|||
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
|
||||
type DashboardController struct {
|
||||
BaseController
|
||||
|
@ -7,5 +15,24 @@ type DashboardController struct {
|
|||
|
||||
// Get renders the dashboard page
|
||||
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")
|
||||
}
|
||||
|
|
|
@ -20,12 +20,12 @@
|
|||
ListIntegratedLogService()
|
||||
.then(listIntegratedLogSuccess, listIntegratedLogFailed);
|
||||
|
||||
function statProjectSuccess(data) {
|
||||
vm.statProjects = data;
|
||||
function statProjectSuccess(response) {
|
||||
vm.statProjects = response.data;
|
||||
}
|
||||
|
||||
function statProjectFailed(data) {
|
||||
console.log('Failed stat project:' + data);
|
||||
function statProjectFailed(response) {
|
||||
console.log('Failed stat project:' + response.data);
|
||||
}
|
||||
|
||||
function listTop10RepositorySuccess(data) {
|
||||
|
|
|
@ -6,33 +6,16 @@
|
|||
.module('harbor.services.project')
|
||||
.factory('StatProjectService', StatProjectService);
|
||||
|
||||
StatProjectService.$inject = ['$http', '$q', '$timeout'];
|
||||
StatProjectService.$inject = ['$http', '$log'];
|
||||
|
||||
function StatProjectService($http, $q, $timeout) {
|
||||
function StatProjectService($http, $log) {
|
||||
|
||||
var mockData = {
|
||||
'projects': 30,
|
||||
'public_projects': 50,
|
||||
'total_projects': 120,
|
||||
'repositories': 50,
|
||||
'public_repositories': 40,
|
||||
'total_repositories': 110
|
||||
};
|
||||
return StatProject;
|
||||
|
||||
function async() {
|
||||
var deferred = $q.defer();
|
||||
|
||||
$timeout(function() {
|
||||
deferred.resolve(mockData);
|
||||
}, 500);
|
||||
|
||||
return deferred.promise;
|
||||
}
|
||||
|
||||
return statProject;
|
||||
|
||||
function statProject() {
|
||||
return async();
|
||||
function StatProject() {
|
||||
$log.info('statistics projects and repositories');
|
||||
return $http
|
||||
.get('/api/statistics');
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -6,12 +6,19 @@
|
|||
<div class="up-section">
|
||||
<h4 class="page-header title-color underlined">// 'summary' | tr //</h4>
|
||||
<dl class="page-content dl-horizontal">
|
||||
<dt>// 'projects' | tr //:</dt><dd>//vm.statProjects['projects']//</dd>
|
||||
<dt>// 'public_projects' | tr //:</dt><dd>//vm.statProjects['public_projects']//</dd>
|
||||
<dt>// 'total_projects' | tr //:</dt><dd>//vm.statProjects['total_projects']//</dd>
|
||||
<dt>// 'repositories' | tr //:</dt><dd>//vm.statProjects['repositories']//</dd>
|
||||
<dt>// 'public_repositories' | tr //:</dt><dd>//vm.statProjects['public_repositories']//</dd>
|
||||
<dt>// 'total_repositories' | tr //:</dt><dd>//vm.statProjects['total_repositories']//</dd>
|
||||
{{ if eq .IsAdmin 1 }}
|
||||
<dt>// 'projects' | tr //:</dt><dd>//vm.statProjects['my_project_count']//</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>
|
||||
{{ 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>
|
||||
</div>
|
||||
</div>
|
||||
|
|
Loading…
Reference in New Issue
Block a user