feat(basin): star counts on repository lists
6 files changed, +10 −6
- static/style.css modified +3 −0
- store.go modified +3 −2
- templates/index.html modified +1 −1
- templates/projects.html modified +1 −1
- templates/stars.html modified +1 −1
- templates/user.html modified +1 −1
static/style.css modified
| @@ -265,3 +265,6 @@ table.blame tr.first td{border-top:1px solid var(--line)} | ||
| 265 | 265 | table.blame td.l{white-space:pre-wrap;overflow-wrap:anywhere;width:100%} |
| 266 | 266 | table.blame td.n{border-right:1px solid var(--bar)} |
| 267 | 267 | .actions a.muted{margin-right:auto;align-self:center} |
| 268 | +.event h4{display:flex;align-items:baseline} | |
| 269 | +.event h4 .tag{margin-left:.4rem} | |
| 270 | +.event h4 .starcount{margin-left:auto;color:var(--muted);font-size:.85rem;font-weight:400} | |
store.go modified
| @@ -162,6 +162,7 @@ type Repo struct { | ||
| 162 | 162 | Tags []string |
| 163 | 163 | Parent int64 |
| 164 | 164 | Archived bool |
| 165 | + Stars int | |
| 165 | 166 | Created time.Time |
| 166 | 167 | Updated time.Time |
| 167 | 168 | } |
| @@ -517,7 +518,7 @@ func scanRepos(rows *sql.Rows) ([]Repo, error) { | ||
| 517 | 518 | var private, archived int |
| 518 | 519 | var tags string |
| 519 | 520 | var created, ucreated int64 |
| 520 | - if err := rows.Scan(&r.ID, &r.Name, &r.Description, &private, &tags, &r.Parent, &archived, &created, &r.Owner.ID, &r.Owner.Name, &ucreated); err != nil { | |
| 521 | + if err := rows.Scan(&r.ID, &r.Name, &r.Description, &private, &tags, &r.Parent, &archived, &r.Stars, &created, &r.Owner.ID, &r.Owner.Name, &ucreated); err != nil { | |
| 521 | 522 | return nil, err |
| 522 | 523 | } |
| 523 | 524 | r.Archived = archived != 0 |
| @@ -531,7 +532,7 @@ func scanRepos(rows *sql.Rows) ([]Repo, error) { | ||
| 531 | 532 | return repos, rows.Err() |
| 532 | 533 | } |
| 533 | 534 | |
| 534 | -const repoColumns = `r.id, r.name, r.description, r.private, r.tags, r.parent, r.archived, r.created, u.id, u.name, u.created from repos r join users u on u.id = r.owner` | |
| 535 | +const repoColumns = `r.id, r.name, r.description, r.private, r.tags, r.parent, r.archived, (select count(*) from stars st where st.repo = r.id), r.created, u.id, u.name, u.created from repos r join users u on u.id = r.owner` | |
| 535 | 536 | |
| 536 | 537 | func (s *Store) RepoByID(id int64) (Repo, error) { |
| 537 | 538 | rows, err := s.db.Query(`select `+repoColumns+` where r.id = ?`, id) |
templates/index.html modified
| @@ -26,5 +26,5 @@ | ||
| 26 | 26 | </section> |
| 27 | 27 | {{end}} |
| 28 | 28 | {{define "repolist"}} |
| 29 | -{{if .}}<div class="events">{{range .}}<div class="event"><h4><a href="/{{.Path}}">{{.Path}}</a>{{if .Private}} <span class="tag">private</span>{{else if .Unlisted}} <span class="tag">unlisted</span>{{end}}</h4>{{if .Description}}<p>{{.Description}}</p>{{end}}{{if .Tags}}<p class="tags">{{range .Tags}}<a href="/projects?tag={{.}}">#{{.}}</a> {{end}}</p>{{end}}</div>{{end}}</div>{{else}}<p class="muted">Nothing here yet.</p>{{end}} | |
| 29 | +{{if .}}<div class="events">{{range .}}<div class="event"><h4><a href="/{{.Path}}">{{.Path}}</a>{{if .Private}} <span class="tag">private</span>{{else if .Unlisted}} <span class="tag">unlisted</span>{{end}}{{if .Stars}}<span class="starcount" title="{{.Stars}} stars">☆ {{.Stars}}</span>{{end}}</h4>{{if .Description}}<p>{{.Description}}</p>{{end}}{{if .Tags}}<p class="tags">{{range .Tags}}<a href="/projects?tag={{.}}">#{{.}}</a> {{end}}</p>{{end}}</div>{{end}}</div>{{else}}<p class="muted">Nothing here yet.</p>{{end}} | |
| 30 | 30 | {{end}} |
templates/projects.html modified
| @@ -13,7 +13,7 @@ | ||
| 13 | 13 | </div> |
| 14 | 14 | </form> |
| 15 | 15 | {{if .Data.Tag}}<p class="muted">Showing projects tagged <a href="/projects?tag={{.Data.Tag}}">#{{.Data.Tag}}</a> · <a href="/projects">clear</a></p>{{end}} |
| 16 | -{{if .Data.Repos}}<div class="events">{{range .Data.Repos}}<div class="event"><h4><a href="/~{{.Owner.Name}}">~{{.Owner.Name}}</a>/<a href="/{{.Path}}">{{.Name}}</a></h4>{{if .Description}}<p>{{.Description}}</p>{{end}}{{if .Tags}}<p class="tags">{{range .Tags}}<a href="/projects?tag={{.}}">#{{.}}</a> {{end}}</p>{{end}}</div>{{end}}</div>{{else}}<p class="info">No projects match.</p>{{end}} | |
| 16 | +{{if .Data.Repos}}<div class="events">{{range .Data.Repos}}<div class="event"><h4><a href="/~{{.Owner.Name}}">~{{.Owner.Name}}</a>/<a href="/{{.Path}}">{{.Name}}</a>{{if .Stars}}<span class="starcount" title="{{.Stars}} stars">☆ {{.Stars}}</span>{{end}}</h4>{{if .Description}}<p>{{.Description}}</p>{{end}}{{if .Tags}}<p class="tags">{{range .Tags}}<a href="/projects?tag={{.}}">#{{.}}</a> {{end}}</p>{{end}}</div>{{end}}</div>{{else}}<p class="info">No projects match.</p>{{end}} | |
| 17 | 17 | </div> |
| 18 | 18 | <aside> |
| 19 | 19 | <h3 class="plain">About</h3> |
templates/stars.html modified
| @@ -3,5 +3,5 @@ | ||
| 3 | 3 | <h2>~{{.Data.Owner.Name}}</h2> |
| 4 | 4 | <nav class="tabs small"><a href="/~{{.Data.Owner.Name}}">about</a><a class="active" href="/~{{.Data.Owner.Name}}/stars">stars{{if .Data.Count}} <span class="count">{{.Data.Count}}</span>{{end}}</a></nav> |
| 5 | 5 | </div> |
| 6 | -{{if .Data.Starred}}<div class="events">{{range .Data.Starred}}<div class="event"><h4><a href="/~{{.Owner.Name}}">~{{.Owner.Name}}</a>/<a href="/{{.Path}}">{{.Name}}</a></h4>{{if .Description}}<p>{{.Description}}</p>{{end}}{{if .Tags}}<p class="tags">{{range .Tags}}<a href="/projects?tag={{.}}">#{{.}}</a> {{end}}</p>{{end}}</div>{{end}}</div>{{else}}<p class="info">~{{.Data.Owner.Name}} has not starred anything yet.</p>{{end}} | |
| 6 | +{{if .Data.Starred}}<div class="events">{{range .Data.Starred}}<div class="event"><h4><a href="/~{{.Owner.Name}}">~{{.Owner.Name}}</a>/<a href="/{{.Path}}">{{.Name}}</a>{{if .Stars}}<span class="starcount" title="{{.Stars}} stars">☆ {{.Stars}}</span>{{end}}</h4>{{if .Description}}<p>{{.Description}}</p>{{end}}{{if .Tags}}<p class="tags">{{range .Tags}}<a href="/projects?tag={{.}}">#{{.}}</a> {{end}}</p>{{end}}</div>{{end}}</div>{{else}}<p class="info">~{{.Data.Owner.Name}} has not starred anything yet.</p>{{end}} | |
| 7 | 7 | {{end}} |
templates/user.html modified
| @@ -16,7 +16,7 @@ | ||
| 16 | 16 | {{if $own}}<a class="btn primary block" href="/create">Create a new repository ▸</a><a class="btn block" href="/settings">Edit your profile ▸</a>{{end}} |
| 17 | 17 | </aside> |
| 18 | 18 | <div class="main"> |
| 19 | -{{if .Data.Repos}}<div class="events">{{range .Data.Repos}}<div class="event"><h4><a href="/{{.Path}}">{{.Name}}</a>{{if .Private}} <span class="tag">private</span>{{else if .Unlisted}} <span class="tag">unlisted</span>{{end}}</h4>{{if .Description}}<p>{{.Description}}</p>{{end}}{{if .Tags}}<p class="tags">{{range .Tags}}<a href="/projects?tag={{.}}">#{{.}}</a> {{end}}</p>{{end}}</div>{{end}}</div>{{else}}<p class="info">This user does not have any repositories.</p>{{end}} | |
| 19 | +{{if .Data.Repos}}<div class="events">{{range .Data.Repos}}<div class="event"><h4><a href="/{{.Path}}">{{.Name}}</a>{{if .Private}} <span class="tag">private</span>{{else if .Unlisted}} <span class="tag">unlisted</span>{{end}}{{if .Stars}}<span class="starcount" title="{{.Stars}} stars">☆ {{.Stars}}</span>{{end}}</h4>{{if .Description}}<p>{{.Description}}</p>{{end}}{{if .Tags}}<p class="tags">{{range .Tags}}<a href="/projects?tag={{.}}">#{{.}}</a> {{end}}</p>{{end}}</div>{{end}}</div>{{else}}<p class="info">This user does not have any repositories.</p>{{end}} | |
| 20 | 20 | </div> |
| 21 | 21 | </div> |
| 22 | 22 | {{end}} |