Selaa lähdekoodia

Added New Route file for Explore

Yoginth 7 vuotta sitten
vanhempi
commit
8f9f95639e
5 muutettua tiedostoa jossa 223 lisäystä ja 229 poistoa
  1. 1 1
      cmd/web.go
  2. 204 0
      routes/explore.go
  3. 0 190
      routes/home.go
  4. 4 0
      templates/admin/navbar.tmpl
  5. 14 38
      templates/explore/home.tmpl

+ 1 - 1
cmd/web.go

@@ -172,7 +172,7 @@ func runWeb(c *cli.Context) error {
 	m.Get("/", ignSignIn, routes.Home)
 	m.Get("/trending", routes.ExploreTrending)
 	m.Group("/explore", func() {
-		m.Get("/", routes.ExploreHome)
+		m.Get("/", routes.Explore)
 		m.Get("/repos", routes.ExploreRepos)
 		m.Get("/users", routes.ExploreUsers)
 		m.Get("/organizations", routes.ExploreOrganizations)

+ 204 - 0
routes/explore.go

@@ -0,0 +1,204 @@
+// Copyright 2015 The Gogs Authors. All rights reserved.
+// Copyright 2018 Gitote. All rights reserved.
+//
+// This source code is licensed under the MIT license found in the
+// LICENSE file in the root directory of this source tree.
+
+package routes
+
+import (
+	"gitote/gitote/models"
+	"gitote/gitote/pkg/context"
+	"gitote/gitote/pkg/setting"
+
+	"gitlab.com/yoginth/paginater"
+)
+
+const (
+	// EXPLORE_HOME page template
+	EXPLORE = "explore/home"
+
+	// EXPLORE_REPOS page template
+	EXPLORE_REPOS = "explore/repos"
+
+	// EXPLORE_USERS page template
+	EXPLORE_USERS = "explore/users"
+
+	// EXPLORE_TRENDING page template
+	EXPLORE_TRENDING = "explore/trending"
+
+	// EXPLORE_ORGANIZATIONS page template
+	EXPLORE_ORGANIZATIONS = "explore/organizations"
+)
+
+// ExploreHome shows explore page
+func Explore(c *context.Context) {
+	c.Data["Title"] = c.Tr("explore")
+	c.Data["PageIsExplore"] = true
+	c.Data["PageIsExploreRepositories"] = true
+
+	repos, count, err := models.SearchRepositoryByName(&models.SearchRepoOptions{
+		UserID:   c.UserID(),
+		OrderBy:  "num_stars DESC",
+		PageSize: 4,
+	})
+	if err != nil {
+		c.ServerError("SearchRepositoryByName", err)
+		return
+	}
+	c.Data["Total"] = count
+
+	if err = models.RepositoryList(repos).LoadAttributes(); err != nil {
+		c.ServerError("RepositoryList.LoadAttributes", err)
+		return
+	}
+	c.Data["Repos"] = repos
+
+	c.Success(EXPLORE)
+}
+
+// ExploreRepos shows explore repositories page
+func ExploreRepos(c *context.Context) {
+	c.Data["Title"] = c.Tr("explore")
+	c.Data["PageIsExplore"] = true
+	c.Data["PageIsExploreRepositories"] = true
+
+	page := c.QueryInt("page")
+	if page <= 0 {
+		page = 1
+	}
+
+	keyword := c.Query("q")
+	// Search a repository
+	repos, count, err := models.SearchRepositoryByName(&models.SearchRepoOptions{
+		Keyword:  keyword,
+		UserID:   c.UserID(),
+		OrderBy:  "updated_unix DESC",
+		Page:     page,
+		PageSize: setting.UI.ExplorePagingNum,
+	})
+	if err != nil {
+		c.ServerError("SearchRepositoryByName", err)
+		return
+	}
+	c.Data["Keyword"] = keyword
+	c.Data["Total"] = count
+	c.Data["Page"] = paginater.New(int(count), setting.UI.ExplorePagingNum, page, 5)
+
+	if err = models.RepositoryList(repos).LoadAttributes(); err != nil {
+		c.ServerError("RepositoryList.LoadAttributes", err)
+		return
+	}
+	c.Data["Repos"] = repos
+
+	c.Success(EXPLORE_REPOS)
+}
+
+// ExploreTrending shows trending repositories page
+func ExploreTrending(c *context.Context) {
+	c.Data["Title"] = c.Tr("explore.trending")
+	c.Data["PageIsTrending"] = true
+
+	repos, count, err := models.SearchRepositoryByName(&models.SearchRepoOptions{
+		UserID:   c.UserID(),
+		OrderBy:  "num_stars DESC",
+		PageSize: 15,
+	})
+	if err != nil {
+		c.ServerError("SearchRepositoryByName", err)
+		return
+	}
+	c.Data["Total"] = count
+
+	if err = models.RepositoryList(repos).LoadAttributes(); err != nil {
+		c.ServerError("RepositoryList.LoadAttributes", err)
+		return
+	}
+	c.Data["Repos"] = repos
+
+	c.Success(EXPLORE_TRENDING)
+}
+
+// UserSearchOptions is the structure of the options choosed by the user
+type UserSearchOptions struct {
+	Type     models.UserType
+	Counter  func() int64
+	Ranger   func(int, int) ([]*models.User, error)
+	PageSize int
+	OrderBy  string
+	TplName  string
+}
+
+// RenderUserSearch renders user search
+func RenderUserSearch(c *context.Context, opts *UserSearchOptions) {
+	page := c.QueryInt("page")
+	if page <= 1 {
+		page = 1
+	}
+
+	var (
+		users []*models.User
+		count int64
+		err   error
+	)
+
+	keyword := c.Query("q")
+	if len(keyword) == 0 {
+		users, err = opts.Ranger(page, opts.PageSize)
+		if err != nil {
+			c.ServerError("Ranger", err)
+			return
+		}
+		count = opts.Counter()
+	} else {
+		users, count, err = models.SearchUserByName(&models.SearchUserOptions{
+			Keyword:  keyword,
+			Type:     opts.Type,
+			OrderBy:  opts.OrderBy,
+			Page:     page,
+			PageSize: opts.PageSize,
+		})
+		if err != nil {
+			c.ServerError("SearchUserByName", err)
+			return
+		}
+	}
+	c.Data["Keyword"] = keyword
+	c.Data["Total"] = count
+	c.Data["Page"] = paginater.New(int(count), opts.PageSize, page, 5)
+	c.Data["Users"] = users
+
+	c.Success(opts.TplName)
+}
+
+// ExploreUsers shows explore users page
+func ExploreUsers(c *context.Context) {
+	c.Data["Title"] = c.Tr("explore")
+	c.Data["PageIsExplore"] = true
+	c.Data["PageIsExploreUsers"] = true
+
+	RenderUserSearch(c, &UserSearchOptions{
+		Type:     models.USER_TYPE_INDIVIDUAL,
+		Counter:  models.CountUsers,
+		Ranger:   models.Users,
+		PageSize: setting.UI.ExplorePagingNum,
+		OrderBy:  "updated_unix DESC",
+		TplName:  EXPLORE_USERS,
+	})
+}
+
+//ExploreOrganizations shows explore organizations page
+func ExploreOrganizations(c *context.Context) {
+	c.Data["Title"] = c.Tr("explore")
+	c.Data["PageIsExplore"] = true
+	c.Data["PageIsExploreOrganizations"] = true
+
+	RenderUserSearch(c, &UserSearchOptions{
+		Type:     models.USER_TYPE_ORGANIZATION,
+		Counter:  models.CountOrganizations,
+		Ranger:   models.Organizations,
+		PageSize: setting.UI.ExplorePagingNum,
+		OrderBy:  "updated_unix DESC",
+		TplName:  EXPLORE_ORGANIZATIONS,
+	})
+}

+ 0 - 190
routes/home.go

@@ -7,32 +7,14 @@
 package routes
 
 import (
-	"gitote/gitote/models"
 	"gitote/gitote/pkg/context"
 	"gitote/gitote/pkg/setting"
 	"gitote/gitote/routes/user"
-
-	"gitlab.com/yoginth/paginater"
 )
 
 const (
 	// HOME page template
 	HOME = "home"
-
-	// EXPLORE_HOME page template
-	EXPLORE_HOME = "explore/home"
-
-	// EXPLORE_REPOS page template
-	EXPLORE_REPOS = "explore/repos"
-
-	// EXPLORE_USERS page template
-	EXPLORE_USERS = "explore/users"
-
-	// EXPLORE_TRENDING page template
-	EXPLORE_TRENDING = "explore/trending"
-
-	// EXPLORE_ORGANIZATIONS page template
-	EXPLORE_ORGANIZATIONS = "explore/organizations"
 )
 
 // Home shows the home page
@@ -58,178 +40,6 @@ func Home(c *context.Context) {
 	c.Success(HOME)
 }
 
-// ExploreHome shows explore page
-func ExploreHome(c *context.Context) {
-	c.Data["Title"] = c.Tr("explore")
-	c.Data["PageIsExplore"] = true
-	c.Data["PageIsExploreRepositories"] = true
-
-	repos, count, err := models.SearchRepositoryByName(&models.SearchRepoOptions{
-		UserID:   c.UserID(),
-		OrderBy:  "num_stars DESC",
-		PageSize: 4,
-	})
-	if err != nil {
-		c.ServerError("SearchRepositoryByName", err)
-		return
-	}
-	c.Data["Total"] = count
-
-	if err = models.RepositoryList(repos).LoadAttributes(); err != nil {
-		c.ServerError("RepositoryList.LoadAttributes", err)
-		return
-	}
-	c.Data["Repos"] = repos
-
-	c.Success(EXPLORE_HOME)
-}
-
-// ExploreRepos shows explore repositories page
-func ExploreRepos(c *context.Context) {
-	c.Data["Title"] = c.Tr("explore")
-	c.Data["PageIsExplore"] = true
-	c.Data["PageIsExploreRepositories"] = true
-
-	page := c.QueryInt("page")
-	if page <= 0 {
-		page = 1
-	}
-
-	keyword := c.Query("q")
-	// Search a repository
-	repos, count, err := models.SearchRepositoryByName(&models.SearchRepoOptions{
-		Keyword:  keyword,
-		UserID:   c.UserID(),
-		OrderBy:  "updated_unix DESC",
-		Page:     page,
-		PageSize: setting.UI.ExplorePagingNum,
-	})
-	if err != nil {
-		c.ServerError("SearchRepositoryByName", err)
-		return
-	}
-	c.Data["Keyword"] = keyword
-	c.Data["Total"] = count
-	c.Data["Page"] = paginater.New(int(count), setting.UI.ExplorePagingNum, page, 5)
-
-	if err = models.RepositoryList(repos).LoadAttributes(); err != nil {
-		c.ServerError("RepositoryList.LoadAttributes", err)
-		return
-	}
-	c.Data["Repos"] = repos
-
-	c.Success(EXPLORE_REPOS)
-}
-
-// ExploreTrending shows trending repositories page
-func ExploreTrending(c *context.Context) {
-	c.Data["Title"] = c.Tr("explore.trending")
-	c.Data["PageIsTrending"] = true
-
-	repos, count, err := models.SearchRepositoryByName(&models.SearchRepoOptions{
-		UserID:   c.UserID(),
-		OrderBy:  "num_stars DESC",
-		PageSize: 15,
-	})
-	if err != nil {
-		c.ServerError("SearchRepositoryByName", err)
-		return
-	}
-	c.Data["Total"] = count
-
-	if err = models.RepositoryList(repos).LoadAttributes(); err != nil {
-		c.ServerError("RepositoryList.LoadAttributes", err)
-		return
-	}
-	c.Data["Repos"] = repos
-
-	c.Success(EXPLORE_TRENDING)
-}
-
-// UserSearchOptions is the structure of the options choosed by the user
-type UserSearchOptions struct {
-	Type     models.UserType
-	Counter  func() int64
-	Ranger   func(int, int) ([]*models.User, error)
-	PageSize int
-	OrderBy  string
-	TplName  string
-}
-
-// RenderUserSearch renders user search
-func RenderUserSearch(c *context.Context, opts *UserSearchOptions) {
-	page := c.QueryInt("page")
-	if page <= 1 {
-		page = 1
-	}
-
-	var (
-		users []*models.User
-		count int64
-		err   error
-	)
-
-	keyword := c.Query("q")
-	if len(keyword) == 0 {
-		users, err = opts.Ranger(page, opts.PageSize)
-		if err != nil {
-			c.ServerError("Ranger", err)
-			return
-		}
-		count = opts.Counter()
-	} else {
-		users, count, err = models.SearchUserByName(&models.SearchUserOptions{
-			Keyword:  keyword,
-			Type:     opts.Type,
-			OrderBy:  opts.OrderBy,
-			Page:     page,
-			PageSize: opts.PageSize,
-		})
-		if err != nil {
-			c.ServerError("SearchUserByName", err)
-			return
-		}
-	}
-	c.Data["Keyword"] = keyword
-	c.Data["Total"] = count
-	c.Data["Page"] = paginater.New(int(count), opts.PageSize, page, 5)
-	c.Data["Users"] = users
-
-	c.Success(opts.TplName)
-}
-
-// ExploreUsers shows explore users page
-func ExploreUsers(c *context.Context) {
-	c.Data["Title"] = c.Tr("explore")
-	c.Data["PageIsExplore"] = true
-	c.Data["PageIsExploreUsers"] = true
-
-	RenderUserSearch(c, &UserSearchOptions{
-		Type:     models.USER_TYPE_INDIVIDUAL,
-		Counter:  models.CountUsers,
-		Ranger:   models.Users,
-		PageSize: setting.UI.ExplorePagingNum,
-		OrderBy:  "updated_unix DESC",
-		TplName:  EXPLORE_USERS,
-	})
-}
-
-//ExploreOrganizations shows explore organizations page
-func ExploreOrganizations(c *context.Context) {
-	c.Data["Title"] = c.Tr("explore")
-	c.Data["PageIsExplore"] = true
-	c.Data["PageIsExploreOrganizations"] = true
-
-	RenderUserSearch(c, &UserSearchOptions{
-		Type:     models.USER_TYPE_ORGANIZATION,
-		Counter:  models.CountOrganizations,
-		Ranger:   models.Organizations,
-		PageSize: setting.UI.ExplorePagingNum,
-		OrderBy:  "updated_unix DESC",
-		TplName:  EXPLORE_ORGANIZATIONS,
-	})
-}
-
 // NotFound renders 404 page if page not found
 func NotFound(c *context.Context) {
 	c.Data["Title"] = "Page Not Found"

+ 4 - 0
templates/admin/navbar.tmpl

@@ -12,6 +12,10 @@
 			😍 Staff Picks
 			<span class="ui violet basic label small">ToDo</span>
 		</a>
+		<a class="item" href="{{AppSubURL}}/admin/news">
+			🌐 News
+			<span class="ui green basic label small">Beta</span>
+		</a>
 		<a class="{{if .PageIsAdminUsers}}active{{end}} item" href="{{AppSubURL}}/admin/users">
 			👦 Users
 		</a>

+ 14 - 38
templates/explore/home.tmpl

@@ -3,45 +3,21 @@
     <div class="pages"> 
         <section style="height:auto" class="pages head">
             <div class="ui link cards explore-card top">
-                <div class="card explore-card card">
-                    <div class="image">
-                        <img class="explore-card mobile" src="https://cdn.gitote.in/explore/aoc.png">
-                    </div>
-                    <div class="content">
-                        <a href="https://adventofcode.com">
-                            <div class="explore-card title">Advent of Code 2018</div>
-                            <div class="explore-card description">
-                                Advent of Code is an small programming puzzles for a variety of skill sets that can be solved in any programming language you like.
-                            </div>
-                        </a>
-                    </div>
-                </div>
-                <div class="card explore-card card">
-                    <div class="image">
-                        <img class="explore-card mobile" src="https://cdn.gitote.in/explore/24pr.png">
-                    </div>
-                    <div class="content">
-                        <a href="https://24pullrequests.com">
-                            <div class="explore-card title">Give back to open source</div>
-                            <div class="explore-card description">
-                                Contribute to the software community in December at 24 Pull Requests
-                            </div>
-                        </a>
-                    </div>
-                </div>
-                <div class="card explore-card card">
-                    <div class="image">
-                        <img class="explore-card mobile" src="https://cdn.gitote.in/explore/gitote.png">
-                    </div>
-                    <div class="content">
-                        <a href="https://gitote.in/gitote/gitote">
-                            <div class="explore-card title">Gitote is now open source</div>
-                            <div class="explore-card description">
-                                Gitote is an open source end-to-end software development platform with built-in version control, issue tracking, code review, and more.
-                            </div>
-                        </a>
+                {{range .Repos}}
+                    <div class="card explore-card card">
+                        <div class="image">
+                            <img class="explore-card mobile" src="https://cdn.gitote.in/explore/aoc.png">
+                        </div>
+                        <div class="content">
+                            <a href="https://adventofcode.com">
+                                <div class="explore-card title">Advent of Code 2018</div>
+                                <div class="explore-card description">
+                                    Advent of Code is an small programming puzzles for a variety of skill sets that can be solved in any programming language you like.
+                                </div>
+                            </a>
+                        </div>
                     </div>
-                </div>
+                {{end}}
             </div>
         </section>