From e65b08b86fa6ccf453342f47c4ce95cff33d8d3e Mon Sep 17 00:00:00 2001 From: kunw Date: Sat, 14 May 2016 13:34:54 +0800 Subject: [PATCH] updates for validation of UI --- static/ng/resources/css/project.css | 4 +- static/ng/resources/css/sign-up.css | 1 - .../optional-menu/optional-menu.directive.js | 5 +-- .../add-project-member.directive.html | 20 +++++---- .../add-project-member.directive.js | 39 ++++++++++++++---- .../project/add-project.directive.html | 18 +++++--- .../project/add-project.directive.js | 41 +++++++++++++------ .../js/components/search/search.directive.js | 3 +- .../components/sign-in/sign-in.directive.html | 21 +++++++--- .../components/sign-in/sign-in.directive.js | 34 +++++++++------ .../account-setting.controller.js | 32 ++++++++++----- .../forgot-password.controller.js | 19 ++++++--- .../js/layout/project/project.controller.js | 1 + .../reset-password.controller.js | 33 +++++++++++---- .../js/services/i18n/locale_messages.js | 18 +++++++- .../js/services/i18n/services.i18n.js | 5 ++- .../js/session/session.current-user.js | 2 +- views/ng/account-settings.htm | 18 ++++---- views/ng/forgot-password.htm | 10 ++--- views/ng/index.htm | 4 +- views/ng/layout.htm | 3 +- views/ng/reset-password.htm | 13 +++--- views/ng/sign-up.htm | 16 ++++---- 23 files changed, 240 insertions(+), 120 deletions(-) diff --git a/static/ng/resources/css/project.css b/static/ng/resources/css/project.css index 6519aaaed..2f0542b4c 100644 --- a/static/ng/resources/css/project.css +++ b/static/ng/resources/css/project.css @@ -35,13 +35,13 @@ } .pane { - height: 80%; + min-height: 500px; overflow-y: auto; } .sub-pane { margin: 0 10px 0 10px; - height: 60%; + min-height: 500px; overflow-y: auto; } diff --git a/static/ng/resources/css/sign-up.css b/static/ng/resources/css/sign-up.css index 213b6e7c6..1096db173 100644 --- a/static/ng/resources/css/sign-up.css +++ b/static/ng/resources/css/sign-up.css @@ -43,7 +43,6 @@ } .error-message { - font-size: 16pt; color: red; width: 100%; margin-right: auto; diff --git a/static/ng/resources/js/components/optional-menu/optional-menu.directive.js b/static/ng/resources/js/components/optional-menu/optional-menu.directive.js index a9a0e02ac..a87f1663c 100644 --- a/static/ng/resources/js/components/optional-menu/optional-menu.directive.js +++ b/static/ng/resources/js/components/optional-menu/optional-menu.directive.js @@ -6,9 +6,9 @@ .module('harbor.optional.menu') .directive('optionalMenu', optionalMenu); - OptionalMenuController.$inject = ['$scope', '$window', 'I18nService', 'LogOutService']; + OptionalMenuController.$inject = ['$scope', '$window', '$cookies', 'I18nService', 'LogOutService']; - function OptionalMenuController($scope, $window, I18nService, LogOutService) { + function OptionalMenuController($scope, $window, $cookies, I18nService, LogOutService) { var vm = this; vm.currentLanguage = I18nService().getCurrentLanguage(); vm.setLanguage = setLanguage; @@ -19,7 +19,6 @@ function setLanguage(name) { I18nService().setCurrentLanguage(name); - $window.location.reload(); } function logOut() { diff --git a/static/ng/resources/js/components/project-member/add-project-member.directive.html b/static/ng/resources/js/components/project-member/add-project-member.directive.html index d34c2d667..937650291 100644 --- a/static/ng/resources/js/components/project-member/add-project-member.directive.html +++ b/static/ng/resources/js/components/project-member/add-project-member.directive.html @@ -1,14 +1,20 @@
-
-
- + +
+ +
+
+ // 'username_is_required' | tr // +
+ // vm.errorMessage | tr // +
-    +     //role.name//   @@ -17,9 +23,9 @@
-
- - +
+ +
diff --git a/static/ng/resources/js/components/project-member/add-project-member.directive.js b/static/ng/resources/js/components/project-member/add-project-member.directive.js index 9eb8bbec1..a22819e35 100644 --- a/static/ng/resources/js/components/project-member/add-project-member.directive.js +++ b/static/ng/resources/js/components/project-member/add-project-member.directive.js @@ -13,19 +13,34 @@ vm.username = ""; vm.roles = roles(); vm.optRole = 1; + + vm.reset = reset; vm.save = save; vm.cancel = cancel; + + vm.hasError = false; + vm.errorMessage = ''; - function save() { - AddProjectMemberService(vm.projectId, vm.optRole, vm.username) - .success(addProjectMemberComplete) - .error(addProjectMemberFailed); - vm.username = ""; - vm.optRole = 1; - vm.reload(); + function reset() { + vm.hasError = false; + vm.errorMessage = ''; + } + + function save(pm) { + if(pm && angular.isDefined(pm.username)) { + AddProjectMemberService(vm.projectId, vm.optRole, vm.username) + .success(addProjectMemberComplete) + .error(addProjectMemberFailed); + vm.username = ""; + vm.optRole = 1; + vm.reload(); + } } - function cancel() { + function cancel(form) { + if(form) { + form.$setPristine(); + } vm.isOpen = false; vm.username = ""; vm.optRole = 1; @@ -36,6 +51,14 @@ } function addProjectMemberFailed(data, status, headers) { + if(status === 409) { + vm.hasError = true; + vm.errorMessage = 'username_already_exist'; + } + if(status == 404) { + vm.hasError = true; + vm.errorMessage = 'username_does_not_exist'; + } console.log('addProjectMemberFailed: status:' + status + ', data:' + data); } diff --git a/static/ng/resources/js/components/project/add-project.directive.html b/static/ng/resources/js/components/project/add-project.directive.html index a171c9b14..6368f3e11 100644 --- a/static/ng/resources/js/components/project/add-project.directive.html +++ b/static/ng/resources/js/components/project/add-project.directive.html @@ -1,9 +1,15 @@
-
-
- + +
+ +
+
+ Project name is required. +
+ // vm.errorMessage // +
 // 'public_projects' | tr // @@ -12,9 +18,9 @@
-
- - +
+ +
diff --git a/static/ng/resources/js/components/project/add-project.directive.js b/static/ng/resources/js/components/project/add-project.directive.js index f5c05b634..91698fea7 100644 --- a/static/ng/resources/js/components/project/add-project.directive.js +++ b/static/ng/resources/js/components/project/add-project.directive.js @@ -13,35 +13,47 @@ vm.projectName = ""; vm.isPublic = false; + vm.reset = reset; vm.addProject = addProject; vm.cancel = cancel; - function addProject() { - - if(vm.projectName == "") { - alert("Please input the project name."); - return; + vm.hasError = false; + vm.errorMessage = ''; + + function reset() { + vm.hasError = false; + vm.errorMessage = ''; + } + + function addProject(p) { + if(p && angular.isDefined(p.projectName)) { + AddProjectService(p.projectName, vm.isPublic) + .success(addProjectSuccess) + .error(addProjectFailed); } - - AddProjectService(vm.projectName, vm.isPublic) - .success(addProjectSuccess) - .error(addProjectFailed); } function addProjectSuccess(data, status) { vm.isOpen = false; vm.projectName = ""; - vm.isPublic = false; + vm.isPublic = false; $scope.$emit('addedSuccess', true); } function addProjectFailed(data, status) { + if(status === 409) { + vm.hasError = true; + vm.errorMessage = 'Project already exists.'; + } console.log('Failed to add project:' + status); } - function cancel(){ + function cancel(form){ + if(form) { + form.$setPristine(); + } vm.isOpen = false; - vm.projectName = ""; + vm.projectName = ''; vm.isPublic = false; } } @@ -54,10 +66,15 @@ 'scope' : { 'isOpen': '=' }, + 'link': link, 'controllerAs': 'vm', 'bindToController': true }; return directive; + + function link(scope, element, attrs, ctrl) { + + } } })(); \ No newline at end of file diff --git a/static/ng/resources/js/components/search/search.directive.js b/static/ng/resources/js/components/search/search.directive.js index fd854efeb..037a1f1d6 100644 --- a/static/ng/resources/js/components/search/search.directive.js +++ b/static/ng/resources/js/components/search/search.directive.js @@ -26,11 +26,10 @@ function searchSuccess(data, status) { console.log('filterBy:' + vm.filterBy + ", data:" + data); vm.searchResult = data[vm.filterBy]; - } function searchFailed(data, status) { - + console.log('Failed search:' + data); } } diff --git a/static/ng/resources/js/components/sign-in/sign-in.directive.html b/static/ng/resources/js/components/sign-in/sign-in.directive.html index 56314df2f..a1a173899 100644 --- a/static/ng/resources/js/components/sign-in/sign-in.directive.html +++ b/static/ng/resources/js/components/sign-in/sign-in.directive.html @@ -1,18 +1,29 @@ -
+
- + +
+
+ // 'username_is_required' | tr // +
+
- + +
+
+ // 'password_is_required' | tr // +
+ // vm.errorMessage | tr // +
- +
@@ -23,5 +34,5 @@ // 'forgot_password' | tr //
-
+
\ No newline at end of file diff --git a/static/ng/resources/js/components/sign-in/sign-in.directive.js b/static/ng/resources/js/components/sign-in/sign-in.directive.js index 712879e9a..0b9205b14 100644 --- a/static/ng/resources/js/components/sign-in/sign-in.directive.js +++ b/static/ng/resources/js/components/sign-in/sign-in.directive.js @@ -6,32 +6,41 @@ .module('harbor.sign.in') .directive('signIn', signIn); - SignInController.$inject = ['SignInService', '$window']; - function SignInController(SignInService, $window) { + SignInController.$inject = ['SignInService', '$window', '$scope']; + function SignInController(SignInService, $window, $scope) { var vm = this; - vm.principal = ""; - vm.password = ""; + + vm.hasError = false; + vm.errorMessage = ''; + + vm.reset = reset; vm.doSignIn = doSignIn; vm.doSignUp = doSignUp; vm.doForgotPassword = doForgotPassword; - - function doSignIn() { - if(vm.principal != "" && vm.password != "") { - SignInService(vm.principal, vm.password) + + function reset() { + vm.hasError = false; + vm.errorMessage = ''; + } + + function doSignIn(user) { + if(user && angular.isDefined(user.principal) && angular.isDefined(user.password)) { + SignInService(user.principal, user.password) .success(signedInSuccess) .error(signedInFailed); - }else{ - $window.alert('Please input your username or password!'); } } function signedInSuccess(data, status) { - console.log(status); $window.location.href = "/ng/project"; } function signedInFailed(data, status) { - console.log(status); + if(status === 401) { + vm.hasError = true; + vm.errorMessage = 'username_or_password_is_incorrect'; + } + console.log('Failed sign in:' + data + ', status:' + status); } function doSignUp() { @@ -53,6 +62,7 @@ 'bindToController': true } return directive; + } })(); \ No newline at end of file diff --git a/static/ng/resources/js/layout/account-setting/account-setting.controller.js b/static/ng/resources/js/layout/account-setting/account-setting.controller.js index 5c94caa0c..ebd633a5e 100644 --- a/static/ng/resources/js/layout/account-setting/account-setting.controller.js +++ b/static/ng/resources/js/layout/account-setting/account-setting.controller.js @@ -12,8 +12,12 @@ var vm = this; vm.isOpen = false; vm.user = {}; - vm.toggleChangePassword = toggleChangePassword; + vm.hasError = false; + vm.errorMessage = ''; + + vm.reset = reset; + vm.toggleChangePassword = toggleChangePassword; vm.changeProfile = changeProfile; vm.changePassword= changePassword; vm.cancel = cancel; @@ -21,14 +25,18 @@ $scope.$on('currentUser', function(e, val) { vm.user = val; }); + + function reset() { + vm.hasError = false; + vm.errorMessage = ''; + } function toggleChangePassword() { if(vm.isOpen) { vm.isOpen = false; }else{ vm.isOpen = true; - } - console.log('vm.isOpen:' + vm.isOpen); + } } function getCurrentUserFailed(data) { @@ -40,25 +48,29 @@ } function changePassword(user) { - console.log(user); - ChangePasswordService(vm.user.UserId, user.oldPassword, user.password) - .success(changePasswordSuccess) - .error(changePasswordFailed); + if(user && angular.isDefined(user.oldPassword) && angular.isDefined(user.password)) { + ChangePasswordService(vm.user.UserId, user.oldPassword, user.password) + .success(changePasswordSuccess) + .error(changePasswordFailed); + } } function changePasswordSuccess(data, status) { - console.log('Successful changed password:' + data); $window.location.href = '/ng/project'; } function changePasswordFailed(data, status) { console.log('Failed changed password:' + data); if(data === 'old_password_is_not_correct') { - vm.oldPasswordIncorrect = true; + vm.hasError = true; + vm.errorMessage = 'old_password_is_incorrect'; } } - function cancel() { + function cancel(form) { + if(form) { + form.$setPristine(); + } $window.location.href = '/ng/project'; } diff --git a/static/ng/resources/js/layout/forgot-password/forgot-password.controller.js b/static/ng/resources/js/layout/forgot-password/forgot-password.controller.js index 7a78d9230..2742b224d 100644 --- a/static/ng/resources/js/layout/forgot-password/forgot-password.controller.js +++ b/static/ng/resources/js/layout/forgot-password/forgot-password.controller.js @@ -10,20 +10,27 @@ function ForgotPasswordController(SendMailService, $window) { var vm = this; + vm.hasError = false; vm.errorMessage = ''; + + vm.reset = reset; vm.sendMail = sendMail; - function sendMail(user) { + function reset(){ vm.hasError = false; - console.log('Email address:' + user.email); - SendMailService(user.email) - .success(sendMailSuccess) - .error(sendMailFailed); + vm.errorMessage = ''; + } + + function sendMail(user) { + if(user && angular.isDefined(user.email)) { + SendMailService(user.email) + .success(sendMailSuccess) + .error(sendMailFailed); + } } function sendMailSuccess(data, status) { - console.log('Successful send mail:' + data); $window.location.href = '/ng'; } diff --git a/static/ng/resources/js/layout/project/project.controller.js b/static/ng/resources/js/layout/project/project.controller.js index 51e913e75..d6f8334ba 100644 --- a/static/ng/resources/js/layout/project/project.controller.js +++ b/static/ng/resources/js/layout/project/project.controller.js @@ -68,6 +68,7 @@ function togglePublicity(e) { vm.publicity = e.publicity; + vm.isOpen = false; vm.retrieve(); console.log('vm.publicity:' + vm.publicity); } diff --git a/static/ng/resources/js/layout/reset-password/reset-password.controller.js b/static/ng/resources/js/layout/reset-password/reset-password.controller.js index 79d6a8666..56b8821be 100644 --- a/static/ng/resources/js/layout/reset-password/reset-password.controller.js +++ b/static/ng/resources/js/layout/reset-password/reset-password.controller.js @@ -20,26 +20,43 @@ function ResetPasswordController($location, ResetPasswordService, $window) { var vm = this; vm.resetUuid = getParameterByName('reset_uuid', $location.absUrl()); + + vm.reset = reset; vm.resetPassword = resetPassword; - console.log(vm.resetUuid); + vm.cancel = cancel; + + vm.hasError = false; + vm.errorMessage = ''; + + function reset() { + vm.hasError = false; + vm.errorMessage = ''; + } + function resetPassword(user) { - console.log('rececived password:' + user.password + ', reset_uuid:' + vm.resetUuid); - ResetPasswordService(vm.resetUuid, user.password) - .success(resetPasswordSuccess) - .error(resetPasswordFailed); + if(user && angular.isDefined(user.resetUuid) && angular.isDefined(user.password)) { + console.log('rececived password:' + user.password + ', reset_uuid:' + vm.resetUuid); + ResetPasswordService(vm.resetUuid, user.password) + .success(resetPasswordSuccess) + .error(resetPasswordFailed); + } } function resetPasswordSuccess(data, status) { - console.log('Successful reset password:' + data); $window.location.href = '/ng'; } function resetPasswordFailed(data) { + vm.hasError = true; + vm.errorMessage = data; console.log('Failed reset password:' + data); } - - + function cancel(form) { + if(form) { + form.$setPristine(); + } + } } })(); \ No newline at end of file diff --git a/static/ng/resources/js/services/i18n/locale_messages.js b/static/ng/resources/js/services/i18n/locale_messages.js index 72671cdec..7170a31fa 100644 --- a/static/ng/resources/js/services/i18n/locale_messages.js +++ b/static/ng/resources/js/services/i18n/locale_messages.js @@ -179,7 +179,7 @@ var global_messages = { 'en-US': 'Please input the Email used when you signed up, a reset password Email will be sent to you.', 'zh-CN': '重置邮件将发送到此邮箱。' }, - 'emaTimestampil_does_not_exist': { + 'email_does_not_exist': { 'en-US': 'Email does not exist', 'zh-CN': '邮箱不存在。' }, @@ -382,5 +382,21 @@ var global_messages = { 'new_password': { 'en-US': 'New Password', 'zh-CN': '新密码' + }, + 'username_already_exist': { + 'en-US': 'Username already exist.', + 'zh-CN': '用户名已存在。' + }, + 'username_does_not_exist': { + 'en-US': 'Username does not exist.', + 'zh-CN': '用户名不存在。' + }, + 'username_or_password_is_incorrect': { + 'en-US': 'Username or password is incorrect', + 'zh-CN': '用户名或密码不正确。' + }, + 'username_email': { + 'en-US': 'Username/Email', + 'zh-CN': '用户名/邮箱' } }; \ No newline at end of file diff --git a/static/ng/resources/js/services/i18n/services.i18n.js b/static/ng/resources/js/services/i18n/services.i18n.js index c47c80ecc..92594b598 100644 --- a/static/ng/resources/js/services/i18n/services.i18n.js +++ b/static/ng/resources/js/services/i18n/services.i18n.js @@ -6,9 +6,9 @@ .module('harbor.services.i18n') .factory('I18nService', I18nService); - I18nService.$inject = ['$cookies']; + I18nService.$inject = ['$cookies', '$window']; - function I18nService($cookies) { + function I18nService($cookies, $window) { var languages = $.extend(true, {}, global_messages); var defaultLanguage = navigator.language || 'en-US'; var languageNames = { @@ -23,6 +23,7 @@ language = defaultLanguage; } $cookies.put('language', language); + $window.location.reload(); }, 'getCurrentLanguage': function() { return $cookies.get('language') || defaultLanguage; diff --git a/static/ng/resources/js/session/session.current-user.js b/static/ng/resources/js/session/session.current-user.js index 6eacb39a8..90b109afc 100644 --- a/static/ng/resources/js/session/session.current-user.js +++ b/static/ng/resources/js/session/session.current-user.js @@ -31,7 +31,7 @@ if(exclusions[i]===url) { return; } - } + } $window.location.href = '/ng'; } } diff --git a/views/ng/account-settings.htm b/views/ng/account-settings.htm index 3da51a478..e8fba870f 100644 --- a/views/ng/account-settings.htm +++ b/views/ng/account-settings.htm @@ -57,7 +57,7 @@
-
+ @@ -66,7 +66,7 @@
- +
* @@ -75,7 +75,7 @@
- +

// 'password_desc' | tr //

@@ -85,7 +85,7 @@
- +
* @@ -94,8 +94,8 @@
- - + +
@@ -106,12 +106,10 @@ // 'new_password_is_required' | tr // // 'new_password_is_invalid' | tr //
-
+
// 'password_does_not_match' | tr //
-
- // 'old_password_is_incorrect' | tr // -
+ // vm.errorMessage | tr //
diff --git a/views/ng/forgot-password.htm b/views/ng/forgot-password.htm index 63351d0ca..977364d02 100644 --- a/views/ng/forgot-password.htm +++ b/views/ng/forgot-password.htm @@ -5,11 +5,11 @@

// 'forgot_password' | tr //

-
+
- +

// 'forgot_password_description' | tr //

@@ -20,13 +20,11 @@
// 'email_is_required' | tr //
-
- // vm.errorMessage | tr // -
+ // vm.errorMessage | tr //
- +
diff --git a/views/ng/index.htm b/views/ng/index.htm index ebaad76c1..893d24a94 100644 --- a/views/ng/index.htm +++ b/views/ng/index.htm @@ -1,4 +1,4 @@ -
+
@@ -43,7 +43,7 @@
-

+

// 'index_desc' | tr //

    diff --git a/views/ng/layout.htm b/views/ng/layout.htm index 5bcd3eeb1..6f8db7cdb 100644 --- a/views/ng/layout.htm +++ b/views/ng/layout.htm @@ -1,7 +1,7 @@ - + {{.HeaderInclude}} {{.Title}} @@ -9,6 +9,5 @@ {{.LayoutContent}} {{.FooterContent}} {{.FooterInclude}} - {{.HeaderInclude}} \ No newline at end of file diff --git a/views/ng/reset-password.htm b/views/ng/reset-password.htm index e5b399e82..3d9b18692 100644 --- a/views/ng/reset-password.htm +++ b/views/ng/reset-password.htm @@ -5,11 +5,11 @@

    // 'reset_password' | tr //

    -
    +
    - +

    // 'password_desc' | tr //

    @@ -19,7 +19,7 @@
    - +
    * @@ -27,8 +27,8 @@
    - - + +
    @@ -36,9 +36,10 @@ // 'password_is_required' | tr // // 'password_is_invalid' | tr //
    -
    +
    // 'password_does_not_match' | tr //
    + // vm.errorMessage //
    diff --git a/views/ng/sign-up.htm b/views/ng/sign-up.htm index ff3ae8744..4b3c8d31b 100644 --- a/views/ng/sign-up.htm +++ b/views/ng/sign-up.htm @@ -5,12 +5,12 @@

    // 'sign_up' | tr //

    -
    +
    -
    +
    // 'username_is_required' | tr // // 'username_is_too_long' | tr // // 'username_contains_illegal_chars' | tr // @@ -25,7 +25,7 @@
    -
    +
    // 'email_is_required' | tr // // 'email_content_illegal' | tr // // 'email_has_been_taken' | tr // @@ -40,7 +40,7 @@
    -
    +
    // 'full_name_is_required' | tr // // 'full_name_contains_illegal_chars' | tr // // 'full_name_is_too_long' | tr // @@ -55,7 +55,7 @@
    -
    +
    // 'password_is_required' | tr // // 'password_is_invalid' | tr //
    @@ -69,7 +69,7 @@
    -
    +
    // 'password_does_not_match' | tr //
    @@ -81,14 +81,14 @@
    -
    +
    // 'comment_is_too_long' | tr //
    - +