2 Commits

Author SHA1 Message Date
037be4d7e8 Bump version 2022-06-07 16:26:39 +09:30
6cf327226d Add basic sorting to management interface 2022-06-07 16:25:45 +09:30
5 changed files with 22 additions and 8 deletions

View File

@@ -21,6 +21,7 @@ type BookmarkManager struct {
type SearchOptions struct { type SearchOptions struct {
Query string Query string
Tags []string Tags []string
Sort string
} }
func NewBookmarkManager(db *DB) *BookmarkManager { func NewBookmarkManager(db *DB) *BookmarkManager {
@@ -138,10 +139,22 @@ func (m *BookmarkManager) Search(opts SearchOptions) ([]entity.Bookmark, error)
bhQuery = bolthold.Query(*bhQuery.And("Tags").ContainsAll(bolthold.Slice(opts.Tags)...)) bhQuery = bolthold.Query(*bhQuery.And("Tags").ContainsAll(bolthold.Slice(opts.Tags)...))
} }
if opts.Sort == "title" {
bhQuery.SortBy("Info.Title")
} else if opts.Sort == "created" {
bhQuery.SortBy("TimestampCreated")
} else if opts.Sort == "scraped" {
bhQuery.SortBy("TimestampLastScraped")
} else {
bhQuery.SortBy("ID")
}
out := []entity.Bookmark{} out := []entity.Bookmark{}
err := m.db.store.ForEach(&bhQuery, err := m.db.store.ForEach(&bhQuery,
func(bm *entity.Bookmark) error { func(bm *entity.Bookmark) error {
out = append(out, *bm) out = append(out, *bm)
return nil return nil
}) })
if err != nil { if err != nil {

View File

@@ -8,7 +8,7 @@ import (
"golang.org/x/mod/semver" "golang.org/x/mod/semver"
) )
const Tag = "v0.0.21" const Tag = "v0.0.22"
var versionInfo struct { var versionInfo struct {
Local struct { Local struct {

View File

@@ -13,8 +13,9 @@
</div> </div>
</div> </div>
{{ template "tags_widget.html" . }} {{ template "tags_widget.html" . }}
</form>
{{ template "manage_results.html" . }} {{ template "manage_results.html" . }}
</form>
</div> </div>
</div> </div>

View File

@@ -2,10 +2,10 @@
<table id="manage-results"> <table id="manage-results">
<tr> <tr>
<th>&nbsp;</th> <th>&nbsp;</th>
<th>title/url</th> <th hx-post="/manage/results?sort=title" hx-target="#manage-results">title/url</th>
<th>tags</th> <th>tags</th>
<th class="show-for-large">created</th> <th hx-post="/manage/results?sort=created" hx-target="#manage-results" class="show-for-large">created</th>
<th class="show-for-large">scraped</th> <th hx-post="/manage/results?sort=scraped" hx-target="#manage-results" class="show-for-large">scraped</th>
</tr> </tr>
{{ range .bookmarks }} {{ range .bookmarks }}
<tr> <tr>

View File

@@ -92,14 +92,14 @@ func Create(bmm *db.BookmarkManager, cmm *db.ConfigManager) *Server {
r.POST("/manage/results", func(c *gin.Context) { r.POST("/manage/results", func(c *gin.Context) {
query := c.PostForm("query") query := c.PostForm("query")
tags := []string{} tags := []string{}
sort := c.Query("sort")
if c.PostForm("tags_hidden") != "" { if c.PostForm("tags_hidden") != "" {
tags = strings.Split(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} meta := gin.H{"config": config, "bookmarks": allBookmarks}
log.Printf("query is %s, tags %v", query, tags)
c.HTML(http.StatusOK, c.HTML(http.StatusOK,
"manage_results.html", meta, "manage_results.html", meta,
) )