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
|
// Used to show a specific package
package packages
import (
"github.com/go-pg/pg/v9/orm"
"html/template"
"net/http"
"soko/pkg/database"
"soko/pkg/models"
"strings"
)
// Show renders a template to show a given package
func Show(w http.ResponseWriter, r *http.Request) {
if strings.HasSuffix(r.URL.Path, "/changelog.html") {
changelog(w,r)
return
}
atom := r.URL.Path[len("/packages/"):]
gpackage := new(models.Package)
err := database.DBCon.Model(gpackage).
Where("atom = ?", atom).
Relation("Versions").
Select()
if err != nil {
http.NotFound(w,r)
return
}
localUseflags, globalUseflags, useExpands := getPackageUseflags(gpackage)
renderPackageTemplate("show",
"*",
GetFuncMap(),
createPackageData(gpackage, localUseflags, globalUseflags, useExpands),
w)
}
// changelog renders a template to show the changelog of a given package
func changelog(w http.ResponseWriter, r *http.Request) {
atom := getAtom(r)
gpackage := new(models.Package)
err := database.DBCon.Model(gpackage).
Where("atom = ?", atom).
Relation("Commits", func(q *orm.Query) (*orm.Query, error) {
return q.Order("preceding_commits DESC").Limit(5), nil
}).
Select()
if err != nil {
panic(err)
}
templates := template.Must(
template.New("Changelog").
Funcs(GetFuncMap()).
ParseGlob("web/templates/packages/changelog/*.tmpl"))
templates.ExecuteTemplate(w, "changelog.tmpl", getChangelogData(gpackage.Commits, atom))
}
|