abstracted summary section as a directive

This commit is contained in:
xiahaoshawn 2016-06-02 15:44:53 +08:00
parent 0250086758
commit 575fc90e61
14 changed files with 90 additions and 72 deletions

View File

@ -1,13 +1,5 @@
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
@ -15,24 +7,5 @@ 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")
}

View File

@ -8,10 +8,12 @@ import (
"github.com/vmware/harbor/utils/log"
)
// SignInController handles requests to /ng/sign_in
type SignInController struct {
BaseController
}
//Get renders sign_in page
func (sic *SignInController) Get() {
sessionUserID := sic.GetSession("userId")
var hasLoggedIn bool

View File

@ -9,6 +9,7 @@
function roles() {
return [
{'id': '0', 'name': 'NA', 'roleName': 'NA'},
{'id': '1', 'name': 'Project Admin', 'roleName': 'projectAdmin'},
{'id': '2', 'name': 'Developer', 'roleName': 'developer'},
{'id': '3', 'name': 'Guest', 'roleName': 'guest'}
@ -25,7 +26,7 @@
for(var i = 0; i < r.length; i++) {
var role = r[i];
if(query.key === 'roleName' && role.roleName === query.value
|| query.key === 'roleId' && role.id === query.value) {
|| query.key === 'roleId' && role.id === String(query.value)) {
return role;
}
}

View File

@ -0,0 +1,15 @@
<h4 class="page-header title-color underlined">// 'summary' | tr //</h4>
<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>// '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>

View File

@ -0,0 +1,45 @@
(function() {
'use strict';
angular
.module('harbor.summary')
.directive('projectSummary', projectSummary);
ProjectSummaryController.$inject = ['StatProjectService'];
function ProjectSummaryController(StatProjectService) {
var vm = this;
StatProjectService()
.success(statProjectSuccess)
.error(statProjectFailed);
function statProjectSuccess(data, status) {
vm.statProjects = data;
if(vm.statProjects.hasOwnProperty("total_project_count")) {
vm.isAdmin = true;
}else {
vm.isAdmin = false;
}
}
function statProjectFailed(status) {
console.log('Failed stat project:' + status);
}
}
function projectSummary() {
var directive = {
'restrict': 'E',
'templateUrl': '/static/ng/resources/js/components/summary/summary.directive.html',
'controller': ProjectSummaryController,
'scope' : true,
'controllerAs': 'vm',
'bindToController': true
};
return directive;
}
})();

View File

@ -0,0 +1,10 @@
(function() {
'use strict';
angular
.module('harbor.summary', [
'harbor.services.project'
]);
})();

View File

@ -27,6 +27,7 @@
'harbor.services.user',
'harbor.services.repository',
'harbor.services.project.member',
'harbor.summary',
'harbor.optional.menu',
'harbor.modal.dialog',
'harbor.sign.in',

View File

@ -6,28 +6,17 @@
.module('harbor.layout.dashboard')
.controller('DashboardController', DashboardController);
DashboardController.$inject = ['StatProjectService', 'ListTop10RepositoryService', 'ListIntegratedLogService'];
DashboardController.$inject = ['ListTop10RepositoryService', 'ListIntegratedLogService'];
function DashboardController(StatProjectService, ListTop10RepositoryService, ListIntegratedLogService) {
function DashboardController(ListTop10RepositoryService, ListIntegratedLogService) {
var vm = this;
StatProjectService()
.then(statProjectSuccess, statProjectFailed);
ListTop10RepositoryService()
.then(listTop10RepositorySuccess, listTop10RepositoryFailed);
ListIntegratedLogService()
.then(listIntegratedLogSuccess, listIntegratedLogFailed);
function statProjectSuccess(response) {
vm.statProjects = response.data;
}
function statProjectFailed(response) {
console.log('Failed stat project:' + response.data);
}
function listTop10RepositorySuccess(data) {
vm.top10Repositories = data;
}

View File

@ -4,7 +4,6 @@
angular
.module('harbor.layout.dashboard', [
'harbor.services.project',
'harbor.services.repository',
'harbor.services.log'
]);

View File

@ -6,18 +6,11 @@
.module('harbor.layout.project')
.controller('ProjectController', ProjectController);
ProjectController.$inject = ['$scope', 'ListProjectService', '$timeout', 'currentUser'];
ProjectController.$inject = ['$scope', 'ListProjectService', '$timeout', 'currentUser', 'getRole'];
function ProjectController($scope, ListProjectService, $timeout, currentUser) {
function ProjectController($scope, ListProjectService, $timeout, currentUser, getRole) {
var vm = this;
vm.MAP = {
0: 'NA',
1: 'Project Admin',
2: 'Developer',
3: 'Guest'
};
vm.isOpen = false;
vm.projectName = '';
vm.publicity = 0;
@ -39,7 +32,8 @@
function listProjectSuccess(data, status) {
data.forEach(function(data){
data.role = vm.MAP[data.role_id];
var currentRole = getRole({'key': 'roleId', 'value': data.role_id});
data.role_name = currentRole.name;
});
vm.projects = data || [];

View File

@ -4,6 +4,7 @@
angular
.module('harbor.layout.project', [
'harbor.project.member',
'harbor.services.project',
'harbor.services.user'
]);

View File

@ -4,22 +4,7 @@
<div class="col-xs-4 col-md-4">
<div class="row">
<div class="up-section">
<h4 class="page-header title-color underlined">// 'summary' | tr //</h4>
<dl class="page-content dl-horizontal">
{{ 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>
<project-Summary></project-Summary>
</div>
</div>
</div>

View File

@ -35,8 +35,8 @@
</tr>
<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>//p.count//</td>
<td>//p.role//</td>
<td>//p.repo_count//</td>
<td>//p.role_name//</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>
</tr>

View File

@ -197,3 +197,6 @@
<script src="/static/ng/resources/js/components/log/log.config.js"></script>
<script src="/static/ng/resources/js/components/log/list-log.directive.js"></script>
<script src="/static/ng/resources/js/components/log/advanced-search.directive.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>