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 110 111 112
| package clib
import ( "github.com/pkg/errors" "github.com/valyala/fasthttp"
"{{{ .Package }}}/app" "{{{ .Package }}}/app/controller" "{{{ .Package }}}/app/controller/csession" "{{{ .Package }}}/app/controller/cutil" "{{{ .Package }}}/app/lib/theme" "{{{ .Package }}}/app/util" "{{{ .Package }}}/views/vtheme" )
func ThemeList(rc *fasthttp.RequestCtx) { controller.Act("theme.list", rc, func(as *app.State, ps *cutil.PageState) (string, error) { ps.Title = "Themes" th := as.Themes.All(ps.Logger) ps.Data = th return controller.Render(rc, as, &vtheme.List{Themes: th}, ps, "Themes||/theme") }) }
func ThemeEdit(rc *fasthttp.RequestCtx) { controller.Act("theme.edit", rc, func(as *app.State, ps *cutil.PageState) (string, error) { key, err := cutil.RCRequiredString(rc, "key", false) if err != nil { return "", err } if key == theme.Default.Key { return controller.FlashAndRedir(false, "Unable to edit default theme", "/theme", rc, ps) } var t *theme.Theme if key == theme.KeyNew { t = theme.Default.Clone(key) } else { t = as.Themes.Get(key, ps.Logger){{{ if .HasModule "themecatalog" }}} if t == nil { if pal := string(rc.URI().QueryArgs().Peek("palette")); pal != "" { themes, err := theme.PaletteThemes(pal) if err != nil { return "", err } t = themes.Get(key) } }{{{ end }}} } if t == nil { return "", errors.Errorf("invalid theme [%s]", key) } ps.Title = "Edit theme [" + t.Key + "]" ps.Data = t page := &vtheme.Edit{Theme: t, Icon: "app", Exists: as.Themes.FileExists(t.Key)} return controller.Render(rc, as, page, ps, "Themes||/theme", t.Key) }) }
func ThemeSave(rc *fasthttp.RequestCtx) { controller.Act("theme.save", rc, func(as *app.State, ps *cutil.PageState) (string, error) { key, err := cutil.RCRequiredString(rc, "key", false) if err != nil { return "", err } frm, err := cutil.ParseForm(rc) if err != nil { return "", err }
orig := as.Themes.Get(key, ps.Logger)
newKey, err := frm.GetString("key", false) if err != nil { return "", err } if newKey == theme.KeyNew { newKey = util.RandomString(12) }
l := orig.Light.Clone().ApplyMap(frm, "light-") d := orig.Dark.Clone().ApplyMap(frm, "dark-")
t := &theme.Theme{Key: newKey, Light: l, Dark: d}
err = as.Themes.Save(t, frm.GetStringOpt("originalKey"), ps.Logger) if err != nil { return "", errors.Wrap(err, "unable to save theme") }
ps.Profile.Theme = newKey err = csession.SaveProfile(ps.Profile, rc, ps.Session, ps.Logger) if err != nil { return "", err }
return controller.ReturnToReferrer("saved changes to theme ["+newKey+"]", "/theme", rc, ps) }) }
func ThemeRemove(rc *fasthttp.RequestCtx) { controller.Act("theme.remove", rc, func(as *app.State, ps *cutil.PageState) (string, error) { key, err := cutil.RCRequiredString(rc, "key", false) if err != nil { return "", err } err = as.Themes.Remove(key, ps.Logger) if err != nil { return "", errors.Wrap(err, "unable to remove theme") } return controller.ReturnToReferrer("removed theme ["+key+"]", "/theme", rc, ps) }) }
|