Compare commits

...

2 Commits

Author SHA1 Message Date
94314ae91e update appearance 2024-06-17 17:25:45 +02:00
2c4b6cac19 change db schema to json field 2024-06-17 17:16:15 +02:00
4 changed files with 135 additions and 144 deletions

View File

@@ -14,86 +14,14 @@
body {
background-image: url('https://files.libcom.org/files/images/library/anarchists.jpg');
background-repeat: no-repeat;
background-attachment: fixed;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;
min-height: 100vh;
display: flex;
flex-direction: column;
background-color: #F5F5F5;
font-family: Copperplate;
}
footer{
margin-top: auto;
}
.h-divider{
margin-left: auto;
margin-right: auto;
height:1px;
width:80%;
border-top:1px solid gray;
}
@media (min-width: 768px) {
.row.equal {
display: flex;
flex-wrap: wrap;
}
}
.inherit_height
{
width:inherit;
height:100%;
}
.rgba-gradient {
background: -webkit-linear-gradient(45deg, rgba(0, 0, 0, 0.5), rgba(0, 0, 0, 0.7) 100%);
}
.rgba-gradient:hover {
background: -webkit-linear-gradient(45deg, rgba(0, 0, 0, 0.8), rgba(0, 0, 0, 0.9) 100%);
}
.card {
background-color: rgba(42, 42, 42, 0.2);
}
.md-form label {
color: #ffffff;
}
h6 {
line-height: 1.7;
}
label {
color: #000000;
}
input {
color: #000000;
}
.black-background {background-color:#ffffff;}
.white {color:#ffffff;}
.black {color:#000000;}
.about white {
color: white;
font-size: 14px;
}
.a {
text-decoration:none;
color:red;
}
</style>
</head>
<body>
@@ -104,8 +32,8 @@ input {
<div class="container">
<div class="row col-md-12">
<div class="col-12 col-md pl-5">
<h2 class='text-light'>tasklist</h2>
<h5 class='text-light'>
<h2 class='text-dark'>tasklist</h2>
<h5 class='text-dark'>
enter your name to make yourself happy
</h5>
</div>
@@ -124,7 +52,7 @@ input {
<social class="white">
<div class="form-group">
<div class="col-md-12 pt-3">
<h2>{{.Title}}</h2>
<h2>{{.Date}}</h2>
{{ if .Updated }}
<h3 class="text-success">Updated</h3>
{{end}}
@@ -136,7 +64,7 @@ input {
<div id="{{.Name}}Help" class="form-text font-italic">{{.Description}}</div>
</div>
{{end}}
<input type="hidden" name="Name" value="{{.Title}}"/>
<input type="hidden" name="Name" value="{{.Date}}"/>
<input type="submit" class="btn btn-primary"></input>
</form>
</div>

10
go.mod
View File

@@ -2,4 +2,12 @@ module tasklist
go 1.20
require github.com/mattn/go-sqlite3 v1.14.16 // indirect
require (
github.com/mattn/go-sqlite3 v1.14.16
github.com/tidwall/gjson v1.17.1
)
require (
github.com/tidwall/match v1.1.1 // indirect
github.com/tidwall/pretty v1.2.0 // indirect
)

6
go.sum
View File

@@ -1,2 +1,8 @@
github.com/mattn/go-sqlite3 v1.14.16 h1:yOQRA0RpS5PFz/oikGwBEqvAWhWg5ufRz4ETLjwpU1Y=
github.com/mattn/go-sqlite3 v1.14.16/go.mod h1:2eHXhiwb8IkHr+BDWZGa96P6+rkvnG63S2DGjv9HUNg=
github.com/tidwall/gjson v1.17.1 h1:wlYEnwqAHgzmhNUFfw7Xalt2JzQvsMx2Se4PcoFCT/U=
github.com/tidwall/gjson v1.17.1/go.mod h1:/wbyibRr2FHMks5tjHJ5F8dMZh3AcwJEMf5vlfC0lxk=
github.com/tidwall/match v1.1.1 h1:+Ho715JplO36QYgwN9PGYNhgZvoUSc9X2c80KVTi+GA=
github.com/tidwall/match v1.1.1/go.mod h1:eRSPERbgtNPcGhD8UCthc6PmLEQXEWd3PRB5JTxsfmM=
github.com/tidwall/pretty v1.2.0 h1:RWIZEg2iJ8/g6fDDYzMpobmaoGh5OLl4AXtGUGPcqCs=
github.com/tidwall/pretty v1.2.0/go.mod h1:ITEVvHYasfjBbM0u2Pg8T2nJnzm8xPwvNhhsoaGGjNU=

179
main.go
View File

@@ -8,52 +8,59 @@ import (
"log"
"net/http"
"time"
"encoding/json"
//"github.com/tidwall/gjson"
_ "github.com/mattn/go-sqlite3"
)
func GetDefaultTasks() []Task {
return []Task{
{
Name: "Title",
Description: ``,
IsOptional: true,
},
{
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: "Title",
// Description: ``,
// IsOptional: true,
//},
//{
// 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: "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: "WeeklyToiletAndKitchen",
Description: `(whiping the floor in kitchen and bathroom, clean toilet, clean sink, check soap and menstruation supplies)`,
Name: "WeeklyToilet",
Description: `(whiping the floor in the bathroom, clean toilet, clean sink, check soap and menstruation supplies)`,
IsOptional: false,
},
{
Name: "WeeklyKitchen",
Description: `(whiping the floor in kitchen, clean sink, empty trash, check surfaces)`,
IsOptional: false,
},
}
@@ -65,13 +72,13 @@ func InitDB(db_name string) *sql.DB {
log.Fatal(err)
}
sqlStmt := "create table if not exists tasklists (name test not null primary key"
sqlStmt := "create table if not exists tasklists (name test not null primary key, Data text);"
// promotion text, opening text, entering text, cleanup text, weeklytoilet text);
for _, task := range GetDefaultTasks() {
sqlStmt += ", " + task.Name + " text"
}
//for _, task := range GetDefaultTasks() {
// sqlStmt += ", " + task.Name + " text"
//}
sqlStmt += ");"
//sqlStmt += ");"
fmt.Println(sqlStmt)
@@ -85,7 +92,7 @@ func InitDB(db_name string) *sql.DB {
}
func GetTaskNameString(FillString string) string {
result := ""
result := "Data"
IsFirst := true
for _, task := range GetDefaultTasks() {
if !IsFirst {
@@ -98,50 +105,62 @@ func GetTaskNameString(FillString string) string {
return result
}
func CreateTasklist(title string, db *sql.DB) Tasklist {
tasks := GetDefaultTasks()
func CreateTasklist(date string, db *sql.DB) Tasklist {
stmt, err := db.Prepare("select " + "Data" + " from tasklists where name = ?")
stmt, err := db.Prepare("select " + GetTaskNameString(", ") + " from tasklists where name = ?")
if err != nil {
fmt.Println(err)
}
defer stmt.Close()
var eventtitle, promotion, opening, entering, preparekuefa, cookkuefa, cleanup, weeklytoilet string
err = stmt.QueryRow(title).Scan(&eventtitle, &promotion, &opening, &entering, &preparekuefa, &cookkuefa, &cleanup, &weeklytoilet)
if err == nil {
tasks[0].Value = eventtitle
tasks[1].Value = promotion
tasks[2].Value = opening
tasks[3].Value = entering
tasks[4].Value = preparekuefa
tasks[5].Value = cookkuefa
tasks[6].Value = cleanup
tasks[7].Value = weeklytoilet
defer stmt.Close()
var data string
err = stmt.QueryRow(date).Scan(&data)
tasks := GetDefaultTasks()
if err != nil {
if err != sql.ErrNoRows {
fmt.Printf("Error in CreateTasklist during QueryRow, Date %s\n", date)
fmt.Println(err)
}
} else {
tasks = TasksFromJson(data)
if tasks == nil {
fmt.Println("Error in CreateTasklist")
fmt.Println(err)
}
}
return Tasklist{
Title: title,
Date: date,
Tasks: tasks,
Updated: false,
}
}
func InsertToDB(tasklist Tasklist, db *sql.DB) {
stmt, err := db.Prepare("select name from tasklists where name = ?")
func InsertToDB(tasklist Tasklist, db *sql.DB) { stmt, err :=
db.Prepare("select name from tasklists where name = ?")
if err != nil {
log.Fatal(err)
}
defer stmt.Close()
var name string
err = stmt.QueryRow(tasklist.Title).Scan(&name)
err = stmt.QueryRow(tasklist.Date).Scan(&name)
if err != nil {
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, tasklist.Tasks[7].Value)
_, err := db.Exec("insert into tasklists(name, "+ "Data" +") values(?, ?)", tasklist.Date, TasksToJson(tasklist.Tasks))
if err != nil {
fmt.Println("Error during insert: ", err)
}
} else {
_, 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.Tasks[7].Value, tasklist.Title)
_, err := db.Exec("update tasklists set " + "Data" +" = ? where name = ?", TasksToJson(tasklist.Tasks), tasklist.Date)
fmt.Println(TasksToJson(tasklist.Tasks))
if err != nil {
fmt.Println("Error during update: ", err)
}
@@ -149,18 +168,43 @@ func InsertToDB(tasklist Tasklist, db *sql.DB) {
}
type Task struct {
Name string
Description string
Value string
IsOptional bool
Name string `json:"Name"`
Description string `json:"Description"`
Value string `json:"Value"`
IsOptional bool `json:"IsOptional"`
}
type Tasklist struct {
Title string
Date string
Tasks []Task
Updated bool
}
func TasksFromJson(tasks string) []Task {
var result []Task
err := json.Unmarshal([]byte(tasks), &result)
if err != nil {
fmt.Println("Error during TasksFromJson")
fmt.Println(err)
return nil
}
return result
}
func TasksToJson(tasks []Task) string {
result, err := json.Marshal(tasks)
if err != nil {
fmt.Println("Error during TasksToJson")
fmt.Println(err)
return ""
}
return string(result)
}
type Tasklists struct {
Tasklists []Tasklist
}
@@ -170,7 +214,7 @@ type QueryResult struct {
}
func (n *Tasklist) Print() {
fmt.Println(n.Title)
fmt.Println(n.Date)
for _, task := range n.Tasks {
fmt.Println("\t Name: ", task.Name)
@@ -194,7 +238,7 @@ func GetNextNDaysOfName(n int, name time.Weekday, current time.Time) []time.Time
return result
}
const DB_NAME = "./tasklist.db"
const DB_NAME = "./tasklistJson.db"
const FORMS_NAME = "./forms.html"
const TASK_DAY = time.Tuesday
const AMOUNT_DAYS = 4
@@ -227,7 +271,7 @@ func main() {
}
for idx, task := range tasklist_arr.Tasklists {
if task.Title == r.FormValue("Name") {
if task.Date == r.FormValue("Name") {
for idx2 := range task.Tasks {
task.Tasks[idx2].Value = r.FormValue(task.Tasks[idx2].Name)
}
@@ -236,9 +280,14 @@ func main() {
}
}
tmpl.Execute(w, tasklist_arr)
err := tmpl.Execute(w, tasklist_arr)
if err != nil {
fmt.Println("Error during tmpl.Execute")
fmt.Println(err)
}
})
fmt.Println("Start listening on port 8080")
http.ListenAndServe(":8080", nil)
}