Compare commits
7 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 79280135a1 | |||
| 4422f3840e | |||
| ffcf7c0438 | |||
| a910aac946 | |||
| eed41aebbb | |||
| 037be4d7e8 | |||
| 6cf327226d |
@@ -21,6 +21,7 @@ type BookmarkManager struct {
|
||||
type SearchOptions struct {
|
||||
Query string
|
||||
Tags []string
|
||||
Sort string
|
||||
}
|
||||
|
||||
func NewBookmarkManager(db *DB) *BookmarkManager {
|
||||
@@ -138,10 +139,32 @@ func (m *BookmarkManager) Search(opts SearchOptions) ([]entity.Bookmark, error)
|
||||
bhQuery = bolthold.Query(*bhQuery.And("Tags").ContainsAll(bolthold.Slice(opts.Tags)...))
|
||||
}
|
||||
|
||||
reverse := false
|
||||
sortOrder := opts.Sort
|
||||
if sortOrder != "" && sortOrder[0] == '-' {
|
||||
reverse = true
|
||||
sortOrder = sortOrder[1:]
|
||||
}
|
||||
|
||||
if sortOrder == "title" {
|
||||
bhQuery.SortBy("Info.Title")
|
||||
} else if sortOrder == "created" {
|
||||
bhQuery.SortBy("TimestampCreated")
|
||||
} else if sortOrder == "scraped" {
|
||||
bhQuery.SortBy("TimestampLastScraped")
|
||||
} else {
|
||||
bhQuery.SortBy("ID")
|
||||
}
|
||||
|
||||
if reverse {
|
||||
bhQuery = *bhQuery.Reverse()
|
||||
}
|
||||
|
||||
out := []entity.Bookmark{}
|
||||
err := m.db.store.ForEach(&bhQuery,
|
||||
func(bm *entity.Bookmark) error {
|
||||
out = append(out, *bm)
|
||||
|
||||
return nil
|
||||
})
|
||||
if err != nil {
|
||||
|
||||
@@ -8,7 +8,7 @@ import (
|
||||
"golang.org/x/mod/semver"
|
||||
)
|
||||
|
||||
const Tag = "v0.0.21"
|
||||
const Tag = "v0.0.24"
|
||||
|
||||
var versionInfo struct {
|
||||
Local struct {
|
||||
|
||||
@@ -13,8 +13,9 @@
|
||||
</div>
|
||||
</div>
|
||||
{{ template "tags_widget.html" . }}
|
||||
{{ template "manage_results.html" . }}
|
||||
|
||||
</form>
|
||||
{{ template "manage_results.html" . }}
|
||||
|
||||
</div>
|
||||
</div>
|
||||
@@ -2,10 +2,10 @@
|
||||
<table id="manage-results">
|
||||
<tr>
|
||||
<th> </th>
|
||||
<th>title/url</th>
|
||||
{{ template "manage_results_column_header.html" .column.title }}
|
||||
<th>tags</th>
|
||||
<th class="show-for-large">created</th>
|
||||
<th class="show-for-large">scraped</th>
|
||||
{{ template "manage_results_column_header.html" .column.created }}
|
||||
{{ template "manage_results_column_header.html" .column.scraped }}
|
||||
</tr>
|
||||
{{ range .bookmarks }}
|
||||
<tr>
|
||||
|
||||
3
web/templates/manage_results_column_header.html
Normal file
3
web/templates/manage_results_column_header.html
Normal file
@@ -0,0 +1,3 @@
|
||||
|
||||
<th class="{{ .Class }}" hx-post="/manage/results?sort={{ .URLString }}" hx-target="#manage-results">{{ .Name }} {{ .TitleArrow }}
|
||||
</th>
|
||||
57
web/web.go
57
web/web.go
@@ -42,6 +42,29 @@ type Server struct {
|
||||
bmm *db.BookmarkManager
|
||||
}
|
||||
|
||||
type ColumnInfo struct {
|
||||
Name string
|
||||
Param string
|
||||
Sorted string
|
||||
Class string
|
||||
}
|
||||
|
||||
func (c ColumnInfo) URLString() string {
|
||||
if c.Sorted == "asc" {
|
||||
return "-" + c.Param
|
||||
}
|
||||
return c.Param
|
||||
}
|
||||
|
||||
func (c ColumnInfo) TitleArrow() string {
|
||||
if c.Sorted == "asc" {
|
||||
return "↑"
|
||||
} else if c.Sorted == "desc" {
|
||||
return "↓"
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
// Create creates a new web server instance and sets up routing.
|
||||
func Create(bmm *db.BookmarkManager, cmm *db.ConfigManager) *Server {
|
||||
|
||||
@@ -92,13 +115,42 @@ func Create(bmm *db.BookmarkManager, cmm *db.ConfigManager) *Server {
|
||||
r.POST("/manage/results", func(c *gin.Context) {
|
||||
query := c.PostForm("query")
|
||||
tags := []string{}
|
||||
sort := c.Query("sort")
|
||||
|
||||
if c.PostForm("tags_hidden") != "" {
|
||||
tags = strings.Split(c.PostForm("tags_hidden"), "|")
|
||||
}
|
||||
allBookmarks, _ := bmm.Search(db.SearchOptions{Query: query, Tags: tags})
|
||||
allBookmarks, _ := bmm.Search(db.SearchOptions{Query: query, Tags: tags, Sort: sort})
|
||||
meta := gin.H{"config": config, "bookmarks": allBookmarks}
|
||||
|
||||
log.Printf("query is %s, tags %v", query, tags)
|
||||
colTitle := &ColumnInfo{Name: "Title/URL", Param: "title"}
|
||||
colCreated := &ColumnInfo{Name: "Created", Param: "created", Class: "show-for-large"}
|
||||
colScraped := &ColumnInfo{Name: "Scraped", Param: "scraped", Class: "show-for-large"}
|
||||
if sort == "title" {
|
||||
colTitle.Sorted = "asc"
|
||||
}
|
||||
if sort == "-title" {
|
||||
colTitle.Sorted = "desc"
|
||||
}
|
||||
if sort == "scraped" {
|
||||
colScraped.Sorted = "asc"
|
||||
}
|
||||
if sort == "-scraped" {
|
||||
colScraped.Sorted = "desc"
|
||||
}
|
||||
if sort == "created" {
|
||||
colCreated.Sorted = "asc"
|
||||
}
|
||||
if sort == "-created" {
|
||||
colCreated.Sorted = "desc"
|
||||
}
|
||||
|
||||
cols := gin.H{
|
||||
"title": colTitle,
|
||||
"created": colCreated,
|
||||
"scraped": colScraped,
|
||||
}
|
||||
meta["column"] = cols
|
||||
|
||||
c.HTML(http.StatusOK,
|
||||
"manage_results.html", meta,
|
||||
@@ -374,6 +426,7 @@ func niceTime(t time.Time) timeVariations {
|
||||
panic(err)
|
||||
}
|
||||
ago := durafmt.Parse(time.Since(t)).LimitFirstN(1).Format(units)
|
||||
ago = strings.ReplaceAll(ago, " ", "")
|
||||
|
||||
return timeVariations{HumanDuration: ago}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user