updates for header components rendering checked from backend of UI.

This commit is contained in:
kunw 2016-05-21 11:26:19 +08:00
parent 758a02c715
commit 02c182d178
9 changed files with 103 additions and 41 deletions

View File

@ -0,0 +1,37 @@
package ng
import (
"net/http"
"github.com/vmware/harbor/dao"
"github.com/vmware/harbor/models"
"github.com/vmware/harbor/utils/log"
)
type NavigationHeaderController struct {
BaseController
}
func (nhc *NavigationHeaderController) Get() {
sessionUserID := nhc.GetSession("userId")
var hasLoggedIn bool
var isAdmin int
if sessionUserID != nil {
hasLoggedIn = true
userID := sessionUserID.(int)
u, err := dao.GetUser(models.User{UserID: userID})
if err != nil {
log.Errorf("Error occurred in GetUser, error: %v", err)
nhc.CustomAbort(http.StatusInternalServerError, "Internal error.")
}
if u == nil {
log.Warningf("User was deleted already, user id: %d, canceling request.", userID)
nhc.CustomAbort(http.StatusUnauthorized, "")
}
isAdmin = u.HasAdminRole
}
nhc.Data["HasLoggedIn"] = hasLoggedIn
nhc.Data["IsAdmin"] = isAdmin
nhc.TplName = "ng/navigation-header.htm"
nhc.Render()
}

View File

@ -0,0 +1,37 @@
package ng
import (
"net/http"
"github.com/vmware/harbor/dao"
"github.com/vmware/harbor/models"
"github.com/vmware/harbor/utils/log"
)
type OptionalMenuController struct {
BaseController
}
func (omc *OptionalMenuController) Get() {
sessionUserID := omc.GetSession("userId")
var hasLoggedIn bool
if sessionUserID != nil {
hasLoggedIn = true
userID := sessionUserID.(int)
u, err := dao.GetUser(models.User{UserID: userID})
if err != nil {
log.Errorf("Error occurred in GetUser, error: %v", err)
omc.CustomAbort(http.StatusInternalServerError, "Internal error.")
}
if u == nil {
log.Warningf("User was deleted already, user id: %d, canceling request.", userID)
omc.CustomAbort(http.StatusUnauthorized, "")
}
omc.Data["Username"] = u.Username
}
omc.Data["HasLoggedIn"] = hasLoggedIn
omc.TplName = "ng/optional-menu.htm"
omc.Render()
}

View File

