Browse Source

Web editor: improve edit file tooltip

Unknwon 3 years ago
parent
commit
6e171c5225

+ 4 - 4
conf/locale/locale_en-US.ini

@@ -436,17 +436,17 @@ commit_changes = Commit Changes
436 436
 default_commit_message = Add an optional extended description...
437 437
 last_commit_info = %s edited this file %s
438 438
 delete_this_file = Delete this file
439
-edit_this_file = Edit this file
440 439
 edit_file = Edit file
441 440
 delete_confirm_message = Are you sure you want to delete this file?
442 441
 delete_commit_message = Write a note about this delete (optional)
443 442
 unable_to_update_file = Unable to update this file, error occurred
444
-must_be_on_branch = You must be on a branch to make or propose changes to this file
445 443
 must_be_writer = You must have write access to make or propose changes to this file
446
-cannot_edit_binary_files = Cannot edit binary files
447 444
 filename_help = To add directory, just type it and press /. To remove a directory, go to the beginning of the field and press backspace.
448
-fork_before_edit = You must fork this before editing
449 445
 new_branch = new branch
446
+editor.cannot_edit_non_text_files = Cannot edit non-text files
447
+editor.edit_this_file = Edit this file
448
+editor.must_be_on_a_branch = You must be on a branch to make or propose changes to this file
449
+editor.fork_before_edit = You must fork this repository before editing the file
450 450
 editor.file_delete_success = File '%s' has been deleted successfully!
451 451
 editor.commit_directly_to_this_branch = Commit directly to the <strong class="branch-name">%s</strong> branch.
452 452
 editor.create_new_branch = Create a <strong>new branch</strong> for this commit and start a pull request.

File diff suppressed because it is too large
+ 2 - 2
modules/bindata/bindata.go


+ 39 - 53
routers/repo/view.go

@@ -24,7 +24,6 @@ import (
24 24
 	"github.com/gogits/gogs/modules/setting"
25 25
 	"github.com/gogits/gogs/modules/template"
26 26
 	"github.com/gogits/gogs/modules/template/highlight"
27
-	"strconv"
28 27
 )
29 28
 
