added hide property for bookmarks

This commit is contained in:
milarin 2023-05-17 19:11:37 +02:00
parent b561ca87c8
commit 1c31908aec
6 changed files with 21 additions and 8 deletions

View File

@ -88,6 +88,7 @@ type Bookmark struct {
Link string `json:"link"`
HideBorder bool `json:"hide_border"`
Order int `json:"order"`
Hide bool `json:"hide"`
}
func (b *Bookmark) GetColor() string {

13
db.go
View File

@ -14,11 +14,12 @@ var (
GetSessionByID = advsql.QueryOne(Database, "SELECT * FROM sessions WHERE id = ?", ScanSessionPkFirst)
DeleteSessionsByExpirationDateBefore = advsql.Delete(Database, "DELETE FROM sessions WHERE expiration_date <= ?")
InsertBookmark = advsql.Insert(Database, "INSERT INTO bookmarks VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)", ScanBookmarkPkFirst)
UpdateBookmark = advsql.Update(Database, "UPDATE bookmarks SET link = ?, image = ?, color = ?, image_size = ?, icon_padding = ?, hide_border = ?, order_priority = ? WHERE session_id = ? AND title = ?", ScanBookmarkPkLast)
GetBookmarkBySessionIDAndTitle = advsql.QueryOne(Database, "SELECT * FROM bookmarks WHERE session_id = ? AND title = ?", ScanBookmarkPkFirst)
GetBookmarksBySessionIdOrdered = advsql.QueryMany(Database, "SELECT * FROM bookmarks WHERE session_id = ? ORDER BY order_priority", ScanBookmarkPkFirst)
DeleteBookmarksBySessionID = advsql.Delete(Database, "DELETE FROM bookmarks WHERE session_id = ?")
InsertBookmark = advsql.Insert(Database, "INSERT INTO bookmarks VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", ScanBookmarkPkFirst)
UpdateBookmark = advsql.Update(Database, "UPDATE bookmarks SET link = ?, image = ?, color = ?, image_size = ?, icon_padding = ?, hide_border = ?, order_priority = ? WHERE session_id = ? AND title = ?", ScanBookmarkPkLast)
GetBookmarkBySessionIDAndTitle = advsql.QueryOne(Database, "SELECT * FROM bookmarks WHERE session_id = ? AND title = ?", ScanBookmarkPkFirst)
GetBookmarksBySessionIdOrdered = advsql.QueryMany(Database, "SELECT * FROM bookmarks WHERE session_id = ? ORDER BY order_priority", ScanBookmarkPkFirst)
GetVisibleBookmarksBySessionIdOrdered = advsql.QueryMany(Database, "SELECT * FROM bookmarks WHERE session_id = ? AND hide = 0 ORDER BY order_priority", ScanBookmarkPkFirst)
DeleteBookmarksBySessionID = advsql.Delete(Database, "DELETE FROM bookmarks WHERE session_id = ?")
InsertSettings = advsql.Insert(Database, "INSERT INTO settings VALUES (?, ?, ?, ?, ?, ?)", ScanSettingsPkFirst)
UpdateSettings = advsql.Update(Database, "UPDATE settings SET background_color = ?, foreground_color = ?, search_query = ?, border_radius = ?, bookmark_size = ? WHERE session_id = ?", ScanSettingsPkLast)
@ -65,6 +66,7 @@ func ScanBookmarkPkFirst(u *Bookmark, encode advsql.ScanFunc) error {
&u.IconPadding,
&u.HideBorder,
&u.Order,
&u.Hide,
)
}
@ -77,6 +79,7 @@ func ScanBookmarkPkLast(u *Bookmark, encode advsql.ScanFunc) error {
&u.IconPadding,
&u.HideBorder,
&u.Order,
&u.Hide,
&u.SessionID,
&u.Title,
)

View File

@ -74,7 +74,7 @@ func handler(w http.ResponseWriter, r *http.Request) {
data := &TmplData{
text: GetText(r),
Bookmarks: channel.ToSliceDeref(GetBookmarksBySessionIdOrdered(session.ID)),
Bookmarks: channel.ToSliceDeref(GetVisibleBookmarksBySessionIdOrdered(session.ID)),
Settings: GetSettingsBySessionID(session.ID),
}
@ -178,6 +178,7 @@ func saveChanges(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusInternalServerError)
return
}
for _, bookmark := range sessionData.Bookmarks {
bookmark.SessionID = session.ID
if err := InsertBookmark(&bookmark); err != nil {

View File

@ -68,6 +68,7 @@ function buildDataForBoomark(element) {
const color = form.querySelector("#bookmark-color");
const hideBorder = form.querySelector("#bookmark-border");
const order = form.querySelector("#bookmark-order");
const hide = form.querySelector("#bookmark-hide");
return {
title: title.value,
@ -77,7 +78,8 @@ function buildDataForBoomark(element) {
color: color.value,
link: link.value,
hide_border: hideBorder.checked,
order: parseInt(order.value)
order: parseInt(order.value),
hide: hide.checked
};
}

View File

@ -27,6 +27,9 @@
<label for="bookmark-border">{{ .Translate "Hide border" }}</label>
<input type="checkbox" id="bookmark-border" name="bookmark-border" {{ if .HideBorder }} checked {{ end }} />
<label for="bookmark-hide">{{ .Translate "Hide bookmark" }}</label>
<input type="checkbox" id="bookmark-hide" name="bookmark-hide" {{ if .Hide }} checked {{ end }} />
<label for="bookmark-order">{{ .Translate "Order priority" }}</label>
<input type="number" id="bookmark-order" name="bookmark-order" value="{{ .Order }}" />
</form>

View File

@ -30,6 +30,7 @@ var (
"Foreground color": "Foreground color",
"Border radius": "Border radius",
"Bookmark size": "Size",
"Hide bookmark": "Hide bookmark",
},
},
@ -43,6 +44,7 @@ var (
"Foreground color": "Textfarbe",
"Border radius": "Randradius",
"Bookmark size": "Größe",
"Hide bookmark": "Verstecken",
},
},
@ -56,6 +58,7 @@ var (
"Foreground color": "描画色",
"Border radius": "境界半径",
"Bookmark size": "大小",
"Hide bookmark": "非表示",
},
},
}