Skip to content

Commit

Permalink
Sort Exs
Browse files Browse the repository at this point in the history
  • Loading branch information
aceberg committed Dec 18, 2023
1 parent f326aa6 commit 0afdd32
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 7 deletions.
7 changes: 4 additions & 3 deletions internal/db/edit.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ func Create(path string) {
sqlStatement := `CREATE TABLE IF NOT EXISTS exercises (
"ID" INTEGER PRIMARY KEY,
"GR" TEXT,
"PLACE" TEXT,
"NAME" TEXT,
"DESCR" TEXT,
"IMAGE" TEXT,
Expand All @@ -35,14 +36,14 @@ func Create(path string) {
// InsertEx - insert one exercise into DB
func InsertEx(path string, ex models.Exercise) {

sqlStatement := `INSERT INTO exercises (GR, NAME, DESCR, IMAGE, COLOR, WEIGHT, REPS)
VALUES ('%s','%s','%s','%s','%s','%d','%d');`
sqlStatement := `INSERT INTO exercises (GR, PLACE, NAME, DESCR, IMAGE, COLOR, WEIGHT, REPS)
VALUES ('%s','%s','%s','%s','%s','%s','%d','%d');`

ex.Group = quoteStr(ex.Group)
ex.Name = quoteStr(ex.Name)
ex.Descr = quoteStr(ex.Descr)

sqlStatement = fmt.Sprintf(sqlStatement, ex.Group, ex.Name, ex.Descr, ex.Image, ex.Color, ex.Weight, ex.Reps)
sqlStatement = fmt.Sprintf(sqlStatement, ex.Group, ex.Place, ex.Name, ex.Descr, ex.Image, ex.Color, ex.Weight, ex.Reps)

exec(path, sqlStatement)
}
Expand Down
1 change: 1 addition & 0 deletions internal/models/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ type Conf struct {
type Exercise struct {
ID int `db:"ID"`
Group string `db:"GR"`
Place string `db:"PLACE"`
Name string `db:"NAME"`
Descr string `db:"DESCR"`
Image string `db:"IMAGE"`
Expand Down
1 change: 1 addition & 0 deletions internal/web/exercise.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ func saveExerciseHandler(c *gin.Context) {
var oneEx models.Exercise

oneEx.Group = c.PostForm("group")
oneEx.Place = c.PostForm("place")
oneEx.Name = c.PostForm("name")
oneEx.Descr = c.PostForm("descr")

Expand Down
10 changes: 7 additions & 3 deletions internal/web/index.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package web
import (
"fmt"
"net/http"
"sort"

"github.com/gin-gonic/gin"

Expand All @@ -20,14 +21,18 @@ func indexHandler(c *gin.Context) {
guiData.ExData = exData
guiData.GroupMap = createGroupMap()

// Sort exercises by Place
sort.Slice(guiData.ExData.Exs, func(i, j int) bool {
return guiData.ExData.Exs[i].Place < guiData.ExData.Exs[j].Place
})

c.HTML(http.StatusOK, "header.html", guiData)
c.HTML(http.StatusOK, "index.html", guiData)
}

func createGroupMap() map[string]string {

grMap := make(map[string]string)
i := 0
grMap := make(map[string]string)

for _, ex := range exData.Exs {

Expand All @@ -37,6 +42,5 @@ func createGroupMap() map[string]string {
i = i + 1
}
}

return grMap
}
Binary file added internal/web/public/favicon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions internal/web/templates/exercise.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@
<td>Group</td>
<td><input name="group" type="text" class="form-control" value="{{ .OneEx.Group }}"></td>
</tr>
<tr>
<td>Place in group</td>
<td><input name="place" type="number" class="form-control" value="{{ .OneEx.Place }}"></td>
</tr>
<tr>
<td>Name</td>
<td><input name="name" type="text" class="form-control" value="{{ .OneEx.Name }}"></td>
Expand Down
2 changes: 1 addition & 1 deletion internal/web/templates/header.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!--Favicon-->
<link rel="icon" type="image/x-icon" href="/fs/public/favicon.ico">
<link rel="icon" type="image/x-icon" href="/fs/public/favicon.png">
<!-- <link href="data:image/x-icon;base64, {{ .Config.Icon }}" rel="icon" type="image/x-icon" /> -->
<!-- Font for icons -->
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/font/bootstrap-icons.css">
Expand Down

0 comments on commit 0afdd32

Please sign in to comment.