mirror of
https://github.com/goharbor/harbor
synced 2024-09-21 07:27:55 +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
|
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")
|
||||||
}
|
}
|
||||||
|
|
|
@ -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) {
|
||||||
|
|
|
@ -6,35 +6,18 @@
|
||||||
.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) {
|
||||||
|
|
||||||
|
return StatProject;
|
||||||
|
|
||||||
var mockData = {
|
function StatProject() {
|
||||||
'projects': 30,
|
$log.info('statistics projects and repositories');
|
||||||
'public_projects': 50,
|
return $http
|
||||||
'total_projects': 120,
|
.get('/api/statistics');
|
||||||
'repositories': 50,
|
|
||||||
'public_repositories': 40,
|
|
||||||
'total_repositories': 110
|
|
||||||
};
|
|
||||||
|
|
||||||
function async() {
|
|
||||||
var deferred = $q.defer();
|
|
||||||
|
|
||||||
$timeout(function() {
|
|
||||||
deferred.resolve(mockData);
|
|
||||||
}, 500);
|
|
||||||
|
|
||||||
return deferred.promise;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return statProject;
|
|
||||||
|
|
||||||
function statProject() {
|
|
||||||
return async();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
})();
|
})();
|
|
@ -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>
|
||||||
|
|
Loading…
Reference in New Issue
Block a user