gunk-dev/the-valley

projects.go

source0820acba4decmain's published tip history
2.2 KiB
1package server
2
3import "net/http"
4
5// projectGroup is one group on the projects page: its name, its own page,
6// and its projects the reader may read.
7type projectGroup struct {
8 Name string
9 URL string
10 Projects []listedProject
11}
12
13// listedProject is one project on the projects page: its path,
14// <group>/<project>, and links to its source and its knots.
15type listedProject struct {
16 Name string
17 Source string
18 Knots string
19}
20
21// projectsPage is the list of projects a reader may read, by group: every
22// group's on /-/projects, or one group's on its own page. A group on its
23// own page has no link to itself.
24type projectsPage struct {
25 Groups []projectGroup
26}
27
28// projects serves /-/projects: every project in the reader's view, by
29// group, in the export's order. With none, the page says so, and answers
30// 200.
31func (q *request) projects() {
32 q.page(http.StatusOK, "projects", "projects", projectsPage{Groups: q.idx.listing})
33}
34
35// group serves /<group>/ and /<group>: the projects page of the group's
36// projects in the reader's view. A group with none answers as a path that
37// does not exist, so the page never says that a group exists.
38func (q *request) group(name string) {
39 i, ok := q.idx.listed[name]
40 if !ok {
41 q.notFound()
42 return
43 }
44 g := q.idx.listing[i]
45 g.URL = ""
46 q.page(http.StatusOK, "projects", g.Name, projectsPage{Groups: []projectGroup{g}})
47}
48
49// projectHead is the header of every page that belongs to one project: its
50// path, <group>/<project>, and its two tabs, source and knots. The tab of
51// the page's own part of the project is current.
52type projectHead struct {
53 Name string
54 Tabs []projectTab
55}
56
57type projectTab struct {
58 Text string
59 URL string
60 Current bool
61}
62
63// head is the project header of a page of project's, whose current tab is
64// current: "source" for its tree, file and history pages, and "knots" for
65// its knots page and each of its knots.
66func (idx *index) head(project, current string) projectHead {
67 base := idx.bases[project]
68 return projectHead{Name: idx.names[project], Tabs: []projectTab{
69 {"source", treeURL(base, idx.projects[project].SourceTip, nil), current == "source"},
70 {"knots", projectKnotsURL(base), current == "knots"},
71 }}
72}