From b7d537fc5d45084522943aad287a82b91bb06d9b Mon Sep 17 00:00:00 2001 From: Jeff Storey Date: Wed, 23 Mar 2016 22:13:03 -0400 Subject: [PATCH] #1533 first cut to show only active repos initially --- router/router.go | 3 ++- template/amber/index.amber | 46 ++++++++++++++++++++++++++++++++++++++ template/amber/repos.amber | 40 ++++++++++++++++++++------------- template/template.go | 1 + web/pages.go | 27 ++++++++++++++++++++++ 5 files changed, 100 insertions(+), 17 deletions(-) create mode 100644 template/amber/index.amber diff --git a/router/router.go b/router/router.go index 43fe0a0d..5f680f30 100644 --- a/router/router.go +++ b/router/router.go @@ -30,6 +30,7 @@ func Load(middleware ...gin.HandlerFunc) http.Handler { e.Use(token.Refresh) e.GET("/", web.ShowIndex) + e.GET("/repos", web.ShowAllRepos) e.GET("/login", web.ShowLogin) e.GET("/login/form", web.ShowLoginForm) e.GET("/logout", web.GetLogout) @@ -163,7 +164,7 @@ func normalize(h http.Handler) http.Handler { parts := strings.Split(r.URL.Path, "/")[1:] switch parts[0] { - case "settings", "api", "login", "logout", "", "authorize", "hook", "static", "gitlab": + case "settings", "repos", "api", "login", "logout", "", "authorize", "hook", "static", "gitlab": // no-op default: diff --git a/template/amber/index.amber b/template/amber/index.amber new file mode 100644 index 00000000..c8c9fd38 --- /dev/null +++ b/template/amber/index.amber @@ -0,0 +1,46 @@ +extends base + +block append head + title Active Repositories + +block header + ol + li Active Repositories + + ul.nav.nav-tabs + li.nav-item + a.nav-link.active[href="/"] Active Repositories + li.nav-item + a.nav-link[href="/repos"] My Repositories + +block content + div.container + if len(Repos) == 0 + div.alert.alert-info + | Your repository list is empty. + + else + div.row.repo-row + input.repo-search[type="search"][placeholder="Filter..."] + div.repo-list + each $repo in Repos + div.col-sm-4 + a.card[href="/"+$repo.FullName] + div.card-header + if $repo.Avatar != "" + img.avatar[src=$repo.Avatar] + else + img.avatar[src="/static/images/dummy.png"] + div.card-block + h3.login #{$repo.Name} + div.full_name.hidden #{$repo.FullName} +block append scripts + if len(Repos) != 0 + script + $(window).load(function(){ + $(".repo-list").searcher({ + itemSelector: ".col-sm-4", + textSelector: ".full_name", + inputSelector: ".repo-search" + }); + }); diff --git a/template/amber/repos.amber b/template/amber/repos.amber index 86af56eb..e5a2974b 100644 --- a/template/amber/repos.amber +++ b/template/amber/repos.amber @@ -1,11 +1,17 @@ extends base block append head - title Dashboard + title All Repositories block header ol - li Dashboard + li All Repositories + + ul.nav.nav-tabs + li.nav-item + a.nav-link[href="/"] Active Repositories + li.nav-item + a.nav-link.active[href="/repos"] My Repositories block content div.container @@ -13,20 +19,22 @@ block content div.alert.alert-info | Your repository list is empty. - div.row.repo-row - input.repo-search[type="search"][placeholder="Filter..."] - div.repo-list - each $repo in Repos - div.col-sm-4 - a.card[href="/"+$repo.FullName] - div.card-header - if $repo.Avatar != "" - img.avatar[src=$repo.Avatar] - else - img.avatar[src="/static/images/dummy.png"] - div.card-block - h3.login #{$repo.Name} - div.full_name.hidden #{$repo.FullName} + else + div.row.repo-row + input.repo-search[type="search"][placeholder="Filter..."] + div.repo-list + each $repo in Repos + div.col-sm-4 + a.card[href="/"+$repo.FullName] + div.card-header + if $repo.Avatar != "" + img.avatar[src=$repo.Avatar] + else + img.avatar[src="/static/images/dummy.png"] + div.card-block + h3.login #{$repo.Name} + div.full_name.hidden #{$repo.FullName} + block append scripts if len(Repos) != 0 script diff --git a/template/template.go b/template/template.go index c7c30ba9..833f525c 100644 --- a/template/template.go +++ b/template/template.go @@ -17,6 +17,7 @@ package template //go:generate sh -c "amberc amber/users.amber > amber_gen/users.html" //go:generate sh -c "amberc amber/user.amber > amber_gen/user.html" //go:generate sh -c "amberc amber/nodes.amber > amber_gen/nodes.html" +//go:generate sh -c "amberc amber/index.amber > amber_gen/index.html" //go:generate go-bindata -pkg template -o template_gen.go amber_gen/ diff --git a/web/pages.go b/web/pages.go index 9fd720f8..46da2730 100644 --- a/web/pages.go +++ b/web/pages.go @@ -29,6 +29,33 @@ func ShowIndex(c *gin.Context) { return } + // filter to only show the currently active ones + activeRepos, err := store.GetRepoListOf(c,repos) + if err != nil { + c.String(400, err.Error()) + return + } + + c.HTML(200, "index.html", gin.H{ + "User": user, + "Repos": activeRepos, + }) +} + +func ShowAllRepos(c *gin.Context) { + user := session.User(c) + if user == nil { + c.Redirect(http.StatusSeeOther, "/login") + return + } + + // get the repository list from the cache + repos, err := cache.GetRepos(c, user) + if err != nil { + c.String(400, err.Error()) + return + } + c.HTML(200, "repos.html", gin.H{ "User": user, "Repos": repos,