init
This commit is contained in:
11
flake.nix
Normal file
11
flake.nix
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
{
|
||||||
|
description = "A very basic flake";
|
||||||
|
|
||||||
|
outputs = { self, nixpkgs }: {
|
||||||
|
|
||||||
|
packages.x86_64-linux.hello = nixpkgs.legacyPackages.x86_64-linux.hello;
|
||||||
|
|
||||||
|
packages.x86_64-linux.default = self.packages.x86_64-linux.hello;
|
||||||
|
|
||||||
|
};
|
||||||
|
}
|
||||||
152
forms.html
Normal file
152
forms.html
Normal file
@@ -0,0 +1,152 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta charset="utf-8">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||||
|
<title>malobeo tasklist</title>
|
||||||
|
<title>Bootstrap Example</title>
|
||||||
|
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4.0.0/dist/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
|
||||||
|
|
||||||
|
<style>
|
||||||
|
|
||||||
|
{ margin: 0; padding: 0; }
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
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>
|
||||||
|
|
||||||
|
<div class="container">
|
||||||
|
<div class="row justify-content-center border-0">
|
||||||
|
<div class="col-xl-12 mt-5 mb-5">
|
||||||
|
<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'>
|
||||||
|
enter your name to make yourself happy
|
||||||
|
</h5>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
|
||||||
|
{{range .Tasklists}}
|
||||||
|
<div class="container">
|
||||||
|
<div class="row justify-content-center border-0">
|
||||||
|
<div class="col-xl-12 mt-5">
|
||||||
|
<div class="inherit_height mask rgba-gradient align-items-center border border-secondary rounded">
|
||||||
|
<social class="white">
|
||||||
|
<div class="form-group">
|
||||||
|
<div class="col-md-12 pt-3">
|
||||||
|
<h2>{{.Title}}</h2>
|
||||||
|
{{ if .Updated }}
|
||||||
|
<h3 class="text-success">Updated</h3>
|
||||||
|
{{end}}
|
||||||
|
<form method="POST">
|
||||||
|
{{range .Tasks}}
|
||||||
|
<div class="mb-3">
|
||||||
|
<label for="Input{{.Name}}" name="Name" class="form-label white">{{.Name}}</label>
|
||||||
|
<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>
|
||||||
|
{{end}}
|
||||||
|
<input type="hidden" name="Name" value="{{.Title}}"/>
|
||||||
|
<input type="submit" class="btn btn-primary"></input>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</social>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{{end}}
|
||||||
|
|
||||||
|
</body>
|
||||||
|
</html>`
|
||||||
5
go.mod
Normal file
5
go.mod
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
module tasklist
|
||||||
|
|
||||||
|
go 1.20
|
||||||
|
|
||||||
|
require github.com/mattn/go-sqlite3 v1.14.16 // indirect
|
||||||
175
main.go
Normal file
175
main.go
Normal file
@@ -0,0 +1,175 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"database/sql"
|
||||||
|
"fmt"
|
||||||
|
"html/template"
|
||||||
|
"log"
|
||||||
|
"net/http"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
_ "github.com/mattn/go-sqlite3"
|
||||||
|
)
|
||||||
|
|
||||||
|
func CreateTasklist(title string, db *sql.DB) Tasklist {
|
||||||
|
tasks := []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)
|
||||||
|
`,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Name: "Opening",
|
||||||
|
Description: `(checking toilet if there is toilet paper and fresh towel, refill fridge, sorting deposit bottles, quickly tidy up the place)`,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
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)`,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Name: "CleanUp",
|
||||||
|
Description: `(includes cleaning up, tidying up, rearranging chairs, closing or arranging somebody to lock the front and back doors)`,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Name: "Weekly Toilet & Kitchen",
|
||||||
|
Description: `(whiping the floor in kitchen and bathroom, clean toilet, clean sink, check soap and menstruation supplies)`,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
stmt, err := db.Prepare("select promotion, opening, entering, cleanup, weeklytoilet 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)
|
||||||
|
|
||||||
|
if err == nil {
|
||||||
|
tasks[0].Value = promotion
|
||||||
|
tasks[1].Value = opening
|
||||||
|
tasks[2].Value = entering
|
||||||
|
tasks[3].Value = cleanup
|
||||||
|
tasks[4].Value = weeklytoilet
|
||||||
|
}
|
||||||
|
|
||||||
|
return Tasklist{
|
||||||
|
Title: title,
|
||||||
|
Tasks: tasks,
|
||||||
|
Updated: false,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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)
|
||||||
|
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)
|
||||||
|
} 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)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println("Error during update: ", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
type Task struct {
|
||||||
|
Name string
|
||||||
|
Description string
|
||||||
|
Value string
|
||||||
|
}
|
||||||
|
|
||||||
|
type Tasklist struct {
|
||||||
|
Title string
|
||||||
|
Tasks []Task
|
||||||
|
Updated bool
|
||||||
|
}
|
||||||
|
|
||||||
|
type Tasklists struct {
|
||||||
|
Tasklists []Tasklist
|
||||||
|
}
|
||||||
|
|
||||||
|
type QueryResult struct {
|
||||||
|
Tasklists []Tasklist
|
||||||
|
}
|
||||||
|
|
||||||
|
func (n *Tasklist) Print() {
|
||||||
|
fmt.Println(n.Title)
|
||||||
|
|
||||||
|
for _, task := range n.Tasks {
|
||||||
|
fmt.Println("\t Name: ", task.Name)
|
||||||
|
fmt.Println("\t Descr: ", task.Description)
|
||||||
|
fmt.Println("\t Value: ", task.Value)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func GetNextNDaysOfName(n int, name time.Weekday, current time.Time) []time.Time {
|
||||||
|
result := make([]time.Time, n)
|
||||||
|
|
||||||
|
for index := 0; index < n; {
|
||||||
|
if current.Weekday() == name {
|
||||||
|
result[index] = current
|
||||||
|
index++
|
||||||
|
}
|
||||||
|
|
||||||
|
current = current.AddDate(0, 0, 1)
|
||||||
|
}
|
||||||
|
|
||||||
|
return result
|
||||||
|
}
|
||||||
|
|
||||||
|
const DB_NAME = "./tasklist.db"
|
||||||
|
const TASK_DAY = time.Tuesday
|
||||||
|
const AMOUNT_DAYS = 4
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
db, err := sql.Open("sqlite3", DB_NAME)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
|
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)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
tmpl := template.Must(template.ParseFiles("forms.html"))
|
||||||
|
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
days := GetNextNDaysOfName(AMOUNT_DAYS, TASK_DAY, time.Now())
|
||||||
|
tasklist_arr := QueryResult{make([]Tasklist, AMOUNT_DAYS)}
|
||||||
|
|
||||||
|
for idx, day := range days {
|
||||||
|
tasklist_arr.Tasklists[idx] = CreateTasklist(day.Format("Jan 2, 2006"), db)
|
||||||
|
}
|
||||||
|
|
||||||
|
if r.Method != http.MethodPost {
|
||||||
|
tmpl.Execute(w, tasklist_arr)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
for idx, task := range tasklist_arr.Tasklists {
|
||||||
|
if task.Title == r.FormValue("Name") {
|
||||||
|
for idx2 := range task.Tasks {
|
||||||
|
task.Tasks[idx2].Value = r.FormValue(task.Tasks[idx2].Name)
|
||||||
|
}
|
||||||
|
tasklist_arr.Tasklists[idx].Updated = true
|
||||||
|
InsertToDB(tasklist_arr.Tasklists[idx], db)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
tmpl.Execute(w, tasklist_arr)
|
||||||
|
|
||||||
|
})
|
||||||
|
|
||||||
|
http.ListenAndServe(":8080", nil)
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user