From 6793ef00692aee3d73d5e37ded0b8cff6b4c1029 Mon Sep 17 00:00:00 2001 From: Hester Gong Date: Thu, 20 Apr 2023 16:58:26 +0800 Subject: [PATCH 1/6] Use secondary pointing menu for tabs on user/organization home page (#24162) Close #24108 Use secondary pointing menu for tabs on user/organization home page so the tabs look the same. Main changes: 1. modified a part of dom structure in `templates/user/overview/header.tmpl` to make it the same as `templates/org/header.tmpl` in order to produce the same ui. 2. Move some css to `web_src/css/shared/repoorgshared.css` to make them shareable between `templates/user/overview/header.tmpl` and `templates/org/header.tmpl` After: https://user-images.githubusercontent.com/17645053/232400617-2add5bec-d483-4ab1-b48d-eaee157f7b09.mov For further improvements. Need some thoughts: For [this TODO](https://github.com/HesterG/gitea/blob/729ad294cbec7a77623b2e3eab750ea7a20e8ee0/templates/user/overview/header.tmpl#L1), it is viable to make it a shared template for [this part](https://github.com/HesterG/gitea/blob/729ad294cbec7a77623b2e3eab750ea7a20e8ee0/templates/user/overview/header.tmpl#L2-L17) and [this part](https://github.com/HesterG/gitea/blob/729ad294cbec7a77623b2e3eab750ea7a20e8ee0/templates/org/header.tmpl#L1-L16) because they are the same except for the variable. But for the menu parts, they are quite different so might not be suitable to use a shared template. So need some thoughts and advice about extracting the shared template from these two headers. --------- Co-authored-by: Giteabot --- templates/user/overview/header.tmpl | 133 ++++++++++++++-------------- web_src/css/index.css | 1 + web_src/css/organization.css | 12 --- web_src/css/repository.css | 9 +- web_src/css/shared/repoorg.css | 19 ++++ 5 files changed, 88 insertions(+), 86 deletions(-) create mode 100644 web_src/css/shared/repoorg.css diff --git a/templates/user/overview/header.tmpl b/templates/user/overview/header.tmpl index b4f7d6f90091..7dfbe345639f 100644 --- a/templates/user/overview/header.tmpl +++ b/templates/user/overview/header.tmpl @@ -1,85 +1,82 @@ -
- - {{with .ContextUser}} -
-
-
-
- {{avatar $.Context . 100}} - {{.DisplayName}} - - {{if .Visibility.IsLimited}}
{{$.locale.Tr "org.settings.visibility.limited_shortname"}}
{{end}} - {{if .Visibility.IsPrivate}}
{{$.locale.Tr "org.settings.visibility.private_shortname"}}
{{end}} -
-
+ +{{with .ContextUser}} +
+
+
+
+ {{avatar $.Context . 100}} + {{.DisplayName}} + + {{if .Visibility.IsLimited}}
{{$.locale.Tr "org.settings.visibility.limited_shortname"}}
{{end}} + {{if .Visibility.IsPrivate}}
{{$.locale.Tr "org.settings.visibility.private_shortname"}}
{{end}} +
- {{end}} +
+{{end}} -
- diff --git a/web_src/css/index.css b/web_src/css/index.css index e8d4e290d084..253083033862 100644 --- a/web_src/css/index.css +++ b/web_src/css/index.css @@ -2,6 +2,7 @@ @import "./animations.css"; @import "./shared/issuelist.css"; +@import "./shared/repoorg.css"; @import "./features/dropzone.css"; @import "./features/gitgraph.css"; @import "./features/heatmap.css"; diff --git a/web_src/css/organization.css b/web_src/css/organization.css index 35eaa3ae2218..42a6dcc5eac8 100644 --- a/web_src/css/organization.css +++ b/web_src/css/organization.css @@ -40,12 +40,6 @@ } } -.organization .head .ui.header .text { - vertical-align: middle; - font-size: 1.6rem; - margin-left: 15px; -} - .organization .head .ui.header .org-visibility .label { margin-left: 5px; margin-top: 5px; @@ -55,12 +49,6 @@ margin-top: 5px; } -.organization .ui.secondary.stackable.pointing.menu { - flex-wrap: wrap; - margin-top: 5px; - margin-bottom: 10px; -} - .organization.new.org form { margin: auto; } diff --git a/web_src/css/repository.css b/web_src/css/repository.css index 8674793bf0eb..77b41e4d1607 100644 --- a/web_src/css/repository.css +++ b/web_src/css/repository.css @@ -153,12 +153,9 @@ padding-left: 23px; } -.repository .ui.tabs.container { - margin-top: 14px; - margin-bottom: 0; -} - -.repository .ui.tabs.container .ui.menu { +/* For the secondary pointing menu, respect its own border-bottom */ +/* style reference: https://semantic-ui.com/collections/menu.html#pointing */ +.repository .ui.tabs.container .ui.menu:not(.secondary.pointing) { border-bottom: 0; } diff --git a/web_src/css/shared/repoorg.css b/web_src/css/shared/repoorg.css new file mode 100644 index 000000000000..ee9d94bafac6 --- /dev/null +++ b/web_src/css/shared/repoorg.css @@ -0,0 +1,19 @@ +.repository .head .ui.header .text, +.organization .head .ui.header .text { + vertical-align: middle; + font-size: 1.6rem; + margin-left: 15px; +} + +.repository .ui.secondary.stackable.pointing.menu, +.organization .ui.secondary.stackable.pointing.menu { + flex-wrap: wrap; + margin-top: 5px; + margin-bottom: 10px; +} + +.repository .ui.tabs.container, +.organization .ui.tabs.container { + margin-top: 14px; + margin-bottom: 0; +} From 8ea33baa1ce49168f74f7588f858c2f8327d5bfb Mon Sep 17 00:00:00 2001 From: yp05327 <576951401@qq.com> Date: Thu, 20 Apr 2023 18:28:27 +0900 Subject: [PATCH 2/6] Introduce eslint-plugin-no-jquery/no-event-shorthand (#24198) https://github.com/go-gitea/gitea/pull/24098#issuecomment-1514010690 --------- Co-authored-by: silverwind --- .eslintrc.yaml | 2 ++ package-lock.json | 10 ++++++++++ package.json | 1 + web_src/js/features/admin/common.js | 4 ++-- web_src/js/features/admin/users.js | 8 ++++---- web_src/js/features/citation.js | 2 +- web_src/js/features/common-global.js | 2 +- web_src/js/features/repo-common.js | 2 +- web_src/js/features/repo-issue.js | 4 ++-- web_src/js/features/repo-legacy.js | 2 +- web_src/js/features/repo-projects.js | 4 ++-- web_src/js/features/user-auth.js | 2 +- 12 files changed, 28 insertions(+), 15 deletions(-) diff --git a/.eslintrc.yaml b/.eslintrc.yaml index bb7e7c09a83d..a3a89e76d4f4 100644 --- a/.eslintrc.yaml +++ b/.eslintrc.yaml @@ -12,6 +12,7 @@ plugins: - eslint-plugin-unicorn - eslint-plugin-import - eslint-plugin-jquery + - eslint-plugin-no-jquery - eslint-plugin-sonarjs - eslint-plugin-custom-elements @@ -192,6 +193,7 @@ rules: jquery/no-val: [0] jquery/no-when: [2] jquery/no-wrap: [2] + no-jquery/no-event-shorthand: [2] key-spacing: [2] keyword-spacing: [2] line-comment-position: [0] diff --git a/package-lock.json b/package-lock.json index 3e8e35615f69..9a2f5dc5783f 100644 --- a/package-lock.json +++ b/package-lock.json @@ -64,6 +64,7 @@ "eslint-plugin-custom-elements": "0.0.8", "eslint-plugin-import": "2.27.5", "eslint-plugin-jquery": "1.5.1", + "eslint-plugin-no-jquery": "2.7.0", "eslint-plugin-sonarjs": "0.19.0", "eslint-plugin-unicorn": "46.0.0", "eslint-plugin-vue": "9.11.0", @@ -4550,6 +4551,15 @@ "eslint": ">=5.4.0" } }, + "node_modules/eslint-plugin-no-jquery": { + "version": "2.7.0", + "resolved": "https://registry.npmjs.org/eslint-plugin-no-jquery/-/eslint-plugin-no-jquery-2.7.0.tgz", + "integrity": "sha512-Aeg7dA6GTH1AcWLlBtWNzOU9efK5KpNi7b0EhBO0o0M+awyzguUUo8gF6hXGjQ9n5h8/uRtYv9zOqQkeC5CG0w==", + "dev": true, + "peerDependencies": { + "eslint": ">=2.3.0" + } + }, "node_modules/eslint-plugin-sonarjs": { "version": "0.19.0", "resolved": "https://registry.npmjs.org/eslint-plugin-sonarjs/-/eslint-plugin-sonarjs-0.19.0.tgz", diff --git a/package.json b/package.json index cca95a16467f..ae3b7446fe5a 100644 --- a/package.json +++ b/package.json @@ -64,6 +64,7 @@ "eslint-plugin-custom-elements": "0.0.8", "eslint-plugin-import": "2.27.5", "eslint-plugin-jquery": "1.5.1", + "eslint-plugin-no-jquery": "2.7.0", "eslint-plugin-sonarjs": "0.19.0", "eslint-plugin-unicorn": "46.0.0", "eslint-plugin-vue": "9.11.0", diff --git a/web_src/js/features/admin/common.js b/web_src/js/features/admin/common.js index 8f895152c77b..84fd35e08104 100644 --- a/web_src/js/features/admin/common.js +++ b/web_src/js/features/admin/common.js @@ -21,7 +21,7 @@ export function initAdminCommon() { $('#login_name').removeAttr('required'); hideElem($('.non-local')); showElem($('.local')); - $('#user_name').focus(); + $('#user_name').trigger('focus'); if ($(this).data('password') === 'required') { $('#password').attr('required', 'required'); @@ -33,7 +33,7 @@ export function initAdminCommon() { $('#login_name').attr('required', 'required'); showElem($('.non-local')); hideElem($('.local')); - $('#login_name').focus(); + $('#login_name').trigger('focus'); $('#password').removeAttr('required'); } diff --git a/web_src/js/features/admin/users.js b/web_src/js/features/admin/users.js index 2221fc492960..c8edaab54932 100644 --- a/web_src/js/features/admin/users.js +++ b/web_src/js/features/admin/users.js @@ -16,19 +16,19 @@ export function initAdminUserListSearchForm() { } } - $form.find(`input[type=radio]`).click(() => { - $form.submit(); + $form.find(`input[type=radio]`).on('click', () => { + $form.trigger('submit'); return false; }); - $form.find('.j-reset-status-filter').click(() => { + $form.find('.j-reset-status-filter').on('click', () => { $form.find(`input[type=radio]`).each((_, e) => { const $e = $(e); if ($e.attr('name').startsWith('status_filter[')) { $e.prop('checked', false); } }); - $form.submit(); + $form.trigger('submit'); return false; }); } diff --git a/web_src/js/features/citation.js b/web_src/js/features/citation.js index c40b1adddd14..65666864f695 100644 --- a/web_src/js/features/citation.js +++ b/web_src/js/features/citation.js @@ -51,7 +51,7 @@ export function initCitationFileCopyContent() { }); $inputContent.on('click', () => { - $inputContent.select(); + $inputContent.trigger('select'); }); $('#cite-repo-button').on('click', () => { diff --git a/web_src/js/features/common-global.js b/web_src/js/features/common-global.js index 0d80dc2091c3..16aedc6433c3 100644 --- a/web_src/js/features/common-global.js +++ b/web_src/js/features/common-global.js @@ -68,7 +68,7 @@ export function initGlobalButtonClickOnEnter() { export function initGlobalCommon() { // Undo Safari emoji glitch fix at high enough zoom levels if (navigator.userAgent.match('Safari')) { - $(window).resize(() => { + $(window).on('resize', () => { const px = mqBinarySearch('width', 0, 4096, 1, 'px'); const em = mqBinarySearch('width', 0, 1024, 0.01, 'em'); if (em * 16 * 1.25 - px <= -1) { diff --git a/web_src/js/features/repo-common.js b/web_src/js/features/repo-common.js index 1a32d7cb6442..d99a1a8da08c 100644 --- a/web_src/js/features/repo-common.js +++ b/web_src/js/features/repo-common.js @@ -69,7 +69,7 @@ export function initRepoCloneLink() { }); $inputLink.on('focus', () => { - $inputLink.select(); + $inputLink.trigger('select'); }); } diff --git a/web_src/js/features/repo-issue.js b/web_src/js/features/repo-issue.js index a6105f7b2419..63fae3a37cb4 100644 --- a/web_src/js/features/repo-issue.js +++ b/web_src/js/features/repo-issue.js @@ -313,7 +313,7 @@ export function initRepoIssueWipTitle() { e.preventDefault(); const $issueTitle = $('#issue_title'); - $issueTitle.focus(); + $issueTitle.trigger('focus'); const value = $issueTitle.val().trim().toUpperCase(); const wipPrefixes = $('.title_wip_desc').data('wip-prefixes'); @@ -573,7 +573,7 @@ export function initRepoIssueTitleEdit() { toggleElem($('#pull-desc-edit')); toggleElem($('.in-edit')); $('#issue-title-wrapper').toggleClass('edit-active'); - $editInput.focus(); + $editInput.trigger('focus'); return false; }; diff --git a/web_src/js/features/repo-legacy.js b/web_src/js/features/repo-legacy.js index 8ac8cd15c19e..851a9b855e6b 100644 --- a/web_src/js/features/repo-legacy.js +++ b/web_src/js/features/repo-legacy.js @@ -57,7 +57,7 @@ export function initRepoCommentForm() { const $selectBranch = $('.ui.select-branch'); const $branchMenu = $selectBranch.find('.reference-list-menu'); const $isNewIssue = $branchMenu.hasClass('new-issue'); - $branchMenu.find('.item:not(.no-select)').click(function () { + $branchMenu.find('.item:not(.no-select)').on('click', function () { const selectedValue = $(this).data('id'); const editMode = $('#editing_mode').val(); $($(this).data('id-selector')).val(selectedValue); diff --git a/web_src/js/features/repo-projects.js b/web_src/js/features/repo-projects.js index a2679130d70f..953671b41d2a 100644 --- a/web_src/js/features/repo-projects.js +++ b/web_src/js/features/repo-projects.js @@ -153,7 +153,7 @@ export function initRepoProject() { }); $('.delete-project-board').each(function () { - $(this).click(function (e) { + $(this).on('click', function (e) { e.preventDefault(); $.ajax({ @@ -169,7 +169,7 @@ export function initRepoProject() { }); }); - $('#new_board_submit').click(function (e) { + $('#new_board_submit').on('click', function (e) { e.preventDefault(); const boardTitle = $('#new_board'); diff --git a/web_src/js/features/user-auth.js b/web_src/js/features/user-auth.js index 34e773fe7db4..60ea14dfaa54 100644 --- a/web_src/js/features/user-auth.js +++ b/web_src/js/features/user-auth.js @@ -5,7 +5,7 @@ export function initUserAuthOauth2() { const $oauth2LoginNav = $('#oauth2-login-navigator'); if ($oauth2LoginNav.length === 0) return; - $oauth2LoginNav.find('.oauth-login-image').click(() => { + $oauth2LoginNav.find('.oauth-login-image').on('click', () => { const oauthLoader = $('#oauth2-login-loader'); const oauthNav = $('#oauth2-login-navigator'); From 70fc47a22a0bfaef7fb16dcc8a6a2e011b10f8d4 Mon Sep 17 00:00:00 2001 From: wxiaoguang Date: Fri, 21 Apr 2023 01:33:30 +0800 Subject: [PATCH 3/6] Fix unclear "Owner" concept (#24233) Some user/org pages use `Owner` variable. It's an incorrect concept since year 2016: what is a user's owner? Actually, new code is right: use `ContextUser`. This PR cleans all legacy "Owner" variables. ## Screenshots for related pages and test results All pages are as before: ### `web/org/home.go` ![image](https://user-images.githubusercontent.com/2114189/233366687-a3643025-1f78-474d-a901-deea35b72f4d.png) ### `web/user/profile.go` ![image](https://user-images.githubusercontent.com/2114189/233366812-2e5c2fbc-3f78-44e7-88c1-ec2f612c241e.png) ### `web/user/setting/profile.go` ![image](https://user-images.githubusercontent.com/2114189/233366928-7a1e52c9-b400-4379-a4be-af06a853c5fa.png) --- routers/web/org/home.go | 1 - routers/web/user/profile.go | 2 +- routers/web/user/setting/profile.go | 2 +- templates/base/head.tmpl | 10 +++--- templates/org/menu.tmpl | 4 +-- templates/user/overview/header.tmpl | 4 +-- templates/user/profile.tmpl | 56 ++++++++++++++--------------- templates/user/settings/repos.tmpl | 2 +- 8 files changed, 40 insertions(+), 41 deletions(-) diff --git a/routers/web/org/home.go b/routers/web/org/home.go index 8c9cc8a9d86b..201eefa61402 100644 --- a/routers/web/org/home.go +++ b/routers/web/org/home.go @@ -143,7 +143,6 @@ func Home(ctx *context.Context) { return } - ctx.Data["Owner"] = org ctx.Data["Repos"] = repos ctx.Data["Total"] = count ctx.Data["MembersTotal"] = membersCount diff --git a/routers/web/user/profile.go b/routers/web/user/profile.go index b39ba58f1245..367bb306b83c 100644 --- a/routers/web/user/profile.go +++ b/routers/web/user/profile.go @@ -63,7 +63,7 @@ func Profile(ctx *context.Context) { ctx.Data["Title"] = ctx.ContextUser.DisplayName() ctx.Data["PageIsUserProfile"] = true - ctx.Data["Owner"] = ctx.ContextUser + ctx.Data["ContextUser"] = ctx.ContextUser ctx.Data["OpenIDs"] = openIDs ctx.Data["IsFollowing"] = isFollowing diff --git a/routers/web/user/setting/profile.go b/routers/web/user/setting/profile.go index f500be763233..0a8a5e6280c4 100644 --- a/routers/web/user/setting/profile.go +++ b/routers/web/user/setting/profile.go @@ -326,7 +326,7 @@ func Repos(ctx *context.Context) { ctx.Data["Repos"] = repos } - ctx.Data["Owner"] = ctxUser + ctx.Data["ContextUser"] = ctxUser pager := context.NewPagination(count, opts.PageSize, opts.Page, 5) pager.SetDefaultParams(ctx) ctx.Data["Page"] = pager diff --git a/templates/base/head.tmpl b/templates/base/head.tmpl index d179140b23b2..3932a585983e 100644 --- a/templates/base/head.tmpl +++ b/templates/base/head.tmpl @@ -30,12 +30,12 @@ {{if .PageIsUserProfile}} - + - - - {{if .Owner.Description}} - + + + {{if .ContextUser.Description}} + {{end}} {{else if .Repository}} {{if .Issue}} diff --git a/templates/org/menu.tmpl b/templates/org/menu.tmpl index 39189b0c8403..1bb19a0673db 100644 --- a/templates/org/menu.tmpl +++ b/templates/org/menu.tmpl @@ -2,8 +2,8 @@