From 0a9775d2a1643089acb6fdb956b4b5ccbfa3103f Mon Sep 17 00:00:00 2001 From: Captain ALM Date: Sun, 17 Jul 2022 14:02:40 +0100 Subject: [PATCH] Finish index.go page code. --- pageHandler/pages/index/index-page.go | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/pageHandler/pages/index/index-page.go b/pageHandler/pages/index/index-page.go index 6166354..bb73fe4 100644 --- a/pageHandler/pages/index/index-page.go +++ b/pageHandler/pages/index/index-page.go @@ -81,7 +81,16 @@ func (p *Page) GetContents(urlParameters url.Values) (contentType string, conten Data: *theData, Light: urlParameters.Has("light"), } - //Set up sorting here + switch strings.ToLower(urlParameters.Get("order")) { + case "end": + theMarshal.OrderEndDate = getSortValue(strings.ToLower(urlParameters.Get("sort"))) + case "name": + theMarshal.OrderName = getSortValue(strings.ToLower(urlParameters.Get("sort"))) + case "duration": + theMarshal.OrderDuration = getSortValue(strings.ToLower(urlParameters.Get("sort"))) + default: + theMarshal.OrderStartDate = getSortValue(strings.ToLower(urlParameters.Get("sort"))) + } theBuffer := &io.BufferedWriter{} err = theTemplate.ExecuteTemplate(theBuffer, templateName, theMarshal) if err != nil { @@ -173,3 +182,11 @@ func (p *Page) getPageData() (*DataYaml, error) { return p.StoredData, nil } } + +func getSortValue(toCheckIn string) int8 { + if toCheckIn == "desc" || toCheckIn == "descending" { + return -1 + } else { + return 1 + } +}