30 29
 const (
@@ -46,33 +45,18 @@ func Home(ctx *context.Context) {
46 45
 	userName := ctx.Repo.Owner.Name
47 46
 	repoName := ctx.Repo.Repository.Name
48 47
 
49
-	repoLink := ctx.Repo.RepoLink
50 48
 	branchLink := ctx.Repo.RepoLink + "/src/" + branchName
51 49
 	treeLink := branchLink
52 50
 	rawLink := ctx.Repo.RepoLink + "/raw/" + branchName
53
-	editLink := ctx.Repo.RepoLink + "/_edit/" + branchName
54
-	newFileLink := ctx.Repo.RepoLink + "/_new/" + branchName
55
-	forkLink := setting.AppSubUrl + "/repo/fork/" + strconv.FormatInt(ctx.Repo.Repository.ID, 10)
56
-	uploadFileLink := ctx.Repo.RepoLink + "/upload/" + branchName
51
+	// newFileLink := ctx.Repo.RepoLink + "/_new/" + branchName
52
+	// uploadFileLink := ctx.Repo.RepoLink + "/upload/" + branchName
57 53
 
58
-	// Get tree path
59
-	treename := ctx.Repo.TreePath
60
-
61
-	if len(treename) > 0 {
62
-		if treename[len(treename)-1] == '/' {
63
-			ctx.Redirect(repoLink + "/src/" + branchName + "/" + treename[:len(treename)-1])
64
-			return
65
-		}
66
-
67
-		treeLink += "/" + treename
68
-	}
69
-
70
-	treePath := treename
71
-	if len(treePath) != 0 {
72
-		treePath = treePath + "/"
54
+	treePath := ctx.Repo.TreePath
55
+	if len(treePath) > 0 {
56
+		treeLink += "/" + treePath
73 57
 	}
74 58
 
75
-	entry, err := ctx.Repo.Commit.GetTreeEntryByPath(treename)
59
+	entry, err := ctx.Repo.Commit.GetTreeEntryByPath(treePath)
76 60
 	if err != nil {
77 61
 		if git.IsErrNotExist(err) {
78 62
 			ctx.Handle(404, "GetTreeEntryByPath", err)
@@ -94,7 +78,7 @@ func Home(ctx *context.Context) {
94 78
 		ctx.Data["IsFile"] = true
95 79
 		ctx.Data["FileName"] = blob.Name()
96 80
 		ctx.Data["HighlightClass"] = highlight.FileNameToHighlightClass(blob.Name())
97
-		ctx.Data["FileLink"] = rawLink + "/" + treename
81
+		ctx.Data["FileLink"] = rawLink + "/" + treePath
98 82
 
99 83
 		buf := make([]byte, 1024)
100 84
 		n, _ := dataRc.Read(buf)
@@ -107,25 +91,30 @@ func Home(ctx *context.Context) {
107 91
 		_, isPDFFile := base.IsPDFFile(buf)
108 92
 		ctx.Data["IsFileText"] = isTextFile
109 93
 
94
+		// Assume file is not editable first.
95
+		if !isTextFile {
96
+			ctx.Data["EditFileTooltip"] = ctx.Tr("repo.editor.cannot_edit_non_text_files")
97
+		}
98
+
110 99
 		switch {
111 100
 		case isPDFFile:
112 101
 			ctx.Data["IsPDFFile"] = true
113
-			ctx.Data["FileEditLinkTooltip"] = ctx.Tr("repo.cannot_edit_binary_files")
114 102
 		case isImageFile:
115 103
 			ctx.Data["IsImageFile"] = true
116
-			ctx.Data["FileEditLinkTooltip"] = ctx.Tr("repo.cannot_edit_binary_files")
117 104
 		case isTextFile:
118 105
 			if blob.Size() >= setting.UI.MaxDisplayFileSize {
119 106
 				ctx.Data["IsFileTooLarge"] = true
120 107
 			} else {
121
-				ctx.Data["IsFileTooLarge"] = false
122 108
 				d, _ := ioutil.ReadAll(dataRc)
123 109
 				buf = append(buf, d...)
124
-				readmeExist := markdown.IsMarkdownFile(blob.Name()) || markdown.IsReadmeFile(blob.Name())
125
-				isMarkdown := readmeExist || markdown.IsMarkdownFile(blob.Name())
126
-				ctx.Data["ReadmeExist"] = readmeExist
110
+
111
+				isMarkdown := markdown.IsMarkdownFile(blob.Name())
127 112
 				ctx.Data["IsMarkdown"] = isMarkdown
128
-				if isMarkdown {
113
+
114
+				readmeExist := isMarkdown || markdown.IsReadmeFile(blob.Name())
115
+				ctx.Data["ReadmeExist"] = readmeExist
116
+				if readmeExist {
117
+					// TODO: don't need to render if it's a README but not Markdown file.
129 118
 					ctx.Data["FileContent"] = string(markdown.Render(buf, path.Dir(treeLink), ctx.Repo.Repository.ComposeMetas()))
130 119
 				} else {
131 120
 					// Building code view blocks with line number on server side.
@@ -153,22 +142,19 @@ func Home(ctx *context.Context) {
153 142
 					ctx.Data["LineNums"] = gotemplate.HTML(output.String())
154 143
 				}
155 144
 			}
145
+
156 146
 			if ctx.Repo.IsWriter() && ctx.Repo.IsViewBranch {
157
-				ctx.Data["FileEditLink"] = editLink + "/" + treename
158
-				ctx.Data["FileEditLinkTooltip"] = ctx.Tr("repo.edit_this_file")
159
-			} else {
160
-				if !ctx.Repo.IsViewBranch {
161
-					ctx.Data["FileEditLinkTooltip"] = ctx.Tr("repo.must_be_on_branch")
162
-				} else if !ctx.Repo.IsWriter() {
163
-					ctx.Data["FileEditLink"] = forkLink
164
-					ctx.Data["FileEditLinkTooltip"] = ctx.Tr("repo.fork_before_edit")
165
-				}
147
+				ctx.Data["CanEditFile"] = true
148
+				ctx.Data["EditFileTooltip"] = ctx.Tr("repo.editor.edit_this_file")
149
+			} else if !ctx.Repo.IsViewBranch {
150
+				ctx.Data["EditFileTooltip"] = ctx.Tr("repo.editor.must_be_on_a_branch")
151
+			} else if !ctx.Repo.IsWriter() {
152
+				ctx.Data["EditFileTooltip"] = ctx.Tr("repo.editor.fork_before_edit")
166 153
 			}
167
-		default:
168
-			ctx.Data["FileEditLinkTooltip"] = ctx.Tr("repo.cannot_edit_binary_files")
169 154
 		}
170 155
 
171 156
 		if ctx.Repo.IsWriter() && ctx.Repo.IsViewBranch {
157
+			ctx.Data["CanDeleteFile"] = true
172 158
 			ctx.Data["FileDeleteLinkTooltip"] = ctx.Tr("repo.delete_this_file")
173 159
 		} else {
174 160
 			if !ctx.Repo.IsViewBranch {
@@ -180,7 +166,7 @@ func Home(ctx *context.Context) {
180 166
 
181 167
 	} else {
182 168
 		// Directory and file list.
183
-		tree, err := ctx.Repo.Commit.SubTree(treename)
169
+		tree, err := ctx.Repo.Commit.SubTree(treePath)
184 170
 		if err != nil {
185 171
 			ctx.Handle(404, "SubTree", err)
186 172
 			return
@@ -224,7 +210,7 @@ func Home(ctx *context.Context) {
224 210
 				}
225 211
 
226 212
 				ctx.Data["FileSize"] = readmeFile.Size()
227
-				ctx.Data["FileLink"] = rawLink + "/" + treename
213
+				ctx.Data["FileLink"] = rawLink + "/" + treePath
228 214
 				_, isTextFile := base.IsTextFile(buf)
229 215
 				ctx.Data["FileIsText"] = isTextFile
230 216
 				ctx.Data["FileName"] = readmeFile.Name()
@@ -254,12 +240,12 @@ func Home(ctx *context.Context) {
254 240
 		}
255 241
 		ctx.Data["LastCommit"] = lastCommit
256 242
 		ctx.Data["LastCommitUser"] = models.ValidateCommitWithEmail(lastCommit)
257
-		if ctx.Repo.IsWriter() && ctx.Repo.IsViewBranch {
258
-			ctx.Data["NewFileLink"] = newFileLink + "/" + treename
259
-			if setting.Repository.Upload.Enabled {
260
-				ctx.Data["UploadFileLink"] = uploadFileLink + "/" + treename
261
-			}
262
-		}
243
+		// if ctx.Repo.IsWriter() && ctx.Repo.IsViewBranch {
244
+		// 	ctx.Data["NewFileLink"] = newFileLink + "/" + treePath
245
+		// 	if setting.Repository.Upload.Enabled {
246
+		// 		ctx.Data["UploadFileLink"] = uploadFileLink + "/" + treePath
247
+		// 	}
248
+		// }
263 249
 	}
264 250
 
265 251
 	ctx.Data["Username"] = userName
@@ -274,8 +260,8 @@ func Home(ctx *context.Context) {
274 260
 	var treenames []string
275 261
 	paths := make([]string, 0)
276 262
 
277
-	if len(treename) > 0 {
278
-		treenames = strings.Split(treename, "/")
263
+	if len(treePath) > 0 {
264
+		treenames = strings.Split(treePath, "/")
279 265
 		for i := range treenames {
280 266
 			paths = append(paths, strings.Join(treenames[0:i+1], "/"))
281 267
 		}
@@ -287,9 +273,9 @@ func Home(ctx *context.Context) {
287 273
 	}
288 274
 
289 275
 	ctx.Data["Paths"] = paths
290
-	ctx.Data["TreeName"] = treename
291
-	ctx.Data["Treenames"] = treenames
292 276
 	ctx.Data["TreePath"] = treePath
277
+	ctx.Data["TreeLink"] = treeLink
278
+	ctx.Data["Treenames"] = treenames
293 279
 	ctx.Data["BranchLink"] = branchLink
294 280
 	ctx.HTML(200, HOME)
295 281
 }

+ 7 - 7
templates/repo/view_file.tmpl

@@ -15,18 +15,18 @@
15 15
 			<div class="ui right file-actions">
16 16
 				<div class="ui buttons">
17 17
 					{{if not .IsViewCommit}}
18
-						<a class="ui button" href="{{.RepoLink}}/src/{{.CommitID}}/{{EscapePound .TreeName}}">{{.i18n.Tr "repo.file_permalink"}}</a>
18
+						<a class="ui button" href="{{.RepoLink}}/src/{{.CommitID}}/{{EscapePound .TreePath}}">{{.i18n.Tr "repo.file_permalink"}}</a>
19 19
 					{{end}}
20
-					<a class="ui button" href="{{.RepoLink}}/commits/{{EscapePound .BranchName}}/{{EscapePound .TreeName}}">{{.i18n.Tr "repo.file_history"}}</a>
20
+					<a class="ui button" href="{{.RepoLink}}/commits/{{EscapePound .BranchName}}/{{EscapePound .TreePath}}">{{.i18n.Tr "repo.file_history"}}</a>
21 21
 					<a class="ui button" href="{{EscapePound .FileLink}}">{{.i18n.Tr "repo.file_raw"}}</a>
22 22
 				</div>
23
-				{{if .FileEditLink}}
24
-					<a href="{{EscapePound $.FileEditLink}}"><i class="poping up octicon octicon-pencil btn-octicon"  data-content="{{.FileEditLinkTooltip}}" data-position="bottom center" data-variation="tiny inverted"></i></a>
23
+				{{if .CanEditFile}}
24
+					<a href="{{.RepoLink}}/_edit/{{EscapePound .BranchName}}/{{EscapePound .TreePath}}"><i class="poping up octicon octicon-pencil btn-octicon"  data-content="{{.EditFileTooltip}}" data-position="bottom center" data-variation="tiny inverted"></i></a>
25 25
 				{{else}}
26
-					<i class="octicon btn-octicon octicon-pencil poping up disabled" data-content="{{.FileEditLinkTooltip}}" data-position="bottom center" data-variation="tiny inverted"></i>
26
+					<i class="octicon btn-octicon octicon-pencil poping up disabled" data-content="{{.EditFileTooltip}}" data-position="bottom center" data-variation="tiny inverted"></i>
27 27
 				{{end}}
28
-				{{if and .IsViewBranch .IsRepositoryWriter}}
29
-					<form id="delete-file-form" class="ui form inline-form" action="{{.RepoLink}}/_delete/{{EscapePound .BranchName}}/{{.TreeName}}" method="post">
28
+				{{if .CanDeleteFile}}
29
+					<form id="delete-file-form" class="ui form inline-form" action="{{.RepoLink}}/_delete/{{EscapePound .BranchName}}/{{.TreePath}}" method="post">
30 30
 						{{.CsrfTokenHtml}}
31 31
 						<button onclick="submitDeleteForm()" class="octicon octicon-trashcan btn-octicon btn-octicon-danger poping up" type="button" data-content="{{.FileDeleteLinkTooltip}}" data-position="bottom center" data-variation="tiny inverted"></button>
32 32
 						<input type="hidden" id="delete-message" name="commit_message" value="">

+ 1 - 1
templates/repo/view_list.tmpl

@@ -40,7 +40,7 @@
40 40
 				{{else}}
41 41
 					<td class="name">
42 42
 						<span class="octicon octicon-file-{{if or $entry.IsDir}}directory{{else}}text{{end}}"></span>
43
-						<a href="{{EscapePound $.BranchLink}}/{{EscapePound $.TreePath}}{{EscapePound $entry.Name}}">{{$entry.Name}}</a>
43
+						<a href="{{EscapePound $.TreeLink}}/{{EscapePound $entry.Name}}">{{$entry.Name}}</a>
44 44
 					</td>
45 45
 				{{end}}
46 46
 				<td class="message collapsing has-emoji">