Переглянути джерело

[GinS] Commit searching

This enables full search support in commits
cgars 7 роки тому
батько
коміт
a4d736737a

+ 1 - 0
cmd/web.go

@@ -183,6 +183,7 @@ func runWeb(c *cli.Context) error {
 			c.Redirect(setting.AppSubURL + "/explore/repos")
 		})
 		m.Get("/data", routes.ExploreData)
+		m.Get("/commits", routes.ExploreCommits)
 		m.Get("/repos", routes.ExploreRepos)
 		m.Get("/users", routes.ExploreUsers)
 		m.Get("/organizations", routes.ExploreOrganizations)

+ 1 - 0
conf/locale/locale_de-DE.ini

@@ -145,6 +145,7 @@ users=Benutzer
 organizations=Organisationen
 search=Suche
 data=Daten Suche
+commits=Commit Suche
 
 [auth]
 create_new_account=Neues Konto erstellen

+ 2 - 1
conf/locale/locale_en-GB.ini

@@ -146,7 +146,8 @@ repos=Repositories
 users=Users
 organizations=Organisations
 search=Search
-data=SearchData
+data=Search Data
+commits=Search Commits
 
 [auth]
 create_new_account=Create New Account

+ 1 - 0
conf/locale/locale_en-US.ini

@@ -147,6 +147,7 @@ users = Users
 organizations = Organizations
 search = Search
 data = Search Data
+commits = Search Commits
 
 [auth]
 create_new_account = Create New Account

+ 5 - 0
routes/api/v1/repo/repo.go

@@ -27,6 +27,11 @@ func Search(c *context.APIContext) {
 		PageSize: convert.ToCorrectPageSize(c.QueryInt("limit")),
 	}
 