@ -14,15 +14,7 @@
vm.currentLanguage = I18nService().getCurrentLanguage();
vm.languageName = I18nService().getLanguageName(vm.currentLanguage);
console.log('current language:' + I18nService().getCurrentLanguage());
vm.isLoggedIn = false;
$timeout(function() {
vm.user = currentUser.get();
console.log('current user:' + angular.toJson(vm.user));
if(angular.isDefined(vm.user)) {
vm.isLoggedIn = true;
}
}, 300);
vm.user = currentUser.get();
vm.setLanguage = setLanguage;
vm.logOut = logOut;
@ -49,7 +41,7 @@
function optionalMenu() {
var directive = {
'restrict': 'E',
'templateUrl': '/static/ng/resources/js/components/optional-menu/optional-menu.directive.html',
'templateUrl': '/ng/optional_menu',
'scope': true,
'controller': OptionalMenuController,
'controllerAs': 'vm',

View File

@ -1,5 +0,0 @@
<ul class="nav-custom" ng-show="vm.isShow">
<li><a tag="dashboard" href="/ng/dashboard">// 'dashboard' | tr //</a></li>
<li><a tag="project" href="/ng/project">// 'projects' | tr //</a></li>
<li><a ng-show="vm.isAdmin" tag="admin_option" href="/ng/admin_option#/all_user">// 'admin_options' | tr //</a></li>
</ul>

View File

@ -10,26 +10,13 @@
function NavigationHeaderController($window, $scope, currentUser, $timeout) {
var vm = this;
vm.isShow = false;
vm.isAdmin = false;
$timeout(function() {
vm.user = currentUser.get();
if(angular.isDefined(vm.user)) {
vm.isShow = true;
if(vm.user.HasAdminRole === 1) {
vm.isAdmin = true;
}
}
}, 300);
vm.url = $window.location.pathname;
}
function navigationHeader() {
var directive = {
restrict: 'E',
templateUrl: '/static/ng/resources/js/layout/navigation/navigation-header.directive.html',
templateUrl: '/ng/navigation_header',
link: link,
scope: true,
controller: NavigationHeaderController,
@ -40,12 +27,11 @@
return directive;
function link(scope, element, attrs, ctrl) {
element.find('a').removeClass('active');
var visited = ctrl.url;
if (visited != "/ng") {
element.find('a[href*="' + visited + '"]').addClass('active');
}
element.on('click', click);
element.find('a').on('click', click);
function click(event) {
element.find('a').removeClass('active');
$(event.target).not('span').addClass('active');

View File

@ -20,4 +20,7 @@ func initNgRouters() {
beego.Router("/ng/log_out", &ng.CommonController{}, "get:LogOut")
beego.Router("/ng/reset", &ng.CommonController{}, "post:ResetPassword")
beego.Router("/ng/sendEmail", &ng.CommonController{}, "get:SendEmail")
beego.Router("/ng/optional_menu", &ng.OptionalMenuController{})
beego.Router("/ng/navigation_header", &ng.NavigationHeaderController{})
}

View File

@ -0,0 +1,9 @@
{{ if eq .HasLoggedIn true }}
<ul class="nav-custom">
<li><a tag="dashboard" href="/ng/dashboard">// 'dashboard' | tr //</a></li>
<li><a tag="project" href="/ng/project">// 'projects' | tr //</a></li>
{{ if eq .IsAdmin 1 }}
<li><a tag="admin_option" href="/ng/admin_option#/all_user">// 'admin_options' | tr //</a></li>
{{ end }}
</ul>
{{ end }}

View File

@ -1,6 +1,7 @@
<div ng-if="vm.isLoggedIn" class="dropdown">
{{if eq .HasLoggedIn true }}
<div class="dropdown">
<a role="button" data-toggle="dropdown" class="btn btn-link" data-target="#" href="">
<span class="glyphicon glyphicon-user"></span> //vm.user.username//
<span class="glyphicon glyphicon-user"></span> {{ .Username }}
</a>
<ul class="dropdown-menu multi-level" role="menu" aria-labelledby="dropdownMenu">
<li><a href="/ng/account_setting"><span class="glyphicon glyphicon-pencil"></span> // 'account_setting' | tr //</a></li>
@ -15,7 +16,8 @@
<li><a href="javascript:void(0)" ng-click="vm.logOut()"><span class="glyphicon glyphicon-log-out"></span> // 'log_out' | tr //</a></li>
</ul>
</div>
<div ng-if="!vm.isLoggedIn" class="dropdown">
{{ else }}
<div class="dropdown">
<a role="button" data-toggle="dropdown" class="btn btn-link" data-target="#" href="">
<span class="glyphicon glyphicon-globe"></span> //vm.languageName//
</a>
@ -23,4 +25,5 @@
<li><a href="javascript:void(0);" ng-click="vm.setLanguage('en-US')">English</a></li>
<li><a href="javascript:void(0);" ng-click="vm.setLanguage('zh-CN')">中文</a></li>
</ul>
</div>
</div>
{{ end }}

View File

@ -13,16 +13,16 @@
<script src="/static/ng/vendors/zc/v2.2.0/ZeroClipboard.js"></script>
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" integrity="sha384-1q8mTJOASx8j1Au+a5WDVnPi2lkFfwwEAa8hDDdjZlpLegxhjVME1fgjWPGmkzs7" crossorigin="anonymous">
<!--<link rel="stylesheet" href="https://cdn.bootcss.com/bootstrap/3.3.6/css/bootstrap.min.css" integrity="sha384-1q8mTJOASx8j1Au+a5WDVnPi2lkFfwwEAa8hDDdjZlpLegxhjVME1fgjWPGmkzs7" crossorigin="anonymous"--->
<!--link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" integrity="sha384-1q8mTJOASx8j1Au+a5WDVnPi2lkFfwwEAa8hDDdjZlpLegxhjVME1fgjWPGmkzs7" crossorigin="anonymous"-->
<link rel="stylesheet" href="https://cdn.bootcss.com/bootstrap/3.3.6/css/bootstrap.min.css" integrity="sha384-1q8mTJOASx8j1Au+a5WDVnPi2lkFfwwEAa8hDDdjZlpLegxhjVME1fgjWPGmkzs7" crossorigin="anonymous">
<!-- Optional theme -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap-theme.min.css" integrity="sha384-fLW2N01lMqjakBkx3l/M9EahuwpSfeNvV63J5ezn3uZzapT0u7EYsXMjQV+0En5r" crossorigin="anonymous">
<!--<link rel="stylesheet" href="https://cdn.bootcss.com/bootstrap/3.3.6/css/bootstrap-theme.min.css" integrity="sha384-fLW2N01lMqjakBkx3l/M9EahuwpSfeNvV63J5ezn3uZzapT0u7EYsXMjQV+0En5r" crossorigin="anonymous"-->
<!--link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap-theme.min.css" integrity="sha384-fLW2N01lMqjakBkx3l/M9EahuwpSfeNvV63J5ezn3uZzapT0u7EYsXMjQV+0En5r" crossorigin="anonymous"-->
<link rel="stylesheet" href="https://cdn.bootcss.com/bootstrap/3.3.6/css/bootstrap-theme.min.css" integrity="sha384-fLW2N01lMqjakBkx3l/M9EahuwpSfeNvV63J5ezn3uZzapT0u7EYsXMjQV+0En5r" crossorigin="anonymous">
<!-- Latest compiled and minified JavaScript -->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js" integrity="sha384-0mSbJDEHialfmuBBQP6A4Qrprq5OVfW37PRR3j5ELqxss1yVqOtnepnHVP9aJ7xS" crossorigin="anonymous"></script>
<!--<script src="https://cdn.bootcss.com/bootstrap/3.3.6/js/bootstrap.min.js"></script-->
<!--script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js" integrity="sha384-0mSbJDEHialfmuBBQP6A4Qrprq5OVfW37PRR3j5ELqxss1yVqOtnepnHVP9aJ7xS" crossorigin="anonymous"></script-->
<script src="https://cdn.bootcss.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
<link rel="stylesheet" href="/static/ng/resources/css/header.css">
<link rel="stylesheet" href="/static/ng/resources/css/footer.css">