-
Notifications
You must be signed in to change notification settings - Fork 0
/
home.go
48 lines (43 loc) · 1.16 KB
/
home.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
package controller
import (
"net/http"
"net/url"
"admini.dev/admini/app"
"admini.dev/admini/app/controller/cutil"
"admini.dev/admini/app/util"
"admini.dev/admini/views"
)
var homeContent = util.ValueMap{
"_": util.AppName,
"urls": map[string]string{
"projects": "/project",
"sources": "/source",
"sandboxes": "/sandbox",
},
}
func Home(w http.ResponseWriter, r *http.Request) {
Act("home", w, r, func(as *app.State, ps *cutil.PageState) (string, error) {
projects, _ := as.Services.Projects.List(ps.Context, ps.Logger)
sources, _ := as.Services.Sources.List(ps.Logger)
ps.Data = homeContent
return Render(r, as, &views.Home{Sources: sources, Projects: projects}, ps)
})
}
func Refresh(w http.ResponseWriter, r *http.Request) {
Act("refresh", w, r, func(as *app.State, ps *cutil.PageState) (string, error) {
redir := "/"
ref := r.Header.Get("Referer")
if ref != "" {
u, err := url.Parse(ref)
if err == nil && u != nil {
redir = u.Path
}
}
as.Themes.Clear()
as.Services.Loaders.Clear()
as.Services.Sources.Clear()
as.Services.Projects.Clear()
const msg = "Cleared all caches"
return FlashAndRedir(true, msg, redir, ps)
})
}