Parcourir la source

[Doi] Add doifile feature

Adds the ability to add a template datacite file to a repository.
* route to show new file module with pre-filled file
* button for adding
* datacite template
cgars il y a 7 ans
Parent
commit
bb39899e50
4 fichiers modifiés avec 99 ajouts et 2 suppressions
  1. 1 0
      cmd/web.go
  2. 57 0
      conf/datacite/datacite.yml
  3. 33 0
      routes/repo/editor.go
  4. 8 2
      templates/repo/header.tmpl

+ 1 - 0
cmd/web.go

@@ -554,6 +554,7 @@ func runWeb(c *cli.Context) error {
 			m.Post("/_preview/*", bindIgnErr(form.EditPreviewDiff{}), repo.DiffPreviewPost)
 			m.Combo("/_delete/*").Get(repo.DeleteFile).
 				Post(bindIgnErr(form.DeleteRepoFile{}), repo.DeleteFilePost)
+			m.Combo("/_add/*").Get(repo.AddFile).Post(bindIgnErr(form.EditRepoFile{}), repo.NewFilePost)
 
 			m.Group("", func() {
 				m.Combo("/_upload/*").Get(repo.UploadFile).

+ 57 - 0
conf/datacite/datacite.yml

@@ -0,0 +1,57 @@
+# Required fields
+# The main researchers involved working on the resource,
+# or the authors of the publication in priority order.
+# May be a corporate/institutional or personal name.
+# Include digital identifier (e.g., ORCID) if possible
+authors:
+  -
+    firstname: "GivenName1"
+    lastname: "FamilyName1"
+    affiliation: "Affiliation1"
+    id: "AuthorID1 (e.g. ORCID)"
+  -
+    firstname: "GivenName2"
+    lastname: "FamilyName2"
+    affiliation: "Affiliation2"
+  -
+    firstname: "GivenName3"
+    lastname: "FamilyName3"
+
+# A name or title to describe the published resource.
+title: "Example Title"
+
+# Any additional information. It is best practice to supply a description for the resource.
+description: |
+  Example description
+  that can contain linebreaks
+  but has to maintain indentation.
+
+# List of keywords the resource should be associated with.
+keywords:
+  - Neuroscience
+  - Electrophysiology
+
+# Any rights information for this resource. Please provide both a license name and a link to the license.
+# Please add also a LICENSE file to the repository
+license:
+  name: "CC0"
+  url: "http://creativecommons.org/publicdomain/zero/1.0"
+
+## Optional Fields
+
+# Any funding reference for this resource. Separate funder name and grant number by comma
+funding:
+  - "DFG, DFG.12345"
+  - "EU, EU.12345"
+
+# Related publications. reftype might be: IsCitedBy, IsSupplementTo, IsReferencedBy, IsPartOf
+# for further valid types see https://schema.datacite.org/meta/kernel-4
+# Please provide digital identifier (e.g., DOI) if possible.
+references:
+  -
+    doi: "10.xxx/zzzz"
+    reftype: "IsSupplementTo"
+    name: "PublicationName"
+  -
+    reftype: "IsPartOf"
+    name: "PublicationName"

+ 33 - 0
routes/repo/editor.go

@@ -21,6 +21,7 @@ import (
 	"github.com/G-Node/gogs/pkg/template"
 	"github.com/G-Node/gogs/pkg/tool"
 	"github.com/G-Node/gogs/pkg/markup"
+	"github.com/G-Node/gogs/pkg/bindata"
 )
 
 const (
@@ -119,6 +120,7 @@ func editFile(c *context.Context, isNewFile bool) {
 	c.Success(EDIT_FILE)
 }
 
+
 func EditFile(c *context.Context) {
 	editFile(c, false)
 }
@@ -572,3 +574,34 @@ func RemoveUploadFileFromServer(c *context.Context, f form.RemoveUploadFile) {
 	log.Trace("Upload file removed: %s", f.File)
 	c.Status(204)
 }
+
+func AddFile(c *context.Context) {
+	link := strings.Split(c.Link, "/")
+	name := link[len(link)-1]
+	treeNames, treePaths := getParentTreeFields(c.Repo.TreePath)
+
+	c.PageIs("Edit")
+	c.RequireHighlightJS()
+	c.RequireSimpleMDE()
+
+	c.Data["IsJSON"] = markup.IsJSON(name)
+	c.Data["IsYAML"] = markup.IsYAML(name)
+	relName := path.Join("conf", "datacite", name)
+	data, _ := bindata.Asset(relName)
+	c.Data["FileContent"] = string(data)
+	c.Data["ParentTreePath"] = path.Dir(c.Repo.TreePath)
+	c.Data["TreeNames"] = treeNames
+	c.Data["TreePaths"] = treePaths
+	c.Data["BranchLink"] = c.Repo.RepoLink + "/src/" + c.Repo.BranchName
+	c.Data["commit_summary"] = ""
+	c.Data["commit_message"] = ""
+	c.Data["commit_choice"] = "direct"
+	c.Data["new_branch_name"] = ""
+	c.Data["last_commit"] = c.Repo.Commit.ID
+	c.Data["MarkdownFileExts"] = strings.Join(setting.Markdown.FileExtensions, ",")
+	c.Data["LineWrapExtensions"] = strings.Join(setting.Repository.Editor.LineWrapExtensions, ",")
+	c.Data["PreviewableFileModes"] = strings.Join(setting.Repository.Editor.PreviewableFileModes, ",")
+	c.Data["EditorconfigURLPrefix"] = fmt.Sprintf("%s/api/v1/repos/%s/editorconfig/", setting.AppSubURL, c.Repo.Repository.FullName())
+
+	c.Success(EDIT_FILE)
+}

+ 8 - 2
templates/repo/header.tmpl

@@ -43,12 +43,18 @@
 							</div>
 							{{else}}
 							{{if and $.IsRepositoryAdmin $.CommitsCount}}
-							<div class="ui labeled button" tabindex="0">
+							<div class="ui labeled button	" tabindex="0">
 								<a class="ui basic button"
-									 data-tooltip="Your repository does not yet fulfill all requirements for a doi. Click to get instructions."
+									 data-tooltip="Your repository does not fulfill all requirements for a doi yet. Click to get instructions."
+									 data-position="bottom center"
 									 href="/G-Node/Info/wiki/DOIfile">
 									<i class="octicon octicon-squirrel"></i> DOIfy
 								</a>
+								<a class="ui basic label" href="{{$.RepoLink}}/_add/{{EscapePound $.BranchName}}/datacite.yml"
+									data-tooltip="Add Doifile"
+									data-position="bottom center">
+									<i class="octicon octicon-file"></i>
+								</a>
 							</div>
 							{{end}}
 							{{end}}