Added a site picker plus options to create new sites
This commit is contained in:
parent
cc0da8d668
commit
d80aacc180
14 changed files with 203 additions and 29 deletions
|
|
@ -9,7 +9,7 @@ import (
|
|||
func LogErrors() func(c fiber.Ctx) error {
|
||||
return func(c fiber.Ctx) error {
|
||||
if err := c.Next(); err != nil {
|
||||
log.Printf("error: %v\n", err)
|
||||
log.Printf("%v: error: %v\n", c.Path(), err)
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
|
|
|
|||
|
|
@ -32,9 +32,19 @@ func RequiresSite(sites *sites.Service) func(c fiber.Ctx) error {
|
|||
return err
|
||||
}
|
||||
}
|
||||
|
||||
c.Locals("site", site)
|
||||
c.SetContext(models.WithSite(c.Context(), site))
|
||||
|
||||
sitesOwnedByUser, err := sites.ListSites(c.Context())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
c.Locals("allSites", sitesOwnedByUser)
|
||||
|
||||
if pubTargets, err := sites.BestPubTarget(c.Context(), site); err == nil {
|
||||
c.Locals("pubTarget", pubTargets)
|
||||
}
|
||||
|
||||
return c.Next()
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -12,10 +12,28 @@ type SiteSettingsHandler struct {
|
|||
SiteService *sites.Service
|
||||
}
|
||||
|
||||
func (s *SiteSettingsHandler) General(ctx fiber.Ctx) error {
|
||||
site := ctx.Locals("site").(models.Site)
|
||||
func (s *SiteSettingsHandler) New(c fiber.Ctx) error {
|
||||
return c.Render("sitesettings/new", fiber.Map{}, "layouts/bare_with_scripts")
|
||||
}
|
||||
|
||||
return ctx.Render("sitesettings/general", fiber.Map{
|
||||
func (s *SiteSettingsHandler) Create(c fiber.Ctx) error {
|
||||
var params sites.CreateSiteParams
|
||||
if err := c.Bind().Body(¶ms); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
newSite, err := s.SiteService.CreateSite(c.Context(), params)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return c.Redirect().To(fmt.Sprintf("/sites/%v/posts", newSite.ID))
|
||||
}
|
||||
|
||||
func (s *SiteSettingsHandler) General(c fiber.Ctx) error {
|
||||
site := c.Locals("site").(models.Site)
|
||||
|
||||
return c.Render("sitesettings/general", fiber.Map{
|
||||
"site": site,
|
||||
"tzones": sites.ListZones(),
|
||||
})
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue