-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathexportgroups.go
63 lines (56 loc) · 1.88 KB
/
exportgroups.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
59
60
61
62
63
package cproject
import (
"fmt"
"net/http"
"projectforge.dev/projectforge/app"
"projectforge.dev/projectforge/app/controller"
"projectforge.dev/projectforge/app/controller/cutil"
"projectforge.dev/projectforge/app/project/export/model"
"projectforge.dev/projectforge/app/util"
"projectforge.dev/projectforge/views/vexport"
)
func ProjectExportGroupsEdit(w http.ResponseWriter, r *http.Request) {
controller.Act("project.export.groups.edit", w, r, func(as *app.State, ps *cutil.PageState) (string, error) {
prj, err := getProject(r, as)
if err != nil {
return "", err
}
args, err := prj.ModuleArgExport(as.Services.Projects, ps.Logger)
if err != nil {
return "", err
}
bc := []string{"projects", prj.Key, fmt.Sprintf("Export||/p/%s/export", prj.Key), "Groups"}
ps.SetTitleAndData(fmt.Sprintf("[%s] Groups", prj.Key), args.Groups)
ex := model.Groups{{Key: "foo", Title: "Foo", Description: "The foos!", Icon: "star", Children: model.Groups{{Key: "bar"}}}}
return controller.Render(w, r, as, &vexport.GroupForm{Project: prj, Groups: args.Groups, Example: ex}, ps, bc...)
})
}
func ProjectExportGroupsSave(w http.ResponseWriter, r *http.Request) {
controller.Act("project.export.groups.save", w, r, func(as *app.State, ps *cutil.PageState) (string, error) {
prj, err := getProject(r, as)
if err != nil {
return "", err
}
frm, err := cutil.ParseForm(r, ps.RequestBody)
if err != nil {
return "", err
}
j := frm.GetStringOpt("groups")
g := model.Groups{}
err = util.FromJSON([]byte(j), &g)
if err != nil {
return "", err
}
pfs, err := as.Services.Projects.GetFilesystem(prj)
if err != nil {
return "", err
}
err = as.Services.Projects.SaveExportGroups(pfs, g)
if err != nil {
return "", err
}
msg := "groups saved successfully"
u := fmt.Sprintf("/p/%s/export", prj.Key)
return controller.FlashAndRedir(true, msg, u, w, ps)
})
}