浏览代码

Merge pull request #78 from achilleas-k/repo-header-doi

Repository page header redesign
Michael Sonntag 5 年之前
父节点
当前提交
505135934d
共有 4 个文件被更改,包括 113 次插入73 次删除
  1. 39 0
      internal/route/repo/repo_gin.go
  2. 13 35
      templates/repo/header.tmpl
  3. 37 0
      templates/repo/header_gin.tmpl
  4. 24 38
      templates/repo/home.tmpl

+ 39 - 0
internal/route/repo/repo_gin.go

@@ -98,6 +98,45 @@ func readDataciteFile(entry *git.TreeEntry, c *context.Context) {
 	if doi := getRepoDOI(c); doi != "" && libgin.IsRegisteredDOI(doi) {
 	if doi := getRepoDOI(c); doi != "" && libgin.IsRegisteredDOI(doi) {
 		c.Data["DOI"] = doi
 		c.Data["DOI"] = doi
 	}
 	}
+
+	c.Data["IsDOIReady"] = isDOIReady(c)
+}
+
+// True if repository is not Private, is not registered, or is registered and
+// has changes.
+func isDOIReady(c *context.Context) bool {
+	dbrepo := c.Repo.Repository
+	gitrepo := c.Repo.GitRepo
+
+	headIsRegistered := func() bool {
+		currentDOI, ok := c.Data["DOI"]
+		if !ok {
+			return false
+		}
+
+		headBranch, err := gitrepo.GetHEADBranch()
+		if err != nil {
+			log.Error(2, "Failed to get HEAD branch for repo at %q: %v", gitrepo.Path, err)
+			return false
+		}
+
+		headCommit, err := gitrepo.GetBranchCommitID(headBranch.Name)
+		if err != nil {
+			log.Error(2, "Failed to get commit ID of branch %q for repo at %q: %v", headBranch.Name, gitrepo.Path, err)
+		}
+
+		// if current valid and registered DOI matches the HEAD commit, can't
+		// register again
+		doiCommit, err := gitrepo.GetTagCommitID(currentDOI.(string))
+		if err != nil {
+			log.Error(2, "Failed to get commit ID of tag %q for repo at %q: %v", currentDOI, gitrepo.Path, err)
+		}
+
+		log.Trace("%s ?= %s", headCommit, doiCommit)
+		return headCommit == doiCommit
+	}()
+
+	return !dbrepo.IsPrivate && !headIsRegistered
 }
 }
 
 
 // getRepoDOI returns the DOI for the repository based on the following rules:
 // getRepoDOI returns the DOI for the repository based on the following rules:

+ 13 - 35
templates/repo/header.tmpl

@@ -31,9 +31,19 @@
 									</a>
 									</a>
 								</div>
 								</div>
 							</form>
 							</form>
+							<form class="display inline" action="{{$.RepoLink}}/action/{{if $.IsStaringRepo}}un{{end}}star?redirect_to={{$.Link}}" method="POST">
+								{{$.CSRFTokenHTML}}
+								<div class="ui labeled button" tabindex="0">
+									<button class="ui basic button">
+										<i class="star{{if not $.IsStaringRepo}} outline{{end}} icon"></i>{{if $.IsStaringRepo}}{{$.i18n.Tr "repo.unstar"}}{{else}}{{$.i18n.Tr "repo.star"}}{{end}}
+									</button>
+									<a class="ui basic label" href="{{.Link}}/stars">
+										{{.NumStars}}
+									</a>
+								</div>
+							</form>
 							{{if .CanBeForked}}
 							{{if .CanBeForked}}
-							<div class="ui labeled button" tabindex="0"
-									 data-tooltip="Please note: annexed file content will not be forked" data-position="bottom center">
+							<div class="ui labeled button" tabindex="0" data-tooltip="Please note: annexed file content will not be forked" data-position="bottom center">
 									<a class="ui basic button {{if eq .OwnerID $.LoggedUserID}}poping up{{end}}" href="{{AppSubURL}}/repo/fork/{{.ID}}">
 									<a class="ui basic button {{if eq .OwnerID $.LoggedUserID}}poping up{{end}}" href="{{AppSubURL}}/repo/fork/{{.ID}}">
 										<i class="octicon octicon-repo-forked"></i>{{$.i18n.Tr "repo.fork"}}
 										<i class="octicon octicon-repo-forked"></i>{{$.i18n.Tr "repo.fork"}}
 									</a>
 									</a>
