added confirm and publish form

This commit is contained in:
TheLastBilly 2023-05-21 21:17:23 -04:00
parent e3b29eef24
commit 9d42264db5
7 changed files with 176 additions and 20 deletions

View File

@ -68,6 +68,7 @@ type Context struct {
First int
Last int
Title string
UserName string
}
type Err struct {
@ -365,6 +366,11 @@ func newComic(title string, image string, description string, tags string) error
return err
}
func deleteComic(id int) error {
_, err := db.Exec("DELETE FROM comic WHERE id = ?;", id)
return err
}
func main() {
var err error

View File

@ -3,9 +3,18 @@ package main
import (
"log"
"fmt"
"strconv"
"strings"
"net/http"
)
type ConfirmContext struct {
Action string
Message string
OnYes string
OnNo string
}
func managerIndexView(w http.ResponseWriter, r * http.Request) {
var err error
@ -17,7 +26,12 @@ func managerIndexView(w http.ResponseWriter, r * http.Request) {
return
}
} ()
if len(strings.TrimPrefix(r.URL.Path, "/")) > 0 {
return404(w,r)
return
}
context := Context{
Comics: nil,
Title: "Black Ram Comics Manager",
@ -45,11 +59,58 @@ func managerIndexView(w http.ResponseWriter, r * http.Request) {
err = executeTemplate(w, "manager", context)
}
func managerRemoveView(w http.ResponseWriter, r * http.Request) {
tmp := strings.TrimPrefix(r.URL.Path, "/remove/")
path := strings.TrimRight(tmp, "/confirmed")
isConfirmed := strings.TrimPrefix(strings.TrimPrefix(tmp, path), "/") == "confirmed"
i, err := strconv.Atoi(path)
if err != nil {
return404(w, r)
return
}
comic, err := getComic(i-1)
if err != nil {
return404(w, r)
return
}
if !isConfirmed {
err = executeTemplate(w, "confirm", ConfirmContext{
Action: fmt.Sprintf("Remove %s", comic.Title),
Message: fmt.Sprintf("Are you sure you want to remove \"%s\"", comic.Title),
OnYes: fmt.Sprintf("/remove/%d/confirmed", i),
OnNo: "/",
})
if err != nil {
return500(w, r)
return
}
return
}
err = deleteComic(comic.ID)
if err != nil {
return500(w, r)
return
}
http.Redirect(w, r, fmt.Sprintf("http://%s:%d", options.Address, options.Port), http.StatusSeeOther)
}
func managerPublishView(w http.ResponseWriter, r * http.Request) {
return500(w, r)
}
func managerEditView(w http.ResponseWriter, r * http.Request) {
}
func startManager(address string, port int, dbPath string, mediaPath string) error {
http.HandleFunc("/", managerIndexView)
http.HandleFunc("/remove/", managerRemoveView)
http.HandleFunc("/publish", managerPublishView)
http.HandleFunc("/edit/", managerEditView)
uri := fmt.Sprintf("%s:%d", address, port)

19
templates/confirm.html Normal file
View File

@ -0,0 +1,19 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<link rel="icon" type="/image/png" href="/static/img/favicon.png"/>
<link rel="stylesheet" href="/static/css/confirm.css">
<link rel="stylesheet" href="/static/css/base.css">
<title>{{ .Action }}</title>
</head>
<body>
<div class="confirm">
<h1>{{ .Message }}</h1>
<div class="options">
<a href="{{ .OnYes }}"><p>Yes</p></a>
<a href="{{ .OnNo }}"><p>No</p></a>
</div>
</div>
</body>
</html>

View File

@ -1,28 +1,39 @@
{{ define "top" }}
<div class="manager-top">
<div class="logging-buttom">
<a href="/logout">
<h1>{{ .UserName }} &ltLogout&gt</h1>
</a>
</div>
</div>
{{ end }}
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<link rel="icon" type="/image/png" href="/static/img/favicon.png"/>
<link rel="stylesheet" href="/static/css/publish.css">
<link rel="stylesheet" href="/static/css/manager.css">
<link rel="stylesheet" href="/static/css/base.css">
<link rel="stylesheet" href="/static/css/top.css">
<title>Black Ram Comic Manager</title>
<title>{{ .Title }}</title>
</head>
<body>
<div class="manager-top">
<div class="logging-buttom">
<a href="/logout">
<h1>User &ltLogout&gt</h1>
</a>
</div>
<div class="create-button">
<a href="/create">
<h1>Create</h1>
</a>
</div>
{{ template "top" . }}
<div class="manager-publish">
<form action="/publish" method="post" enctype="multipart/form-data">
<label for="title">&ltTitle&gt</label>
<input type="text" class="title" name="title" onkeypress="return event.keyCode != 13;">
<input type="file" name="image" style="display:none;" id="browse">
<label type="submit" class="browse fake-button" for="browse" class="fake-button"
accept=".jpg, .jpeg, .png">Browse</label>
<input type="submit" style="display:none;" id="publish">
<label type="submit" class="publish fake-button" for="publish">Publish</label>
</form>
</div>
{{ if .Comics }}
<div class="manager-list">
<table>
<tr>
@ -31,6 +42,7 @@
<th scope="col">&ltImage&gt</th>
<th scope="col">&ltActions&gt</th>
</tr>
{{ if .Comics }}
{{ range $comic := .Comics }}
<tr>
<td>{{ $comic.Title }}</td>
@ -41,14 +53,13 @@
</a>
</td>
<td class="actions">
<a href="/edit/{{ $comic.No }}">Edit</a>
<a href="/remove/{{ $comic.No }}">Remove</a>
<a href="/edit/{{ $comic.No }}">&ltEdit&gt</a>
<a href="/remove/{{ $comic.No }}">&ltRemove&gt</a>
</td>
</tr>
{{ end }}
{{ end }}
</table>
</div>
{{ end }}
</body>
</html>
</html>

View File

View File

@ -24,7 +24,7 @@
background-color: #282828;
}
.create-button {
.publish-button {
margin-left: auto;
}

View File

@ -0,0 +1,59 @@
.manager-publish .title {
outline: none;
border: none;
background: none;
color: #ebdbb2;
font-size: 1.5em;
font-weight: bold;
word-break: break-word;
border-bottom: 0.125em solid #ebdbb2;
}
.manager-publish label {
margin-top: 0.25em;
margin-bottom: 0.25em;
}
.manager-publish {
display: flex;
margin-top: 1em;
margin-bottom: 1em;
}
.manager-publish label {
text-align: center;
width: 100%;
display: inline-block;
font-size: 30px;
background-color: #ebdbb2;
color: #282828;
text-transform: uppercase;
font-weight: bold;
}
.manager-publish label:hover {
color: #ebdbb2;
background-color: #282828;
}
.manager-publish input {
padding: 0;
margin: 0;
}
.manager-publish .description {
height: 5em;
}
.manager-publish * {
width: 100%;
}
.manager-publish .description {
width: 100%;
display: flex;
}
.fake-button {
cursor:pointer;
}