Edit/delete bookmarks feature
This commit is contained in:
parent
226fa4a143
commit
173474d23f
@ -39,6 +39,16 @@ func (m *BookmarkManager) AddBookmark(bm *entity.Bookmark) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *BookmarkManager) DeleteBookmark(bm *entity.Bookmark) error {
|
||||
err := m.db.store.FindOne(bm, bolthold.Where("URL").Eq(bm.URL))
|
||||
if err == bolthold.ErrNotFound {
|
||||
return fmt.Errorf("bookmark does not exist")
|
||||
}
|
||||
|
||||
m.db.store.DeleteMatching(bm, bolthold.Where("ID").Eq(bm.ID))
|
||||
return nil
|
||||
}
|
||||
|
||||
// ListBookmarks returns all bookmarks.
|
||||
func (m *BookmarkManager) ListBookmarks() ([]entity.Bookmark, error) {
|
||||
bookmarks := make([]entity.Bookmark, 0, 0)
|
||||
|
@ -53,6 +53,8 @@
|
||||
{{ template "manage.html" . }}
|
||||
{{ else if eq .page "config" }}
|
||||
{{ template "config.html" . }}
|
||||
{{ else if eq .page "edit" }}
|
||||
{{ template "edit.html" . }}
|
||||
{{ end }}
|
||||
{{/* template "foundation_sample.html" . */}}
|
||||
</div>
|
||||
|
7
web/templates/edit.html
Normal file
7
web/templates/edit.html
Normal file
@ -0,0 +1,7 @@
|
||||
<div class="grid-x grid-padding-x">
|
||||
<div class="large-12 cell">
|
||||
|
||||
<h5>Edit</h5>
|
||||
{{ template "edit_form.html" . }}
|
||||
</div>
|
||||
</div>
|
32
web/templates/edit_form.html
Normal file
32
web/templates/edit_form.html
Normal file
@ -0,0 +1,32 @@
|
||||
|
||||
<form onsubmit="return false;" id="edit-form" hx-target="#edit-form">
|
||||
<table>
|
||||
<tr>
|
||||
<th>Title</th>
|
||||
<td>{{ .bookmark.Info.Title }}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th>URL</th>
|
||||
<td>{{ .bookmark.URL }}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th>tags</th>
|
||||
<td>
|
||||
{{ template "tags_widget.html" .tw }}
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<th>Created</th>
|
||||
<td>{{ (nicetime .bookmark.TimestampCreated).HumanDuration }}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th>Last Scraped</th>
|
||||
<td>{{ (nicetime .bookmark.TimestampLastScraped).HumanDuration }}</td>
|
||||
</tr>
|
||||
</table>
|
||||
<p>
|
||||
<button type="button" hx-confirm="Delete this bookmark permanently?" hx-delete="/edit/{{.bookmark.ID}}" class="alert button">delete</button>
|
||||
<button type="button" class="button" hx-post="/edit/{{.bookmark.ID}}">save</button>
|
||||
</p>
|
||||
</form>
|
2
web/templates/edit_form_deleted.html
Normal file
2
web/templates/edit_form_deleted.html
Normal file
@ -0,0 +1,2 @@
|
||||
|
||||
<p>Bookmark deleted</p>
|
@ -5,7 +5,7 @@
|
||||
|
||||
<table>
|
||||
<tr>
|
||||
<th>id</th>
|
||||
<th> </th>
|
||||
<th>title/url</th>
|
||||
<th>tags</th>
|
||||
<th class="show-for-large">created</th>
|
||||
@ -13,7 +13,7 @@
|
||||
</tr>
|
||||
{{ range .bookmarks }}
|
||||
<tr>
|
||||
<th>{{ .ID }}</th>
|
||||
<th><a class="button" href="/edit/{{ .ID }}">edit</a></th>
|
||||
<td>
|
||||
<a href="{{ .URL }}">{{ .Info.Title }}</a>
|
||||
<br>
|
||||
|
@ -5,7 +5,7 @@
|
||||
hx-target="#label-widget"
|
||||
hx-trigger="change">
|
||||
<label for="tag-entry"
|
||||
class="Xtext-right Xmiddle">Tags</label>
|
||||
class="">Tags</label>
|
||||
|
||||
<input id="tag-entry" type="text" name="tag" placeholder="enter tags" />
|
||||
</div>
|
||||
|
62
web/web.go
62
web/web.go
@ -174,7 +174,7 @@ func Create(bmm *db.BookmarkManager, cmm *db.ConfigManager) *Server {
|
||||
|
||||
r.POST("/tags", func(c *gin.Context) {
|
||||
|
||||
newTag := c.PostForm("tag")
|
||||
newTag := c.PostForm("tag") // new tag
|
||||
oldTags := strings.Split(c.PostForm("tags_hidden"), "|")
|
||||
|
||||
remove := c.Query("remove")
|
||||
@ -235,6 +235,66 @@ func Create(bmm *db.BookmarkManager, cmm *db.ConfigManager) *Server {
|
||||
)
|
||||
})
|
||||
|
||||
r.GET("/edit/:id", func(c *gin.Context) {
|
||||
bookmarkIDstring := c.Param("id")
|
||||
bookmarkID, ok := strconv.ParseUint(bookmarkIDstring, 10, 64)
|
||||
if ok != nil {
|
||||
c.String(http.StatusBadRequest, "bad id")
|
||||
return
|
||||
}
|
||||
|
||||
bookmark := bmm.LoadBookmarkByID(bookmarkID)
|
||||
meta := gin.H{"page": "edit", "bookmark": bookmark, "tw": gin.H{"tags": bookmark.Tags, "tags_hidden": strings.Join(bookmark.Tags, "|")}}
|
||||
|
||||
c.HTML(http.StatusOK,
|
||||
"_layout.html", meta,
|
||||
)
|
||||
})
|
||||
|
||||
r.POST("/edit/:id", func(c *gin.Context) {
|
||||
bookmarkIDstring := c.Param("id")
|
||||
bookmarkID, ok := strconv.ParseUint(bookmarkIDstring, 10, 64)
|
||||
if ok != nil {
|
||||
c.String(http.StatusBadRequest, "bad id")
|
||||
return
|
||||
}
|
||||
|
||||
bookmark := bmm.LoadBookmarkByID(bookmarkID)
|
||||
|
||||
// freshen tags
|
||||
if c.PostForm("tags_hidden") == "" {
|
||||
// empty
|
||||
bookmark.Tags = []string{}
|
||||
} else {
|
||||
bookmark.Tags = strings.Split(c.PostForm("tags_hidden"), "|")
|
||||
}
|
||||
bmm.SaveBookmark(&bookmark)
|
||||
|
||||
meta := gin.H{"page": "edit", "bookmark": bookmark, "tw": gin.H{"tags": bookmark.Tags, "tags_hidden": strings.Join(bookmark.Tags, "|")}}
|
||||
|
||||
c.HTML(http.StatusOK,
|
||||
"edit_form.html", meta,
|
||||
)
|
||||
})
|
||||
|
||||
r.DELETE("/edit/:id", func(c *gin.Context) {
|
||||
bookmarkIDstring := c.Param("id")
|
||||
bookmarkID, ok := strconv.ParseUint(bookmarkIDstring, 10, 64)
|
||||
if ok != nil {
|
||||
c.String(http.StatusBadRequest, "bad id")
|
||||
return
|
||||
}
|
||||
|
||||
bookmark := bmm.LoadBookmarkByID(bookmarkID)
|
||||
err := bmm.DeleteBookmark(&bookmark)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
c.HTML(http.StatusOK,
|
||||
"edit_form_deleted.html", nil,
|
||||
)
|
||||
})
|
||||
|
||||
return server
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user