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 7 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))
}
86 changes: 73 additions & 13 deletions templates/repo/branch/list.tmpl
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
{{template "base/head" .}}
<script>
window.config.i18n_branch = {
rename_branch_to: '{{.locale.Tr "repo.branch.rename_branch_to"}}',
sillyguodong marked this conversation as resolved.
Show resolved Hide resolved
}
</script>
<div role="main" aria-label="{{.Title}}" class="page-content ui repository branches">
{{template "repo/header" .}}
<div class="ui container">
Expand All @@ -22,23 +27,39 @@
</td>
<td class="right aligned overflow-visible">
{{if and $.IsWriter (not $.Repository.IsArchived) (not .IsDeleted)}}
<button class="ui basic jump button icon show-create-branch-modal" data-tooltip-content="{{$.locale.Tr "repo.branch.new_branch_from" ($.DefaultBranch)}}" data-branch-from="{{$.DefaultBranch}}" data-branch-from-urlcomponent="{{PathEscapeSegments $.DefaultBranch}}" data-modal="#create-branch-modal">
<a role="button"
sillyguodong marked this conversation as resolved.
Show resolved Hide resolved
class="muted show-modal show-create-branch-modal gt-mx-3"
data-modal="#create-branch-modal"
data-branch-from="{{$.DefaultBranch}}"
data-branch-from-urlcomponent="{{PathEscapeSegments $.DefaultBranch}}"
data-tooltip-content="{{$.locale.Tr "repo.branch.new_branch_from" ($.DefaultBranch)}}"
>
{{svg "octicon-git-branch"}}
</button>
</a>
{{end}}
{{if .EnableFeed}}
<a role="button" class="ui basic button icon" href="{{$.FeedURL}}/rss/branch/{{PathEscapeSegments .DefaultBranch}}">
<a role="button" class="muted gt-mx-3" href="{{$.FeedURL}}/rss/branch/{{PathEscapeSegments .DefaultBranch}}">
{{svg "octicon-rss"}}
</a>
{{end}}
{{if not $.DisableDownloadSourceArchives}}
<button class="ui basic jump dropdown icon button" data-tooltip-content="{{$.locale.Tr "repo.branch.download" ($.DefaultBranch)}}">
<div role="button" class="ui dropdown muted gt-mx-3" data-tooltip-content="{{$.locale.Tr "repo.branch.download" ($.DefaultBranch)}}">
sillyguodong marked this conversation as resolved.
Show resolved Hide resolved
{{svg "octicon-download"}}
<div class="menu">
<a class="item archive-link" href="{{$.RepoLink}}/archive/{{PathEscapeSegments $.DefaultBranch}}.zip" rel="nofollow">{{svg "octicon-file-zip"}}&nbsp;ZIP</a>
<a class="item archive-link" href="{{$.RepoLink}}/archive/{{PathEscapeSegments $.DefaultBranch}}.tar.gz" rel="nofollow">{{svg "octicon-file-zip"}}&nbsp;TAR.GZ</a>
</div>
</button>
</div>
{{end}}
{{if and $.IsWriter (not $.Repository.IsArchived) (not .IsDeleted) (not .IsProtected)}}
sillyguodong marked this conversation as resolved.
Show resolved Hide resolved
<a role="button"
class="muted show-modal show-rename-branch-modal gt-mx-3"
data-modal="#rename-branch-modal"
data-old-branch-name="{{$.DefaultBranch}}"
data-tooltip-content="{{$.locale.Tr "repo.branch.rename" ($.DefaultBranch)}}"
>
{{svg "octicon-pencil"}}
</a>
{{end}}
</td>
</tr>
Expand Down Expand Up @@ -114,35 +135,51 @@
</td>
<td class="three wide right aligned overflow-visible">
{{if and $.IsWriter (not $.Repository.IsArchived) (not .IsDeleted)}}
<button class="ui basic jump button icon show-create-branch-modal" data-branch-from="{{.Name}}" data-branch-from-urlcomponent="{{PathEscapeSegments .Name}}" data-tooltip-content="{{$.locale.Tr "repo.branch.new_branch_from" .Name}}" data-modal="#create-branch-modal" data-name="{{.Name}}">
<a role="button"
class="muted show-modal show-create-branch-modal gt-mx-3"
data-branch-from="{{.Name}}"
data-branch-from-urlcomponent="{{PathEscapeSegments .Name}}"
data-tooltip-content="{{$.locale.Tr "repo.branch.new_branch_from" .Name}}"
data-modal="#create-branch-modal" data-name="{{.Name}}"
>
{{svg "octicon-git-branch"}}
</button>
</a>
{{end}}
{{if $.EnableFeed}}
<a role="button" class="ui basic button icon" href="{{$.FeedURL}}/rss/branch/{{PathEscapeSegments .Name}}">
<a role="button" class="muted gt-mx-3" href="{{$.FeedURL}}/rss/branch/{{PathEscapeSegments .Name}}">
{{svg "octicon-rss"}}
</a>
{{end}}
{{if and (not .IsDeleted) (not $.DisableDownloadSourceArchives)}}
<button class="ui basic jump dropdown icon button" data-tooltip-content="{{$.locale.Tr "repo.branch.download" (.Name)}}">
<div role="button" class="ui dropdown muted gt-mx-3" data-tooltip-content="{{$.locale.Tr "repo.branch.download" (.Name)}}">
{{svg "octicon-download"}}
<div class="menu">
<a class="item archive-link" href="{{$.RepoLink}}/archive/{{PathEscapeSegments .Name}}.zip" rel="nofollow">{{svg "octicon-file-zip"}}&nbsp;ZIP</a>
<a class="item archive-link" href="{{$.RepoLink}}/archive/{{PathEscapeSegments .Name}}.tar.gz" rel="nofollow">{{svg "octicon-file-zip"}}&nbsp;TAR.GZ</a>
</div>
</div>
{{end}}
{{if and $.IsWriter (not $.Repository.IsArchived) (not .IsDeleted) (not .IsProtected)}}
<a role="button"
class="muted show-modal show-rename-branch-modal gt-mx-3"
data-old-branch-name="{{.Name}}"
data-modal="#rename-branch-modal"
data-tooltip-content="{{$.locale.Tr "repo.branch.rename" (.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)}}">
<a role="button" class="muted undo-button gt-mx-3" data-url="{{$.Link}}/restore?branch_id={{.DeletedBranch.ID}}&name={{.DeletedBranch.Name}}&page={{$.Page.Paginater.Current}}" data-tooltip-content="{{$.locale.Tr "repo.branch.restore" (.Name)}}">
<span class="text blue">
{{svg "octicon-reply"}}
</span>
</button>
</a>
{{else}}
<button class="ui basic jump button icon delete-button delete-branch-button" data-url="{{$.Link}}/delete?name={{.Name}}&page={{$.Page.Paginater.Current}}" data-tooltip-content="{{$.locale.Tr "repo.branch.delete" (.Name)}}" data-name="{{.Name}}">
<a role="button" class="muted delete-button delete-branch-button gt-mx-3" data-url="{{$.Link}}/delete?name={{.Name}}&page={{$.Page.Paginater.Current}}" data-tooltip-content="{{$.locale.Tr "repo.branch.delete" (.Name)}}" data-name="{{.Name}}">
{{svg "octicon-trash"}}
</button>
</a>
{{end}}
{{end}}
</td>
Expand Down Expand Up @@ -193,4 +230,27 @@
</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">
<input id="to" name="to" required>
sillyguodong marked this conversation as resolved.
Show resolved Hide resolved
</div>
<div class="center">
sillyguodong marked this conversation as resolved.
Show resolved Hide resolved
{{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
8 changes: 8 additions & 0 deletions web_src/css/repository.css
Original file line number Diff line number Diff line change
Expand Up @@ -1332,6 +1332,14 @@
left: 0;
}

.repository.branches .table a:hover {
text-decoration: none;
sillyguodong marked this conversation as resolved.
Show resolved Hide resolved
}

.repository.branches .table .ui.dropdown:hover {
color: var(--color-primary);
sillyguodong marked this conversation as resolved.
Show resolved Hide resolved
}

.repository.commits .header .search input {
font-weight: normal;
padding: 5px 10px;
Expand Down
18 changes: 17 additions & 1 deletion web_src/js/features/repo-branch.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
import $ from 'jquery';

const {i18n_branch} = window.config;
const renameBranchFromInputSelector = 'input#from';
const renameBranchToSpanSelector = '#modal-rename-branch-to-span';

export function initRepoBranchButton() {
initRepoCreateBranchButton();
initRepoRenameBranchButton();
}

function initRepoCreateBranchButton() {
$('.show-create-branch-modal').on('click', function () {
let modalFormName = $(this).attr('data-modal-form');
if (!modalFormName) {
Expand All @@ -13,6 +22,13 @@ export function initRepoBranchButton() {
}

$(fromSpanName).text($(this).attr('data-branch-from'));
$($(this).attr('data-modal')).modal('show');
sillyguodong marked this conversation as resolved.
Show resolved Hide resolved
});
}

function initRepoRenameBranchButton() {
$('.show-rename-branch-modal').on('click', function () {
const oldBranchName = $(this).attr('data-old-branch-name');
$(renameBranchFromInputSelector)?.val(oldBranchName);
sillyguodong marked this conversation as resolved.
Show resolved Hide resolved
$(renameBranchToSpanSelector).text(i18n_branch.rename_branch_to.replace('%s', oldBranchName));
});
}