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
|
// miscellaneous utility functions used for arches
package arches
import (
"html/template"
"net/http"
"soko/pkg/app/utils"
"soko/pkg/database"
"soko/pkg/models"
)
// getPageData creates the data used in all
// templates used in the arches section
func getPageData() interface{} {
return struct {
Header models.Header
Application models.Application
}{
Header: models.Header{Title: "Architectures – ", Tab: "arches", },
Application: utils.GetApplicationData(),
}
}
// getStabilizedVersionsForArch returns the given number of recently
// stabilized versions of a specific arch
func getStabilizedVersionsForArch(arch string, n int) ([]*models.Version, error) {
var stabilizedVersions []*models.Version
var updates []models.KeywordChange
err := database.DBCon.Model(&updates).
Relation("Version").
Relation("Commit").
Order("commit.preceding_commits DESC").
Where("stabilized::jsonb @> ?", "\""+arch+"\"").
Limit(n).
Select()
if err != nil {
return nil, err
}
for _, update := range updates {
if update.Version != nil {
update.Version.Commits = []*models.Commit{update.Commit}
stabilizedVersions = append(stabilizedVersions, update.Version)
}
}
return stabilizedVersions, err
}
// getKeywordedVersionsForArch returns the given number of recently
// keyworded versions of a specific arch
func getKeywordedVersionsForArch(arch string, n int) ([]*models.Version, error) {
var stabilizedVersions []*models.Version
var updates []models.KeywordChange
err := database.DBCon.Model(&updates).
Relation("Version").
Relation("Commit").
Order("commit.preceding_commits DESC").
Where("added::jsonb @> ?", "\""+arch+"\"").
Limit(n).
Select()
if err != nil {
return nil, err
}
for _, update := range updates {
if update.Version != nil {
update.Version.Commits = []*models.Commit{update.Commit}
stabilizedVersions = append(stabilizedVersions, update.Version)
}
}
return stabilizedVersions, err
}
// RenderPackageTemplates renders the arches templates using the given data
func renderPackageTemplates(page string, funcMap template.FuncMap, data interface{}, w http.ResponseWriter) {
templates := template.Must(
template.Must(
template.Must(
template.New(page).
Funcs(funcMap).
ParseGlob("web/templates/layout/*.tmpl")).
ParseGlob("web/templates/packages/changedVersionRow.tmpl")).
ParseGlob("web/templates/arches/changedVersions.tmpl"))
templates.ExecuteTemplate(w, page+".tmpl", data)
}
// CreateFeedData creates the data used in changedVersions template
func createFeedData(arch string, name string, feedtype string, versions []*models.Version) interface{} {
return struct {
Header models.Header
Arch string
Name string
FeedName string
Versions []*models.Version
Application models.Application
}{
Header: models.Header{Title: "Architectures – ", Tab: "arches", },
Arch: arch,
Name: name,
FeedName: feedtype,
Versions: versions,
Application: utils.GetApplicationData(),
}
}
|