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"` Link string `json:"link"`
HideBorder bool `json:"hide_border"` HideBorder bool `json:"hide_border"`
Order int `json:"order"` Order int `json:"order"`
Hide bool `json:"hide"`
} }
func (b *Bookmark) GetColor() string { 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) GetSessionByID = advsql.QueryOne(Database, "SELECT * FROM sessions WHERE id = ?", ScanSessionPkFirst)
DeleteSessionsByExpirationDateBefore = advsql.Delete(Database, "DELETE FROM sessions WHERE expiration_date <= ?") DeleteSessionsByExpirationDateBefore = advsql.Delete(Database, "DELETE FROM sessions WHERE expiration_date <= ?")
InsertBookmark = advsql.Insert(Database, "INSERT INTO bookmarks VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)", ScanBookmarkPkFirst) 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) 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) 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) 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 = ?") 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) 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) 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.IconPadding,
&u.HideBorder, &u.HideBorder,
&u.Order, &u.Order,
&u.Hide,
) )
} }
@ -77,6 +79,7 @@ func ScanBookmarkPkLast(u *Bookmark, encode advsql.ScanFunc) error {
&u.IconPadding, &u.IconPadding,
&u.HideBorder, &u.HideBorder,
&u.Order, &u.Order,
&u.Hide,
&u.SessionID, &u.SessionID,
&u.Title, &u.Title,
) )

View File

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

View File

@ -37,7 +37,7 @@ function main() {
function saveChanges() { function saveChanges() {
const bookmarks = []; const bookmarks = [];
document.querySelectorAll(".customizer").forEach(element => bookmarks.push(buildDataForBoomark(element))); document.querySelectorAll(".customizer").forEach(element => bookmarks.push(buildDataForBoomark(element)));
const settings = { const settings = {
background_color: document.querySelector("#bg-color").value, background_color: document.querySelector("#bg-color").value,
foreground_color: document.querySelector("#fg-color").value, foreground_color: document.querySelector("#fg-color").value,
@ -68,6 +68,7 @@ function buildDataForBoomark(element) {
const color = form.querySelector("#bookmark-color"); const color = form.querySelector("#bookmark-color");
const hideBorder = form.querySelector("#bookmark-border"); const hideBorder = form.querySelector("#bookmark-border");
const order = form.querySelector("#bookmark-order"); const order = form.querySelector("#bookmark-order");
const hide = form.querySelector("#bookmark-hide");
return { return {
title: title.value, title: title.value,
@ -77,7 +78,8 @@ function buildDataForBoomark(element) {
color: color.value, color: color.value,
link: link.value, link: link.value,
hide_border: hideBorder.checked, 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> <label for="bookmark-border">{{ .Translate "Hide border" }}</label>
<input type="checkbox" id="bookmark-border" name="bookmark-border" {{ if .HideBorder }} checked {{ end }} /> <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> <label for="bookmark-order">{{ .Translate "Order priority" }}</label>
<input type="number" id="bookmark-order" name="bookmark-order" value="{{ .Order }}" /> <input type="number" id="bookmark-order" name="bookmark-order" value="{{ .Order }}" />
</form> </form>

View File

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