Skip to content

Commit 87e1ce7

Browse files
committed
update
1 parent cdae87a commit 87e1ce7

File tree

12 files changed

+95
-81
lines changed

12 files changed

+95
-81
lines changed

routers/web/repo/blame.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ func RefBlame(ctx *context.Context) {
7474

7575
tplName := tplRepoViewContent
7676
if !ctx.FormBool("only_content") {
77-
prepareHomeTreeSideBarSwitch(ctx)
77+
prepareTreeSideBarSwitch(ctx)
7878
tplName = tplRepoView
7979
}
8080

routers/web/repo/editor.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,8 @@ func EditFile(ctx *context.Context) {
280280
return
281281
}
282282

283+
prepareTreeSideBarSwitch(ctx)
284+
283285
// on the "New File" page, we should add an empty path field to make end users could input a new name
284286
prepareTreePathFieldsAndPaths(ctx, util.Iif(isNewFile, ctx.Repo.TreePath+"/", ctx.Repo.TreePath))
285287

routers/web/repo/view.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313
"net/http"
1414
"net/url"
1515
"path"
16+
"strconv"
1617
"strings"
1718
"time"
1819

@@ -257,6 +258,19 @@ func LastCommit(ctx *context.Context) {
257258
ctx.HTML(http.StatusOK, tplRepoViewList)
258259
}
259260

261+
func prepareTreeSideBarSwitch(ctx *context.Context) {
262+
showFileTree := true
263+
if ctx.Doer != nil {
264+
v, err := user_model.GetUserSetting(ctx, ctx.Doer.ID, user_model.SettingsKeyCodeViewShowFileTree, "true")
265+
if err != nil {
266+
log.Error("GetUserSetting: %v", err)
267+
} else {
268+
showFileTree, _ = strconv.ParseBool(v)
269+
}
270+
}
271+
ctx.Data["UserSettingCodeViewShowFileTree"] = showFileTree
272+
}
273+
260274
func prepareDirectoryFileIcons(ctx *context.Context, files []git.CommitInfo) {
261275
renderedIconPool := fileicon.NewRenderedIconPool()
262276
fileIcons := map[string]template.HTML{}

routers/web/repo/view_home.go

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,13 @@ import (
99
"html/template"
1010
"net/http"
1111
"path"
12-
"strconv"
1312
"strings"
1413
"time"
1514

1615
"code.gitea.io/gitea/models/db"
1716
git_model "code.gitea.io/gitea/models/git"
1817
repo_model "code.gitea.io/gitea/models/repo"
1918
unit_model "code.gitea.io/gitea/models/unit"
20-
user_model "code.gitea.io/gitea/models/user"
2119
"code.gitea.io/gitea/modules/git"
2220
"code.gitea.io/gitea/modules/gitrepo"
2321
"code.gitea.io/gitea/modules/htmlutil"
@@ -318,19 +316,6 @@ func handleRepoHomeFeed(ctx *context.Context) bool {
318316
return true
319317
}
320318

321-
func prepareHomeTreeSideBarSwitch(ctx *context.Context) {
322-
showFileTree := true
323-
if ctx.Doer != nil {
324-
v, err := user_model.GetUserSetting(ctx, ctx.Doer.ID, user_model.SettingsKeyCodeViewShowFileTree, "true")
325-
if err != nil {
326-
log.Error("GetUserSetting: %v", err)
327-
} else {
328-
showFileTree, _ = strconv.ParseBool(v)
329-
}
330-
}
331-
ctx.Data["UserSettingCodeViewShowFileTree"] = showFileTree
332-
}
333-
334319
func redirectSrcToRaw(ctx *context.Context) bool {
335320
// GitHub redirects a tree path with "?raw=1" to the raw path
336321
// It is useful to embed some raw contents into Markdown files,
@@ -386,7 +371,7 @@ func Home(ctx *context.Context) {
386371
return
387372
}
388373

389-
prepareHomeTreeSideBarSwitch(ctx)
374+
prepareTreeSideBarSwitch(ctx)
390375

391376
// get the current git entry which doer user is currently looking at.
392377
entry, err := ctx.Repo.Commit.GetTreeEntryByPath(ctx.Repo.TreePath)

templates/repo/editor/edit.tmpl

Lines changed: 66 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,63 +1,77 @@
11
{{template "base/head" .}}
22
<div role="main" aria-label="{{.Title}}" class="page-content repository file editor edit">
33
{{template "repo/header" .}}
4-
<div class="ui container fluid padded repo-view-container">
4+
<div class="ui container fluid">
55
{{template "base/alert" .}}
6-
<div class="tw-flex tw-flex-col repo-view-file-tree-container not-mobile" data-edit data-user-is-signed-in>
7-
{{template "repo/view_file_tree" .}}
8-
</div>
9-
<div class="repo-view-content">
10-
<form class="ui edit form form-fetch-action" method="post" action="{{.CommitFormOptions.TargetFormAction}}"
11-
data-text-empty-confirm-header="{{ctx.Locale.Tr "repo.editor.commit_empty_file_header"}}"
12-
data-text-empty-confirm-content="{{ctx.Locale.Tr "repo.editor.commit_empty_file_text"}}"
13-
>
14-
{{.CsrfTokenHtml}}
15-
{{template "repo/editor/common_top" .}}
16-
<div class="repo-editor-header">
17-
<button class="repo-view-file-tree-toggle-show ui compact basic button icon not-mobile tw-hidden"
18-
data-global-click="onRepoViewFileTreeToggle" data-toggle-action="show"
19-
data-tooltip-content="{{ctx.Locale.Tr "repo.diff.show_file_tree"}}"
20-
type="button">
21-
{{svg "octicon-sidebar-collapse"}}
22-
</button>
23-
{{template "repo/editor/common_breadcrumb" .}}
24-
</div>
25-
{{if not .NotEditableReason}}
26-
<div class="field">
27-
<div class="ui top attached header">
28-
<div class="ui compact small menu small-menu-items repo-editor-menu">
29-
<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>
30-
<a class="item" data-tab="preview" data-preview-url="{{.Repository.Link}}/markup" data-preview-context-ref="{{.RepoLink}}/src/{{.RefTypeNameSubURL}}">{{svg "octicon-eye"}} {{ctx.Locale.Tr "preview"}}</a>
31-
{{if not .IsNewFile}}
32-
<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>
33-
{{end}}
34-
</div>
35-
</div>
36-
<div class="ui bottom attached segment tw-p-0">
37-
<div class="ui active tab tw-rounded-b" data-tab="write">
38-
<textarea id="edit_area" name="content" class="tw-hidden" data-id="repo-{{.Repository.Name}}-{{.TreePath}}"
39-
data-previewable-extensions="{{.PreviewableExtensions}}"
40-
data-line-wrap-extensions="{{.LineWrapExtensions}}">{{.FileContent}}</textarea>
41-
<div class="editor-loading is-loading"></div>
42-
</div>
43-
<div class="ui tab tw-px-4 tw-py-3" data-tab="preview">
44-
{{ctx.Locale.Tr "loading"}}
6+
<div class="repo-view-container">
7+
<div class="tw-flex tw-flex-col repo-view-file-tree-container not-mobile {{if or (not .UserSettingCodeViewShowFileTree) .IsEditingFileOnly}}tw-hidden{{end}}" data-user-is-signed-in>
8+
{{template "repo/view_file_tree" .}}
9+
</div>
10+
<div class="repo-view-content">
11+
<form class="ui edit form form-fetch-action" method="post" action="{{.CommitFormOptions.TargetFormAction}}"
12+
data-text-empty-confirm-header="{{ctx.Locale.Tr "repo.editor.commit_empty_file_header"}}"
13+
data-text-empty-confirm-content="{{ctx.Locale.Tr "repo.editor.commit_empty_file_text"}}"
14+
>
15+
{{.CsrfTokenHtml}}
16+
{{template "repo/editor/common_top" .}}
17+
<div class="repo-editor-header">
18+
<button class="repo-view-file-tree-toggle-show ui compact basic button icon not-mobile {{if and .UserSettingCodeViewShowFileTree (not .IsEditingFileOnly)}}tw-hidden{{end}}"
19+
data-global-click="onRepoViewFileTreeToggle" data-toggle-action="show"
20+
data-tooltip-content="{{ctx.Locale.Tr "repo.diff.show_file_tree"}}"
21+
type="button">
22+
{{svg "octicon-sidebar-collapse"}}
23+
</button>
24+
{{template "repo/editor/common_breadcrumb" .}}
25+
</div>
26+
{{if not .NotEditableReason}}
27+
<div class="field">
28+
<div class="ui top attached header">
29+
<div class="ui compact small menu small-menu-items repo-editor-menu">
30+
<a class="active item" data-tab="write">
31+
{{svg "octicon-code"}} {{if .IsNewFile}}{{ctx.Locale.Tr "repo.editor.new_file"}}{{else}}{{ctx.Locale.Tr "repo.editor.edit_file"}}{{end}}
32+
</a>
33+
<a class="item" data-tab="preview" data-preview-url="{{.Repository.Link}}/markup" data-preview-context-ref="{{.RepoLink}}/src/{{.RefTypeNameSubURL}}">
34+
{{svg "octicon-eye"}} {{ctx.Locale.Tr "preview"}}</a>
35+
{{if not .IsNewFile}}
36+
<a class="item" data-tab="diff"
37+
hx-params="context,content"
38+
hx-vals='{"context":"{{.BranchLink}}"}'
39+
hx-include="#edit_area"
40+
hx-swap="innerHTML"
41+
hx-target=".tab[data-tab='diff']"
42+
hx-indicator=".tab[data-tab='diff']"
43+
hx-post="{{.RepoLink}}/_preview/{{.BranchName | PathEscapeSegments}}/{{.TreePath | PathEscapeSegments}}">
44+
{{svg "octicon-diff"}} {{ctx.Locale.Tr "repo.editor.preview_changes"}}
45+
</a>
46+
{{end}}
47+
</div>
4548
</div>
46-
<div class="ui tab" data-tab="diff">
47-
<div class="tw-p-16"></div>
49+
<div class="ui bottom attached segment tw-p-0">
50+
<div class="ui active tab tw-rounded-b" data-tab="write">
51+
<textarea id="edit_area" name="content" class="tw-hidden" data-id="repo-{{.Repository.Name}}-{{.TreePath}}"
52+
data-previewable-extensions="{{.PreviewableExtensions}}"
53+
data-line-wrap-extensions="{{.LineWrapExtensions}}">{{.FileContent}}</textarea>
54+
<div class="editor-loading is-loading"></div>
55+
</div>
56+
<div class="ui tab tw-px-4 tw-py-3" data-tab="preview">
57+
{{ctx.Locale.Tr "loading"}}
58+
</div>
59+
<div class="ui tab" data-tab="diff">
60+
<div class="tw-p-16"></div>
61+
</div>
4862
</div>
4963
</div>
50-
</div>
51-
{{else}}
52-
<div class="field">
53-
<div class="ui segment tw-text-center">
54-
<h4 class="tw-font-semibold tw-mb-2">{{.NotEditableReason}}</h4>
55-
<p>{{ctx.Locale.Tr "repo.editor.file_not_editable_hint"}}</p>
64+
{{else}}
65+
<div class="field">
66+
<div class="ui segment tw-text-center">
67+
<h4 class="tw-font-semibold tw-mb-2">{{.NotEditableReason}}</h4>
68+
<p>{{ctx.Locale.Tr "repo.editor.file_not_editable_hint"}}</p>
69+
</div>
5670
</div>
57-
</div>
58-
{{end}}
59-
{{template "repo/editor/commit_form" .}}
60-
</form>
71+
{{end}}
72+
{{template "repo/editor/commit_form" .}}
73+
</form>
74+
</div>
6175
</div>
6276
</div>
6377
</div>

templates/repo/view_file_tree.tmpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,5 @@
1212
data-repo-link="{{.RepoLink}}"
1313
data-tree-path="{{$.TreePath}}"
1414
data-current-ref-name-sub-url="{{.RefTypeNameSubURL}}"
15-
data-is-edit="{{.PageIsEdit}}"
15+
data-page-is-edit="{{not .PageIsViewCode}}"
1616
></div>

web_src/css/editor/fileeditor.css

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
display: flex;
1717
margin: 4px 0;
1818
padding: 3px 0;
19+
gap: 0.5rem
1920
}
2021

2122
.editor-toolbar {

web_src/js/components/ViewFileTree.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ const props = defineProps({
99
repoLink: {type: String, required: true},
1010
treePath: {type: String, required: true},
1111
currentRefNameSubURL: {type: String, required: true},
12-
isEdit: {type: Boolean, required: false},
12+
pageIsEdit: {type: Boolean, required: true},
1313
});
1414
1515
const store = createViewFileTreeStore(props);

web_src/js/components/ViewFileTreeItem.vue

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,10 @@ const doLoadChildren = async () => {
3737
};
3838
3939
const onItemClick = (e: MouseEvent) => {
40-
// only handle the click event with page partial reloading if the user didn't press any special key
41-
// let browsers handle special keys like "Ctrl+Click"
42-
if (!isPlainClick(e)) return;
40+
// only handle the click event with partial page reloading if
41+
// - the user didn't press any special key let browsers handle special keys like "Ctrl+Click"
42+
// - the user doesn't edit the file (a full page reload shows a confirmation dialog if the editor has unsaved changed)
43+
if (!isPlainClick(e) || props.store.pageIsEdit) return;
4344
e.preventDefault();
4445
if (props.item.entryMode === 'tree') doLoadChildren();
4546
store.navigateTreeView(props.item.fullPath);

web_src/js/components/ViewFileTreeStore.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,11 @@ import {pathEscapeSegments} from '../utils/url.ts';
44
import {createElementFromHTML} from '../utils/dom.ts';
55
import {html} from '../utils/html.ts';
66

7-
export function createViewFileTreeStore(props: { repoLink: string, treePath: string, currentRefNameSubURL: string, isEdit?: boolean }) {
7+
export function createViewFileTreeStore(props: { repoLink: string, treePath: string, currentRefNameSubURL: string, pageIsEdit: boolean }) {
88
const store = reactive({
99
rootFiles: [],
1010
selectedItem: props.treePath,
11+
pageIsEdit: props.pageIsEdit,
1112

1213
async loadChildren(treePath: string, subPath: string = '') {
1314
const response = await GET(`${props.repoLink}/tree-view/${props.currentRefNameSubURL}/${pathEscapeSegments(treePath)}?sub_path=${encodeURIComponent(subPath)}`);
@@ -32,11 +33,6 @@ export function createViewFileTreeStore(props: { repoLink: string, treePath: str
3233

3334
async navigateTreeView(treePath: string) {
3435
const url = store.buildTreePathWebUrl(treePath);
35-
// do full page reload to show confirmation dialog if editor has unsaved changed
36-
if (props.isEdit) {
37-
window.location.href = url;
38-
return;
39-
}
4036
window.history.pushState({treePath, url}, null, url);
4137
store.selectedItem = treePath;
4238
await store.loadViewContent(url);

0 commit comments

Comments
 (0)