Compare commits
5 commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 7f7cafdd93 | |||
| 0a4efb8630 | |||
| 85a867753d | |||
| 8edb962f9b | |||
| a3dc4eddfa |
21 changed files with 895 additions and 917 deletions
|
|
@ -1,18 +1,8 @@
|
|||
# This is an example .goreleaser.yml file with some sensible defaults.
|
||||
# Make sure to check the documentation at https://goreleaser.com
|
||||
|
||||
# The lines below are called `modelines`. See `:help modeline`
|
||||
# Feel free to remove those if you don't want/need to use them.
|
||||
# yaml-language-server: $schema=https://goreleaser.com/static/schema.json
|
||||
# vim: set ts=2 sw=2 tw=0 fo=cnqoj
|
||||
|
||||
version: 2
|
||||
|
||||
before:
|
||||
hooks:
|
||||
# You may remove this if you don't use go modules.
|
||||
- go mod tidy
|
||||
# you may remove this if you don't need go generate
|
||||
- go generate ./...
|
||||
|
||||
builds:
|
||||
|
|
@ -25,24 +15,8 @@ builds:
|
|||
- windows
|
||||
- darwin
|
||||
|
||||
signs:
|
||||
- cmd: cosign
|
||||
args:
|
||||
- "sign-blob"
|
||||
- "--key=cosign.key"
|
||||
- "--output-signature=${signature}"
|
||||
- "${artifact}"
|
||||
artifacts: all
|
||||
|
||||
windows:
|
||||
publisher: "Ihr Name oder Firmenname"
|
||||
product_name: "Ihr Produktname"
|
||||
file_version: "{{ .Version }}"
|
||||
copyright: "Copyright © {{ .Year }} Ihr Name"
|
||||
|
||||
archives:
|
||||
- format: tar.gz
|
||||
# this name template makes the OS and Arch compatible with the results of `uname`.
|
||||
name_template: >-
|
||||
{{ .ProjectName }}_
|
||||
{{- title .Os }}_
|
||||
|
|
@ -50,7 +24,6 @@ archives:
|
|||
{{- else if eq .Arch "386" }}i386
|
||||
{{- else }}{{ .Arch }}{{ end }}
|
||||
{{- if .Arm }}v{{ .Arm }}{{ end }}
|
||||
# use zip for windows archives
|
||||
format_overrides:
|
||||
- goos: windows
|
||||
format: zip
|
||||
|
|
|
|||
|
|
@ -1 +1 @@
|
|||
# echoTest
|
||||
# Englischnoten
|
||||
|
|
|
|||
15
controllers/add.go
Normal file
15
controllers/add.go
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
package controllers
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/labstack/echo/v4"
|
||||
)
|
||||
|
||||
func (c *Controller) AddBewertungRoute(ctx echo.Context) error {
|
||||
new := c.ParseBewertungen(ctx)
|
||||
if new.Nachname != "" {
|
||||
*c.Bewertungen = append(*c.Bewertungen, new)
|
||||
}
|
||||
return ctx.Redirect(http.StatusSeeOther, "/")
|
||||
}
|
||||
|
|
@ -1,342 +0,0 @@
|
|||
package controllers
|
||||
|
||||
import (
|
||||
"echoTest/model"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"github.com/chasefleming/elem-go"
|
||||
"github.com/chasefleming/elem-go/attrs"
|
||||
"github.com/chasefleming/elem-go/htmx"
|
||||
"github.com/labstack/echo/v4"
|
||||
)
|
||||
|
||||
func UpdateGewertetRoute(bewertung model.Bewertung) elem.Node {
|
||||
checkbox := elem.Input(attrs.Props{
|
||||
attrs.Type: "checkbox",
|
||||
attrs.Checked: strconv.FormatBool(bewertung.Gewertet),
|
||||
htmx.HXPost: "/toggle/" + strconv.Itoa(bewertung.ID),
|
||||
htmx.HXTarget: "#bewertung-" + strconv.Itoa(bewertung.ID),
|
||||
})
|
||||
return checkbox
|
||||
}
|
||||
|
||||
func RenderBewertungenRoute(c echo.Context) error {
|
||||
return c.HTML(http.StatusOK, renderBewertungen(Bewertungen))
|
||||
}
|
||||
|
||||
func ToggleWertungRoute(c echo.Context) error {
|
||||
id, _ := strconv.Atoi(c.Param("id"))
|
||||
var updatedBewertung model.Bewertung
|
||||
for i, bewertung := range Bewertungen {
|
||||
if bewertung.ID == id {
|
||||
Bewertungen[i].Gewertet = !bewertung.Gewertet
|
||||
updatedBewertung = Bewertungen[i]
|
||||
break
|
||||
}
|
||||
}
|
||||
return c.HTML(http.StatusOK, createBewertungNode(updatedBewertung).Render())
|
||||
}
|
||||
func addBewertungRoute(c echo.Context) error {
|
||||
new := parseBewertungen(c)
|
||||
if new.Nachname != "" {
|
||||
Bewertungen = append(Bewertungen, new)
|
||||
}
|
||||
return c.Redirect(http.StatusSeeOther, "/")
|
||||
}
|
||||
func parseBewertungen(c echo.Context) Bewertung {
|
||||
newName := validateName(c)
|
||||
vorname := c.FormValue("vorname")
|
||||
if MaxPunkte.HvMax == 0.00 {
|
||||
hvMax, _ := strconv.ParseFloat(c.FormValue("hv_max"), 64)
|
||||
lvMax, _ := strconv.ParseFloat(c.FormValue("lv_max"), 64)
|
||||
hvGewichtung, _ := strconv.ParseFloat(c.FormValue("hv_gewichtung"), 64)
|
||||
lvGewichtung, _ := strconv.ParseFloat(c.FormValue("lv_gewichtung"), 64)
|
||||
MaxPunkte.HvMax = hvMax
|
||||
MaxPunkte.LvMax = lvMax
|
||||
MaxPunkte.LvGewichtung = lvGewichtung
|
||||
MaxPunkte.HvGewichtung = hvGewichtung
|
||||
}
|
||||
hvPunkte, _ := strconv.ParseFloat(c.FormValue("hv_punkte"), 64)
|
||||
lvPunkte, _ := strconv.ParseFloat(c.FormValue("lv_punkte"), 64)
|
||||
hvProzent := 100.00 / maxPunkte.HvMax * hvPunkte
|
||||
lvProzent := 100.00 / maxPunkte.LvMax * lvPunkte
|
||||
hvNote := setNote(hvProzent)
|
||||
lvNote := setNote(lvProzent)
|
||||
gesamtProzent := hvProzent*maxPunkte.HvGewichtung/100 + lvProzent*maxPunkte.LvGewichtung/100
|
||||
gesamtNote := setNote(gesamtProzent)
|
||||
|
||||
// Create a new Bewertung struct
|
||||
return model.Bewertung{
|
||||
ID: len(bewertungen) + 1,
|
||||
Vorname: string(vorname),
|
||||
Nachname: string(newName),
|
||||
HvPunkte: hvPunkte,
|
||||
HvProzent: hvProzent,
|
||||
HvNote: int(hvNote),
|
||||
LvPunkte: lvPunkte,
|
||||
LvProzent: lvProzent,
|
||||
LvNote: int(lvNote),
|
||||
GesamtProzent: gesamtProzent,
|
||||
GesamtNote: int(gesamtNote),
|
||||
Gewertet: true,
|
||||
}
|
||||
}
|
||||
func createBewertungNode(bewertung Bewertung) elem.Node {
|
||||
checkbox := elem.Input(attrs.Props{
|
||||
attrs.Type: "checkbox",
|
||||
attrs.Checked: strconv.FormatBool(bewertung.Gewertet),
|
||||
htmx.HXPost: "/toggle/" + strconv.Itoa(bewertung.ID),
|
||||
htmx.HXTarget: "#bewertung-" + strconv.Itoa(bewertung.ID),
|
||||
htmx.HXSwap: "outerHTML",
|
||||
})
|
||||
|
||||
return elem.Tr(attrs.Props{
|
||||
attrs.ID: "bewertung-" + strconv.Itoa(bewertung.ID),
|
||||
},
|
||||
elem.Td(nil, checkbox),
|
||||
elem.Td(nil, elem.Text(bewertung.Vorname)),
|
||||
elem.Td(nil, elem.Text(bewertung.Nachname)),
|
||||
elem.Td(nil, elem.Text(strconv.FormatFloat(bewertung.HvPunkte, 'f', 2, 64))),
|
||||
elem.Td(nil, elem.Text(strconv.FormatFloat(bewertung.HvProzent, 'f', 2, 64))),
|
||||
elem.Td(nil, elem.Text(strconv.Itoa(bewertung.HvNote))),
|
||||
elem.Td(nil, elem.Text(strconv.FormatFloat(bewertung.LvPunkte, 'f', 2, 64))),
|
||||
elem.Td(nil, elem.Text(strconv.FormatFloat(bewertung.LvProzent, 'f', 2, 64))),
|
||||
elem.Td(nil, elem.Text(strconv.Itoa(bewertung.LvNote))),
|
||||
elem.Td(nil, elem.Text(strconv.FormatFloat(bewertung.GesamtProzent, 'f', 2, 64))),
|
||||
elem.Td(nil, elem.Text(strconv.Itoa(bewertung.GesamtNote))),
|
||||
)
|
||||
}
|
||||
|
||||
func renderBewertungen(bewertungen []Bewertung) string {
|
||||
inputPunkte := elem.Div(nil)
|
||||
if maxPunkte.HvGewichtung == 0.00 {
|
||||
inputPunkte = elem.Div(attrs.Props{attrs.Class: "tile is-ancestor"},
|
||||
elem.Div(attrs.Props{attrs.Class: "tile field is-parent"},
|
||||
elem.Input(attrs.Props{
|
||||
attrs.Class: "input is-child",
|
||||
attrs.Type: "text",
|
||||
attrs.Name: "hv_max",
|
||||
attrs.Placeholder: "HV-Max-Punkte",
|
||||
},
|
||||
),
|
||||
),
|
||||
elem.Div(attrs.Props{attrs.Class: "tile field is-parent"},
|
||||
elem.Input(attrs.Props{
|
||||
attrs.Class: "input is-child",
|
||||
attrs.Type: "text",
|
||||
attrs.Name: "hv_gewichtung",
|
||||
attrs.Placeholder: "HV-Gewichtung in %",
|
||||
},
|
||||
),
|
||||
),
|
||||
elem.Div(attrs.Props{attrs.Class: "tile field is-parent"},
|
||||
elem.Input(attrs.Props{
|
||||
attrs.Class: "input is-child",
|
||||
attrs.Type: "text",
|
||||
attrs.Name: "lv_max",
|
||||
attrs.Placeholder: "LV-Max-Punkte",
|
||||
},
|
||||
),
|
||||
),
|
||||
elem.Div(attrs.Props{attrs.Class: "tile field is-parent"},
|
||||
elem.Input(attrs.Props{
|
||||
attrs.Class: "input is-child",
|
||||
attrs.Type: "text",
|
||||
attrs.Name: "lv_gewichtung",
|
||||
attrs.Placeholder: "LV-Gewichtung in %",
|
||||
},
|
||||
),
|
||||
),
|
||||
)
|
||||
} else {
|
||||
inputPunkte = elem.Div(attrs.Props{attrs.Class: "tile is-ancestor"},
|
||||
elem.Div(attrs.Props{attrs.Class: "tile field is-parent"},
|
||||
elem.Input(attrs.Props{
|
||||
attrs.Class: "input is-child",
|
||||
attrs.Type: "text",
|
||||
attrs.Name: "hv_max",
|
||||
attrs.Placeholder: "HV-Max-Punkte",
|
||||
attrs.Value: fmt.Sprintf("%.2f", maxPunkte.HvMax),
|
||||
},
|
||||
),
|
||||
),
|
||||
elem.Div(attrs.Props{attrs.Class: "tile field is-parent"},
|
||||
elem.Input(attrs.Props{
|
||||
attrs.Class: "input is-child",
|
||||
attrs.Type: "text",
|
||||
attrs.Name: "hv_gewichtung",
|
||||
attrs.Placeholder: "HV-Gewichtung in %",
|
||||
attrs.Value: fmt.Sprintf("%.2f", maxPunkte.HvGewichtung),
|
||||
},
|
||||
),
|
||||
),
|
||||
elem.Div(attrs.Props{attrs.Class: "tile field is-parent"},
|
||||
elem.Input(attrs.Props{
|
||||
attrs.Class: "input is-child",
|
||||
attrs.Type: "text",
|
||||
attrs.Name: "lv_max",
|
||||
attrs.Placeholder: "LV-Max-Punkte",
|
||||
attrs.Value: fmt.Sprintf("%.2f", maxPunkte.LvMax),
|
||||
},
|
||||
),
|
||||
),
|
||||
elem.Div(attrs.Props{attrs.Class: "tile field is-parent"},
|
||||
elem.Input(attrs.Props{
|
||||
attrs.Class: "input is-child",
|
||||
attrs.Type: "text",
|
||||
attrs.Name: "lv_gewichtung",
|
||||
attrs.Placeholder: "LV-Gewichtung in %",
|
||||
attrs.Value: fmt.Sprintf("%.2f", maxPunkte.LvGewichtung),
|
||||
},
|
||||
),
|
||||
),
|
||||
)
|
||||
}
|
||||
|
||||
headContent := elem.Head(nil,
|
||||
elem.Meta(attrs.Props{attrs.Charset: "UTF-8", attrs.Name: "viewport", attrs.Content: "width=device-width, initial-scale=1.0"}),
|
||||
elem.Script(attrs.Props{attrs.Src: "https://unpkg.com/htmx.org"}),
|
||||
elem.Link(attrs.Props{attrs.Rel: "stylesheet", attrs.Href: "https://cdn.jsdelivr.net/npm/bulma@0.9.4/css/bulma.min.css"}),
|
||||
)
|
||||
|
||||
headerContent := elem.Header(attrs.Props{
|
||||
attrs.Class: "navbar",
|
||||
attrs.Role: "navigation",
|
||||
attrs.AriaLabel: "main navigation",
|
||||
},
|
||||
elem.Div(attrs.Props{
|
||||
attrs.ID: "navbarBasicExample",
|
||||
attrs.Class: "navbar-menu",
|
||||
},
|
||||
elem.Div(attrs.Props{
|
||||
attrs.Class: "navbar-start",
|
||||
},
|
||||
elem.A(attrs.Props{
|
||||
attrs.Class: "navbar-item",
|
||||
}, elem.Text("Home"),
|
||||
),
|
||||
),
|
||||
elem.Div(attrs.Props{
|
||||
attrs.Class: "navbar-end",
|
||||
},
|
||||
elem.Span(attrs.Props{
|
||||
attrs.Class: "navbar-item",
|
||||
},
|
||||
elem.Button(attrs.Props{
|
||||
attrs.Class: "button is-primary",
|
||||
htmx.HXTrigger: "click",
|
||||
htmx.HXGet: "/end",
|
||||
}, elem.Text("Beenden"),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
)
|
||||
|
||||
bodyContent := elem.Div(attrs.Props{attrs.Class: "container is-widescreen"},
|
||||
elem.Div(attrs.Props{attrs.Class: "card tile is-vertical is-ancestor"},
|
||||
elem.Header(attrs.Props{attrs.Class: "card-header"},
|
||||
elem.P(attrs.Props{attrs.Class: "card-header-title"}, elem.Text("Englischarbeit"))),
|
||||
elem.Div(attrs.Props{attrs.Class: "card-content"},
|
||||
elem.Div(attrs.Props{attrs.Class: "content tile is-parent is-vertical gap"},
|
||||
elem.H1(attrs.Props{attrs.Class: "tilte"}, elem.Text("Bewertungen")),
|
||||
elem.Form(attrs.Props{attrs.Method: "post", attrs.Action: "/add"}, inputPunkte,
|
||||
elem.Div(attrs.Props{attrs.Class: "tile is-ancestor"},
|
||||
elem.Div(attrs.Props{attrs.Class: "tile field is-parent"},
|
||||
elem.Input(attrs.Props{
|
||||
attrs.Type: "text",
|
||||
attrs.Name: "vorname",
|
||||
attrs.Class: "input is-child",
|
||||
attrs.Placeholder: "Vorname",
|
||||
},
|
||||
),
|
||||
),
|
||||
elem.Div(attrs.Props{attrs.Class: "tile field is-parent"},
|
||||
elem.Input(attrs.Props{
|
||||
attrs.Type: "text",
|
||||
attrs.Name: "nachname",
|
||||
attrs.Class: "input is-child",
|
||||
attrs.Placeholder: "Nachname",
|
||||
},
|
||||
),
|
||||
),
|
||||
elem.Div(attrs.Props{attrs.Class: "tile field is-parent"},
|
||||
elem.Input(attrs.Props{
|
||||
attrs.Type: "text",
|
||||
attrs.Name: "hv_punkte",
|
||||
attrs.Class: "input is-child",
|
||||
attrs.Placeholder: "HV-Punkte",
|
||||
},
|
||||
),
|
||||
),
|
||||
elem.Div(attrs.Props{attrs.Class: "tile field is-parent"},
|
||||
elem.Input(attrs.Props{
|
||||
attrs.Type: "text",
|
||||
attrs.Name: "lv_punkte",
|
||||
attrs.Class: "input is-child",
|
||||
attrs.Placeholder: "LV-Punkte",
|
||||
},
|
||||
),
|
||||
),
|
||||
elem.Div(attrs.Props{attrs.Class: "tile field is-parent"},
|
||||
elem.Button(
|
||||
attrs.Props{
|
||||
attrs.Type: "submit",
|
||||
attrs.Class: "button tile is-child",
|
||||
},
|
||||
elem.Text("Add"),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
elem.Div(attrs.Props{attrs.Class: "table-container"},
|
||||
elem.Table(attrs.Props{attrs.Class: "table is-hoverable"},
|
||||
elem.THead(nil,
|
||||
elem.Tr(nil,
|
||||
elem.Th(nil, elem.Text("Gewertet")),
|
||||
elem.Th(nil, elem.Text("Vorname")),
|
||||
elem.Th(nil, elem.Text("Nachname")),
|
||||
elem.Th(nil, elem.Text("HV-Punkte")),
|
||||
elem.Th(nil, elem.Text("HV-Prozent")),
|
||||
elem.Th(nil, elem.Text("HV-Note")),
|
||||
elem.Th(nil, elem.Text("LV-Punkte")),
|
||||
elem.Th(nil, elem.Text("LV-Prozent")),
|
||||
elem.Th(nil, elem.Text("LV-Note")),
|
||||
elem.Th(nil, elem.Text("Gesamt-Prozent")),
|
||||
elem.Th(nil, elem.Text("Gesamt-Note")),
|
||||
),
|
||||
),
|
||||
elem.TBody(nil,
|
||||
elem.TransformEach(bewertungen, createBewertungNode)...),
|
||||
),
|
||||
),
|
||||
elem.Div(nil,
|
||||
elem.Button(attrs.Props{
|
||||
htmx.HXTrigger: "click",
|
||||
htmx.HXGet: "/export",
|
||||
attrs.Class: "button",
|
||||
},
|
||||
elem.Text("export"),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
)
|
||||
footerContent := elem.Footer(attrs.Props{
|
||||
attrs.Class: "footer",
|
||||
},
|
||||
elem.Div(attrs.Props{
|
||||
attrs.Class: "content has-text-centered",
|
||||
},
|
||||
elem.P(nil, elem.Text("© 2023 Alle Rechte vorbehalten.")),
|
||||
),
|
||||
)
|
||||
|
||||
tbodyContent := elem.TBody(nil)
|
||||
htmlContent := elem.Html(nil, elem.Raw("<!DOCTYPE html>"), headContent, headerContent, bodyContent, tbodyContent, footerContent)
|
||||
|
||||
return htmlContent.Render()
|
||||
}
|
||||
12
controllers/controller.go
Normal file
12
controllers/controller.go
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
package controllers
|
||||
|
||||
import "echoTest/models"
|
||||
|
||||
type Controller struct {
|
||||
Bewertungen *[]models.Bewertung
|
||||
MaxPunkte *models.MaxPunkte
|
||||
}
|
||||
|
||||
func NewController(bewertungen *[]models.Bewertung, maxPunkte *models.MaxPunkte) *Controller {
|
||||
return &Controller{Bewertungen: bewertungen, MaxPunkte: maxPunkte}
|
||||
}
|
||||
16
controllers/create.go
Normal file
16
controllers/create.go
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
package controllers
|
||||
|
||||
import (
|
||||
"context"
|
||||
"echoTest/models"
|
||||
"echoTest/templates"
|
||||
"io"
|
||||
|
||||
"github.com/a-h/templ"
|
||||
)
|
||||
|
||||
func (c *Controller) CreateBewertungNode(bewertung models.Bewertung) templ.Component {
|
||||
return templ.ComponentFunc(func(ctx context.Context, w io.Writer) error {
|
||||
return templates.BewertungenTable([]models.Bewertung{bewertung}).Render(ctx, w)
|
||||
})
|
||||
}
|
||||
13
controllers/end.go
Normal file
13
controllers/end.go
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
package controllers
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"os"
|
||||
|
||||
"github.com/labstack/echo/v4"
|
||||
)
|
||||
|
||||
func (c *Controller) EndRoute(ctx echo.Context) error {
|
||||
os.Exit(0)
|
||||
return ctx.HTML(http.StatusOK, "Tschüss")
|
||||
}
|
||||
43
controllers/export.go
Normal file
43
controllers/export.go
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
package controllers
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"github.com/jung-kurt/gofpdf"
|
||||
"github.com/labstack/echo/v4"
|
||||
)
|
||||
|
||||
func (c *Controller) ExportBewertungenRoute(ctx echo.Context) error {
|
||||
log.Println("Exporting")
|
||||
pdf := gofpdf.New("P", "mm", "A4", "")
|
||||
pdf.AddPage()
|
||||
pdf.SetFont("Arial", "B", 12)
|
||||
pdf.CellFormat(27, 10, "Vorname", "1", 0, "", false, 0, "")
|
||||
pdf.CellFormat(27, 10, "Nachname", "1", 0, "", false, 0, "")
|
||||
pdf.CellFormat(27, 10, "HV-Punkte", "1", 0, "", false, 0, "")
|
||||
pdf.CellFormat(27, 10, "HV-Note", "1", 0, "", false, 0, "")
|
||||
pdf.CellFormat(27, 10, "LV-Punkte", "1", 0, "", false, 0, "")
|
||||
pdf.CellFormat(27, 10, "LV-Note", "1", 0, "", false, 0, "")
|
||||
pdf.CellFormat(27, 10, "Gesamtnote", "1", 0, "", false, 0, "")
|
||||
pdf.Ln(-1)
|
||||
pdf.SetFont("Arial", "", 11)
|
||||
for _, bewertung := range *c.Bewertungen {
|
||||
pdf.CellFormat(27, 10, bewertung.Vorname, "1", 0, "", false, 0, "")
|
||||
pdf.CellFormat(27, 10, bewertung.Nachname, "1", 0, "", false, 0, "")
|
||||
pdf.CellFormat(27, 10, strconv.FormatFloat(bewertung.HvPunkte, 'f', 2, 64), "1", 0, "", false, 0, "")
|
||||
pdf.CellFormat(27, 10, strconv.FormatInt(int64(bewertung.HvNote), 10), "1", 0, "", false, 0, "")
|
||||
pdf.CellFormat(27, 10, strconv.FormatFloat(bewertung.LvPunkte, 'f', 2, 64), "1", 0, "", false, 0, "")
|
||||
pdf.CellFormat(27, 10, strconv.FormatInt(int64(bewertung.LvNote), 10), "1", 0, "", false, 0, "")
|
||||
pdf.CellFormat(27, 10, strconv.FormatInt(int64(bewertung.GesamtNote), 10), "1", 0, "", false, 0, "")
|
||||
pdf.Ln(-1)
|
||||
}
|
||||
err := pdf.OutputFileAndClose("bewertungen.pdf")
|
||||
if err != nil {
|
||||
fmt.Println("Fehler beim Exportieren der Bewertungen:", err)
|
||||
return err
|
||||
}
|
||||
return ctx.HTML(http.StatusOK, "Export beendet")
|
||||
}
|
||||
46
controllers/parse.go
Normal file
46
controllers/parse.go
Normal file
|
|
@ -0,0 +1,46 @@
|
|||
package controllers
|
||||
|
||||
import (
|
||||
"echoTest/models"
|
||||
"echoTest/utils"
|
||||
"strconv"
|
||||
|
||||
"github.com/labstack/echo/v4"
|
||||
)
|
||||
|
||||
func (c *Controller) ParseBewertungen(ctx echo.Context) models.Bewertung {
|
||||
newName := utils.ValidateName(ctx, c.Bewertungen)
|
||||
vorname := ctx.FormValue("vorname")
|
||||
if c.MaxPunkte.HvMax == 0.00 {
|
||||
hvMax, _ := strconv.ParseFloat(ctx.FormValue("hv_max"), 64)
|
||||
lvMax, _ := strconv.ParseFloat(ctx.FormValue("lv_max"), 64)
|
||||
hvGewichtung, _ := strconv.ParseFloat(ctx.FormValue("hv_gewichtung"), 64)
|
||||
lvGewichtung, _ := strconv.ParseFloat(ctx.FormValue("lv_gewichtung"), 64)
|
||||
c.MaxPunkte.HvMax = hvMax
|
||||
c.MaxPunkte.LvMax = lvMax
|
||||
c.MaxPunkte.LvGewichtung = lvGewichtung
|
||||
c.MaxPunkte.HvGewichtung = hvGewichtung
|
||||
}
|
||||
hvPunkte, _ := strconv.ParseFloat(ctx.FormValue("hv_punkte"), 64)
|
||||
lvPunkte, _ := strconv.ParseFloat(ctx.FormValue("lv_punkte"), 64)
|
||||
hvProzent := 100.00 / c.MaxPunkte.HvMax * hvPunkte
|
||||
lvProzent := 100.00 / c.MaxPunkte.LvMax * lvPunkte
|
||||
hvNote := utils.SetNote(hvProzent)
|
||||
lvNote := utils.SetNote(lvProzent)
|
||||
gesamtProzent := hvProzent*c.MaxPunkte.HvGewichtung/100 + lvProzent*c.MaxPunkte.LvGewichtung/100
|
||||
gesamtNote := utils.SetNote(gesamtProzent)
|
||||
return models.Bewertung{
|
||||
ID: len(*c.Bewertungen) + 1,
|
||||
Vorname: string(vorname),
|
||||
Nachname: string(newName),
|
||||
HvPunkte: hvPunkte,
|
||||
HvProzent: hvProzent,
|
||||
HvNote: int(hvNote),
|
||||
LvPunkte: lvPunkte,
|
||||
LvProzent: lvProzent,
|
||||
LvNote: int(lvNote),
|
||||
GesamtProzent: gesamtProzent,
|
||||
GesamtNote: int(gesamtNote),
|
||||
Gewertet: true,
|
||||
}
|
||||
}
|
||||
11
controllers/render.go
Normal file
11
controllers/render.go
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
package controllers
|
||||
|
||||
import (
|
||||
"echoTest/templates"
|
||||
|
||||
"github.com/labstack/echo/v4"
|
||||
)
|
||||
|
||||
func (c *Controller) RenderBewertungenRoute(ctx echo.Context) error {
|
||||
return templates.BewertungenPage(*c.Bewertungen, *c.MaxPunkte).Render(ctx.Request().Context(), ctx.Response().Writer)
|
||||
}
|
||||
23
controllers/toggle.go
Normal file
23
controllers/toggle.go
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
package controllers
|
||||
|
||||
import (
|
||||
"echoTest/models"
|
||||
"echoTest/templates"
|
||||
"strconv"
|
||||
|
||||
"github.com/labstack/echo/v4"
|
||||
)
|
||||
|
||||
func (c *Controller) ToggleWertungRoute(ctx echo.Context) error {
|
||||
id, _ := strconv.Atoi(ctx.Param("id"))
|
||||
var updatedBewertung models.Bewertung
|
||||
for i, bewertung := range *c.Bewertungen {
|
||||
if bewertung.ID == id {
|
||||
(*c.Bewertungen)[i].Gewertet = !bewertung.Gewertet
|
||||
updatedBewertung = (*c.Bewertungen)[i]
|
||||
break
|
||||
}
|
||||
}
|
||||
// return c.CreateBewertungNode(updatedBewertung).Render(ctx.Request().Context(), ctx.Response().Writer)
|
||||
return templates.BewertungRow(updatedBewertung).Render(ctx.Request().Context(), ctx.Response().Writer)
|
||||
}
|
||||
18
go.mod
18
go.mod
|
|
@ -3,25 +3,21 @@ module echoTest
|
|||
go 1.21.5
|
||||
|
||||
require (
|
||||
github.com/chasefleming/elem-go v0.27.0
|
||||
github.com/a-h/templ v0.2.793
|
||||
github.com/jung-kurt/gofpdf v1.16.2
|
||||
github.com/labstack/echo/v4 v4.12.0
|
||||
github.com/stretchr/testify v1.8.4
|
||||
github.com/labstack/echo/v4 v4.13.3
|
||||
)
|
||||
|
||||
require (
|
||||
github.com/davecgh/go-spew v1.1.1 // indirect
|
||||
github.com/golang-jwt/jwt v3.2.2+incompatible // indirect
|
||||
github.com/labstack/gommon v0.4.2 // indirect
|
||||
github.com/mattn/go-colorable v0.1.13 // indirect
|
||||
github.com/mattn/go-isatty v0.0.20 // indirect
|
||||
github.com/pmezard/go-difflib v1.0.0 // indirect
|
||||
github.com/valyala/bytebufferpool v1.0.0 // indirect
|
||||
github.com/valyala/fasttemplate v1.2.2 // indirect
|
||||
golang.org/x/crypto v0.26.0 // indirect
|
||||
golang.org/x/net v0.28.0 // indirect
|
||||
golang.org/x/sys v0.24.0 // indirect
|
||||
golang.org/x/text v0.17.0 // indirect
|
||||
golang.org/x/time v0.6.0 // indirect
|
||||
gopkg.in/yaml.v3 v3.0.1 // indirect
|
||||
golang.org/x/crypto v0.31.0 // indirect
|
||||
golang.org/x/net v0.33.0 // indirect
|
||||
golang.org/x/sys v0.28.0 // indirect
|
||||
golang.org/x/text v0.21.0 // indirect
|
||||
golang.org/x/time v0.8.0 // indirect
|
||||
)
|
||||
|
|
|
|||
35
go.sum
35
go.sum
|
|
@ -1,20 +1,20 @@
|
|||
github.com/a-h/templ v0.2.793 h1:Io+/ocnfGWYO4VHdR0zBbf39PQlnzVCVVD+wEEs6/qY=
|
||||
github.com/a-h/templ v0.2.793/go.mod h1:lq48JXoUvuQrU0VThrK31yFwdRjTCnIE5bcPCM9IP1w=
|
||||
github.com/boombuler/barcode v1.0.0/go.mod h1:paBWMcWSl3LHKBqUq+rly7CNSldXjb2rDl3JlRe0mD8=
|
||||
github.com/chasefleming/elem-go v0.16.0 h1:kAmR/1tIdnkuEogtG6zDLAWHM7hGbpuD2wjPtbJSHoY=
|
||||
github.com/chasefleming/elem-go v0.16.0/go.mod h1:hz73qILBIKnTgOujnSMtEj20/epI+f6vg71RUilJAA4=
|
||||
github.com/chasefleming/elem-go v0.27.0 h1:rJhkr7CZuUhx0dN7QAgdKqL+F9Eu5PRTXNxm06h4/9Y=
|
||||
github.com/chasefleming/elem-go v0.27.0/go.mod h1:hz73qILBIKnTgOujnSMtEj20/epI+f6vg71RUilJAA4=
|
||||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/golang-jwt/jwt v3.2.2+incompatible h1:IfV12K8xAKAnZqdXVzCZ+TOjboZ2keLg81eXfW3O+oY=
|
||||
github.com/golang-jwt/jwt v3.2.2+incompatible/go.mod h1:8pz2t5EyA70fFQQSrl6XZXzqecmYZeUEB8OUGHkxJ+I=
|
||||
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
|
||||
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
|
||||
github.com/jung-kurt/gofpdf v1.0.0/go.mod h1:7Id9E/uU8ce6rXgefFLlgrJj/GYY22cpxn+r32jIOes=
|
||||
github.com/jung-kurt/gofpdf v1.16.2 h1:jgbatWHfRlPYiK85qgevsZTHviWXKwB1TTiKdz5PtRc=
|
||||
github.com/jung-kurt/gofpdf v1.16.2/go.mod h1:1hl7y57EsiPAkLbOwzpzqgx1A30nQCk/YmFV8S2vmK0=
|
||||
github.com/labstack/echo/v4 v4.11.4 h1:vDZmA+qNeh1pd/cCkEicDMrjtrnMGQ1QFI9gWN1zGq8=
|
||||
github.com/labstack/echo/v4 v4.11.4/go.mod h1:noh7EvLwqDsmh/X/HWKPUl1AjzJrhyptRyEbQJfxen8=
|
||||
github.com/labstack/echo/v4 v4.12.0 h1:IKpw49IMryVB2p1a4dzwlhP1O2Tf2E0Ir/450lH+kI0=
|
||||
github.com/labstack/echo/v4 v4.12.0/go.mod h1:UP9Cr2DJXbOK3Kr9ONYzNowSh7HP0aG0ShAyycHSJvM=
|
||||
github.com/labstack/echo/v4 v4.13.3 h1:pwhpCPrTl5qry5HRdM5FwdXnhXSLSY+WE+YQSeCaafY=
|
||||
github.com/labstack/echo/v4 v4.13.3/go.mod h1:o90YNEeQWjDozo584l7AwhJMHN0bOC4tAfg+Xox9q5g=
|
||||
github.com/labstack/gommon v0.4.2 h1:F8qTUNXgG1+6WQmqoUWnz8WiEU60mXVVw0P4ht1WRA0=
|
||||
github.com/labstack/gommon v0.4.2/go.mod h1:QlUFxVM+SNXhDL/Z7YhocGIBYOiwB0mXm1+1bAPHPyU=
|
||||
github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA=
|
||||
|
|
@ -30,35 +30,34 @@ github.com/ruudk/golang-pdf417 v0.0.0-20181029194003-1af4ab5afa58/go.mod h1:6lfF
|
|||
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
|
||||
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
|
||||
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
|
||||
github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA=
|
||||
github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6KllzawFIhcdPw=
|
||||
github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc=
|
||||
github.com/valyala/fasttemplate v1.2.2 h1:lxLXG0uE3Qnshl9QyaK6XJxMXlQZELvChBOCmQD0Loo=
|
||||
github.com/valyala/fasttemplate v1.2.2/go.mod h1:KHLXt3tVN2HBp8eijSv/kGJopbvo7S+qRAEEKiv+SiQ=
|
||||
golang.org/x/crypto v0.21.0 h1:X31++rzVUdKhX5sWmSOFZxx8UW/ldWx55cbf08iNAMA=
|
||||
golang.org/x/crypto v0.21.0/go.mod h1:0BP7YvVV9gBbVKyeTG0Gyn+gZm94bibOW5BjDEYAOMs=
|
||||
golang.org/x/crypto v0.26.0 h1:RrRspgV4mU+YwB4FYnuBoKsUapNIL5cohGAmSH3azsw=
|
||||
golang.org/x/crypto v0.26.0/go.mod h1:GY7jblb9wI+FOo5y8/S2oY4zWP07AkOJ4+jxCqdqn54=
|
||||
golang.org/x/crypto v0.31.0 h1:ihbySMvVjLAeSH1IbfcRTkD/iNscyz8rGzjF/E5hV6U=
|
||||
golang.org/x/crypto v0.31.0/go.mod h1:kDsLvtWBEx7MV9tJOj9bnXsPbxwJQ6csT/x4KIN4Ssk=
|
||||
golang.org/x/image v0.0.0-20190910094157-69e4b8554b2a/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0=
|
||||
golang.org/x/net v0.23.0 h1:7EYJ93RZ9vYSZAIb2x3lnuvqO5zneoD6IvWjuhfxjTs=
|
||||
golang.org/x/net v0.23.0/go.mod h1:JKghWKKOSdJwpW2GEx0Ja7fmaKnMsbu+MWVZTokSYmg=
|
||||
golang.org/x/net v0.28.0 h1:a9JDOJc5GMUJ0+UDqmLT86WiEy7iWyIhz8gz8E4e5hE=
|
||||
golang.org/x/net v0.28.0/go.mod h1:yqtgsTWOOnlGLG9GFRrK3++bGOUEkNBoHZc8MEDWPNg=
|
||||
golang.org/x/net v0.33.0 h1:74SYHlV8BIgHIFC/LrYkOGIwL19eTYXQ5wc6TBuO36I=
|
||||
golang.org/x/net v0.33.0/go.mod h1:HXLR5J+9DxmrqMwG9qjGCxZ+zKXxBru04zlTvWlWuN4=
|
||||
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.18.0 h1:DBdB3niSjOA/O0blCZBqDefyWNYveAYMNF1Wum0DYQ4=
|
||||
golang.org/x/sys v0.18.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
|
||||
golang.org/x/sys v0.24.0 h1:Twjiwq9dn6R1fQcyiK+wQyHWfaz/BJB+YIpzU/Cv3Xg=
|
||||
golang.org/x/sys v0.24.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
|
||||
golang.org/x/sys v0.28.0 h1:Fksou7UEQUWlKvIdsqzJmUmCX3cZuD2+P3XyyzwMhlA=
|
||||
golang.org/x/sys v0.28.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
|
||||
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||
golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ=
|
||||
golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=
|
||||
golang.org/x/text v0.17.0 h1:XtiM5bkSOt+ewxlOE/aE/AKEHibwj/6gvWMl9Rsh0Qc=
|
||||
golang.org/x/text v0.17.0/go.mod h1:BuEKDfySbSR4drPmRPG/7iBdf8hvFMuRexcpahXilzY=
|
||||
golang.org/x/time v0.5.0 h1:o7cqy6amK/52YcAKIPlM3a+Fpj35zvRj2TP+e1xFSfk=
|
||||
golang.org/x/time v0.5.0/go.mod h1:3BpzKBy/shNhVucY/MWOyx10tF3SFh9QdLuxbVysPQM=
|
||||
golang.org/x/text v0.21.0 h1:zyQAAkrwaneQ066sspRyJaG9VNi/YJ1NfzcGB3hZ/qo=
|
||||
golang.org/x/text v0.21.0/go.mod h1:4IBbMaMmOPCJ8SecivzSH54+73PCFmPWxNTLm+vZkEQ=
|
||||
golang.org/x/time v0.6.0 h1:eTDhh4ZXt5Qf0augr54TN6suAUudPcawVZeIAPU7D4U=
|
||||
golang.org/x/time v0.6.0/go.mod h1:3BpzKBy/shNhVucY/MWOyx10tF3SFh9QdLuxbVysPQM=
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
golang.org/x/time v0.8.0 h1:9i3RxcPv3PZnitoVGMPDKZSq1xW1gK1Xy3ArNOGZfEg=
|
||||
golang.org/x/time v0.8.0/go.mod h1:3BpzKBy/shNhVucY/MWOyx10tF3SFh9QdLuxbVysPQM=
|
||||
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
||||
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||
|
|
|
|||
487
main.go
487
main.go
|
|
@ -1,47 +1,17 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
"os"
|
||||
"os/exec"
|
||||
"runtime"
|
||||
"strconv"
|
||||
|
||||
"github.com/chasefleming/elem-go"
|
||||
"github.com/chasefleming/elem-go/attrs"
|
||||
"github.com/chasefleming/elem-go/htmx"
|
||||
"github.com/jung-kurt/gofpdf"
|
||||
"echoTest/controllers"
|
||||
"echoTest/models"
|
||||
"echoTest/utils"
|
||||
|
||||
"github.com/labstack/echo/v4"
|
||||
"github.com/labstack/echo/v4/middleware"
|
||||
)
|
||||
|
||||
type Bewertung struct {
|
||||
Vorname string
|
||||
Nachname string
|
||||
ID int
|
||||
HvPunkte float64
|
||||
HvProzent float64
|
||||
HvNote int
|
||||
LvPunkte float64
|
||||
LvProzent float64
|
||||
LvNote int
|
||||
GesamtProzent float64
|
||||
GesamtNote int
|
||||
Gewertet bool
|
||||
}
|
||||
|
||||
type MaxPunkte struct {
|
||||
HvMax float64
|
||||
LvMax float64
|
||||
HvGewichtung float64
|
||||
LvGewichtung float64
|
||||
}
|
||||
|
||||
var (
|
||||
bewertungen []Bewertung
|
||||
maxPunkte = MaxPunkte{
|
||||
bewertungen []models.Bewertung
|
||||
maxPunkte = models.MaxPunkte{
|
||||
HvMax: 0.00,
|
||||
HvGewichtung: 0.00,
|
||||
LvMax: 0.00,
|
||||
|
|
@ -51,452 +21,21 @@ var (
|
|||
|
||||
func main() {
|
||||
e := echo.New()
|
||||
|
||||
e.Use(middleware.Logger())
|
||||
e.Use(middleware.Recover())
|
||||
|
||||
e.GET("/", renderBewertungenRoute)
|
||||
e.POST("/toggle/:id", toggleWertungRoute)
|
||||
e.POST("/add", addBewertungRoute)
|
||||
e.GET("/export", exportBewertungenRoute)
|
||||
e.GET("/end", endRoute)
|
||||
controller := controllers.NewController(&bewertungen, &maxPunkte)
|
||||
|
||||
e.GET("/", controller.RenderBewertungenRoute)
|
||||
e.POST("/toggle/:id", controller.ToggleWertungRoute)
|
||||
e.POST("/add", controller.AddBewertungRoute)
|
||||
e.GET("/export", controller.ExportBewertungenRoute)
|
||||
e.GET("/end", controller.EndRoute)
|
||||
|
||||
go func() {
|
||||
e.Logger.Fatal(e.Start(":3000"))
|
||||
}()
|
||||
|
||||
openInBrowser("http://localhost:3000")
|
||||
|
||||
utils.OpenInBrowser("http://localhost:3000")
|
||||
select {}
|
||||
}
|
||||
|
||||
func renderBewertungenRoute(c echo.Context) error {
|
||||
return c.HTML(http.StatusOK, renderBewertungen(bewertungen))
|
||||
}
|
||||
|
||||
func toggleWertungRoute(c echo.Context) error {
|
||||
id, _ := strconv.Atoi(c.Param("id"))
|
||||
var updatedBewertung Bewertung
|
||||
for i, bewertung := range bewertungen {
|
||||
if bewertung.ID == id {
|
||||
bewertungen[i].Gewertet = !bewertung.Gewertet
|
||||
updatedBewertung = bewertungen[i]
|
||||
break
|
||||
}
|
||||
}
|
||||
return c.HTML(http.StatusOK, createBewertungNode(updatedBewertung).Render())
|
||||
}
|
||||
|
||||
func addBewertungRoute(c echo.Context) error {
|
||||
new := parseBewertungen(c)
|
||||
if new.Nachname != "" {
|
||||
bewertungen = append(bewertungen, new)
|
||||
}
|
||||
return c.Redirect(http.StatusSeeOther, "/")
|
||||
}
|
||||
|
||||
func parseBewertungen(c echo.Context) Bewertung {
|
||||
newName := validateName(c)
|
||||
vorname := c.FormValue("vorname")
|
||||
if maxPunkte.HvMax == 0.00 {
|
||||
hvMax, _ := strconv.ParseFloat(c.FormValue("hv_max"), 64)
|
||||
lvMax, _ := strconv.ParseFloat(c.FormValue("lv_max"), 64)
|
||||
hvGewichtung, _ := strconv.ParseFloat(c.FormValue("hv_gewichtung"), 64)
|
||||
lvGewichtung, _ := strconv.ParseFloat(c.FormValue("lv_gewichtung"), 64)
|
||||
maxPunkte.HvMax = hvMax
|
||||
maxPunkte.LvMax = lvMax
|
||||
maxPunkte.LvGewichtung = lvGewichtung
|
||||
maxPunkte.HvGewichtung = hvGewichtung
|
||||
}
|
||||
hvPunkte, _ := strconv.ParseFloat(c.FormValue("hv_punkte"), 64)
|
||||
lvPunkte, _ := strconv.ParseFloat(c.FormValue("lv_punkte"), 64)
|
||||
hvProzent := 100.00 / maxPunkte.HvMax * hvPunkte
|
||||
lvProzent := 100.00 / maxPunkte.LvMax * lvPunkte
|
||||
hvNote := setNote(hvProzent)
|
||||
lvNote := setNote(lvProzent)
|
||||
gesamtProzent := hvProzent*maxPunkte.HvGewichtung/100 + lvProzent*maxPunkte.LvGewichtung/100
|
||||
gesamtNote := setNote(gesamtProzent)
|
||||
|
||||
return Bewertung{
|
||||
ID: len(bewertungen) + 1,
|
||||
Vorname: string(vorname),
|
||||
Nachname: string(newName),
|
||||
HvPunkte: hvPunkte,
|
||||
HvProzent: hvProzent,
|
||||
HvNote: int(hvNote),
|
||||
LvPunkte: lvPunkte,
|
||||
LvProzent: lvProzent,
|
||||
LvNote: int(lvNote),
|
||||
GesamtProzent: gesamtProzent,
|
||||
GesamtNote: int(gesamtNote),
|
||||
Gewertet: true,
|
||||
}
|
||||
}
|
||||
|
||||
func updateGewertetRoute(bewertung Bewertung) elem.Node {
|
||||
checkbox := elem.Input(attrs.Props{
|
||||
attrs.Type: "checkbox",
|
||||
attrs.Checked: strconv.FormatBool(bewertung.Gewertet),
|
||||
htmx.HXPost: "/toggle/" + strconv.Itoa(bewertung.ID),
|
||||
htmx.HXTarget: "#bewertung-" + strconv.Itoa(bewertung.ID),
|
||||
})
|
||||
return checkbox
|
||||
}
|
||||
|
||||
func createBewertungNode(bewertung Bewertung) elem.Node {
|
||||
checkbox := elem.Input(attrs.Props{
|
||||
attrs.Type: "checkbox",
|
||||
attrs.Checked: strconv.FormatBool(bewertung.Gewertet),
|
||||
htmx.HXPost: "/toggle/" + strconv.Itoa(bewertung.ID),
|
||||
htmx.HXTarget: "#bewertung-" + strconv.Itoa(bewertung.ID),
|
||||
htmx.HXSwap: "outerHTML",
|
||||
})
|
||||
|
||||
return elem.Tr(attrs.Props{
|
||||
attrs.ID: "bewertung-" + strconv.Itoa(bewertung.ID),
|
||||
},
|
||||
elem.Td(nil, checkbox),
|
||||
elem.Td(nil, elem.Text(bewertung.Vorname)),
|
||||
elem.Td(nil, elem.Text(bewertung.Nachname)),
|
||||
elem.Td(nil, elem.Text(strconv.FormatFloat(bewertung.HvPunkte, 'f', 2, 64))),
|
||||
elem.Td(nil, elem.Text(strconv.FormatFloat(bewertung.HvProzent, 'f', 2, 64))),
|
||||
elem.Td(nil, elem.Text(strconv.Itoa(bewertung.HvNote))),
|
||||
elem.Td(nil, elem.Text(strconv.FormatFloat(bewertung.LvPunkte, 'f', 2, 64))),
|
||||
elem.Td(nil, elem.Text(strconv.FormatFloat(bewertung.LvProzent, 'f', 2, 64))),
|
||||
elem.Td(nil, elem.Text(strconv.Itoa(bewertung.LvNote))),
|
||||
elem.Td(nil, elem.Text(strconv.FormatFloat(bewertung.GesamtProzent, 'f', 2, 64))),
|
||||
elem.Td(nil, elem.Text(strconv.Itoa(bewertung.GesamtNote))),
|
||||
)
|
||||
}
|
||||
|
||||
func renderBewertungen(bewertungen []Bewertung) string {
|
||||
inputPunkte := elem.Div(nil)
|
||||
if maxPunkte.HvGewichtung == 0.00 {
|
||||
inputPunkte = elem.Div(attrs.Props{attrs.Class: "tile is-ancestor"},
|
||||
elem.Div(attrs.Props{attrs.Class: "tile field is-parent"},
|
||||
elem.Input(attrs.Props{
|
||||
attrs.Class: "input is-child",
|
||||
attrs.Type: "text",
|
||||
attrs.Name: "hv_max",
|
||||
attrs.Placeholder: "HV-Max-Punkte",
|
||||
},
|
||||
),
|
||||
),
|
||||
elem.Div(attrs.Props{attrs.Class: "tile field is-parent"},
|
||||
elem.Input(attrs.Props{
|
||||
attrs.Class: "input is-child",
|
||||
attrs.Type: "text",
|
||||
attrs.Name: "hv_gewichtung",
|
||||
attrs.Placeholder: "HV-Gewichtung in %",
|
||||
},
|
||||
),
|
||||
),
|
||||
elem.Div(attrs.Props{attrs.Class: "tile field is-parent"},
|
||||
elem.Input(attrs.Props{
|
||||
attrs.Class: "input is-child",
|
||||
attrs.Type: "text",
|
||||
attrs.Name: "lv_max",
|
||||
attrs.Placeholder: "LV-Max-Punkte",
|
||||
},
|
||||
),
|
||||
),
|
||||
elem.Div(attrs.Props{attrs.Class: "tile field is-parent"},
|
||||
elem.Input(attrs.Props{
|
||||
attrs.Class: "input is-child",
|
||||
attrs.Type: "text",
|
||||
attrs.Name: "lv_gewichtung",
|
||||
attrs.Placeholder: "LV-Gewichtung in %",
|
||||
},
|
||||
),
|
||||
),
|
||||
)
|
||||
} else {
|
||||
inputPunkte = elem.Div(attrs.Props{attrs.Class: "tile is-ancestor"},
|
||||
elem.Div(attrs.Props{attrs.Class: "tile field is-parent"},
|
||||
elem.Input(attrs.Props{
|
||||
attrs.Class: "input is-child",
|
||||
attrs.Type: "text",
|
||||
attrs.Name: "hv_max",
|
||||
attrs.Placeholder: "HV-Max-Punkte",
|
||||
attrs.Value: fmt.Sprintf("%.2f", maxPunkte.HvMax),
|
||||
},
|
||||
),
|
||||
),
|
||||
elem.Div(attrs.Props{attrs.Class: "tile field is-parent"},
|
||||
elem.Input(attrs.Props{
|
||||
attrs.Class: "input is-child",
|
||||
attrs.Type: "text",
|
||||
attrs.Name: "hv_gewichtung",
|
||||
attrs.Placeholder: "HV-Gewichtung in %",
|
||||
attrs.Value: fmt.Sprintf("%.2f", maxPunkte.HvGewichtung),
|
||||
},
|
||||
),
|
||||
),
|
||||
elem.Div(attrs.Props{attrs.Class: "tile field is-parent"},
|
||||
elem.Input(attrs.Props{
|
||||
attrs.Class: "input is-child",
|
||||
attrs.Type: "text",
|
||||
attrs.Name: "lv_max",
|
||||
attrs.Placeholder: "LV-Max-Punkte",
|
||||
attrs.Value: fmt.Sprintf("%.2f", maxPunkte.LvMax),
|
||||
},
|
||||
),
|
||||
),
|
||||
elem.Div(attrs.Props{attrs.Class: "tile field is-parent"},
|
||||
elem.Input(attrs.Props{
|
||||
attrs.Class: "input is-child",
|
||||
attrs.Type: "text",
|
||||
attrs.Name: "lv_gewichtung",
|
||||
attrs.Placeholder: "LV-Gewichtung in %",
|
||||
attrs.Value: fmt.Sprintf("%.2f", maxPunkte.LvGewichtung),
|
||||
},
|
||||
),
|
||||
),
|
||||
)
|
||||
}
|
||||
|
||||
headContent := elem.Head(nil,
|
||||
elem.Meta(attrs.Props{attrs.Charset: "UTF-8", attrs.Name: "viewport", attrs.Content: "width=device-width, initial-scale=1.0"}),
|
||||
elem.Script(attrs.Props{attrs.Src: "https://unpkg.com/htmx.org"}),
|
||||
elem.Link(attrs.Props{attrs.Rel: "stylesheet", attrs.Href: "https://cdn.jsdelivr.net/npm/bulma@0.9.4/css/bulma.min.css"}),
|
||||
)
|
||||
|
||||
headerContent := elem.Header(attrs.Props{
|
||||
attrs.Class: "navbar",
|
||||
attrs.Role: "navigation",
|
||||
attrs.AriaLabel: "main navigation",
|
||||
},
|
||||
elem.Div(attrs.Props{
|
||||
attrs.ID: "navbarBasicExample",
|
||||
attrs.Class: "navbar-menu",
|
||||
},
|
||||
elem.Div(attrs.Props{
|
||||
attrs.Class: "navbar-start",
|
||||
},
|
||||
elem.A(attrs.Props{
|
||||
attrs.Class: "navbar-item",
|
||||
}, elem.Text("Home"),
|
||||
),
|
||||
),
|
||||
elem.Div(attrs.Props{
|
||||
attrs.Class: "navbar-end",
|
||||
},
|
||||
elem.Span(attrs.Props{
|
||||
attrs.Class: "navbar-item",
|
||||
},
|
||||
elem.Button(attrs.Props{
|
||||
attrs.Class: "button is-primary",
|
||||
htmx.HXTrigger: "click",
|
||||
htmx.HXGet: "/end",
|
||||
}, elem.Text("Beenden"),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
)
|
||||
|
||||
bodyContent := elem.Div(attrs.Props{attrs.Class: "container is-widescreen"},
|
||||
elem.Div(attrs.Props{attrs.Class: "card tile is-vertical is-ancestor"},
|
||||
elem.Header(attrs.Props{attrs.Class: "card-header"},
|
||||
elem.P(attrs.Props{attrs.Class: "card-header-title"}, elem.Text("Englischarbeit"))),
|
||||
elem.Div(attrs.Props{attrs.Class: "card-content"},
|
||||
elem.Div(attrs.Props{attrs.Class: "content tile is-parent is-vertical gap"},
|
||||
elem.H1(attrs.Props{attrs.Class: "tilte"}, elem.Text("Bewertungen")),
|
||||
elem.Form(attrs.Props{attrs.Method: "post", attrs.Action: "/add"}, inputPunkte,
|
||||
elem.Div(attrs.Props{attrs.Class: "tile is-ancestor"},
|
||||
elem.Div(attrs.Props{attrs.Class: "tile field is-parent"},
|
||||
elem.Input(attrs.Props{
|
||||
attrs.Type: "text",
|
||||
attrs.Name: "vorname",
|
||||
attrs.Class: "input is-child",
|
||||
attrs.Placeholder: "Vorname",
|
||||
},
|
||||
),
|
||||
),
|
||||
elem.Div(attrs.Props{attrs.Class: "tile field is-parent"},
|
||||
elem.Input(attrs.Props{
|
||||
attrs.Type: "text",
|
||||
attrs.Name: "nachname",
|
||||
attrs.Class: "input is-child",
|
||||
attrs.Placeholder: "Nachname",
|
||||
},
|
||||
),
|
||||
),
|
||||
elem.Div(attrs.Props{attrs.Class: "tile field is-parent"},
|
||||
elem.Input(attrs.Props{
|
||||
attrs.Type: "text",
|
||||
attrs.Name: "hv_punkte",
|
||||
attrs.Class: "input is-child",
|
||||
attrs.Placeholder: "HV-Punkte",
|
||||
},
|
||||
),
|
||||
),
|
||||
elem.Div(attrs.Props{attrs.Class: "tile field is-parent"},
|
||||
elem.Input(attrs.Props{
|
||||
attrs.Type: "text",
|
||||
attrs.Name: "lv_punkte",
|
||||
attrs.Class: "input is-child",
|
||||
attrs.Placeholder: "LV-Punkte",
|
||||
},
|
||||
),
|
||||
),
|
||||
elem.Div(attrs.Props{attrs.Class: "tile field is-parent"},
|
||||
elem.Button(
|
||||
attrs.Props{
|
||||
attrs.Type: "submit",
|
||||
attrs.Class: "button tile is-child",
|
||||
},
|
||||
elem.Text("Add"),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
elem.Div(attrs.Props{attrs.Class: "table-container"},
|
||||
elem.Table(attrs.Props{attrs.Class: "table is-hoverable"},
|
||||
elem.THead(nil,
|
||||
elem.Tr(nil,
|
||||
elem.Th(nil, elem.Text("Gewertet")),
|
||||
elem.Th(nil, elem.Text("Vorname")),
|
||||
elem.Th(nil, elem.Text("Nachname")),
|
||||
elem.Th(nil, elem.Text("HV-Punkte")),
|
||||
elem.Th(nil, elem.Text("HV-Prozent")),
|
||||
elem.Th(nil, elem.Text("HV-Note")),
|
||||
elem.Th(nil, elem.Text("LV-Punkte")),
|
||||
elem.Th(nil, elem.Text("LV-Prozent")),
|
||||
elem.Th(nil, elem.Text("LV-Note")),
|
||||
elem.Th(nil, elem.Text("Gesamt-Prozent")),
|
||||
elem.Th(nil, elem.Text("Gesamt-Note")),
|
||||
),
|
||||
),
|
||||
elem.TBody(nil,
|
||||
elem.TransformEach(bewertungen, createBewertungNode)...),
|
||||
),
|
||||
),
|
||||
elem.Div(nil,
|
||||
elem.Button(attrs.Props{
|
||||
htmx.HXTrigger: "click",
|
||||
htmx.HXGet: "/export",
|
||||
attrs.Class: "button",
|
||||
},
|
||||
elem.Text("export"),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
)
|
||||
footerContent := elem.Footer(attrs.Props{
|
||||
attrs.Class: "footer",
|
||||
},
|
||||
elem.Div(attrs.Props{
|
||||
attrs.Class: "content has-text-centered",
|
||||
},
|
||||
elem.P(nil, elem.Text("© 2023 Alle Rechte vorbehalten.")),
|
||||
),
|
||||
)
|
||||
|
||||
tbodyContent := elem.TBody(nil)
|
||||
htmlContent := elem.Html(nil, elem.Raw("<!DOCTYPE html>"), headContent, headerContent, bodyContent, tbodyContent, footerContent)
|
||||
|
||||
return htmlContent.Render()
|
||||
}
|
||||
|
||||
func setNote(prozent float64) float64 {
|
||||
switch {
|
||||
case prozent <= 22:
|
||||
return 6.00
|
||||
case prozent <= 49:
|
||||
return 5.00
|
||||
case prozent <= 64:
|
||||
return 4.00
|
||||
case prozent <= 79:
|
||||
return 3.00
|
||||
case prozent <= 94:
|
||||
return 2.00
|
||||
default:
|
||||
return 1.00
|
||||
}
|
||||
}
|
||||
|
||||
func checkGewichtung(lv, hv float64) bool {
|
||||
if hv/100+lv/100 > 1 {
|
||||
return false
|
||||
} else if hv/100+lv/100 < 1 {
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
// Die Funktion zum Öffnen des Standardbrowsers
|
||||
func openInBrowser(url string) {
|
||||
var cmd *exec.Cmd
|
||||
|
||||
switch os := runtime.GOOS; os {
|
||||
case "darwin":
|
||||
// macOS
|
||||
cmd = exec.Command("open", url)
|
||||
case "windows":
|
||||
// Windows
|
||||
cmd = exec.Command("cmd", "/c", "start", url)
|
||||
default:
|
||||
// Linux und andere
|
||||
cmd = exec.Command("xdg-open", url)
|
||||
}
|
||||
|
||||
err := cmd.Start()
|
||||
if err != nil {
|
||||
fmt.Println("Fehler beim Öffnen des Browsers:", err)
|
||||
}
|
||||
}
|
||||
|
||||
func validateName(c echo.Context) string {
|
||||
newNachname := c.FormValue("nachname")
|
||||
newVorname := c.FormValue("vorname")
|
||||
for _, bewertung := range bewertungen {
|
||||
fmt.Printf("Name: %v", bewertung.Nachname)
|
||||
if bewertung.Nachname == newNachname && bewertung.Vorname == newVorname {
|
||||
return ""
|
||||
}
|
||||
}
|
||||
return newNachname
|
||||
}
|
||||
|
||||
func exportBewertungenRoute(c echo.Context) error {
|
||||
pdf := gofpdf.New("P", "mm", "A4", "")
|
||||
pdf.AddPage()
|
||||
|
||||
pdf.SetFont("Arial", "B", 12)
|
||||
pdf.CellFormat(27, 10, "Vorname", "1", 0, "", false, 0, "")
|
||||
pdf.CellFormat(27, 10, "Nachname", "1", 0, "", false, 0, "")
|
||||
pdf.CellFormat(27, 10, "HV-Punkte", "1", 0, "", false, 0, "")
|
||||
pdf.CellFormat(27, 10, "HV-Note", "1", 0, "", false, 0, "")
|
||||
pdf.CellFormat(27, 10, "LV-Punkte", "1", 0, "", false, 0, "")
|
||||
pdf.CellFormat(27, 10, "LV-Note", "1", 0, "", false, 0, "")
|
||||
pdf.CellFormat(27, 10, "Gesamtnote", "1", 0, "", false, 0, "")
|
||||
pdf.Ln(-1)
|
||||
|
||||
pdf.SetFont("Arial", "", 11)
|
||||
for _, bewertung := range bewertungen {
|
||||
pdf.CellFormat(27, 10, bewertung.Vorname, "1", 0, "", false, 0, "")
|
||||
pdf.CellFormat(27, 10, bewertung.Nachname, "1", 0, "", false, 0, "")
|
||||
pdf.CellFormat(27, 10, strconv.FormatFloat(bewertung.HvPunkte, 'f', 2, 64), "1", 0, "", false, 0, "")
|
||||
pdf.CellFormat(27, 10, strconv.FormatInt(int64(bewertung.HvNote), 10), "1", 0, "", false, 0, "")
|
||||
pdf.CellFormat(27, 10, strconv.FormatFloat(bewertung.LvPunkte, 'f', 2, 64), "1", 0, "", false, 0, "")
|
||||
pdf.CellFormat(27, 10, strconv.FormatInt(int64(bewertung.LvNote), 10), "1", 0, "", false, 0, "")
|
||||
pdf.CellFormat(27, 10, strconv.FormatInt(int64(bewertung.GesamtNote), 10), "1", 0, "", false, 0, "")
|
||||
pdf.Ln(-1)
|
||||
}
|
||||
|
||||
err := pdf.OutputFileAndClose("bewertungen.pdf")
|
||||
if err != nil {
|
||||
fmt.Println("Fehler beim Exportieren der Bewertungen:", err)
|
||||
return err
|
||||
}
|
||||
|
||||
return c.HTML(http.StatusOK, "Export beendet")
|
||||
}
|
||||
|
||||
func endRoute(c echo.Context) error {
|
||||
os.Exit(0)
|
||||
return c.HTML(http.StatusOK, "Tschüss")
|
||||
}
|
||||
|
|
|
|||
34
main_test.go
34
main_test.go
|
|
@ -1,34 +0,0 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"testing"
|
||||
|
||||
"github.com/labstack/echo/v4"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestRenderBewertungenRoute(t *testing.T) {
|
||||
e := echo.New()
|
||||
req := httptest.NewRequest(http.MethodGet, "/", nil)
|
||||
rec := httptest.NewRecorder()
|
||||
c := e.NewContext(req, rec)
|
||||
|
||||
err := renderBewertungenRoute(c)
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, http.StatusOK, rec.Code)
|
||||
}
|
||||
|
||||
func TestToggleWertungRoute(t *testing.T) {
|
||||
e := echo.New()
|
||||
req := httptest.NewRequest(http.MethodPost, "/toggle/1", nil)
|
||||
rec := httptest.NewRecorder()
|
||||
c := e.NewContext(req, rec)
|
||||
c.SetParamNames("id")
|
||||
c.SetParamValues("1")
|
||||
|
||||
err := toggleWertungRoute(c)
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, http.StatusOK, rec.Code)
|
||||
}
|
||||
|
|
@ -1,6 +1,5 @@
|
|||
package model
|
||||
package models
|
||||
|
||||
// Todo model
|
||||
type Bewertung struct {
|
||||
Vorname string
|
||||
Nachname string
|
||||
|
|
@ -15,10 +14,3 @@ type Bewertung struct {
|
|||
GesamtNote int
|
||||
Gewertet bool
|
||||
}
|
||||
|
||||
type MaxPunkte struct {
|
||||
HvMax float64
|
||||
LvMax float64
|
||||
HvGewichtung float64
|
||||
LvGewichtung float64
|
||||
}
|
||||
8
models/maxpunkte.go
Normal file
8
models/maxpunkte.go
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
package models
|
||||
|
||||
type MaxPunkte struct {
|
||||
HvMax float64
|
||||
LvMax float64
|
||||
HvGewichtung float64
|
||||
LvGewichtung float64
|
||||
}
|
||||
147
templates/templates.templ
Normal file
147
templates/templates.templ
Normal file
|
|
@ -0,0 +1,147 @@
|
|||
package templates
|
||||
|
||||
import (
|
||||
"strconv"
|
||||
"fmt"
|
||||
"echoTest/models"
|
||||
)
|
||||
|
||||
templ layout(title string) {
|
||||
<!DOCTYPE html>
|
||||
<html data-theme="light">
|
||||
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<title>{title}</title>
|
||||
<script src="https://unpkg.com/htmx.org@1.9.6"></script>
|
||||
<link href="https://cdn.jsdelivr.net/npm/daisyui@4.12.14/dist/full.css" rel="stylesheet" type="text/css" />
|
||||
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@catppuccin/daisyui@1.2.1/dist/catppuccin.css" />
|
||||
<script src="https://cdn.tailwindcss.com"></script>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<div data-theme="macchiato">
|
||||
<div class="navbar bg-base-100">
|
||||
<div class="flex-1">
|
||||
<a class="btn btn-ghost normal-case text-xl">Home</a>
|
||||
</div>
|
||||
<div class="flex-none">
|
||||
<button class="btn btn-primary" hx-get="/end">Beenden</button>
|
||||
</div>
|
||||
</div>
|
||||
<div class="container mx-auto p-4">
|
||||
{children...}
|
||||
</div>
|
||||
<footer class="footer footer-center p-4 bg-base-300 text-base-content">
|
||||
<div>
|
||||
<p>© 2023 Alle Rechte vorbehalten.</p>
|
||||
</div>
|
||||
</footer>
|
||||
</div>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
}
|
||||
|
||||
templ BewertungenForm(maxPunkte models.MaxPunkte) {
|
||||
<form method="post" action="/add" class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-4 gap-4 mb-4">
|
||||
<div class="form-control">
|
||||
<label for="hv_max" class="label">HV Punkte</label>
|
||||
<input id="hv_max" class="input input-bordered" type="text" name="hv_max" value={fmt.Sprintf("%.2f",
|
||||
maxPunkte.HvMax)} />
|
||||
</div>
|
||||
<div class="form-control">
|
||||
<label for="hv_gewichtung" class="label">HV Gewichtung in %</label>
|
||||
<input id="hv_gewichtung" class="input input-bordered" type="text" name="hv_gewichtung" value={fmt.Sprintf("%.2f",
|
||||
maxPunkte.HvGewichtung)} />
|
||||
</div>
|
||||
<div class="form-control">
|
||||
<label for="lv_max" class="label">LV Punkte</label>
|
||||
<input id="lv_max" class="input input-bordered" type="text" name="lv_max" value={fmt.Sprintf("%.2f",
|
||||
maxPunkte.LvMax)} />
|
||||
</div>
|
||||
<div class="form-control">
|
||||
<label for="lv_gewichtung" class="label">LV Gewichtung in %</label>
|
||||
<input id="lv_gewichtung" class="input input-bordered" type="text" name="lv_gewichtung" value={fmt.Sprintf("%.2f",
|
||||
maxPunkte.LvGewichtung)} />
|
||||
</div>
|
||||
<div class="form-control">
|
||||
<input type="text" name="vorname" class="input input-bordered" placeholder="Vorname" />
|
||||
</div>
|
||||
<div class="form-control">
|
||||
<input type="text" name="nachname" class="input input-bordered" placeholder="Nachname" />
|
||||
</div>
|
||||
<div class="form-control">
|
||||
<input type="text" name="hv_punkte" class="input input-bordered" placeholder="HV-Punkte" />
|
||||
</div>
|
||||
<div class="form-control">
|
||||
<input type="text" name="lv_punkte" class="input input-bordered" placeholder="LV-Punkte" />
|
||||
</div>
|
||||
<div class="form-control">
|
||||
<button type="submit" class="btn btn-primary">Add</button>
|
||||
</div>
|
||||
</form>
|
||||
}
|
||||
|
||||
templ BewertungenTable(bewertungen []models.Bewertung) {
|
||||
<div class="overflow-x-auto">
|
||||
<table class="table table-zebra">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Gewertet</th>
|
||||
<th>Vorname</th>
|
||||
<th>Nachname</th>
|
||||
<th>HV-Punkte</th>
|
||||
<th>HV-Prozent</th>
|
||||
<th>HV-Note</th>
|
||||
<th>LV-Punkte</th>
|
||||
<th>LV-Prozent</th>
|
||||
<th>LV-Note</th>
|
||||
<th>Gesamt-Prozent</th>
|
||||
<th>Gesamt-Note</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
for _, b := range bewertungen {
|
||||
@BewertungRow(b)
|
||||
}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
}
|
||||
|
||||
templ BewertungRow(b models.Bewertung) {
|
||||
<tr id={"bewertung-" + strconv.Itoa(b.ID)}>
|
||||
<td>
|
||||
<input type="checkbox" class="toggle" checked?={b.Gewertet} hx-post={"/toggle/" + strconv.Itoa(b.ID)}
|
||||
hx-target={"#bewertung-" + strconv.Itoa(b.ID)} hx-swap="outerHTML" />
|
||||
</td>
|
||||
<td>{b.Vorname}</td>
|
||||
<td>{b.Nachname}</td>
|
||||
<td>{fmt.Sprintf("%.2f", b.HvPunkte)}</td>
|
||||
<td>{fmt.Sprintf("%.2f", b.HvProzent)}</td>
|
||||
<td>{strconv.Itoa(b.HvNote)}</td>
|
||||
<td>{fmt.Sprintf("%.2f", b.LvPunkte)}</td>
|
||||
<td>{fmt.Sprintf("%.2f", b.LvProzent)}</td>
|
||||
<td>{strconv.Itoa(b.LvNote)}</td>
|
||||
<td>{fmt.Sprintf("%.2f", b.GesamtProzent)}</td>
|
||||
<td>{strconv.Itoa(b.GesamtNote)}</td>
|
||||
</tr>
|
||||
}
|
||||
|
||||
templ BewertungenPage(bewertungen []models.Bewertung, maxPunkte models.MaxPunkte) {
|
||||
@layout("Englischarbeit") {
|
||||
<div class="card bg-base-100 shadow-xl">
|
||||
<div class="card-body">
|
||||
<h2 class="card-title">Englischarbeit</h2>
|
||||
<h3 class="text-lg font-bold">Bewertungen</h3>
|
||||
@BewertungenForm(maxPunkte)
|
||||
@BewertungenTable(bewertungen)
|
||||
<div class="card-actions justify-end">
|
||||
<button hx-get="/export" class="btn btn-primary">Export</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
}
|
||||
458
templates/templates_templ.go
Normal file
458
templates/templates_templ.go
Normal file
|
|
@ -0,0 +1,458 @@
|
|||
// Code generated by templ - DO NOT EDIT.
|
||||
|
||||
// templ: version: v0.2.793
|
||||
package templates
|
||||
|
||||
//lint:file-ignore SA4006 This context is only used if a nested component is present.
|
||||
|
||||
import "github.com/a-h/templ"
|
||||
import templruntime "github.com/a-h/templ/runtime"
|
||||
|
||||
import (
|
||||
"echoTest/models"
|
||||
"fmt"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
func layout(title string) templ.Component {
|
||||
return templruntime.GeneratedTemplate(func(templ_7745c5c3_Input templruntime.GeneratedComponentInput) (templ_7745c5c3_Err error) {
|
||||
templ_7745c5c3_W, ctx := templ_7745c5c3_Input.Writer, templ_7745c5c3_Input.Context
|
||||
if templ_7745c5c3_CtxErr := ctx.Err(); templ_7745c5c3_CtxErr != nil {
|
||||
return templ_7745c5c3_CtxErr
|
||||
}
|
||||
templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templruntime.GetBuffer(templ_7745c5c3_W)
|
||||
if !templ_7745c5c3_IsBuffer {
|
||||
defer func() {
|
||||
templ_7745c5c3_BufErr := templruntime.ReleaseBuffer(templ_7745c5c3_Buffer)
|
||||
if templ_7745c5c3_Err == nil {
|
||||
templ_7745c5c3_Err = templ_7745c5c3_BufErr
|
||||
}
|
||||
}()
|
||||
}
|
||||
ctx = templ.InitializeContext(ctx)
|
||||
templ_7745c5c3_Var1 := templ.GetChildren(ctx)
|
||||
if templ_7745c5c3_Var1 == nil {
|
||||
templ_7745c5c3_Var1 = templ.NopComponent
|
||||
}
|
||||
ctx = templ.ClearChildren(ctx)
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("<!doctype html><html data-theme=\"light\"><head><meta charset=\"UTF-8\"><meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\"><title>")
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
var templ_7745c5c3_Var2 string
|
||||
templ_7745c5c3_Var2, templ_7745c5c3_Err = templ.JoinStringErrs(title)
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `templates/templates.templ`, Line: 16, Col: 15}
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var2))
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("</title><script src=\"https://unpkg.com/htmx.org@1.9.6\"></script><link href=\"https://cdn.jsdelivr.net/npm/daisyui@4.12.14/dist/full.css\" rel=\"stylesheet\" type=\"text/css\"><link rel=\"stylesheet\" href=\"https://cdn.jsdelivr.net/npm/@catppuccin/daisyui@1.2.1/dist/catppuccin.css\"><script src=\"https://cdn.tailwindcss.com\"></script></head><body><div data-theme=\"macchiato\"><div class=\"navbar bg-base-100\"><div class=\"flex-1\"><a class=\"btn btn-ghost normal-case text-xl\">Home</a></div><div class=\"flex-none\"><button class=\"btn btn-primary\" hx-get=\"/end\">Beenden</button></div></div><div class=\"container mx-auto p-4\">")
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
templ_7745c5c3_Err = templ_7745c5c3_Var1.Render(ctx, templ_7745c5c3_Buffer)
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("</div><footer class=\"footer footer-center p-4 bg-base-300 text-base-content\"><div><p>© 2023 Alle Rechte vorbehalten.</p></div></footer></div></body></html>")
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
return templ_7745c5c3_Err
|
||||
})
|
||||
}
|
||||
|
||||
func BewertungenForm(maxPunkte models.MaxPunkte) templ.Component {
|
||||
return templruntime.GeneratedTemplate(func(templ_7745c5c3_Input templruntime.GeneratedComponentInput) (templ_7745c5c3_Err error) {
|
||||
templ_7745c5c3_W, ctx := templ_7745c5c3_Input.Writer, templ_7745c5c3_Input.Context
|
||||
if templ_7745c5c3_CtxErr := ctx.Err(); templ_7745c5c3_CtxErr != nil {
|
||||
return templ_7745c5c3_CtxErr
|
||||
}
|
||||
templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templruntime.GetBuffer(templ_7745c5c3_W)
|
||||
if !templ_7745c5c3_IsBuffer {
|
||||
defer func() {
|
||||
templ_7745c5c3_BufErr := templruntime.ReleaseBuffer(templ_7745c5c3_Buffer)
|
||||
if templ_7745c5c3_Err == nil {
|
||||
templ_7745c5c3_Err = templ_7745c5c3_BufErr
|
||||
}
|
||||
}()
|
||||
}
|
||||
ctx = templ.InitializeContext(ctx)
|
||||
templ_7745c5c3_Var3 := templ.GetChildren(ctx)
|
||||
if templ_7745c5c3_Var3 == nil {
|
||||
templ_7745c5c3_Var3 = templ.NopComponent
|
||||
}
|
||||
ctx = templ.ClearChildren(ctx)
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("<form method=\"post\" action=\"/add\" class=\"grid grid-cols-1 md:grid-cols-2 lg:grid-cols-4 gap-4 mb-4\"><div class=\"form-control\"><label for=\"hv_max\" class=\"label\">HV Punkte</label> <input id=\"hv_max\" class=\"input input-bordered\" type=\"text\" name=\"hv_max\" value=\"")
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
var templ_7745c5c3_Var4 string
|
||||
templ_7745c5c3_Var4, templ_7745c5c3_Err = templ.JoinStringErrs(fmt.Sprintf("%.2f",
|
||||
maxPunkte.HvMax))
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `templates/templates.templ`, Line: 52, Col: 22}
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var4))
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("\"></div><div class=\"form-control\"><label for=\"hv_gewichtung\" class=\"label\">HV Gewichtung in %</label> <input id=\"hv_gewichtung\" class=\"input input-bordered\" type=\"text\" name=\"hv_gewichtung\" value=\"")
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
var templ_7745c5c3_Var5 string
|
||||
templ_7745c5c3_Var5, templ_7745c5c3_Err = templ.JoinStringErrs(fmt.Sprintf("%.2f",
|
||||
maxPunkte.HvGewichtung))
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `templates/templates.templ`, Line: 57, Col: 29}
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var5))
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("\"></div><div class=\"form-control\"><label for=\"lv_max\" class=\"label\">LV Punkte</label> <input id=\"lv_max\" class=\"input input-bordered\" type=\"text\" name=\"lv_max\" value=\"")
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
var templ_7745c5c3_Var6 string
|
||||
templ_7745c5c3_Var6, templ_7745c5c3_Err = templ.JoinStringErrs(fmt.Sprintf("%.2f",
|
||||
maxPunkte.LvMax))
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `templates/templates.templ`, Line: 62, Col: 22}
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var6))
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("\"></div><div class=\"form-control\"><label for=\"lv_gewichtung\" class=\"label\">LV Gewichtung in %</label> <input id=\"lv_gewichtung\" class=\"input input-bordered\" type=\"text\" name=\"lv_gewichtung\" value=\"")
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
var templ_7745c5c3_Var7 string
|
||||
templ_7745c5c3_Var7, templ_7745c5c3_Err = templ.JoinStringErrs(fmt.Sprintf("%.2f",
|
||||
maxPunkte.LvGewichtung))
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `templates/templates.templ`, Line: 67, Col: 29}
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var7))
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("\"></div><div class=\"form-control\"><input type=\"text\" name=\"vorname\" class=\"input input-bordered\" placeholder=\"Vorname\"></div><div class=\"form-control\"><input type=\"text\" name=\"nachname\" class=\"input input-bordered\" placeholder=\"Nachname\"></div><div class=\"form-control\"><input type=\"text\" name=\"hv_punkte\" class=\"input input-bordered\" placeholder=\"HV-Punkte\"></div><div class=\"form-control\"><input type=\"text\" name=\"lv_punkte\" class=\"input input-bordered\" placeholder=\"LV-Punkte\"></div><div class=\"form-control\"><button type=\"submit\" class=\"btn btn-primary\">Add</button></div></form>")
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
return templ_7745c5c3_Err
|
||||
})
|
||||
}
|
||||
|
||||
func BewertungenTable(bewertungen []models.Bewertung) templ.Component {
|
||||
return templruntime.GeneratedTemplate(func(templ_7745c5c3_Input templruntime.GeneratedComponentInput) (templ_7745c5c3_Err error) {
|
||||
templ_7745c5c3_W, ctx := templ_7745c5c3_Input.Writer, templ_7745c5c3_Input.Context
|
||||
if templ_7745c5c3_CtxErr := ctx.Err(); templ_7745c5c3_CtxErr != nil {
|
||||
return templ_7745c5c3_CtxErr
|
||||
}
|
||||
templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templruntime.GetBuffer(templ_7745c5c3_W)
|
||||
if !templ_7745c5c3_IsBuffer {
|
||||
defer func() {
|
||||
templ_7745c5c3_BufErr := templruntime.ReleaseBuffer(templ_7745c5c3_Buffer)
|
||||
if templ_7745c5c3_Err == nil {
|
||||
templ_7745c5c3_Err = templ_7745c5c3_BufErr
|
||||
}
|
||||
}()
|
||||
}
|
||||
ctx = templ.InitializeContext(ctx)
|
||||
templ_7745c5c3_Var8 := templ.GetChildren(ctx)
|
||||
if templ_7745c5c3_Var8 == nil {
|
||||
templ_7745c5c3_Var8 = templ.NopComponent
|
||||
}
|
||||
ctx = templ.ClearChildren(ctx)
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("<div class=\"overflow-x-auto\"><table class=\"table table-zebra\"><thead><tr><th>Gewertet</th><th>Vorname</th><th>Nachname</th><th>HV-Punkte</th><th>HV-Prozent</th><th>HV-Note</th><th>LV-Punkte</th><th>LV-Prozent</th><th>LV-Note</th><th>Gesamt-Prozent</th><th>Gesamt-Note</th></tr></thead> <tbody>")
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
for _, b := range bewertungen {
|
||||
templ_7745c5c3_Err = BewertungRow(b).Render(ctx, templ_7745c5c3_Buffer)
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("</tbody></table></div>")
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
return templ_7745c5c3_Err
|
||||
})
|
||||
}
|
||||
|
||||
func BewertungRow(b models.Bewertung) templ.Component {
|
||||
return templruntime.GeneratedTemplate(func(templ_7745c5c3_Input templruntime.GeneratedComponentInput) (templ_7745c5c3_Err error) {
|
||||
templ_7745c5c3_W, ctx := templ_7745c5c3_Input.Writer, templ_7745c5c3_Input.Context
|
||||
if templ_7745c5c3_CtxErr := ctx.Err(); templ_7745c5c3_CtxErr != nil {
|
||||
return templ_7745c5c3_CtxErr
|
||||
}
|
||||
templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templruntime.GetBuffer(templ_7745c5c3_W)
|
||||
if !templ_7745c5c3_IsBuffer {
|
||||
defer func() {
|
||||
templ_7745c5c3_BufErr := templruntime.ReleaseBuffer(templ_7745c5c3_Buffer)
|
||||
if templ_7745c5c3_Err == nil {
|
||||
templ_7745c5c3_Err = templ_7745c5c3_BufErr
|
||||
}
|
||||
}()
|
||||
}
|
||||
ctx = templ.InitializeContext(ctx)
|
||||
templ_7745c5c3_Var9 := templ.GetChildren(ctx)
|
||||
if templ_7745c5c3_Var9 == nil {
|
||||
templ_7745c5c3_Var9 = templ.NopComponent
|
||||
}
|
||||
ctx = templ.ClearChildren(ctx)
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("<tr id=\"")
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
var templ_7745c5c3_Var10 string
|
||||
templ_7745c5c3_Var10, templ_7745c5c3_Err = templ.JoinStringErrs("bewertung-" + strconv.Itoa(b.ID))
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `templates/templates.templ`, Line: 115, Col: 41}
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var10))
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("\"><td><input type=\"checkbox\" class=\"toggle\"")
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
if b.Gewertet {
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(" checked")
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(" hx-post=\"")
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
var templ_7745c5c3_Var11 string
|
||||
templ_7745c5c3_Var11, templ_7745c5c3_Err = templ.JoinStringErrs("/toggle/" + strconv.Itoa(b.ID))
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `templates/templates.templ`, Line: 117, Col: 104}
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var11))
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("\" hx-target=\"")
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
var templ_7745c5c3_Var12 string
|
||||
templ_7745c5c3_Var12, templ_7745c5c3_Err = templ.JoinStringErrs("#bewertung-" + strconv.Itoa(b.ID))
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `templates/templates.templ`, Line: 118, Col: 51}
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var12))
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("\" hx-swap=\"outerHTML\"></td><td>")
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
var templ_7745c5c3_Var13 string
|
||||
templ_7745c5c3_Var13, templ_7745c5c3_Err = templ.JoinStringErrs(b.Vorname)
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `templates/templates.templ`, Line: 120, Col: 16}
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var13))
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("</td><td>")
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
var templ_7745c5c3_Var14 string
|
||||
templ_7745c5c3_Var14, templ_7745c5c3_Err = templ.JoinStringErrs(b.Nachname)
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `templates/templates.templ`, Line: 121, Col: 17}
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var14))
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("</td><td>")
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
var templ_7745c5c3_Var15 string
|
||||
templ_7745c5c3_Var15, templ_7745c5c3_Err = templ.JoinStringErrs(fmt.Sprintf("%.2f", b.HvPunkte))
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `templates/templates.templ`, Line: 122, Col: 38}
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var15))
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("</td><td>")
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
var templ_7745c5c3_Var16 string
|
||||
templ_7745c5c3_Var16, templ_7745c5c3_Err = templ.JoinStringErrs(fmt.Sprintf("%.2f", b.HvProzent))
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `templates/templates.templ`, Line: 123, Col: 39}
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var16))
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("</td><td>")
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
var templ_7745c5c3_Var17 string
|
||||
templ_7745c5c3_Var17, templ_7745c5c3_Err = templ.JoinStringErrs(strconv.Itoa(b.HvNote))
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `templates/templates.templ`, Line: 124, Col: 29}
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var17))
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("</td><td>")
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
var templ_7745c5c3_Var18 string
|
||||
templ_7745c5c3_Var18, templ_7745c5c3_Err = templ.JoinStringErrs(fmt.Sprintf("%.2f", b.LvPunkte))
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `templates/templates.templ`, Line: 125, Col: 38}
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var18))
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("</td><td>")
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
var templ_7745c5c3_Var19 string
|
||||
templ_7745c5c3_Var19, templ_7745c5c3_Err = templ.JoinStringErrs(fmt.Sprintf("%.2f", b.LvProzent))
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `templates/templates.templ`, Line: 126, Col: 39}
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var19))
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("</td><td>")
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
var templ_7745c5c3_Var20 string
|
||||
templ_7745c5c3_Var20, templ_7745c5c3_Err = templ.JoinStringErrs(strconv.Itoa(b.LvNote))
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `templates/templates.templ`, Line: 127, Col: 29}
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var20))
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("</td><td>")
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
var templ_7745c5c3_Var21 string
|
||||
templ_7745c5c3_Var21, templ_7745c5c3_Err = templ.JoinStringErrs(fmt.Sprintf("%.2f", b.GesamtProzent))
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `templates/templates.templ`, Line: 128, Col: 43}
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var21))
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("</td><td>")
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
var templ_7745c5c3_Var22 string
|
||||
templ_7745c5c3_Var22, templ_7745c5c3_Err = templ.JoinStringErrs(strconv.Itoa(b.GesamtNote))
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ.Error{Err: templ_7745c5c3_Err, FileName: `templates/templates.templ`, Line: 129, Col: 33}
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var22))
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("</td></tr>")
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
return templ_7745c5c3_Err
|
||||
})
|
||||
}
|
||||
|
||||
func BewertungenPage(bewertungen []models.Bewertung, maxPunkte models.MaxPunkte) templ.Component {
|
||||
return templruntime.GeneratedTemplate(func(templ_7745c5c3_Input templruntime.GeneratedComponentInput) (templ_7745c5c3_Err error) {
|
||||
templ_7745c5c3_W, ctx := templ_7745c5c3_Input.Writer, templ_7745c5c3_Input.Context
|
||||
if templ_7745c5c3_CtxErr := ctx.Err(); templ_7745c5c3_CtxErr != nil {
|
||||
return templ_7745c5c3_CtxErr
|
||||
}
|
||||
templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templruntime.GetBuffer(templ_7745c5c3_W)
|
||||
if !templ_7745c5c3_IsBuffer {
|
||||
defer func() {
|
||||
templ_7745c5c3_BufErr := templruntime.ReleaseBuffer(templ_7745c5c3_Buffer)
|
||||
if templ_7745c5c3_Err == nil {
|
||||
templ_7745c5c3_Err = templ_7745c5c3_BufErr
|
||||
}
|
||||
}()
|
||||
}
|
||||
ctx = templ.InitializeContext(ctx)
|
||||
templ_7745c5c3_Var23 := templ.GetChildren(ctx)
|
||||
if templ_7745c5c3_Var23 == nil {
|
||||
templ_7745c5c3_Var23 = templ.NopComponent
|
||||
}
|
||||
ctx = templ.ClearChildren(ctx)
|
||||
templ_7745c5c3_Var24 := templruntime.GeneratedTemplate(func(templ_7745c5c3_Input templruntime.GeneratedComponentInput) (templ_7745c5c3_Err error) {
|
||||
templ_7745c5c3_W, ctx := templ_7745c5c3_Input.Writer, templ_7745c5c3_Input.Context
|
||||
templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templruntime.GetBuffer(templ_7745c5c3_W)
|
||||
if !templ_7745c5c3_IsBuffer {
|
||||
defer func() {
|
||||
templ_7745c5c3_BufErr := templruntime.ReleaseBuffer(templ_7745c5c3_Buffer)
|
||||
if templ_7745c5c3_Err == nil {
|
||||
templ_7745c5c3_Err = templ_7745c5c3_BufErr
|
||||
}
|
||||
}()
|
||||
}
|
||||
ctx = templ.InitializeContext(ctx)
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("<div class=\"card bg-base-100 shadow-xl\"><div class=\"card-body\"><h2 class=\"card-title\">Englischarbeit</h2><h3 class=\"text-lg font-bold\">Bewertungen</h3>")
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
templ_7745c5c3_Err = BewertungenForm(maxPunkte).Render(ctx, templ_7745c5c3_Buffer)
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
templ_7745c5c3_Err = BewertungenTable(bewertungen).Render(ctx, templ_7745c5c3_Buffer)
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("<div class=\"card-actions justify-end\"><button hx-get=\"/export\" class=\"btn btn-primary\">Export</button></div></div></div>")
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
return templ_7745c5c3_Err
|
||||
})
|
||||
templ_7745c5c3_Err = layout("Englischarbeit").Render(templ.WithChildren(ctx, templ_7745c5c3_Var24), templ_7745c5c3_Buffer)
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
return templ_7745c5c3_Err
|
||||
})
|
||||
}
|
||||
|
||||
var _ = templruntime.GeneratedTemplate
|
||||
1
utils.go
1
utils.go
|
|
@ -1 +0,0 @@
|
|||
package main
|
||||
64
utils/utils.go
Normal file
64
utils/utils.go
Normal file
|
|
@ -0,0 +1,64 @@
|
|||
package utils
|
||||
|
||||
import (
|
||||
"echoTest/models"
|
||||
"fmt"
|
||||
"os/exec"
|
||||
"runtime"
|
||||
|
||||
"github.com/labstack/echo/v4"
|
||||
)
|
||||
|
||||
func SetNote(prozent float64) float64 {
|
||||
switch {
|
||||
case prozent <= 22:
|
||||
return 6.00
|
||||
case prozent <= 49:
|
||||
return 5.00
|
||||
case prozent <= 64:
|
||||
return 4.00
|
||||
case prozent <= 79:
|
||||
return 3.00
|
||||
case prozent <= 94:
|
||||
return 2.00
|
||||
default:
|
||||
return 1.00
|
||||
}
|
||||
}
|
||||
|
||||
func CheckGewichtung(lv, hv float64) bool {
|
||||
if hv/100+lv/100 > 1 {
|
||||
return false
|
||||
} else if hv/100+lv/100 < 1 {
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
func OpenInBrowser(url string) {
|
||||
var cmd *exec.Cmd
|
||||
switch os := runtime.GOOS; os {
|
||||
case "darwin":
|
||||
cmd = exec.Command("open", url)
|
||||
case "windows":
|
||||
cmd = exec.Command("cmd", "/c", "start", url)
|
||||
default:
|
||||
cmd = exec.Command("xdg-open", url)
|
||||
}
|
||||
err := cmd.Start()
|
||||
if err != nil {
|
||||
fmt.Println("Fehler beim Öffnen des Browsers:", err)
|
||||
}
|
||||
}
|
||||
|
||||
func ValidateName(c echo.Context, bewertungen *[]models.Bewertung) string {
|
||||
newNachname := c.FormValue("nachname")
|
||||
newVorname := c.FormValue("vorname")
|
||||
for _, bewertung := range *bewertungen {
|
||||
fmt.Printf("Name: %v", bewertung.Nachname)
|
||||
if bewertung.Nachname == newNachname && bewertung.Vorname == newVorname {
|
||||
return ""
|
||||
}
|
||||
}
|
||||
return newNachname
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue