Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move Rename branch from repo settings page to the page of branches list #24380

Merged
merged 18 commits into from
Apr 30, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions options/locale/locale_en-US.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
8 changes: 4 additions & 4 deletions routers/web/repo/setting_protected_branch.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand All @@ -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))
}
1 change: 1 addition & 0 deletions templates/base/head_script.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -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 */}}
Expand Down
34 changes: 34 additions & 0 deletions templates/repo/branch/list.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@
</div>
</button>
{{end}}
{{if and $.IsWriter (not $.Repository.IsArchived) (not .IsDeleted) (not .IsProtected)}}
<button class="ui basic jump button icon show-rename-branch-modal" data-tooltip-content="{{$.locale.Tr "repo.branch.rename" ($.DefaultBranch)}}" data-old-branch-name="{{$.DefaultBranch}}">
{{svg "octicon-pencil"}}
</button>
{{end}}
</td>
</tr>
</tbody>
Expand Down Expand Up @@ -132,6 +137,11 @@
</div>
</button>
{{end}}
{{if and $.IsWriter (not $.Repository.IsArchived) (not .IsDeleted) (not .IsProtected)}}
<button class="ui basic jump button icon show-rename-branch-modal" data-tooltip-content="{{$.locale.Tr "repo.branch.rename" (.Name)}}" data-old-branch-name="{{.Name}}">
{{svg "octicon-pencil"}}
</button>
{{end}}
{{if and $.IsWriter (not $.IsMirror) (not $.Repository.IsArchived) (not .IsProtected)}}
{{if .IsDeleted}}
<button class="ui basic jump button icon undo-button" data-url="{{$.Link}}/restore?branch_id={{.DeletedBranch.ID}}&name={{.DeletedBranch.Name}}&page={{$.Page.Paginater.Current}}" data-tooltip-content="{{$.locale.Tr "repo.branch.restore" (.Name)}}">
Expand Down Expand Up @@ -193,4 +203,28 @@
</form>
</div>
</div>

<div class="ui g-modal-confim modal" id="rename-branch-modal">
<div class="header">
{{.locale.Tr "repo.settings.rename_branch"}}
</div>
<div class="content">
<form class="ui form" id="rename-branch-form" action="{{$.Repository.Link}}/settings/rename_branch" method="post">
{{.CsrfTokenHtml}}
<div class="field">
<label>
<span class="text" id="modal-rename-branch-to-span"></span>
</label>
</div>
<input id="from" name="from" value="" type="hidden" required>
<div class="required field{{if .Err_BranchName}} error{{end}}">
<input id="to" name="to" required>
</div>

<div class="center">
{{template "base/modal_actions_confirm" (dict "locale" $.locale "ModalButtonTypes" "confirm")}}
</div>
</form>
</div>
</div>
{{template "base/footer" .}}
22 changes: 0 additions & 22 deletions templates/repo/settings/branches.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -66,28 +66,6 @@
</div>
</div>
</div>

{{if $.Repository.CanCreateBranch}}
<h4 class="ui top attached header">
{{.locale.Tr "repo.settings.rename_branch"}}
</h4>
<div class="ui attached segment">
<form class="ui form" action="{{$.Repository.Link}}/settings/rename_branch" method="post">
{{.CsrfTokenHtml}}
<div class="required field">
<label for="from">{{.locale.Tr "repo.settings.rename_branch_from"}}</label>
<input id="from" name="from" required>
</div>
<div class="required field {{if .Err_BranchName}}error{{end}}">
<label for="to">{{.locale.Tr "repo.settings.rename_branch_to"}}</label>
<input id="to" name="to" required>
</div>
<div class="field">
<button class="ui green button">{{$.locale.Tr "repo.settings.update_settings"}}</button>
</div>
</form>
</div>
{{end}}
{{end}}
</div>

Expand Down
25 changes: 25 additions & 0 deletions web_src/js/features/repo-branch.js
Original file line number Diff line number Diff line change
@@ -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) {
Expand All @@ -16,3 +29,15 @@ 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);
$(renameBranchToSpanSelector).text(i18n.rename_branch_to.replace('%s', oldBranchName));
$(renameBranchModalSelector).modal('show');
});
}