Skip to content

Commit 8a35bb3

Browse files
committed
add project deletion confirmation
1 parent 3c994ec commit 8a35bb3

File tree

2 files changed

+24
-5
lines changed

2 files changed

+24
-5
lines changed

main.go

+23-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package main
22

33
import (
4+
"flag"
45
"fmt"
56
"html/template"
67
"net/http"
@@ -64,14 +65,32 @@ func add(x, y int) string {
6465
}
6566

6667
func main() {
67-
mux := http.NewServeMux()
68-
repo := NewRepository()
68+
isDevEnv := flag.Bool("dev", false, "Tells the program whether it is running in a development environment or not (defaults to false)")
69+
flag.Parse()
6970
funcMap := template.FuncMap{
7071
"add": add,
7172
"parse": parse,
7273
}
74+
var templates *template.Template
75+
if *isDevEnv {
76+
templates = template.Must(template.New("stupidfuckingbitch").Funcs(funcMap).ParseFiles(
77+
"main.html",
78+
"projects-list.html",
79+
"projects-description.html",
80+
"projects-steps-table.html",
81+
))
82+
83+
} else {
84+
templates = template.Must(template.New("stupidfuckingbitch").Funcs(funcMap).ParseFiles(
85+
"/usr/share/pm/html/main.html",
86+
"/usr/share/pm/html/projects-list.html",
87+
"/usr/share/pm/html/projects-description.html",
88+
"/usr/share/pm/html/projects-steps-table.html",
89+
))
90+
}
91+
mux := http.NewServeMux()
92+
repo := NewRepository()
7393

74-
templates := template.Must(template.New("stupidfuckingbitch").Funcs(funcMap).ParseFiles("main.html", "projects-list.html", "projects-description.html", "projects-steps-table.html"))
7594
mux.HandleFunc("POST /projects/", func(w http.ResponseWriter, r *http.Request) {
7695
fmt.Println("Matched POST /projects")
7796
p := Project{
@@ -163,7 +182,7 @@ func main() {
163182
http.Redirect(w, r, "/projects/"+projectId, http.StatusSeeOther)
164183
})
165184

166-
port := ":8080"
185+
port := "0.0.0.0:8080"
167186
fmt.Println("Listening on http://localhost" + port)
168187
http.ListenAndServe(port, mux)
169188
}

projects-list.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
<button hx-get="/projects/{{.Id}}" hx-target="body" hx-push-url="true">{{.Name}}</button>
1515
{{end}}
1616
{{if gt (len $.Projects) 1 }}
17-
<button style="color: red" hx-delete="/projects/{{.Id}}" hx-swap="innerHTML" hx-target="body">X</button>
17+
<button style="color: red" hx-confirm="Are you sure you want to delete the project &quot;{{.Name}}&quot;?" hx-delete="/projects/{{.Id}}" hx-swap="innerHTML" hx-target="body">X</button>
1818
{{end}}
1919
<input type="hidden" name="project-id" id="project-id" value={{.Id}}>
2020
</li>

0 commit comments

Comments
 (0)