add have logged in and no items handles.

This commit is contained in:
kunw 2016-05-24 18:22:06 +08:00
parent 2011453d4b
commit 6216799942
14 changed files with 129 additions and 16 deletions

37
controllers/ng/signin.go Normal file
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 SignInController struct {
BaseController
}
func (sic *SignInController) Get() {
sessionUserID := sic.GetSession("userId")
var hasLoggedIn bool
var username string
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)
sic.CustomAbort(http.StatusInternalServerError, "Internal error.")
}
if u == nil {
log.Warningf("User was deleted already, user id: %d, canceling request.", userID)
sic.CustomAbort(http.StatusUnauthorized, "")
}
username = u.Username
}
sic.Data["Username"] = username
sic.Data["HasLoggedIn"] = hasLoggedIn
sic.TplName = "ng/sign-in.htm"
sic.Render()
}

View File

@ -6,6 +6,29 @@ body {
position: fixed;
}
.has-logged-in {
position: relative;
top: 50px;
}
.has-logged-in h4 {
float: left;
width: 100%;
line-height: 2em;
text-align: center;
}
.has-logged-in .last-logged-in-time {
text-align: center;
}
.has-logged-in .control-button {
height: 2em;
width: 100%;
padding-right: 10%;
clear: both;
}
.container-fluid-custom {
background-color: #EFEFEF;
max-height: 100%;

View File

@ -56,4 +56,9 @@
.well-custom {
position: relative;
width: 100%;
}
.empty-hint {
text-align: center;
vertical-align: middle;
}

View File

@ -8,7 +8,10 @@
</span>
</div>
</div>
<div class="panel-group" id="accordion" role="tablist" aria-multiselectable="true">
<div ng-if="vm.repositories.length === 0" class="empty-hint">
<h3 style="margin-top: 200px;" class="text-muted">// 'no_repositories' | tr //</h3>
</div>
<div ng-if="vm.repositories.length > 0" class="panel-group" id="accordion" role="tablist" aria-multiselectable="true">
<modal-dialog action="vm.deleteImage()" content-type="text/html" title="//vm.modalTitle//" message="//vm.modalMessage//"></modal-dialog>
<div class="panel panel-default" ng-repeat="repo in vm.repositories">
<div class="panel-heading" role="tab" id="heading//$index + 1//">

View File

@ -25,7 +25,6 @@
vm.retrieve = retrieve;
vm.projectId = $routeParams.project_id;
vm.tagCount = {};
vm.retrieve();
$scope.$on('repoName', function(e, val) {
@ -58,7 +57,7 @@
}
function getRepositoryComplete(data, status) {
vm.repositories = data;
vm.repositories = data || [];
}
function getRepositoryFailed(response) {

View File

@ -6,8 +6,8 @@
.module('harbor.sign.in')
.directive('signIn', signIn);
SignInController.$inject = ['SignInService', '$window', '$scope'];
function SignInController(SignInService, $window, $scope) {
SignInController.$inject = ['SignInService', 'LogOutService', 'currentUser', 'I18nService', '$window', '$scope'];
function SignInController(SignInService, LogOutService, currentUser, I18nService, $window, $scope) {
var vm = this;
vm.hasError = false;
@ -18,6 +18,9 @@
vm.doSignUp = doSignUp;
vm.doForgotPassword = doForgotPassword;
vm.doContinue = doContinue;
vm.doLogOut = doLogOut;
function reset() {
vm.hasError = false;
vm.errorMessage = '';
@ -50,12 +53,32 @@
function doForgotPassword() {
$window.location.href = '/ng/forgot_password';
}
function doContinue() {
$window.location.href = '/ng/dashboard';
}
function doLogOut() {
LogOutService()
.success(logOutSuccess)
.error(logOutFailed);
}
function logOutSuccess(data, status) {
currentUser.unset();
I18nService().unset();
$window.location.href= '/ng';
}
function logOutFailed(data, status) {
console.log('Failed to log out:' + data);
}
}
function signIn() {
var directive = {
'restrict': 'E',
'templateUrl': '/static/ng/resources/js/components/sign-in/sign-in.directive.html',
'templateUrl': '/ng/sign_in',
'scope': true,
'controller': SignInController,
'controllerAs': 'vm',

View File

@ -31,7 +31,7 @@
}
function listProjectSuccess(data, status) {
vm.projects = data;
vm.projects = data || [];
}
function listProjectFailed(e) {

View File

@ -117,5 +117,10 @@ var locale_messages = {
'alert_delete_tag_title': 'Delete tag - $0',
'alert_delete_tag': 'Delete this "$0" tag now?',
'close': 'Close',
'ok': 'OK'
'ok': 'OK',
'welcome': 'Welcome ',
'to_harbor': ' to Harbor!',
'continue' : 'Continue',
'no_projects_add_new_project': 'No projects, add new project now.',
'no_repositories': 'No repositories, use "push command" to upload new images.'
};

View File

@ -115,5 +115,10 @@ var locale_messages = {
'alert_delete_tag_title': '删除镜像标签 - $0',
'alert_delete_tag': '删除镜像标签 "$0" ?',
'close': '关闭',
'ok': '确认'
'ok': '确认',
'welcome': '欢迎 ',
'to_harbor': ' 使用Harbor!',
'continue' : '继续',
'no_projects_add_new_project': '当前没有项目,请新增项目。',
'no_repositories': '当前没有镜像仓库,使用"push命令"上传镜像。'
};

View File

@ -25,4 +25,5 @@ func initNgRouters() {
beego.Router("/ng/optional_menu", &ng.OptionalMenuController{})
beego.Router("/ng/navigation_header", &ng.NavigationHeaderController{})
beego.Router("/ng/sign_in", &ng.SignInController{})
}

View File

@ -17,15 +17,15 @@
<div class="page-content">
<div style="margin-left: auto; margin-right: auto; width: 100%;">
<div class="thumbnail display-inline-block">
<img src="static/ng/resources/img/Step1.png" alt="Step 1">
<img src="/static/ng/resources/img/Step1.png" alt="Step 1">
<h5 class="step-content">// 'anybody_can_read_public_projects' | tr //</h5>
</div>
<div class="thumbnail display-inline-block">
<img src="static/ng/resources/img/Step2.png" alt="Step 2">
<img src="/static/ng/resources/img/Step2.png" alt="Step 2">
<h5 class="step-content">// 'create_projects_and_connect_repositories' | tr //</h5>
</div>
<div class="thumbnail display-inline-block">
<img src="static/ng/resources/img/Step3.png" alt="Step 3">
<img src="/static/ng/resources/img/Step3.png" alt="Step 3">
<h5 class="step-content">// 'user_management_and_role_assignment' | tr //</h5>
</div>
</div>

View File

@ -30,13 +30,16 @@
<th>// 'project_name' | tr //</th><th>// 'repositories' | tr //</th><th>// 'role' | tr //</th><th>// 'creation_time' | tr //</th><th>// 'publicity' | tr //</th>
</thead>
<tbody>
<tr ng-repeat="p in vm.projects">
<tr>
<td colspan="5" height="320px" class="empty-hint" ng-if="vm.projects.length === 0"><h3 class="text-muted">// 'no_projects_add_new_project' | tr //</h3></td>
</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>N/A</td>
<td>N/A</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>
</tr>
</tbody>
</table>
</div>

View File

@ -6,7 +6,7 @@
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="#"><img class="img-responsive" src="/static/ng/resources/img/Harbor_Logo_rec.png" alt="Harbor's Logo"/></a>
<a class="navbar-brand" href="/ng"><img class="img-responsive" src="/static/ng/resources/img/Harbor_Logo_rec.png" alt="Harbor's Logo"/></a>
</div>
<!-- Collect the nav links, forms, and other content for toggling -->
<div class="collapse navbar-collapse" id="bs-harbor-navbar-collapse-1">

View File

@ -1,3 +1,11 @@
{{ if eq .HasLoggedIn true }}
<div class="has-logged-in">
<h4>// 'welcome' | tr // <strong>{{ .Username }}</strong> // 'to_harbor' | tr //</h4>
<!--p class="text-muted last-logged-in-time">Last login time: //vm.lastLoggedInTime//</p-->
<p class="control-button"><input type="button" class="btn btn-default pull-right" value="// 'continue' | tr //" ng-click="vm.doContinue()"></p>
<p class="control-button"><input type="button" class="btn btn-link pull-right" value="// 'log_out' | tr //" ng-click="vm.doLogOut()"></p>
</div>
{{ else }}
<form name="form" class="form-horizontal css-form" ng-submit="form.$valid" novalidate>
<div class="form-group">
<div class="col-sm-offset-1 col-sm-10">
@ -35,4 +43,5 @@
</div>
</div>
</div>
</form>
</form>
{{ end }}