|
|
@ -19,6 +19,8 @@ package main
|
|
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
import (
|
|
|
|
"bytes"
|
|
|
|
"bytes"
|
|
|
|
|
|
|
|
"database/sql"
|
|
|
|
|
|
|
|
"errors"
|
|
|
|
"fmt"
|
|
|
|
"fmt"
|
|
|
|
"html/template"
|
|
|
|
"html/template"
|
|
|
|
"io/fs"
|
|
|
|
"io/fs"
|
|
|
@ -27,11 +29,11 @@ import (
|
|
|
|
"strings"
|
|
|
|
"strings"
|
|
|
|
"time"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
|
|
|
|
"github.com/Masterminds/sprig/v3"
|
|
|
|
|
|
|
|
"github.com/gorilla/csrf"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"git.cacert.org/cacert-boardvoting/internal/models"
|
|
|
|
"git.cacert.org/cacert-boardvoting/internal/models"
|
|
|
|
"git.cacert.org/cacert-boardvoting/ui"
|
|
|
|
"git.cacert.org/cacert-boardvoting/ui"
|
|
|
|
|
|
|
|
"github.com/Masterminds/sprig/v3"
|
|
|
|
|
|
|
|
"github.com/gorilla/csrf"
|
|
|
|
|
|
|
|
"github.com/julienschmidt/httprouter"
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
func newTemplateCache() (map[string]*template.Template, error) {
|
|
|
|
func newTemplateCache() (map[string]*template.Template, error) {
|
|
|
@ -81,6 +83,11 @@ type templateData struct {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
PrevPage, NextPage string
|
|
|
|
PrevPage, NextPage string
|
|
|
|
Motions []*models.MotionForDisplay
|
|
|
|
Motions []*models.MotionForDisplay
|
|
|
|
|
|
|
|
Motion *models.MotionForDisplay
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func (app *application) newTemplateData(r *http.Request) *templateData {
|
|
|
|
|
|
|
|
return &templateData{}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func (app *application) render(w http.ResponseWriter, status int, page string, data *templateData) {
|
|
|
|
func (app *application) render(w http.ResponseWriter, status int, page string, data *templateData) {
|
|
|
@ -164,7 +171,9 @@ func (app *application) motionList(w http.ResponseWriter, r *http.Request) {
|
|
|
|
return
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
templateData := &templateData{Motions: motions}
|
|
|
|
templateData := app.newTemplateData(r)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
templateData.Motions = motions
|
|
|
|
|
|
|
|
|
|
|
|
err = templateData.setPaginationParameters(first, last)
|
|
|
|
err = templateData.setPaginationParameters(first, last)
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
@ -208,19 +217,53 @@ func calculateMotionListOptions(r *http.Request) (*models.MotionListOptions, err
|
|
|
|
return listOptions, nil
|
|
|
|
return listOptions, nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func (app *application) home(w http.ResponseWriter, r *http.Request) {
|
|
|
|
func (app *application) motionDetails(w http.ResponseWriter, r *http.Request) {
|
|
|
|
if r.URL.Path != "/" {
|
|
|
|
params := httprouter.ParamsFromContext(r.Context())
|
|
|
|
http.NotFound(w, r)
|
|
|
|
|
|
|
|
|
|
|
|
tag := params.ByName("tag")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
showVotes := r.URL.Query().Has("showvotes")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
motion, err := app.motions.GetMotionByTag(r.Context(), tag, showVotes)
|
|
|
|
|
|
|
|
if err != nil && !errors.Is(err, sql.ErrNoRows) {
|
|
|
|
|
|
|
|
app.serverError(w, err)
|
|
|
|
|
|
|
|
|
|
|
|
return
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if r.Method != "GET" && r.Method != "HEAD" {
|
|
|
|
if motion == nil {
|
|
|
|
w.Header().Set("Allow", "GET,HEAD")
|
|
|
|
app.notFound(w)
|
|
|
|
app.clientError(w, http.StatusMethodNotAllowed)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
http.Redirect(w, r, "/motions/", http.StatusMovedPermanently)
|
|
|
|
data := app.newTemplateData(r)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
data.Motion = motion
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
app.render(w, http.StatusOK, "motion.html", data)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func (app *application) newMotionForm(writer http.ResponseWriter, request *http.Request) {
|
|
|
|
|
|
|
|
panic("not implemented")
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func (app *application) newMotionSubmit(writer http.ResponseWriter, request *http.Request) {
|
|
|
|
|
|
|
|
panic("not implemented")
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func (app *application) voteForm(writer http.ResponseWriter, request *http.Request) {
|
|
|
|
|
|
|
|
panic("not implemented")
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func (app *application) voteSubmit(writer http.ResponseWriter, request *http.Request) {
|
|
|
|
|
|
|
|
panic("not implemented")
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func (app *application) proxyVoteForm(writer http.ResponseWriter, request *http.Request) {
|
|
|
|
|
|
|
|
panic("not implemented")
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func (app *application) proxyVoteSubmit(writer http.ResponseWriter, request *http.Request) {
|
|
|
|
|
|
|
|
panic("not implemented")
|
|
|
|
}
|
|
|
|
}
|
|
|
|