aboutsummaryrefslogtreecommitdiff
blob: cf80fb6610c1456fb2613b811d5d81852a26964a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
package categories

import "net/http"
import "strconv"
import "strings"
import "soko/pkg/app/layout"
import "soko/pkg/models"

func packageLetter(name string) string {
	return strings.ToLower(strings.TrimLeft(name, "_")[:1])
}

script filter() {
	const value = document.querySelector("#filter").value.toLowerCase();
	const rows = document.querySelectorAll("#table tr");
	for (let i = 0; i < rows.length; i++) {
		rows[i].style.display = rows[i].cells[0].innerText.toLowerCase().includes(value) ? "" : "none";
	}
}

templ showPackages(categoryName string, packages []packageInfo) {
	<div class="row">
		<div class="col-12">
			<div class="row">
				<div class="col-md-9">
					<p>
						<input onKeyup={ filter() } id="filter" type="text" class="form-control form-control-xl" placeholder={ "Search packages in " + categoryName }/>
					</p>
					<div class="card border-top-0 rounded">
						<table class="table mb-0 rounded" id="table">
							for i, pkg := range packages {
								<tr
									if i == 0 || packageLetter(pkg.Package) != packageLetter(packages[i-1].Package) {
										id={ packageLetter(pkg.Package) }
									}
								>
									<th class="kk-nobreak-cell"><a href={ templ.URL("/packages/" + categoryName + "/" + pkg.Package) }>{ pkg.Package }</a></th>
									<td>{ pkg.Description }</td>
								</tr>
							}
						</table>
					</div>
					@filter()
				</div>
				<div class="col-md-3">
					<h4>Statistics</h4>
					<dd class="ml-3">
						<dl>Packages: { strconv.Itoa(len(packages)) }</dl>
					</dd>
					<h4 class="mt-4">Filter by Category</h4>
					<div class="row pl-4 pr-5 mr-5">
						for i, pkg := range packages {
							if i == 0 || packageLetter(pkg.Package) != packageLetter(packages[i-1].Package) {
								<div class="col-md-2 px-2">
									<a href={ templ.URL("#" + packageLetter(pkg.Package)) } class="text-muted text-capitalize">
										{ packageLetter(pkg.Package) }
									</a>
								</div>
							}
						}
					</div>
				</div>
			</div>
		</div>
	</div>
}

templ show(component templ.Component) {
	<div class="container mb-5 tab-pane fade show active" id="overview" role="tabpanel" aria-labelledby="overview-tab">
		@component
	</div>
}

func renderShowPage(w http.ResponseWriter, r *http.Request, currentTab string, category *models.Category, component templ.Component) {
	layout.TabbedLayout(category.Name, "packages", category.Name, "fa fa-fw fa-cubes", category.Description, []layout.SubTab{
		{
			Name: "Packages",
			Link: templ.URL("/categories/" + category.Name),
			Icon: "fa fa-list-ul mr-1",
		},
		{
			Name:       "Stabilization",
			Link:       templ.URL("/categories/" + category.Name + "/stabilization"),
			Icon:       "fa fa-check-circle-o mr-1",
			BadgeValue: strconv.Itoa(category.PackagesInformation.StableRequests),
		},
		{
			Name:       "Outdated",
			Link:       templ.URL("/categories/" + category.Name + "/outdated"),
			Icon:       "fa fa-tag mr-1",
			BadgeValue: strconv.Itoa(category.PackagesInformation.Outdated),
		},
		{
			Name:       "Pull requests",
			Link:       templ.URL("/categories/" + category.Name + "/pull-requests"),
			Icon:       "octicon octicon-git-pull-request opticon-resource-icon ml-1",
			BadgeValue: strconv.Itoa(category.PackagesInformation.PullRequests),
		},
		{
			Name:       "Bugs",
			Link:       templ.URL("/categories/" + category.Name + "/bugs"),
			Icon:       "fa fa-bug",
			BadgeValue: strconv.Itoa(category.PackagesInformation.Bugs),
		},
		{
			Name:       "Security",
			Link:       templ.URL("/categories/" + category.Name + "/security"),
			Icon:       "fa fa-shield",
			BadgeValue: strconv.Itoa(category.PackagesInformation.SecurityBugs),
		},
	}, currentTab, show(component)).Render(r.Context(), w)
}