mirror of
https://codeberg.org/forgejo/forgejo
synced 2024-11-25 19:26:09 +01:00
DRY: Add existing ctx value to data-branch-path
This commit is contained in:
parent
4d73c51a26
commit
a0d1f75f74
|
@ -211,6 +211,7 @@ func editFile(ctx *context.Context, isNewFile bool) {
|
||||||
ctx.Data["TreeNames"] = treeNames
|
ctx.Data["TreeNames"] = treeNames
|
||||||
ctx.Data["TreePaths"] = treePaths
|
ctx.Data["TreePaths"] = treePaths
|
||||||
ctx.Data["BranchLink"] = ctx.Repo.RepoLink + "/src/" + ctx.Repo.BranchNameSubURL()
|
ctx.Data["BranchLink"] = ctx.Repo.RepoLink + "/src/" + ctx.Repo.BranchNameSubURL()
|
||||||
|
ctx.Data["BranchPath"] = ctx.Repo.BranchNameSubURL()
|
||||||
ctx.Data["commit_summary"] = ""
|
ctx.Data["commit_summary"] = ""
|
||||||
ctx.Data["commit_message"] = ""
|
ctx.Data["commit_message"] = ""
|
||||||
if canCommit {
|
if canCommit {
|
||||||
|
|
|
@ -28,7 +28,7 @@
|
||||||
<div class="field">
|
<div class="field">
|
||||||
<div class="ui top attached tabular menu" data-write="write" data-preview="preview" data-diff="diff">
|
<div class="ui top attached tabular menu" data-write="write" data-preview="preview" data-diff="diff">
|
||||||
<a class="active item" data-tab="write">{{svg "octicon-code"}} {{if .IsNewFile}}{{ctx.Locale.Tr "repo.editor.new_file"}}{{else}}{{ctx.Locale.Tr "repo.editor.edit_file"}}{{end}}</a>
|
<a class="active item" data-tab="write">{{svg "octicon-code"}} {{if .IsNewFile}}{{ctx.Locale.Tr "repo.editor.new_file"}}{{else}}{{ctx.Locale.Tr "repo.editor.edit_file"}}{{end}}</a>
|
||||||
<a class="item" data-tab="preview" data-url="{{.Repository.Link}}/markup" data-context="{{.RepoLink}}/src/{{.BranchNameSubURL}}" data-markup-mode="file">{{svg "octicon-eye"}} {{ctx.Locale.Tr "preview"}}</a>
|
<a class="item" data-tab="preview" data-url="{{.Repository.Link}}/markup" data-context="{{.RepoLink}}/src/{{.BranchNameSubURL}}" data-branch-path="{{.BranchNameSubURL}}" data-relative-path="{{.Repository.Link}}" data-markup-mode="file">{{svg "octicon-eye"}} {{ctx.Locale.Tr "preview"}}</a>
|
||||||
{{if not .IsNewFile}}
|
{{if not .IsNewFile}}
|
||||||
<a class="item" data-tab="diff" hx-params="context,content" hx-vals='{"context":"{{.BranchLink}}"}' hx-include="#edit_area" hx-swap="innerHTML" hx-target=".tab[data-tab='diff']" hx-indicator=".tab[data-tab='diff']" hx-post="{{.RepoLink}}/_preview/{{.BranchName | PathEscapeSegments}}/{{.TreePath | PathEscapeSegments}}">{{svg "octicon-diff"}} {{ctx.Locale.Tr "repo.editor.preview_changes"}}</a>
|
<a class="item" data-tab="diff" hx-params="context,content" hx-vals='{"context":"{{.BranchLink}}"}' hx-include="#edit_area" hx-swap="innerHTML" hx-target=".tab[data-tab='diff']" hx-indicator=".tab[data-tab='diff']" hx-post="{{.RepoLink}}/_preview/{{.BranchName | PathEscapeSegments}}/{{.TreePath | PathEscapeSegments}}">{{svg "octicon-diff"}} {{ctx.Locale.Tr "repo.editor.preview_changes"}}</a>
|
||||||
{{end}}
|
{{end}}
|
||||||
|
|
|
@ -23,20 +23,11 @@ function initEditPreviewTab($form) {
|
||||||
}
|
}
|
||||||
context = context.substring(0, context.lastIndexOf('/'));
|
context = context.substring(0, context.lastIndexOf('/'));
|
||||||
|
|
||||||
// fetch branch path, Eg: `/branch/main`
|
|
||||||
const pathSegments = context.split("/").filter(segment => segment !== "");
|
|
||||||
const last2Seg = pathSegments.slice(-2);
|
|
||||||
const branchPath = "/" + last2Seg.join("/")
|
|
||||||
|
|
||||||
// fetch relative path to the current repository as `/<username>/<repository>`
|
|
||||||
// Eg: `/jon-doe/repo1`
|
|
||||||
const relativePath = context.split("/src"+branchPath)[0]
|
|
||||||
|
|
||||||
const formData = new FormData();
|
const formData = new FormData();
|
||||||
formData.append('mode', mode);
|
formData.append('mode', mode);
|
||||||
formData.append('context', context);
|
formData.append('context', context);
|
||||||
formData.append('branch_path', branchPath)
|
formData.append('branch_path', $this.data('branch-path'))
|
||||||
formData.append('relative_path', relativePath)
|
formData.append('relative_path', $this.data('relative-path'))
|
||||||
formData.append(
|
formData.append(
|
||||||
'text',
|
'text',
|
||||||
$form.find(`.tab[data-tab="${$tabMenu.data('write')}"] textarea`).val(),
|
$form.find(`.tab[data-tab="${$tabMenu.data('write')}"] textarea`).val(),
|
||||||
|
|
Loading…
Reference in a new issue