From f50a9ac38d50247ad2b3eaa1442e06b156d63f50 Mon Sep 17 00:00:00 2001 From: xiahaoshawn Date: Thu, 19 May 2016 15:51:42 +0800 Subject: [PATCH 1/3] set up jshint task --- static/ng/Gruntfile.js | 60 ++++++++++++++++++++++++++++++++++++++++++ static/ng/package.json | 10 +++++++ 2 files changed, 70 insertions(+) create mode 100644 static/ng/Gruntfile.js create mode 100644 static/ng/package.json diff --git a/static/ng/Gruntfile.js b/static/ng/Gruntfile.js new file mode 100644 index 000000000..289622977 --- /dev/null +++ b/static/ng/Gruntfile.js @@ -0,0 +1,60 @@ +/*global module:false*/ +module.exports = function(grunt) { + + 'use strict'; + // Project configuration. + grunt.initConfig({ + // Task configuration. + jshint: { + options: { + browser: true, + curly: true, + freeze: true, + bitwise: true, + eqeqeq: true, + strict: true, + immed: true, + latedef: false, + newcap: false, + smarttabs: true, + noarg: true, + devel: true, + sub: true, + undef: true, + unused: false, + boss: true, + eqnull: true, + globals: { + jQuery: true, + angular: true, + $: true, + } + }, + gruntfile: { + src: 'Gruntfile.js' + }, + scripts: { + src: ['resources/**/**/*.js'] + } + }, + watch: { + gruntfile: { + files: '<%= jshint.gruntfile.src %>', + tasks: ['jshint:gruntfile'] + }, + scripts: { + files: '<%= jshint.scripts.src %>', + tasks: ['jshint:scripts'] + } + } + }); + + // These plugins provide necessary tasks. + grunt.loadNpmTasks('grunt-contrib-nodeunit'); + grunt.loadNpmTasks('grunt-contrib-jshint'); + grunt.loadNpmTasks('grunt-contrib-watch'); + + // Default task. + grunt.registerTask('default', ['jshint']); + +}; diff --git a/static/ng/package.json b/static/ng/package.json new file mode 100644 index 000000000..2bbc855f8 --- /dev/null +++ b/static/ng/package.json @@ -0,0 +1,10 @@ +{ + "engines": { + "node": ">= 0.10.0" + }, + "devDependencies": { + "grunt": "~0.4.5", + "grunt-contrib-jshint": "~0.10.0", + "grunt-contrib-watch": "~0.6.1", + } +} From 11a1f85282252e56d6caeeb21e8b852a09b2cb29 Mon Sep 17 00:00:00 2001 From: xiahaoshawn Date: Thu, 19 May 2016 17:34:00 +0800 Subject: [PATCH 2/3] delete nodeunit plugin --- static/ng/Gruntfile.js | 1 - static/ng/package.json | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/static/ng/Gruntfile.js b/static/ng/Gruntfile.js index 289622977..567dd3850 100644 --- a/static/ng/Gruntfile.js +++ b/static/ng/Gruntfile.js @@ -50,7 +50,6 @@ module.exports = function(grunt) { }); // These plugins provide necessary tasks. - grunt.loadNpmTasks('grunt-contrib-nodeunit'); grunt.loadNpmTasks('grunt-contrib-jshint'); grunt.loadNpmTasks('grunt-contrib-watch'); diff --git a/static/ng/package.json b/static/ng/package.json index 2bbc855f8..763d881ec 100644 --- a/static/ng/package.json +++ b/static/ng/package.json @@ -5,6 +5,6 @@ "devDependencies": { "grunt": "~0.4.5", "grunt-contrib-jshint": "~0.10.0", - "grunt-contrib-watch": "~0.6.1", + "grunt-contrib-watch": "~0.6.1" } } From 51fa12769b2b6683a95aa1881667e9e655e58f0d Mon Sep 17 00:00:00 2001 From: xiahaoshawn Date: Mon, 23 May 2016 15:43:15 +0800 Subject: [PATCH 3/3] add comments to the exported type --- controllers/ng/accountsetting.go | 2 ++ controllers/ng/adminoption.go | 2 ++ controllers/ng/base.go | 24 +++++++++++++++--------- controllers/ng/dashboard.go | 2 ++ controllers/ng/index.go | 2 ++ controllers/ng/navigationheader.go | 2 ++ controllers/ng/optionalmenu.go | 2 ++ controllers/ng/password.go | 2 ++ controllers/ng/project.go | 2 ++ controllers/ng/repository.go | 2 ++ controllers/ng/search.go | 2 ++ controllers/ng/signup.go | 2 ++ 12 files changed, 37 insertions(+), 9 deletions(-) diff --git a/controllers/ng/accountsetting.go b/controllers/ng/accountsetting.go index f98ff56c9..5bb240d9c 100644 --- a/controllers/ng/accountsetting.go +++ b/controllers/ng/accountsetting.go @@ -1,9 +1,11 @@ package ng +// AccountSettingController handles request to /ng/account_setting type AccountSettingController struct { BaseController } +// Get renders the account settings page func (asc *AccountSettingController) Get() { asc.Forward("Account Settings", "account-settings.htm") } diff --git a/controllers/ng/adminoption.go b/controllers/ng/adminoption.go index c0a56bb2d..1fc366296 100644 --- a/controllers/ng/adminoption.go +++ b/controllers/ng/adminoption.go @@ -1,9 +1,11 @@ package ng +// AdminOptionController handles requests to /ng/admin_option type AdminOptionController struct { BaseController } +// Get renders the admin options page func (aoc *AdminOptionController) Get() { aoc.Forward("Admin Options", "admin-options.htm") } diff --git a/controllers/ng/base.go b/controllers/ng/base.go index 3b0b94fc6..4171894e1 100644 --- a/controllers/ng/base.go +++ b/controllers/ng/base.go @@ -11,6 +11,7 @@ import ( "github.com/vmware/harbor/utils/log" ) +// BaseController wraps common methods such as i18n support, forward, which can be leveraged by other UI render controllers. type BaseController struct { beego.Controller i18n.Locale @@ -84,32 +85,37 @@ func (b *BaseController) Prepare() { } -func (bc *BaseController) Forward(title, templateName string) { - bc.Layout = filepath.Join(prefixNg, "layout.htm") - bc.TplName = filepath.Join(prefixNg, templateName) - bc.Data["Title"] = title - bc.LayoutSections = make(map[string]string) - bc.LayoutSections["HeaderInclude"] = filepath.Join(prefixNg, viewPath, "header-include.htm") - bc.LayoutSections["FooterInclude"] = filepath.Join(prefixNg, viewPath, "footer-include.htm") - bc.LayoutSections["HeaderContent"] = filepath.Join(prefixNg, viewPath, "header-content.htm") - bc.LayoutSections["FooterContent"] = filepath.Join(prefixNg, viewPath, "footer-content.htm") +// Forward to setup layout and template for content for a page. +func (b *BaseController) Forward(title, templateName string) { + b.Layout = filepath.Join(prefixNg, "layout.htm") + b.TplName = filepath.Join(prefixNg, templateName) + b.Data["Title"] = title + b.LayoutSections = make(map[string]string) + b.LayoutSections["HeaderInclude"] = filepath.Join(prefixNg, viewPath, "header-include.htm") + b.LayoutSections["FooterInclude"] = filepath.Join(prefixNg, viewPath, "footer-include.htm") + b.LayoutSections["HeaderContent"] = filepath.Join(prefixNg, viewPath, "header-content.htm") + b.LayoutSections["FooterContent"] = filepath.Join(prefixNg, viewPath, "footer-content.htm") } var langTypes []*langType +// CommonController handles request from UI that doesn't expect a page, such as /SwitchLanguage /logout ... type CommonController struct { BaseController } +// Render returns nil. func (cc *CommonController) Render() error { return nil } +// LogOut Habor UI func (cc *CommonController) LogOut() { cc.DestroySession() } +// SwitchLanguage User can swith to prefered language func (cc *CommonController) SwitchLanguage() { lang := cc.GetString("lang") if _, exist := supportLanguages[lang]; exist { diff --git a/controllers/ng/dashboard.go b/controllers/ng/dashboard.go index ca9ddc95c..9fa0a6448 100644 --- a/controllers/ng/dashboard.go +++ b/controllers/ng/dashboard.go @@ -1,9 +1,11 @@ package ng +// DashboardController handles requests to /ng/dashboard type DashboardController struct { BaseController } +// Get renders the dashboard page func (dc *DashboardController) Get() { dc.Forward("Dashboard", "dashboard.htm") } diff --git a/controllers/ng/index.go b/controllers/ng/index.go index 0c34fe58b..69020cbad 100644 --- a/controllers/ng/index.go +++ b/controllers/ng/index.go @@ -1,9 +1,11 @@ package ng +// IndexController handles request to /ng type IndexController struct { BaseController } +// Get renders the index page func (ic *IndexController) Get() { ic.Forward("Index", "index.htm") } diff --git a/controllers/ng/navigationheader.go b/controllers/ng/navigationheader.go index 69276bbb9..2f88723f9 100644 --- a/controllers/ng/navigationheader.go +++ b/controllers/ng/navigationheader.go @@ -8,10 +8,12 @@ import ( "github.com/vmware/harbor/utils/log" ) +// NavigationHeaderController handles requests to /ng/navigation_header type NavigationHeaderController struct { BaseController } +// Get renders user's navigation header func (nhc *NavigationHeaderController) Get() { sessionUserID := nhc.GetSession("userId") var hasLoggedIn bool diff --git a/controllers/ng/optionalmenu.go b/controllers/ng/optionalmenu.go index 6945681dc..7afac21e6 100644 --- a/controllers/ng/optionalmenu.go +++ b/controllers/ng/optionalmenu.go @@ -8,10 +8,12 @@ import ( "github.com/vmware/harbor/utils/log" ) +// OptionalMenuController handles request to /ng/optional_menu type OptionalMenuController struct { BaseController } +// Get renders optional menu, Admin user has "Add User" menu func (omc *OptionalMenuController) Get() { sessionUserID := omc.GetSession("userId") diff --git a/controllers/ng/password.go b/controllers/ng/password.go index f6f169c4a..4a655ff95 100644 --- a/controllers/ng/password.go +++ b/controllers/ng/password.go @@ -95,10 +95,12 @@ func (cc *CommonController) SendEmail() { } +// ForgotPasswordController handles requests to /ng/forgot_password type ForgotPasswordController struct { BaseController } +// Get renders forgot password page func (fpc *ForgotPasswordController) Get() { fpc.Forward("Forgot Password", "forgot-password.htm") } diff --git a/controllers/ng/project.go b/controllers/ng/project.go index 79a02185f..af5dcd7a9 100644 --- a/controllers/ng/project.go +++ b/controllers/ng/project.go @@ -1,9 +1,11 @@ package ng +// ProjectController handles requests to /ng/projec type ProjectController struct { BaseController } +// Get renders project page func (pc *ProjectController) Get() { pc.Forward("My Projects", "project.htm") } diff --git a/controllers/ng/repository.go b/controllers/ng/repository.go index 696def246..e9173f15e 100644 --- a/controllers/ng/repository.go +++ b/controllers/ng/repository.go @@ -2,10 +2,12 @@ package ng import "os" +// RepositoryController handles request to /ng/repository type RepositoryController struct { BaseController } +// Get renders repository page func (rc *RepositoryController) Get() { rc.Data["HarborRegUrl"] = os.Getenv("HARBOR_REG_URL") rc.Forward("Repository", "repository.htm") diff --git a/controllers/ng/search.go b/controllers/ng/search.go index 341c864a0..0d6f3321e 100644 --- a/controllers/ng/search.go +++ b/controllers/ng/search.go @@ -1,9 +1,11 @@ package ng +// SearchController handles request to ng/search type SearchController struct { BaseController } +// Get rendlers search bar func (sc *SearchController) Get() { sc.Forward("Search", "search.htm") } diff --git a/controllers/ng/signup.go b/controllers/ng/signup.go index e2883f4a9..28d77761a 100644 --- a/controllers/ng/signup.go +++ b/controllers/ng/signup.go @@ -1,9 +1,11 @@ package ng +// SignUpController handles requests to /ng/sign_up type SignUpController struct { BaseController } +// Get renders sign up page func (suc *SignUpController) Get() { suc.Forward("Sign Up", "sign-up.htm") }