@@ -42,39 +52,6 @@
 									</a>
 									</a>
 								</div>
 								</div>
 							{{end}}
 							{{end}}
-							{{if not $.DOI}}
-								{{if and (and $.HasDatacite $.IsRepositoryAdmin) (not .IsPrivate)}}
-								<div class="ui labeled button" tabindex="0">
-									<a class="ui basic button"
-										 href="/{{.Owner.Name}}/{{.Name}}/doi">
-										<i class="octicon octicon-squirrel"></i> DOIfy
-									</a>
-								</div>
-								{{else}}
-								{{if and $.IsRepositoryAdmin $.CommitsCount}}
-								<div class="ui labeled button	" tabindex="0">
-									<a class="ui basic button"
-										 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/DOI">
-										<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}}
-							{{else}}
-										<div class="nobg ui image label">
-											<a href="https://doi.org/{{$.DOI}}">
-												<div class="gin doi">DOI</div>
-											</a>
-												<div class="gin doinr">{{$.DOI}}</div>
-										</div>
-							{{end}}
 						</div>
 						</div>
 					{{end}}
 					{{end}}
 				</div>
 				</div>
@@ -82,6 +59,7 @@
 		</div><!-- end grid -->
 		</div><!-- end grid -->
 	</div><!-- end container -->
 	</div><!-- end container -->
 {{end}}
 {{end}}
+{{template "repo/header_gin" .}}
 {{if not .IsDiffCompare}}
 {{if not .IsDiffCompare}}
 	<div class="ui tabs container">
 	<div class="ui tabs container">
 		<div class="ui tabular menu navbar">
 		<div class="ui tabular menu navbar">

+ 37 - 0
templates/repo/header_gin.tmpl

@@ -0,0 +1,37 @@
+<div class="ui container"><!-- start container -->
+	<div class="ui vertically padded grid head"><!-- start grid -->
+		<div class="column"><!-- start column -->
+			<div class="ui header">
+				{{if not $.IsGuest}}
+					<div class="ui right">
+						{{if and $.IsRepositoryAdmin .PageIsRepoHome}}
+							{{if $.IsDOIReady}} {{/* Ready to (re)register: Show button */}}
+							<div class="ui labeled button" tabindex="0">
+								<a class="ui basic button" href="/{{.Repository.Owner.Name}}/{{.Repository.Name}}/doi"><i class="octicon octicon-squirrel"></i> Request DOI</a>
+							</div>
+							{{else if not $.DOI}} {{/*Link to registration instructions*/}}
+								<div class="ui labeled button	" tabindex="0">
+									<a class="ui basic button" 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/DOI">
+										<i class="octicon octicon-squirrel"></i> How to publish
+									</a>
+									<a class="ui basic label" href="{{$.RepoLink}}/_add/{{EscapePound $.BranchName}}/datacite.yml" data-tooltip="Add datacite file" data-position="bottom center">
+										<i class="octicon octicon-file"></i>
+									</a>
+								</div>
+							{{end}} {{/* End registration button */}}
+						{{end}} {{/* Admin section */}}
+							
+						{{if $.DOI}} {{/* Registered repo: Show DOI badge */}}
+							<div class="nobg ui image label">
+								<a href="https://doi.org/{{$.DOI}}">
+									<div class="gin doi">DOI</div>
+								</a>
+								<div class="gin doinr">{{$.DOI}}</div>
+							</div>
+						{{end}} {{/* End DOI badge */}}
+					</div>
+				{{end}}
+			</div>
+		</div>
+	</div>
+</div>

+ 24 - 38
templates/repo/home.tmpl