+	// workaround for the all querry with logged users
+	if opts.Keyword == "." && c.User.ID > 0 {
+		opts.Keyword = ""
+		log.Trace("User %i asked for all repos")
+	}
 	// Check visibility.
 	if c.IsLogged && opts.OwnerID > 0 {
 		if c.User.ID == opts.OwnerID {

+ 25 - 3
routes/search.go

@@ -12,7 +12,8 @@ import (
 )
 
 const (
-	EXPLORE_DATA = "explore/data"
+	EXPLORE_DATA    = "explore/data"
+	EXPLORE_COMMITS = "explore/commits"
 )
 
 func Search(c *context.Context, keywords string) ([]byte, error) {
@@ -62,11 +63,32 @@ func ExploreData(c *context.Context) {
 	res := gindex.SearchResults{}
 	err = json.Unmarshal(data, &res)
 	if err != nil {
-		c.Handle(http.StatusInternalServerError, "Could nor display result", err)
+		c.Handle(http.StatusInternalServerError, "Could not display result", err)
 		return
 	}
 	c.Data["Blobs"] = res.Blobs
-	c.Data["Commits"] = res.Commits
 	c.HTML(200, EXPLORE_DATA)
+}
+
+func ExploreCommits(c *context.Context) {
+	c.Data["Title"] = c.Tr("explore")
+	c.Data["PageIsExplore"] = true
+	c.Data["PageIsExploreCommits"] = true
 
+	keywords := c.Query("q")
+	data, err := Search(c, keywords)
+
+	if err != nil {
+		c.Handle(http.StatusInternalServerError, "Could nor querry", err)
+		return
+	}
+
+	res := gindex.SearchResults{}
+	err = json.Unmarshal(data, &res)
+	if err != nil {
+		c.Handle(http.StatusInternalServerError, "Could not display result", err)
+		return
+	}
+	c.Data["Commits"] = res.Commits
+	c.HTML(200, EXPLORE_COMMITS)
 }

+ 2 - 0
templates/explore/blob_list.tmpl

@@ -16,6 +16,7 @@
 					{{.Score}}
 				</div>
 			</div>
+			{{if .Highlight}}
 			<div class="ui horizontal divider">
 				hits
 			</div>
@@ -26,6 +27,7 @@
 				{{. | Safe}}
 			</div>
 			{{end}}
+			{{end}}
 		</div>
 	</div>
 	<div class="ui divider"></div>

+ 31 - 0
templates/explore/commit_list.tmpl

@@ -0,0 +1,31 @@
+<div class="ui blob-list">
+	{{range .Commits}}
+	<div class="ui segment">
+		<div class="ui header">
+			<div>
+				<a href="{{AppSubURL}}/{{.Source.GinRepoName}}">
+					<span class="octicon octicon-repo"></span>
+					{{.Source.GinRepoName}}
+				</a>
+				<a href="{{AppSubURL}}/{{.Source.GinRepoName}}/commit/{{.Source.Oid}}">
+					<div class="ui sha label">{{ShortSHA1 .Source.Oid.String}}</div>
+				</a>
+				<div class="ui right">
+					<i class="heartbeat icon"></i>
+					{{.Score}}
+				</div>
+			</div>
+		</div>
+		{{if .Highlight}}
+		<div class="ui divider"></div>
+		<div class="ui divided list">
+			{{range .Highlight.Message}}
+			<div class="item">
+				{{. | Safe}}
+			</div>
+			{{end}}
+		</div>
+		{{end}}
+	</div>
+	{{end}}
+</div>

+ 14 - 0
templates/explore/commits.tmpl

@@ -0,0 +1,14 @@
+{{template "base/head" .}}
+<div class="explore data">
+	<div class="ui container">
+		<div class="ui grid">
+			{{template "explore/navbar" .}}
+			<div class="twelve wide column content">
+				{{template "explore/search" .}}
+				{{template "explore/commit_list" .}}
+				{{template "explore/page" .}}
+			</div>
+		</div>
+	</div>
+</div>
+	{{template "base/footer" .}}

+ 3 - 0
templates/explore/navbar.tmpl

@@ -11,6 +11,9 @@
 		<a class="{{if .PageIsExploreData}}active{{end}} item" href="{{AppSubURL}}/explore/data">
 			<span class="octicon octicon-file"></span> {{.i18n.Tr "explore.data"}}
 		</a>
+		<a class="{{if .PageIsExploreCommits}}active{{end}} item" href="{{AppSubURL}}/explore/commits">
+			<span class="octicon octicon-git-commit"></span> {{.i18n.Tr "explore.commits"}}
+		</a>
 		<a class="{{if .PageIsExploreUsers}}active{{end}} item" href="{{AppSubURL}}/explore/users">
 			<span class="octicon octicon-person"></span> {{.i18n.Tr "explore.users"}}
 		</a>

+ 6 - 6
vendor/vendor.json

@@ -9,16 +9,16 @@
 			"revisionTime": "2017-10-25T13:28:53Z"
 		},
 		{
-			"checksumSHA1": "dTbFlXX0KDsbWUA9UemWnRbi3hk=",
+			"checksumSHA1": "LnRv1Ks+MlNEtH5YyfzN7YDwchY=",
 			"path": "github.com/G-Node/gin-dex",
-			"revision": "8ceedcfb22776c266dfb48f29aee9de655531b8c",
-			"revisionTime": "2017-11-05T17:46:00Z"
+			"revision": "d4994f3bb1774be302aa9be2fdd4db28b454b01e",
+			"revisionTime": "2017-11-17T12:52:54Z"
 		},
 		{
-			"checksumSHA1": "gWVNLlIxyc2AbxVn9c00i7kWAKU=",
+			"checksumSHA1": "/nx4C9e6SWnuATeRNXMyVaEOwFw=",
 			"path": "github.com/G-Node/gin-dex/gindex",
-			"revision": "8ceedcfb22776c266dfb48f29aee9de655531b8c",
-			"revisionTime": "2017-11-05T17:46:00Z"
+			"revision": "d4994f3bb1774be302aa9be2fdd4db28b454b01e",
+			"revisionTime": "2017-11-17T12:52:54Z"
 		},
 		{
 			"checksumSHA1": "/OCenqqlNlqcINpnIQwK6Givd+w=",