extend tasks

This commit is contained in:
2023-05-09 17:41:27 +02:00
parent 7db6de7a30
commit 77c0c815e0
2 changed files with 78 additions and 21 deletions

View File

@@ -131,7 +131,7 @@ input {
<form method="POST">
{{range .Tasks}}
<div class="mb-3">
<label for="Input{{.Name}}" name="Name" class="form-label white">{{.Name}}</label>
<h4><b><label for="Input{{.Name}}" name="Name" class="form-label white">{{.Name}}</label></b></h4>
<input type="text" name={{.Name}} class="form-control" value="{{.Value}}" id="Input{{.Name}}" aria-describedby="{{.Name}}Help">
<div id="{{.Name}}Help" class="form-text font-italic">{{.Description}}</div>
</div>

97
main.go
View File

@@ -11,46 +11,106 @@ import (
_ "github.com/mattn/go-sqlite3"
)
func CreateTasklist(title string, db *sql.DB) Tasklist {
tasks := []Task{
func GetDefaultTasks() []Task {
return []Task{
{
Name: "Promotion",
Description: `
(make a post on the website to promote openings times and for each film event, posting description and announcement on telegram channel, forwarding it to telegram groups, making a fb event, making a post about fb event on the fb page, sharing the event to fb groups)
`,
IsOptional: false,
},
{
Name: "Opening",
Description: `(checking toilet if there is toilet paper and fresh towel, refill fridge, sorting deposit bottles, quickly tidy up the place)`,
IsOptional: false,
},
{
Name: "Entering",
Description: `(checking if there are new books to be entered into the library catalogue, categorizing them, stamping them, putting them into the book shelf)`,
IsOptional: true,
},
{
Name: "PrepareKuefa",
Description: `(includes preparing the cutting boards and knives and all devices needed to prepare food. Including potential visitors in this action, preparing chairs, tables and benches outside of malo for people to eat and chill outside)`,
IsOptional: true,
},
{
Name: "CookingKuefa",
Description: `(choosing a dish/recipe, doing shopping or arranging somebody to do shopping, cooking, serving)`,
IsOptional: true,
},
{
Name: "CleanUp",
Description: `(includes cleaning up, tidying up, rearranging chairs, closing or arranging somebody to lock the front and back doors)`,
IsOptional: false,
},
{
Name: "Weekly Toilet & Kitchen",
Name: "WeeklyToiletAndKitchen",
Description: `(whiping the floor in kitchen and bathroom, clean toilet, clean sink, check soap and menstruation supplies)`,
IsOptional: false,
},
}
}
stmt, err := db.Prepare("select promotion, opening, entering, cleanup, weeklytoilet from tasklists where name = ?")
func InitDB() *sql.DB {
db, err := sql.Open("sqlite3", DB_NAME)
if err != nil {
log.Fatal(err)
}
sqlStmt := "create table if not exists tasklists (name test not null primary key"
// promotion text, opening text, entering text, cleanup text, weeklytoilet text);
for _, task := range GetDefaultTasks() {
sqlStmt += ", " + task.Name + " text"
}
sqlStmt += ");"
fmt.Println(sqlStmt)
_, err = db.Exec(sqlStmt)
if err != nil {
log.Printf("%q: %s\n", err, sqlStmt)
return nil
}
return db
}
func GetTaskNameString(FillString string) string {
result := ""
IsFirst := true
for _, task := range GetDefaultTasks() {
if !IsFirst {
result += FillString
}
result += task.Name
IsFirst = false
}
return result
}
func CreateTasklist(title string, db *sql.DB) Tasklist {
tasks := GetDefaultTasks()
stmt, err := db.Prepare("select " + GetTaskNameString(", ") + " from tasklists where name = ?")
if err != nil {
fmt.Println(err)
}
defer stmt.Close()
var promotion, opening, entering, cleanup, weeklytoilet string
err = stmt.QueryRow(title).Scan(&promotion, &opening, &entering, &cleanup, &weeklytoilet)
var promotion, opening, entering, preparekuefa, cookkuefa, cleanup, weeklytoilet string
err = stmt.QueryRow(title).Scan(&promotion, &opening, &entering, &preparekuefa, &cookkuefa, &cleanup, &weeklytoilet)
if err == nil {
tasks[0].Value = promotion
tasks[1].Value = opening
tasks[2].Value = entering
tasks[3].Value = cleanup
tasks[4].Value = weeklytoilet
tasks[3].Value = preparekuefa
tasks[4].Value = cookkuefa
tasks[5].Value = cleanup
tasks[6].Value = weeklytoilet
}
return Tasklist{
@@ -69,9 +129,12 @@ func InsertToDB(tasklist Tasklist, db *sql.DB) {
var name string
err = stmt.QueryRow(tasklist.Title).Scan(&name)
if err != nil {
db.Exec("insert into tasklists(name, promotion, opening, entering, cleanup, weeklytoilet) values(?, ?, ?, ?, ?, ?)", tasklist.Title, tasklist.Tasks[0].Value, tasklist.Tasks[1].Value, tasklist.Tasks[2].Value, tasklist.Tasks[3].Value, tasklist.Tasks[4].Value)
db.Exec("insert into tasklists(name, "+GetTaskNameString(", ")+") values(?, ?, ?, ?, ?, ?, ?, ?)", tasklist.Title, tasklist.Tasks[0].Value, tasklist.Tasks[1].Value, tasklist.Tasks[2].Value, tasklist.Tasks[3].Value, tasklist.Tasks[4].Value, tasklist.Tasks[5].Value, tasklist.Tasks[6].Value)
if err != nil {
fmt.Println("Error during insert: ", err)
}
} else {
_, err := db.Exec("update tasklists set promotion = ?,opening = ?,entering = ?,cleanup = ?,weeklytoilet = ? where name = ?", tasklist.Tasks[0].Value, tasklist.Tasks[1].Value, tasklist.Tasks[2].Value, tasklist.Tasks[3].Value, tasklist.Tasks[4].Value, tasklist.Title)
_, err := db.Exec("update tasklists set "+GetTaskNameString(" = ?,")+" = ? where name = ?", tasklist.Tasks[0].Value, tasklist.Tasks[1].Value, tasklist.Tasks[2].Value, tasklist.Tasks[3].Value, tasklist.Tasks[4].Value, tasklist.Tasks[5].Value, tasklist.Tasks[6].Value, tasklist.Title)
if err != nil {
fmt.Println("Error during update: ", err)
}
@@ -82,6 +145,7 @@ type Task struct {
Name string
Description string
Value string
IsOptional bool
}
type Tasklist struct {
@@ -128,18 +192,11 @@ const TASK_DAY = time.Tuesday
const AMOUNT_DAYS = 4
func main() {
db, err := sql.Open("sqlite3", DB_NAME)
if err != nil {
log.Fatal(err)
}
db := InitDB()
defer db.Close()
sqlStmt := `
create table if not exists tasklists (name test not null primary key, promotion text, opening text, entering text, cleanup text, weeklytoilet text);
`
_, err = db.Exec(sqlStmt)
if err != nil {
log.Printf("%q: %s\n", err, sqlStmt)
if db == nil {
fmt.Println("Creating db failed. exiting")
return
}