From 393ee1c3cd731f47d7b2aa15f59ba9c49709e691 Mon Sep 17 00:00:00 2001 From: sillyguodong Date: Thu, 27 Apr 2023 17:00:53 +0800 Subject: [PATCH 01/16] move to the page of branches list --- options/locale/locale_en-US.ini | 3 ++ routers/web/repo/setting_protected_branch.go | 8 ++--- templates/base/head_script.tmpl | 1 + templates/repo/branch/list.tmpl | 35 ++++++++++++++++++++ templates/repo/settings/branches.tmpl | 22 ------------ web_src/js/features/repo-branch.js | 26 +++++++++++++++ 6 files changed, 69 insertions(+), 26 deletions(-) diff --git a/options/locale/locale_en-US.ini b/options/locale/locale_en-US.ini index 54e041d7854a8..bcef3f457a274 100644 --- a/options/locale/locale_en-US.ini +++ b/options/locale/locale_en-US.ini @@ -2396,10 +2396,13 @@ branch.protected_deletion_failed = Branch "%s" is protected. It cannot be delete branch.default_deletion_failed = Branch "%s" is the default branch. It cannot be deleted. branch.restore = Restore Branch "%s" branch.download = Download Branch "%s" +branch.rename = Rename Branch "%s" branch.included_desc = This branch is part of the default branch branch.included = Included branch.create_new_branch = Create branch from branch: branch.confirm_create_branch = Create branch +branch.rename_branch_to = Rename "%s" to: +branch.confirm_rename_branch = Rename branch branch.create_branch_operation = Create branch branch.new_branch = Create new branch branch.new_branch_from = Create new branch from "%s" diff --git a/routers/web/repo/setting_protected_branch.go b/routers/web/repo/setting_protected_branch.go index 34e84c4656827..f01ee98ce0757 100644 --- a/routers/web/repo/setting_protected_branch.go +++ b/routers/web/repo/setting_protected_branch.go @@ -352,7 +352,7 @@ func RenameBranchPost(ctx *context.Context) { if ctx.HasError() { ctx.Flash.Error(ctx.GetErrMsg()) - ctx.Redirect(fmt.Sprintf("%s/settings/branches", ctx.Repo.RepoLink)) + ctx.Redirect(fmt.Sprintf("%s/branches", ctx.Repo.RepoLink)) return } @@ -364,16 +364,16 @@ func RenameBranchPost(ctx *context.Context) { if msg == "target_exist" { ctx.Flash.Error(ctx.Tr("repo.settings.rename_branch_failed_exist", form.To)) - ctx.Redirect(fmt.Sprintf("%s/settings/branches", ctx.Repo.RepoLink)) + ctx.Redirect(fmt.Sprintf("%s/branches", ctx.Repo.RepoLink)) return } if msg == "from_not_exist" { ctx.Flash.Error(ctx.Tr("repo.settings.rename_branch_failed_not_exist", form.From)) - ctx.Redirect(fmt.Sprintf("%s/settings/branches", ctx.Repo.RepoLink)) + ctx.Redirect(fmt.Sprintf("%s/branches", ctx.Repo.RepoLink)) return } ctx.Flash.Success(ctx.Tr("repo.settings.rename_branch_success", form.From, form.To)) - ctx.Redirect(fmt.Sprintf("%s/settings/branches", ctx.Repo.RepoLink)) + ctx.Redirect(fmt.Sprintf("%s/branches", ctx.Repo.RepoLink)) } diff --git a/templates/base/head_script.tmpl b/templates/base/head_script.tmpl index d19fae629bd97..0d8418449a266 100644 --- a/templates/base/head_script.tmpl +++ b/templates/base/head_script.tmpl @@ -39,6 +39,7 @@ If you introduce mistakes in it, Gitea JavaScript code wouldn't run correctly. error_occurred: '{{.locale.Tr "error.occurred"}}', network_error: '{{.locale.Tr "error.network_error"}}', remove_label_str: '{{.locale.Tr "remove_label_str"}}', + rename_branch_to: '{{.locale.Tr "repo.branch.rename_branch_to"}}', }, }; {{/* in case some pages don't render the pageData, we make sure it is an object to prevent null access */}} diff --git a/templates/repo/branch/list.tmpl b/templates/repo/branch/list.tmpl index 596d9ae78bd67..c05e1aa51ee1d 100644 --- a/templates/repo/branch/list.tmpl +++ b/templates/repo/branch/list.tmpl @@ -40,6 +40,11 @@ {{end}} + {{if and $.IsWriter (not $.Repository.IsArchived) (not .IsDeleted) (not .IsProtected)}} + + {{end}} @@ -132,6 +137,11 @@ {{end}} + {{if and $.IsWriter (not $.Repository.IsArchived) (not .IsDeleted) (not .IsProtected)}} + + {{end}} {{if and $.IsWriter (not $.IsMirror) (not $.Repository.IsArchived) (not .IsProtected)}} {{if .IsDeleted}} + + + + + {{template "base/footer" .}} diff --git a/templates/repo/settings/branches.tmpl b/templates/repo/settings/branches.tmpl index f74a2a837db66..78cf767225b48 100644 --- a/templates/repo/settings/branches.tmpl +++ b/templates/repo/settings/branches.tmpl @@ -66,28 +66,6 @@ - - {{if $.Repository.CanCreateBranch}} -

