|
|
|
@ -71,7 +71,19 @@ func newTemplateCache() (map[string]*template.Template, error) {
|
|
|
|
|
return cache, nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (app *application) render(w http.ResponseWriter, status int, page string, data interface{}) {
|
|
|
|
|
type templateData struct {
|
|
|
|
|
Voter *models.Voter
|
|
|
|
|
Flashes []string
|
|
|
|
|
Params struct {
|
|
|
|
|
Flags struct {
|
|
|
|
|
Unvoted bool
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
PrevPage, NextPage string
|
|
|
|
|
Motions []*models.MotionForDisplay
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (app *application) render(w http.ResponseWriter, status int, page string, data *templateData) {
|
|
|
|
|
ts, ok := app.templateCache[page]
|
|
|
|
|
if !ok {
|
|
|
|
|
app.serverError(w, fmt.Errorf("the template %s does not exist", page))
|
|
|
|
@ -93,19 +105,7 @@ func (app *application) render(w http.ResponseWriter, status int, page string, d
|
|
|
|
|
_, _ = buf.WriteTo(w)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type motionListTemplateData struct {
|
|
|
|
|
Voter *models.Voter
|
|
|
|
|
Flashes []string
|
|
|
|
|
Params struct {
|
|
|
|
|
Flags struct {
|
|
|
|
|
Unvoted bool
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
PrevPage, NextPage string
|
|
|
|
|
Motions []*models.MotionForDisplay
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (m *motionListTemplateData) setPaginationParameters(first, last *time.Time) error {
|
|
|
|
|
func (m *templateData) setPaginationParameters(first, last *time.Time) error {
|
|
|
|
|
motions := m.Motions
|
|
|
|
|
|
|
|
|
|
if len(motions) > 0 && first.Before(motions[len(motions)-1].Proposed) {
|
|
|
|
@ -164,7 +164,7 @@ func (app *application) motionList(w http.ResponseWriter, r *http.Request) {
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
templateData := &motionListTemplateData{Motions: motions}
|
|
|
|
|
templateData := &templateData{Motions: motions}
|
|
|
|
|
|
|
|
|
|
err = templateData.setPaginationParameters(first, last)
|
|
|
|
|
if err != nil {
|
|
|
|
@ -173,7 +173,7 @@ func (app *application) motionList(w http.ResponseWriter, r *http.Request) {
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
app.render(w, http.StatusOK, "motions.html", &templateData)
|
|
|
|
|
app.render(w, http.StatusOK, "motions.html", templateData)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func calculateMotionListOptions(r *http.Request) (*models.MotionListOptions, error) {
|
|
|
|
|