-
Notifications
You must be signed in to change notification settings - Fork 4
/
module.go
58 lines (49 loc) · 1.5 KB
/
module.go
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
package cmodule
import (
"fmt"
"github.com/valyala/fasthttp"
"projectforge.dev/projectforge/app"
"projectforge.dev/projectforge/app/controller"
"projectforge.dev/projectforge/app/controller/cutil"
"projectforge.dev/projectforge/app/module"
"projectforge.dev/projectforge/app/project"
"projectforge.dev/projectforge/views/vmodule"
)
func ModuleList(rc *fasthttp.RequestCtx) {
controller.Act("module.root", rc, func(as *app.State, ps *cutil.PageState) (string, error) {
mods := as.Services.Modules.Modules()
ps.Title = "Module Listing"
ps.Data = mods
return controller.Render(rc, as, &vmodule.List{Modules: mods}, ps, "modules")
})
}
func ModuleDetail(rc *fasthttp.RequestCtx) {
controller.Act("module.detail", rc, func(as *app.State, ps *cutil.PageState) (string, error) {
mod, err := getModule(rc, as, ps)
if err != nil {
return "", err
}
var usages project.Projects
for _, p := range as.Services.Projects.Projects() {
if p.HasModule(mod.Key) {
usages = append(usages, p)
}
}
ps.Data = mod
ps.Title = fmt.Sprintf("[%s] Module", mod.Key)
return controller.Render(rc, as, &vmodule.Detail{Module: mod, Usages: usages}, ps, "modules", mod.Key)
})
}
func getModule(rc *fasthttp.RequestCtx, as *app.State, ps *cutil.PageState) (*module.Module, error) {
key, err := cutil.RCRequiredString(rc, "key", true)
if err != nil {
return nil, err
}
mod, err := as.Services.Modules.Get(key)
if err != nil {
return nil, err
}
ps.Title = mod.Title()
ps.Data = mod
return mod, nil
}