Skip to content

Commit b2965f0

Browse files
committed
add password and encryption input
1 parent 6c46f10 commit b2965f0

File tree

6 files changed

+31
-10
lines changed

6 files changed

+31
-10
lines changed

.hintrc

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"extends": [
3+
"development"
4+
],
5+
"hints": {
6+
"axe/forms": [
7+
"default",
8+
{
9+
"label": "off"
10+
}
11+
]
12+
}
13+
}

internal/app/web_handler.go

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

33
import (
4+
"encoding/json"
45
"log/slog"
56
"net/http"
67

@@ -35,10 +36,8 @@ func (r *webHandler) GetById(c *gin.Context) {
3536
id := c.Param("id")
3637
slog.Info("request id", "id", id)
3738
a, _ := r.Service.GetbyId(id)
38-
data := make(map[string]string)
39-
data["content"] = a[0].Content
40-
data["id"] = a[0].Id
41-
c.HTML(http.StatusOK, "index.html", data)
39+
x, _ := json.Marshal(a[0])
40+
c.HTML(http.StatusOK, "index.html", gin.H{"id": id, "data": string(x)})
4241
}
4342

4443
func (r *webHandler) DeleteById(c *gin.Context) {

internal/pkg/.keep

Whitespace-only changes.

internal/pkg/model/form_data.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@ type FormData struct {
44
Id string `form:"id" json:"id"`
55
Content string `form:"content" json:"content"`
66
Password string `form:"password" json:"password"`
7-
IsEncrypted bool `form:"isEncrypted" json:"is_encrypted"`
7+
IsEncrypted bool `form:"is_encrypted" json:"is_encrypted"`
88
}

internal/pkg/util/util.go

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package util
2+
3+
import "encoding/json"
4+
5+
func StructToMap(input interface{}) (result *map[string]interface{}, err error) {
6+
temp, _ := json.Marshal(input)
7+
json.Unmarshal(temp, &result)
8+
return
9+
}

web/template/home/index.html

+5-5
Original file line numberDiff line numberDiff line change
@@ -26,21 +26,21 @@
2626
<div class="flex-none w-14 h-14">
2727

2828
</div>
29-
<div class="grow h-fit" x-data="{ content: '{{.content}}' }" x-init="$refs.contentx.textContent=content">
29+
<div class="grow h-fit" x-data="{{.data}}" x-init="$refs.contentx.textContent=content">
3030
<form hx-post="/save">
3131
<div x-ref="contentx" @input="content = $event.target.textContent" contenteditable="true" class="bg-base-600 w-1/12 min-h-fit overflow-y-auto"></div>
3232
<input title="=" type="hidden" name="content" x-model="content"/>
3333
<!-- <textarea title="content" cols="200" rows="30" class="p-2 border-none outline-none overflow-y-auto bg-base-700 bg-gradient-to-r bg-opacity-50"></textarea> -->
3434
<div class="flex gap-2">
35-
<label for="id">Url</label><input class="text-base-950" id="id" type="text" value="{{.id}}"/>
36-
<label for="password">Password</label><input class="text-base-950" id="password" type="text" value="{{.password}}"/>
37-
<input id="isEncrypted" type="checkbox" value="{{.isEncrypted}}"/><label for="isEncrypted">Encrypt</label>
35+
<label for="id">Url</label><input class="text-base-950" name="id" type="text" x-model="id"/>
36+
<label for="password">Password</label><input class="text-base-950" name="password" type="text" x-model="password"/>
37+
<input name="is_encrypted" type="checkbox" value="true" x-model="is_encrypted"/><label for="is_encrypted">Encrypt</label>
3838
<button type="submit">Save</button>
3939
<button type="button" id="deleteButton">Delete</button>
4040
</div>
4141
</form>
4242
<dialog>
43-
<p>Greetings, one and all!</p>
43+
<p>Do you want to delete?</p>
4444
<form method="dialog">
4545
<button type="button" hx-trigger="click" hx-delete="/{{.id}}">OK</button>
4646
</form>

0 commit comments

Comments
 (0)