aboutsummaryrefslogtreecommitdiff
path: root/templates/repo/view_file.tmpl
blob: 0e4acb7fa67c4383055911ccf8ab05438c6022df (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
<div id="file-content" class="{{TabSizeClass .Editorconfig .FileName}}">
	<h4 class="ui top attached header" id="{{if .ReadmeExist}}repo-readme{{else}}repo-read-file{{end}}">
		{{if .ReadmeExist}}
			<i class="octicon octicon-book"></i>
			{{if .ReadmeInList}}
				<strong>{{.FileName}}</strong>
			{{else}}
				<strong>{{.FileName}}</strong> <span class="text grey normal">{{FileSize .FileSize}}</span>
			{{end}}
		{{else}}
			<i class="octicon octicon-file-text ui left"></i>
			<strong>{{.FileName}}</strong> <span class="text grey normal">{{FileSize .FileSize}}</span>
		{{end}}
		{{if not .ReadmeInList}}
			<div class="ui right file-actions">
				<div class="ui buttons">
					{{if not .IsViewCommit}}
						<a class="ui button" href="{{.RepoLink}}/src/{{.CommitID}}/{{EscapePound .TreePath}}">{{.i18n.Tr "repo.file_permalink"}}</a>
					{{end}}
					<a class="ui button" href="{{.RepoLink}}/commits/{{EscapePound .BranchName}}/{{EscapePound .TreePath}}">{{.i18n.Tr "repo.file_history"}}</a>
					<a class="ui button" href="{{EscapePound $.RawFileLink}}">{{.i18n.Tr "repo.file_raw"}}</a>
				</div>
				{{if .Repository.CanEnableEditor}}
					{{if .CanEditFile}}
						<a href="{{.RepoLink}}/_edit/{{EscapePound .BranchName}}/{{EscapePound .TreePath}}"><i class="octicon octicon-pencil btn-octicon poping up"  data-content="{{.EditFileTooltip}}" data-position="bottom center" data-variation="tiny inverted"></i></a>
					{{else}}
						<i class="octicon octicon-pencil btn-octicon poping up disabled" data-content="{{.EditFileTooltip}}" data-position="bottom center" data-variation="tiny inverted"></i>
					{{end}}
					{{if .CanDeleteFile}}
						<a href="{{.RepoLink}}/_delete/{{EscapePound .BranchName}}/{{EscapePound .TreePath}}"><i class="octicon octicon-trashcan btn-octicon btn-octicon-danger poping up"  data-content="{{.DeleteFileTooltip}}" data-position="bottom center" data-variation="tiny inverted"></i></a>
					{{else}}
						<i class="octicon octicon-trashcan btn-octicon poping up disabled" data-content="{{.DeleteFileTooltip}}" data-position="bottom center" data-variation="tiny inverted"></i>
					{{end}}
				{{end}}
			</div>
		{{end}}
	</h4>
	<div class="ui unstackable attached table segment">
		<div id="{{if .IsIPythonNotebook}}ipython-notebook{{end}}" class="file-view {{if .IsMarkdown}}markdown{{else if .IsIPythonNotebook}}ipython-notebook{{else if .ReadmeInList}}plain-text{{else if and .IsTextFile}}code-view{{end}} has-emoji">
			{{if .IsMarkdown}}
				{{if .FileContent}}{{.FileContent | Str2HTML}}{{end}}
			{{else if .IsIPythonNotebook}}
				<script>
					$.getJSON("{{.RawFileLink}}", null, function(notebook_json) {
						var notebook = nb.parse(notebook_json);
						var rendered = notebook.render();
						$.ajax({
							type: "POST",
							url: '{{AppSubURL}}/-/api/sanitize_ipynb',
							data: rendered.outerHTML,
							processData: false,
							contentType: false,
						}).done(function(data) {
							$("#ipython-notebook").append(data);
							$("#ipython-notebook code").each(function(i, block) {
								$(block).addClass("py").addClass("python");
								hljs.highlightBlock(block);
							});

							// Overwrite image method to append proper prefix to the source URL
							var renderer = new marked.Renderer();
							var context = '{{.RawFileLink}}';
							context = context.substring(0, context.lastIndexOf("/"));
							renderer.image = function (href, title, text) {
								return `<img src="${context}/${href}"`
							};
							$("#ipython-notebook .nb-markdown-cell").each(function(i, markdown) {
								$(markdown).html(marked($(markdown).html(), {renderer: renderer}));
							});
						});
					});
				</script>
			{{else if .ReadmeInList}}
				{{if .FileContent}}{{.FileContent | Str2HTML}}{{end}}
			{{else if not .IsTextFile}}
				<div class="view-raw ui center">
					{{if .IsImageFile}}
						<img src="{{EscapePound $.RawFileLink}}">
					{{else if .IsVideoFile}}
						<video controls src="{{EscapePound $.RawFileLink}}">
							<strong>{{.i18n.Tr "repo.video_not_supported_in_browser"}}</strong>
						</video>
					{{else if .IsPDFFile}}
						<iframe width="100%" height="600px" src="{{AppSubURL}}/plugins/pdfjs-1.4.20/web/viewer.html?file={{EscapePound $.RawFileLink}}"></iframe>
					{{else}}
						<a href="{{EscapePound $.RawFileLink}}" rel="nofollow" class="btn btn-gray btn-radius">{{.i18n.Tr "repo.file_view_raw"}}</a>
					{{end}}
				</div>
			{{else if .FileSize}}
				<table>
					<tbody>
						<tr>
						{{if .IsFileTooLarge}}
							<td><strong>{{.i18n.Tr "repo.file_too_large"}}</strong></td>
						{{else}}
							<td class="lines-num">{{.LineNums}}</td>
							<td class="lines-code"><pre><code class="{{.HighlightClass}}"><ol class="linenums">{{.FileContent}}</ol></code></pre></td>
						{{end}}
						</tr>
					</tbody>
				</table>
			{{end}}
		</div>
	</div>
</div>

<script>
function submitDeleteForm() {
    var message = prompt("{{.i18n.Tr "repo.delete_confirm_message"}}\n\n{{.i18n.Tr "repo.delete_commit_summary"}}", "Delete '{{.TreeName}}'");
    if (message != null) {
        $("#delete-message").val(message);
        $("#delete-file-form").submit()
    }
}
</script>