Kaynağa Gözat

[GinR] OdML files should be rendered on default

cgars 7 yıl önce
ebeveyn
işleme
c98b6f250e
3 değiştirilmiş dosya ile 32 ekleme ve 24 silme
  1. 4 0
      public/css/gogs.css
  2. 6 4
      routes/repo/view.go
  3. 22 20
      templates/repo/view_file.tmpl

+ 4 - 0
public/css/gogs.css

@@ -3238,3 +3238,7 @@ figure figcaption {
 #cloudberry-view {
   margin-top: 14px;
 }
+
+#codetab #odmltab{
+  padding: 0;
+}

+ 6 - 4
routes/repo/view.go

@@ -277,10 +277,12 @@ func renderFile(c *context.Context, entry *git.TreeEntry, treeLink, rawLink stri
 			c.Data["IsIPythonNotebook"] = true
 		case markup.JSON:
 			c.Data["IsJSON"] = true
-			c.Data["FileContent"] = string(buf)
+			c.Data["RawFileContent"] = string(buf)
+			fallthrough
 		case markup.YAML:
 			c.Data["IsYAML"] = true
-			c.Data["FileContent"] = string(buf)
+			c.Data["RawFileContent"]=string(buf)
+			fallthrough
 		case markup.UNRECOGNIZED:
 			if tool.IsOdmlFile(buf) {
 				c.Data["IsOdML"] = true
@@ -290,8 +292,8 @@ func renderFile(c *context.Context, entry *git.TreeEntry, treeLink, rawLink stri
 				decoder.CharsetReader = charset.NewReaderLabel
 				decoder.Decode(&od)
 				data, _ := json.Marshal(od)
-				c.Data["FileContent"] = string(data)
-				break
+				c.Data["OdML"] = string(data)
+				goto End
 			} else {
 				goto End
 			}

+ 22 - 20
templates/repo/view_file.tmpl

@@ -37,16 +37,16 @@
 	</h4>
 	{{if or .IsJSON (or .IsYAML .IsOdML)}}
 	<div class="ui top attached tabular menu">
-		<a class="item active" data-tab="code"><i class="octicon octicon-file-code"></i> Code</a>
-		<a class="item" data-tab="view"><i class="octicon octicon-file"></i> View</a>
+		<a class="item {{if or .IsJSON .IsYAML}}active{{end}}" data-tab="code"><i class="octicon octicon-file-code"></i> Code</a>
+		<a class="item {{if .IsOdML}}active{{end}}" data-tab="view"><i class="octicon octicon-file"></i> View</a>
 	</div>
 	{{end}}
-	<div class="{{if or .IsJSON (or .IsYAML .IsOdML)}}ui bottom attached tab segment" data-tab="view{{else}}ui attached table segment{{end}}">
+	<div class="{{if or .IsJSON (or .IsYAML .IsOdML)}}ui bottom attached tab {{if .IsOdML}} active{{end}} segment" data-tab="view{{else}}ui attached table segment{{end}}">
 		<div id="{{if not (or .IsJSON .IsYAML)}}{{if .IsIPythonNotebook}}ipython-notebook{{end}}" class="file-view {{if .IsMarkdown}}markdown{{else if .IsIPythonNotebook}}ipython-notebook{{else if .IsIPythonNotebook}}ipython-notebook{{else if .ReadmeInList}}plain-text{{else if and .IsTextFile}}code-view{{end}} has-emoji{{end}}">
 			{{if .IsMarkdown}}
 				{{if .FileContent}}{{.FileContent | Str2html}}{{end}}
 			{{else if .IsOdML}}
-			<div class="ui fluid action input">
+			<div class="ui fluid input">
 				<input class="search-input form-control" placeholder="Search"></input>
 			</div>
 			<div id="jstree"></div>
@@ -61,7 +61,7 @@
 					});
 					$('#jstree').jstree({
 						'core': {
-							'data': [{{.FileContent| Str2JS}}]
+							'data': [{{.OdML| Str2JS}}]
 				},
 					"search": {
 						"case_insensitive": true,
@@ -81,7 +81,7 @@
 				var editor = new JSONEditor(container, options);
 
 				// set json
-				var json = {{.FileContent| Str2JS}}
+				var json = {{.RawFileContent| Str2JS}}
 				editor.set(json);
 
 				// get json
@@ -95,7 +95,7 @@
 				var options = {mode:"view"};
 				var editor = new JSONEditor(container, options);
 				// set json
-				var json = YAML.parse({{.FileContent}})
+				var json = YAML.parse({{.RawFileContent}})
 				editor.set(json);
 
 				// get json
@@ -164,19 +164,21 @@
 		</div>
 	</div>
 	{{if or .IsJSON (or .IsYAML .IsOdML)}}
-	<div class="ui bottom attached tab active segment" data-tab="code">
-	<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>
+	<div class="ui bottom attached tab {{if not .IsOdML}}active{{end}} segment" data-tab="code" id="codetab">
+		<div class="file-view code-view has-emoji">
+			<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>
+		</div>
 	</div>
 	{{end}}
 </div>