diff --git a/router/router.go b/router/router.go index 43fe0a0de..5f680f303 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 000000000..a31f59940 --- /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"] Available 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 86af56eb7..be79afe58 100644 --- a/template/amber/repos.amber +++ b/template/amber/repos.amber @@ -1,11 +1,17 @@ extends base block append head - title Dashboard + title Available Repositories block header ol - li Dashboard + li Available Repositories + + ul.nav.nav-tabs + li.nav-item + a.nav-link[href="/"] Active Repositories + li.nav-item + a.nav-link.active[href="/repos"] Available Repositories block content div.container @@ -13,27 +19,29 @@ 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 $(window).load(function(){ - $(".repo-list").searcher({ - itemSelector: ".col-sm-4", - textSelector: ".full_name", - inputSelector: ".repo-search" - }); + $(".repo-list").searcher({ + itemSelector: ".col-sm-4", + textSelector: ".full_name", + inputSelector: ".repo-search" + }); }); diff --git a/template/template.go b/template/template.go index c7c30ba9c..047275ff3 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 9fd720f8c..46da27304 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,