From bd54cb528f74cff026cc00176649b5e2df38edd0 Mon Sep 17 00:00:00 2001 From: kunw Date: Tue, 6 Sep 2016 15:33:50 +0800 Subject: [PATCH] add about menu item to show version info. --- controllers/base.go | 2 ++ .../optional-menu/optional-menu.directive.js | 19 +++++++++-- .../js/layout/details/details.controller.js | 1 + .../js/layout/header/header.controller.js | 34 +++++++++++++++++++ .../js/services/i18n/locale_messages_en-US.js | 3 ++ .../js/services/i18n/locale_messages_zh-CN.js | 3 ++ views/optional-menu.htm | 11 +++--- views/sections/header-content.htm | 3 +- 8 files changed, 67 insertions(+), 9 deletions(-) diff --git a/controllers/base.go b/controllers/base.go index bd3171926..1b54c9f5a 100644 --- a/controllers/base.go +++ b/controllers/base.go @@ -113,6 +113,8 @@ func (b *BaseController) Prepare() { b.SelfRegistration = true } b.Data["SelfRegistration"] = b.SelfRegistration + + b.Data["Version"] = os.Getenv("VERSION") } // Forward to setup layout and template for content for a page. diff --git a/static/resources/js/components/optional-menu/optional-menu.directive.js b/static/resources/js/components/optional-menu/optional-menu.directive.js index 4852b7eeb..8435b5bfc 100644 --- a/static/resources/js/components/optional-menu/optional-menu.directive.js +++ b/static/resources/js/components/optional-menu/optional-menu.directive.js @@ -20,9 +20,9 @@ .module('harbor.optional.menu') .directive('optionalMenu', optionalMenu); - OptionalMenuController.$inject = ['$window', 'I18nService', 'LogOutService', 'currentUser', '$timeout']; + OptionalMenuController.$inject = ['$scope', '$window', 'I18nService', 'LogOutService', 'currentUser', '$timeout', 'trFilter', '$filter']; - function OptionalMenuController($window, I18nService, LogOutService, currentUser, $timeout) { + function OptionalMenuController($scope, $window, I18nService, LogOutService, currentUser, $timeoutm, trFilter, $filter) { var vm = this; vm.currentLanguage = I18nService().getCurrentLanguage(); @@ -36,6 +36,7 @@ vm.user = currentUser.get(); vm.setLanguage = setLanguage; vm.logOut = logOut; + vm.about = about; function setLanguage(language) { I18nService().setCurrentLanguage(language); @@ -54,13 +55,25 @@ function logOutFailed(data, status) { console.log('Failed to log out:' + data); } + function about() { + $scope.$emit('modalTitle', $filter('tr')('about_harbor')); + $scope.$emit('modalMessage', $filter('tr')('current_version', [vm.version])); + var raiseInfo = { + 'confirmOnly': true, + 'contentType': 'text/html', + 'action': function() {} + }; + $scope.$emit('raiseInfo', raiseInfo); + } } function optionalMenu() { var directive = { 'restrict': 'E', 'templateUrl': '/optional_menu?timestamp=' + new Date().getTime(), - 'scope': true, + 'scope': { + 'version': '@' + }, 'controller': OptionalMenuController, 'controllerAs': 'vm', 'bindToController': true diff --git a/static/resources/js/layout/details/details.controller.js b/static/resources/js/layout/details/details.controller.js index ce3ae9cc2..d07679cbc 100644 --- a/static/resources/js/layout/details/details.controller.js +++ b/static/resources/js/layout/details/details.controller.js @@ -76,6 +76,7 @@ function togglePublicity(e) { vm.publicity = e.publicity; + vm.target = 'repositories'; } } diff --git a/static/resources/js/layout/header/header.controller.js b/static/resources/js/layout/header/header.controller.js index 869ab9d09..bbdf02276 100644 --- a/static/resources/js/layout/header/header.controller.js +++ b/static/resources/js/layout/header/header.controller.js @@ -42,6 +42,40 @@ vm.searchInput = getParameterByName('q', $window.location.search); console.log('vm.searchInput at header:' + vm.searchInput); } + + $scope.$on('modalTitle', function(e, val) { + vm.modalTitle = val; + }); + + $scope.$on('modalMessage', function(e, val) { + vm.modalMessage = val; + }); + + $scope.$on('raiseInfo', function(e, val) { + if(val) { + vm.action = function() { + val.action(); + $scope.$broadcast('showDialog', false); + }; + vm.contentType = val.contentType; + vm.confirmOnly = val.confirmOnly; + + $scope.$broadcast('showDialog', true); + } + }); + + $scope.$on('raiseInfo', function(e, val) { + if(val) { + vm.action = function() { + val.action(); + $scope.$broadcast('showDialog', false); + }; + vm.contentType = val.contentType; + vm.confirmOnly = val.confirmOnly; + + $scope.$broadcast('showDialog', true); + } + }); } })(); \ No newline at end of file diff --git a/static/resources/js/services/i18n/locale_messages_en-US.js b/static/resources/js/services/i18n/locale_messages_en-US.js index 633e646ca..8d129f391 100644 --- a/static/resources/js/services/i18n/locale_messages_en-US.js +++ b/static/resources/js/services/i18n/locale_messages_en-US.js @@ -226,6 +226,9 @@ var locale_messages = { 'stopped': 'Stopped', 'retrying': 'Retrying', 'error': 'Error', + 'about': 'About', + 'about_harbor': 'About Harbor', + 'current_version': '  $0', 'failed_to_get_project_member': 'Failed to get current project member.', 'failed_to_delete_repo': 'Failed to delete repository. ', 'failed_to_delete_repo_insuffient_permissions': 'Failed to delete repository, insuffient permissions.', diff --git a/static/resources/js/services/i18n/locale_messages_zh-CN.js b/static/resources/js/services/i18n/locale_messages_zh-CN.js index b55f42a66..d71173333 100644 --- a/static/resources/js/services/i18n/locale_messages_zh-CN.js +++ b/static/resources/js/services/i18n/locale_messages_zh-CN.js @@ -226,6 +226,9 @@ var locale_messages = { 'stopped': '已终止', 'retrying': '重试中', 'error': '错误', + 'about': '关于', + 'about_harbor': '关于 Harbor', + 'current_version': '  $0', 'failed_to_get_project_member': '无法获取当前项目成员。', 'failed_to_delete_repo': '无法删除镜像仓库。', 'failed_to_delete_repo_insuffient_permissions': '无法删除镜像仓库,权限不足。', diff --git a/views/optional-menu.htm b/views/optional-menu.htm index 6950fe206..b32ec201f 100644 --- a/views/optional-menu.htm +++ b/views/optional-menu.htm @@ -19,23 +19,24 @@ {{ else }}