GrapesJS was not working: too complex for users and not enough for designers. Therefore, we decided to use a simple WYSIWYG widget for the campsite types’ description, while we will do the actual HTML template with an external editor. Once that is done, we will convert that HTML to Go templates and get the description’s content from the database. Now the pages section has no sense: all the pages will be straight Go templates. Only the pages for “special things”, like campsite types, will use the database, and only for some fields, not the whole page.
56 lines
1.4 KiB
Go
56 lines
1.4 KiB
Go
/*
|
|
* SPDX-FileCopyrightText: 2023 jordi fita mas <jfita@peritasoft.com>
|
|
* SPDX-License-Identifier: AGPL-3.0-only
|
|
*/
|
|
|
|
package app
|
|
|
|
import (
|
|
"net/http"
|
|
|
|
"dev.tandem.ws/tandem/camper/pkg/auth"
|
|
"dev.tandem.ws/tandem/camper/pkg/campsite"
|
|
"dev.tandem.ws/tandem/camper/pkg/database"
|
|
httplib "dev.tandem.ws/tandem/camper/pkg/http"
|
|
"dev.tandem.ws/tandem/camper/pkg/template"
|
|
)
|
|
|
|
type publicHandler struct {
|
|
campsite *campsite.PublicHandler
|
|
}
|
|
|
|
func newPublicHandler() *publicHandler {
|
|
return &publicHandler{
|
|
campsite: campsite.NewPublicHandler(),
|
|
}
|
|
}
|
|
|
|
func (h *publicHandler) Handler(user *auth.User, company *auth.Company, conn *database.Conn) http.Handler {
|
|
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
var head string
|
|
head, r.URL.Path = httplib.ShiftPath(r.URL.Path)
|
|
switch head {
|
|
case "":
|
|
home := newHomePage()
|
|
home.MustRender(w, r, user, company, conn)
|
|
case "campsites":
|
|
h.campsite.Handler(user, company, conn).ServeHTTP(w, r)
|
|
default:
|
|
http.NotFound(w, r)
|
|
}
|
|
})
|
|
}
|
|
|
|
type homePage struct {
|
|
*template.PublicPage
|
|
}
|
|
|
|
func newHomePage() *homePage {
|
|
return &homePage{template.NewPublicPage()}
|
|
}
|
|
|
|
func (p *homePage) MustRender(w http.ResponseWriter, r *http.Request, user *auth.User, company *auth.Company, conn *database.Conn) {
|
|
p.Setup(r, user, company, conn)
|
|
template.MustRenderPublic(w, r, user, company, "home.gohtml", p)
|
|
}
|