@@ -26,14 +26,9 @@
 			{{if .PullRequestCtx.Allowed}}
 			{{if .PullRequestCtx.Allowed}}
 				<div class="fitted item" data-tooltip="Please note: annexed file content will not be part of a pull request">
 				<div class="fitted item" data-tooltip="Please note: annexed file content will not be part of a pull request">
 					<a href="{{.BaseRepo.Link}}/compare/{{EscapePound .BaseRepo.DefaultBranch}}...{{EscapePound .PullRequestCtx.HeadInfo}}">
 					<a href="{{.BaseRepo.Link}}/compare/{{EscapePound .BaseRepo.DefaultBranch}}...{{EscapePound .PullRequestCtx.HeadInfo}}">
-						<button class="ui green small button"><i class="octicon octicon-git-compare"></i>Pull request</button>
+						<button class="ui green small button"><i class="octicon octicon-git-compare"></i></button>
 					</a>
 					</a>
 				</div>
 				</div>
-				{{else if or .IsRepositoryWriter .HasForked}}
-					<div class="fitted item"
-							data-tooltip="Pull requests have been disabled for this repository" data-position="top center">
-							<button class="ui disabled small button"><i class="octicon octicon-git-compare"></i></button>
-					</div>
 			{{end}}
 			{{end}}
 			{{template "repo/branch_dropdown" .}}
 			{{template "repo/branch_dropdown" .}}
 			<div class="fitted item">
 			<div class="fitted item">
@@ -53,7 +48,6 @@
 				</div>
 				</div>
 			</div>
 			</div>
 			<div class="right fitted item">
 			<div class="right fitted item">
-				<div class="ui action small input" id="clone-panel">
 				{{if .Repository.CanEnableEditor}}
 				{{if .Repository.CanEnableEditor}}
 					<div id="file-buttons" class="ui tiny blue buttons">
 					<div id="file-buttons" class="ui tiny blue buttons">
 						{{if .CanAddFile}}
 						{{if .CanAddFile}}
@@ -70,14 +64,10 @@
 				{{end}}
 				{{end}}
 
 
 				<!-- Only show clone panel in repository home page -->
 				<!-- Only show clone panel in repository home page -->
-				{{ $n := len .TreeNames}}
-				{{ $l := Subtract $n 1}}
 				{{if eq $n 0}}
 				{{if eq $n 0}}
-
-						<button class="ui basic clone button" id="repo-clone-gin" data-link="{{.CloneLink.Gin}}">
-							GIN
-						</button>
-						{{if and (not $.DisableHTTP) $.ShowHTTP}}
+					<div class="ui action small input" id="clone-panel">
+						<button class="ui basic clone button" id="repo-clone-gin" data-link="{{.CloneLink.Gin}}">GIN</button>
+						{{if not $.DisableHTTP}}
 							<button class="ui basic clone button" id="repo-clone-https" data-link="{{.CloneLink.HTTPS}}">
 							<button class="ui basic clone button" id="repo-clone-https" data-link="{{.CloneLink.HTTPS}}">
 								{{if UseHTTPS}}HTTPS{{else}}HTTP{{end}}
 								{{if UseHTTPS}}HTTPS{{else}}HTTP{{end}}
 							</button>
 							</button>
@@ -87,37 +77,33 @@
 								SSH
 								SSH
 							</button>
 							</button>
 						{{end}}
 						{{end}}
-						<input id="repo-clone-url" value="{{if not $.DisableHTTP}}{{$.CloneLink.HTTPS}}{{else}}{{$.CloneLink.SSH}}{{end}}" readonly >
+						<input id="repo-clone-url" value="{{if not $.DisableHTTP}}{{$.CloneLink.HTTPS}}{{else}}{{$.CloneLink.SSH}}{{end}}" readonly>
 						<button class="ui basic icon button poping up clipboard" id="clipboard-btn" data-original="{{.i18n.Tr "repo.copy_link"}}" data-success="{{.i18n.Tr "repo.copy_link_success"}}" data-error="{{.i18n.Tr "repo.copy_link_error"}}" data-content="{{.i18n.Tr "repo.copy_link"}}" data-variation="inverted tiny" data-clipboard-target="#repo-clone-url">
 						<button class="ui basic icon button poping up clipboard" id="clipboard-btn" data-original="{{.i18n.Tr "repo.copy_link"}}" data-success="{{.i18n.Tr "repo.copy_link_success"}}" data-error="{{.i18n.Tr "repo.copy_link_error"}}" data-content="{{.i18n.Tr "repo.copy_link"}}" data-variation="inverted tiny" data-clipboard-target="#repo-clone-url">
 							<i class="octicon octicon-clippy"></i>
 							<i class="octicon octicon-clippy"></i>
 						</button>
 						</button>
 						<div id="download-repo-button" class="ui basic icon button poping up" data-original="Archives">
 						<div id="download-repo-button" class="ui basic icon button poping up" data-original="Archives">
-						<i class="download icon"></i>
-						</div>
-
-						<!-- Download modal -->
-						<div id="download_modal" class="ui modal warning">
-							<i class="close icon"></i>
-							<div class="content">
-								<div class="ui header">So you want to download data without special tooling (e.g. git, git-annex or GIN)?</div>
-								<p>Here is what you can do:</p>
-								<p>Download the small files and the file structure as an archive (.zip or .tar.gz). Annexed files (by default, files larger than 10 MB) will be
-								included as pointer files (stubs) but the data will not be included. To get the content of the big files you need to download them individually
-								from this web page.</p>
-								<p>Download the small files as a GIN archive (.gin.zip). This includes all the git information,
-								including the history of the repository and the possibility to download the content of large files using git annex or the GIN client.</p>
-							</div>
-							<div class="actions">
-								<a class="ui positive button" href="{{$.RepoLink}}/archive/{{EscapePound $.BranchName}}.zip"><i class="octicon octicon-file-zip"></i> Download zip</a>
-								<a class="ui positive button" href="{{$.RepoLink}}/archive/{{EscapePound $.BranchName}}.tar.gz"><i class="octicon octicon-file-zip"></i> Download tar.gz</a>
-								<a class="ui positive button" href="{{$.RepoLink}}/archive/{{EscapePound $.BranchName}}.gin.zip"><i
-									class="octicon octicon-file-zip"></i> Download GIN archive</a>
+							<i class="download icon"></i>
+							<!-- Download modal -->
+							<div id="download_modal" class="ui modal warning">
+								<i class="close icon"></i>
+								<div class="content">
+									<div class="ui header">Download repository archive</div>
+									<p>To download data without special tooling (e.g. git, git-annex or GIN) you can:</p>
+									<p>Download the small files and the file structure as an archive (.zip or .tar.gz). Annexed files (by default, files larger than 10 MB) will be
+									included as pointer files (stubs) but the data will not be included. To get the content of the big files you need to download them individually
+									from this web page.</p>
+									<p>Download the small files as a GIN archive (.gin.zip). This includes all the git information,
+									including the history of the repository and the possibility to download the content of large files using git annex or the GIN client.</p>
+								</div>
+								<div class="actions">
+									<a class="ui positive button" href="{{$.RepoLink}}/archive/{{EscapePound $.BranchName}}.zip"><i class="octicon octicon-file-zip"></i> Download zip</a>
+									<a class="ui positive button" href="{{$.RepoLink}}/archive/{{EscapePound $.BranchName}}.tar.gz"><i class="octicon octicon-file-zip"></i> Download tar.gz</a>
+									<a class="ui positive button" href="{{$.RepoLink}}/archive/{{EscapePound $.BranchName}}.gin.zip"><i class="octicon octicon-file-zip"></i> Download GIN archive</a>
+								</div>
 							</div>
 							</div>
 						</div>
 						</div>
-
-
+					</div>
 				{{end}}
 				{{end}}
-				</div>
 			</div>
 			</div>
 		</div>
 		</div>
 		{{if .IsViewFile}}
 		{{if .IsViewFile}}