Compare commits
23 Commits
feat_nixos
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
|
b67eb2d778
|
|||
|
511bfb8f73
|
|||
|
b61466549e
|
|||
| c5fff78c83 | |||
| 9cdab949f4 | |||
| 610269a142 | |||
| 886feef65a | |||
| e9bd8610fe | |||
| 8ac550d160 | |||
| 895c19269b | |||
| cd5c0f18ea | |||
| 7ebdc08457 | |||
| f7bd5bd5e3 | |||
| 41c0d16428 | |||
| 514437473e | |||
| c6de5b4723 | |||
| a4a9bf571d | |||
| c60fc43f73 | |||
| c6ae5019dd | |||
| b9f8fe84d9 | |||
| 94314ae91e | |||
| 2c4b6cac19 | |||
| 74e2f4e0a2 |
20
.gitea/workflows/checks.yaml
Normal file
20
.gitea/workflows/checks.yaml
Normal file
@@ -0,0 +1,20 @@
|
||||
name: "Check"
|
||||
on:
|
||||
pull_request:
|
||||
push:
|
||||
jobs:
|
||||
tests:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- name: Install dependencies for Nix setup action
|
||||
run: |
|
||||
apt update -y
|
||||
apt install sudo -y
|
||||
- uses: cachix/install-nix-action@v27
|
||||
- name: enable kvm support
|
||||
run: |
|
||||
echo "system-features = nixos-test benchmark big-parallel kvm" >> /etc/nix/nix.conf
|
||||
echo "Added features to nix conf"
|
||||
cat /etc/nix/nix.conf
|
||||
- run: nix flake check
|
||||
1
.gitignore
vendored
1
.gitignore
vendored
@@ -1,2 +1,3 @@
|
||||
*.db
|
||||
result
|
||||
main
|
||||
|
||||
84
forms.html
84
forms.html
@@ -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>
|
||||
|
||||
2
go.mod
2
go.mod
@@ -2,4 +2,4 @@ module tasklist
|
||||
|
||||
go 1.20
|
||||
|
||||
require github.com/mattn/go-sqlite3 v1.14.16 // indirect
|
||||
require github.com/mattn/go-sqlite3 v1.14.16
|
||||
|
||||
192
main.go
192
main.go
@@ -2,6 +2,7 @@ package main
|
||||
|
||||
import (
|
||||
"database/sql"
|
||||
"encoding/json"
|
||||
"flag"
|
||||
"fmt"
|
||||
"html/template"
|
||||
@@ -14,46 +15,54 @@ import (
|
||||
|
||||
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: "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",
|
||||
Name: "Closing",
|
||||
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, empty trash, 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,
|
||||
},
|
||||
{
|
||||
Name: "Trash",
|
||||
Description: `(empty the trash and take care the boxes are not ultra disgusting)`,
|
||||
IsOptional: false,
|
||||
},
|
||||
{
|
||||
Name: "Plants",
|
||||
Description: `(take care of the plants. they need water, but not too much!)`,
|
||||
IsOptional: false,
|
||||
},
|
||||
{
|
||||
Name: "Fridge",
|
||||
Description: `(Check the fridges (kitchen and main room) for nasty stuff and try to remove it.)`,
|
||||
IsOptional: false,
|
||||
},
|
||||
{
|
||||
Name: "Check Mailbox",
|
||||
Description: `(Go to mailbox, open it, look if there are letters inside, if yes bring them into malo)`,
|
||||
IsOptional: false,
|
||||
},
|
||||
{
|
||||
Name: "Poster Check",
|
||||
Description: `(Check current Posters in the main window, make sure they look nice and are not outdated)`,
|
||||
IsOptional: false,
|
||||
},
|
||||
{
|
||||
Name: "Weekly Insta Post",
|
||||
Description: `(Post something on instagram, like a newly printed zine, kuefa or whatever)`,
|
||||
IsOptional: false,
|
||||
},
|
||||
}
|
||||
@@ -65,16 +74,7 @@ func InitDB(db_name string) *sql.DB {
|
||||
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)
|
||||
|
||||
sqlStmt := "create table if not exists tasklists (name test not null primary key, Data text);"
|
||||
_, err = db.Exec(sqlStmt)
|
||||
if err != nil {
|
||||
log.Printf("%q: %s\n", err, sqlStmt)
|
||||
@@ -85,7 +85,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,30 +98,34 @@ 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,
|
||||
}
|
||||
@@ -129,19 +133,27 @@ func CreateTasklist(title string, db *sql.DB) Tasklist {
|
||||
|
||||
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 +161,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 +207,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 +231,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
|
||||
@@ -213,6 +250,18 @@ func main() {
|
||||
}
|
||||
|
||||
tmpl := template.Must(template.ParseFiles(*formsName))
|
||||
|
||||
http.HandleFunc("/api/next", func(w http.ResponseWriter, r *http.Request) {
|
||||
days := GetNextNDaysOfName(1, TASK_DAY, time.Now())
|
||||
tasklist_arr := QueryResult{make([]Tasklist, 1)}
|
||||
|
||||
for idx, day := range days {
|
||||
tasklist_arr.Tasklists[idx] = CreateTasklist(day.Format("Jan 2, 2006"), db)
|
||||
}
|
||||
|
||||
fmt.Fprintf(w, TasksToJson(tasklist_arr.Tasklists[0].Tasks))
|
||||
})
|
||||
|
||||
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
|
||||
days := GetNextNDaysOfName(AMOUNT_DAYS, TASK_DAY, time.Now())
|
||||
tasklist_arr := QueryResult{make([]Tasklist, AMOUNT_DAYS)}
|
||||
@@ -227,7 +276,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 +285,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)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user