- {{.locale.Tr "repo.settings.rename_branch"}} -

-
-
- {{.CsrfTokenHtml}} -
- - -
-
- - -
-
- -
-
-
- {{end}} {{end}} diff --git a/web_src/js/features/repo-branch.js b/web_src/js/features/repo-branch.js index 946f7f90a447a..6c92be0d1a87e 100644 --- a/web_src/js/features/repo-branch.js +++ b/web_src/js/features/repo-branch.js @@ -1,6 +1,19 @@ import $ from 'jquery'; +const { i18n } = window.config; +const renameBranchFromInputSelector = "input#from" +const renameBranchModalSelector = "#rename-branch-modal" +const renameBranchToSpanSelector = "#modal-rename-branch-to-span" + export function initRepoBranchButton() { + initRepoCreateBranchButton(); + initRepoRenameBranchButton(); +} + +function initRepoCreateBranchButton() { + const showCreateBranchModal = $('.show-create-branch-modal'); + if (showCreateBranchModal.length === 0) return; + $('.show-create-branch-modal').on('click', function () { let modalFormName = $(this).attr('data-modal-form'); if (!modalFormName) { @@ -16,3 +29,16 @@ export function initRepoBranchButton() { $($(this).attr('data-modal')).modal('show'); }); } + +function initRepoRenameBranchButton() { + const showRenameBranchModal = $('.show-rename-branch-modal'); + if (showRenameBranchModal.length === 0) return; + + $('.show-rename-branch-modal').on('click', function () { + const oldBranchName = $(this).attr('data-old-branch-name'); + $(renameBranchFromInputSelector)?.val(oldBranchName); + console.log($(renameBranchFromInputSelector)); + $(renameBranchToSpanSelector).text(i18n.rename_branch_to.replace('%s', oldBranchName)); + $(renameBranchModalSelector).modal('show'); + }) +} From 89dfff46d2078a056db1fae925df6c824b78ab66 Mon Sep 17 00:00:00 2001 From: sillyguodong Date: Thu, 27 Apr 2023 17:24:14 +0800 Subject: [PATCH 02/16] fix lint --- web_src/js/features/repo-branch.js | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/web_src/js/features/repo-branch.js b/web_src/js/features/repo-branch.js index 6c92be0d1a87e..27cf709fdadd1 100644 --- a/web_src/js/features/repo-branch.js +++ b/web_src/js/features/repo-branch.js @@ -1,9 +1,9 @@ import $ from 'jquery'; -const { i18n } = window.config; -const renameBranchFromInputSelector = "input#from" -const renameBranchModalSelector = "#rename-branch-modal" -const renameBranchToSpanSelector = "#modal-rename-branch-to-span" +const {i18n} = window.config; +const renameBranchFromInputSelector = 'input#from'; +const renameBranchModalSelector = '#rename-branch-modal'; +const renameBranchToSpanSelector = '#modal-rename-branch-to-span'; export function initRepoBranchButton() { initRepoCreateBranchButton(); @@ -37,8 +37,7 @@ function initRepoRenameBranchButton() { $('.show-rename-branch-modal').on('click', function () { const oldBranchName = $(this).attr('data-old-branch-name'); $(renameBranchFromInputSelector)?.val(oldBranchName); - console.log($(renameBranchFromInputSelector)); $(renameBranchToSpanSelector).text(i18n.rename_branch_to.replace('%s', oldBranchName)); $(renameBranchModalSelector).modal('show'); - }) + }); } From 721e8cbe3fe9840d260b4d09591fa1afaee738f7 Mon Sep 17 00:00:00 2001 From: sillyguodong Date: Thu, 27 Apr 2023 17:46:34 +0800 Subject: [PATCH 03/16] use comfirm component --- templates/repo/branch/list.tmpl | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/templates/repo/branch/list.tmpl b/templates/repo/branch/list.tmpl index c05e1aa51ee1d..e3eab660c87e7 100644 --- a/templates/repo/branch/list.tmpl +++ b/templates/repo/branch/list.tmpl @@ -204,7 +204,7 @@ - {{end}} {{if and $.IsWriter (not $.Repository.IsArchived) (not .IsDeleted) (not .IsProtected)}} - {{end}} {{if and $.IsWriter (not $.IsMirror) (not $.Repository.IsArchived) (not .IsProtected)}} {{if .IsDeleted}} - + {{else}} - + {{end}} {{end}} @@ -217,7 +217,7 @@ -
+
@@ -228,3 +228,9 @@
{{template "base/footer" .}} + + diff --git a/web_src/css/repository.css b/web_src/css/repository.css index 80e2e1cb8b405..e0b494c567ef9 100644 --- a/web_src/css/repository.css +++ b/web_src/css/repository.css @@ -1332,6 +1332,15 @@ left: 0; } +.repository.branches .table a:hover { + text-decoration: none; +} + +.repository.branches .table .ui.dropdown:hover { + color: var(--color-primary); +} + + .repository.commits .header .search input { font-weight: normal; padding: 5px 10px; diff --git a/web_src/js/features/repo-branch.js b/web_src/js/features/repo-branch.js index 27cf709fdadd1..bfb32ad96cb6b 100644 --- a/web_src/js/features/repo-branch.js +++ b/web_src/js/features/repo-branch.js @@ -1,6 +1,6 @@ import $ from 'jquery'; -const {i18n} = window.config; +const {i18n_branch} = window.config; const renameBranchFromInputSelector = 'input#from'; const renameBranchModalSelector = '#rename-branch-modal'; const renameBranchToSpanSelector = '#modal-rename-branch-to-span'; @@ -37,7 +37,7 @@ function initRepoRenameBranchButton() { $('.show-rename-branch-modal').on('click', function () { const oldBranchName = $(this).attr('data-old-branch-name'); $(renameBranchFromInputSelector)?.val(oldBranchName); - $(renameBranchToSpanSelector).text(i18n.rename_branch_to.replace('%s', oldBranchName)); + $(renameBranchToSpanSelector).text(i18n_branch.rename_branch_to.replace('%s', oldBranchName)); $(renameBranchModalSelector).modal('show'); }); } From 23b053b31a91e3994f41b4f3f767d4fc6dcb904e Mon Sep 17 00:00:00 2001 From: sillyguodong Date: Fri, 28 Apr 2023 11:53:42 +0800 Subject: [PATCH 05/16] reuse show-modal logic --- templates/repo/branch/list.tmpl | 41 ++++++++++++++++++++++-------- web_src/js/features/repo-branch.js | 10 +------- 2 files changed, 32 insertions(+), 19 deletions(-) diff --git a/templates/repo/branch/list.tmpl b/templates/repo/branch/list.tmpl index 1a9a8ae091049..2a7cf941db166 100644 --- a/templates/repo/branch/list.tmpl +++ b/templates/repo/branch/list.tmpl @@ -1,4 +1,9 @@ {{template "base/head" .}} +
{{template "repo/header" .}}
@@ -22,7 +27,13 @@ {{if and $.IsWriter (not $.Repository.IsArchived) (not .IsDeleted)}} - + {{svg "octicon-git-branch"}} {{end}} @@ -41,7 +52,12 @@
{{end}} {{if and $.IsWriter (not $.Repository.IsArchived) (not .IsDeleted) (not .IsProtected)}} - + {{svg "octicon-pencil"}} {{end}} @@ -119,7 +135,13 @@ {{if and $.IsWriter (not $.Repository.IsArchived) (not .IsDeleted)}} - + {{svg "octicon-git-branch"}} {{end}} @@ -138,7 +160,12 @@
{{end}} {{if and $.IsWriter (not $.Repository.IsArchived) (not .IsDeleted) (not .IsProtected)}} - + {{svg "octicon-pencil"}} {{end}} @@ -228,9 +255,3 @@ {{template "base/footer" .}} - - diff --git a/web_src/js/features/repo-branch.js b/web_src/js/features/repo-branch.js index bfb32ad96cb6b..8bbe6b797e804 100644 --- a/web_src/js/features/repo-branch.js +++ b/web_src/js/features/repo-branch.js @@ -2,7 +2,6 @@ import $ from 'jquery'; const {i18n_branch} = window.config; const renameBranchFromInputSelector = 'input#from'; -const renameBranchModalSelector = '#rename-branch-modal'; const renameBranchToSpanSelector = '#modal-rename-branch-to-span'; export function initRepoBranchButton() { @@ -11,9 +10,6 @@ export function initRepoBranchButton() { } function initRepoCreateBranchButton() { - const showCreateBranchModal = $('.show-create-branch-modal'); - if (showCreateBranchModal.length === 0) return; - $('.show-create-branch-modal').on('click', function () { let modalFormName = $(this).attr('data-modal-form'); if (!modalFormName) { @@ -26,18 +22,14 @@ function initRepoCreateBranchButton() { } $(fromSpanName).text($(this).attr('data-branch-from')); - $($(this).attr('data-modal')).modal('show'); }); } function initRepoRenameBranchButton() { - const showRenameBranchModal = $('.show-rename-branch-modal'); - if (showRenameBranchModal.length === 0) return; - $('.show-rename-branch-modal').on('click', function () { const oldBranchName = $(this).attr('data-old-branch-name'); $(renameBranchFromInputSelector)?.val(oldBranchName); + console.log('config', i18n_branch, window.config.i18n_branch) $(renameBranchToSpanSelector).text(i18n_branch.rename_branch_to.replace('%s', oldBranchName)); - $(renameBranchModalSelector).modal('show'); }); } From 93f0ddda6ae87c47f82860ca99d8f820ac2bd6ba Mon Sep 17 00:00:00 2001 From: sillyguodong Date: Fri, 28 Apr 2023 12:02:36 +0800 Subject: [PATCH 06/16] lint --- templates/repo/branch/list.tmpl | 33 +++++++++++++++--------------- web_src/js/features/repo-branch.js | 1 - 2 files changed, 16 insertions(+), 18 deletions(-) diff --git a/templates/repo/branch/list.tmpl b/templates/repo/branch/list.tmpl index 2a7cf941db166..0c169e5946f04 100644 --- a/templates/repo/branch/list.tmpl +++ b/templates/repo/branch/list.tmpl @@ -27,12 +27,12 @@ {{if and $.IsWriter (not $.Repository.IsArchived) (not .IsDeleted)}} - {{svg "octicon-git-branch"}} @@ -52,8 +52,8 @@ {{end}} {{if and $.IsWriter (not $.Repository.IsArchived) (not .IsDeleted) (not .IsProtected)}} - {{if and $.IsWriter (not $.Repository.IsArchived) (not .IsDeleted)}} - {{svg "octicon-git-branch"}} @@ -161,10 +161,10 @@ {{end}} {{if and $.IsWriter (not $.Repository.IsArchived) (not .IsDeleted) (not .IsProtected)}} {{svg "octicon-pencil"}} @@ -247,7 +247,6 @@
-
{{template "base/modal_actions_confirm" (dict "locale" $.locale "ModalButtonTypes" "confirm")}}
diff --git a/web_src/js/features/repo-branch.js b/web_src/js/features/repo-branch.js index 8bbe6b797e804..1fb4d1658a9ad 100644 --- a/web_src/js/features/repo-branch.js +++ b/web_src/js/features/repo-branch.js @@ -29,7 +29,6 @@ function initRepoRenameBranchButton() { $('.show-rename-branch-modal').on('click', function () { const oldBranchName = $(this).attr('data-old-branch-name'); $(renameBranchFromInputSelector)?.val(oldBranchName); - console.log('config', i18n_branch, window.config.i18n_branch) $(renameBranchToSpanSelector).text(i18n_branch.rename_branch_to.replace('%s', oldBranchName)); }); } From 3fbf817f8074c2119def8de41c23e1eb51af8da0 Mon Sep 17 00:00:00 2001 From: sillyguodong Date: Fri, 28 Apr 2023 12:06:10 +0800 Subject: [PATCH 07/16] delete blank line --- web_src/css/repository.css | 1 - 1 file changed, 1 deletion(-) diff --git a/web_src/css/repository.css b/web_src/css/repository.css index e0b494c567ef9..699bc460df6e9 100644 --- a/web_src/css/repository.css +++ b/web_src/css/repository.css @@ -1340,7 +1340,6 @@ color: var(--color-primary); } - .repository.commits .header .search input { font-weight: normal; padding: 5px 10px; From 8a77aefb5967fe853d4dba86ba7aaa02c75fb021 Mon Sep 17 00:00:00 2001 From: sillyguodong Date: Fri, 28 Apr 2023 13:54:47 +0800 Subject: [PATCH 08/16] pass i18n by element attr --- templates/repo/branch/list.tmpl | 7 +------ web_src/js/features/repo-branch.js | 3 +-- 2 files changed, 2 insertions(+), 8 deletions(-) diff --git a/templates/repo/branch/list.tmpl b/templates/repo/branch/list.tmpl index 0c169e5946f04..487720f55361e 100644 --- a/templates/repo/branch/list.tmpl +++ b/templates/repo/branch/list.tmpl @@ -1,9 +1,4 @@ {{template "base/head" .}} -
{{template "repo/header" .}}
@@ -240,7 +235,7 @@ {{.CsrfTokenHtml}}
diff --git a/web_src/js/features/repo-branch.js b/web_src/js/features/repo-branch.js index 1fb4d1658a9ad..a1821e0c1cf7e 100644 --- a/web_src/js/features/repo-branch.js +++ b/web_src/js/features/repo-branch.js @@ -1,6 +1,5 @@ import $ from 'jquery'; -const {i18n_branch} = window.config; const renameBranchFromInputSelector = 'input#from'; const renameBranchToSpanSelector = '#modal-rename-branch-to-span'; @@ -29,6 +28,6 @@ function initRepoRenameBranchButton() { $('.show-rename-branch-modal').on('click', function () { const oldBranchName = $(this).attr('data-old-branch-name'); $(renameBranchFromInputSelector)?.val(oldBranchName); - $(renameBranchToSpanSelector).text(i18n_branch.rename_branch_to.replace('%s', oldBranchName)); + $(renameBranchToSpanSelector).text($(renameBranchToSpanSelector).attr('data-rename-branch-to').replace('%s', oldBranchName)); }); } From 85e65dc1f8b0fc3fbef67201caaa34b2d21a0162 Mon Sep 17 00:00:00 2001 From: sillyguodong Date: Fri, 28 Apr 2023 18:09:19 +0800 Subject: [PATCH 09/16] can't rename branch if is mirror --- templates/repo/branch/list.tmpl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/templates/repo/branch/list.tmpl b/templates/repo/branch/list.tmpl index 487720f55361e..fcbc8f51f3edd 100644 --- a/templates/repo/branch/list.tmpl +++ b/templates/repo/branch/list.tmpl @@ -46,7 +46,7 @@
{{end}} - {{if and $.IsWriter (not $.Repository.IsArchived) (not .IsDeleted) (not .IsProtected)}} + {{if and $.IsWriter (not $.Repository.IsArchived) (not .IsDeleted) (not $.IsMirror)}}
{{end}} - {{if and $.IsWriter (not $.Repository.IsArchived) (not .IsDeleted) (not .IsProtected)}} + {{if and $.IsWriter (not $.Repository.IsArchived) (not .IsDeleted) (not $.IsMirror)}} Date: Sat, 29 Apr 2023 09:13:42 +0800 Subject: [PATCH 10/16] use {{end}} {{if .EnableFeed}} - + {{svg "octicon-rss"}} {{end}} {{if not $.DisableDownloadSourceArchives}} -