From 09a859501fc1fb1f4f781cfdd448f359b7ef4983 Mon Sep 17 00:00:00 2001 From: Adam Mathes Date: Mon, 30 Jan 2017 18:43:29 -0800 Subject: add back in starred functionality, fix login page --- init.sql | 1 + models/item/item.go | 16 +++++++++++----- static/login.html | 6 ------ static/ui.js | 8 +++----- web/web.go | 7 ++++++- 5 files changed, 21 insertions(+), 17 deletions(-) diff --git a/init.sql b/init.sql index 7b01fda..d050359 100644 --- a/init.sql +++ b/init.sql @@ -16,6 +16,7 @@ CREATE TABLE item ( description TEXT, publish_date TIMESTAMP DEFAULT CURRENT_TIMESTAMP NOT NULL, read_state BOOLEAN DEFAULT FALSE NOT NULL, + starred BOOLEAN DEFAULT FALSE NOT NULL, FOREIGN KEY (feed_id) REFERENCES feed(id) ON DELETE CASCADE, UNIQUE KEY (url), INDEX (publish_date), diff --git a/models/item/item.go b/models/item/item.go index 51166c4..3cf8a19 100644 --- a/models/item/item.go +++ b/models/item/item.go @@ -14,6 +14,7 @@ type Item struct { Url string `json:"url"` Description string `json:"description"` ReadState bool `json:"read"` + Starred bool `json:"starred"` FeedId int64 PublishDate string `json:"publish_date"` FeedTitle string `json:"feed_title"` @@ -42,8 +43,8 @@ func (i *Item) Create() error { func (i *Item) Save() { _, err := models.DB.Exec(`UPDATE item - SET read_state=? - WHERE id=?`, i.ReadState, i.Id) + SET read_state=?, starred=? + WHERE id=?`, i.ReadState, i.Starred, i.Id) if err != nil { log.Println(err) } @@ -58,12 +59,12 @@ func (i *Item) FullSave() { } } -func Filter(max_id int64, feed_id int64, unread_only bool) ([]*Item, error) { +func Filter(max_id int64, feed_id int64, unread_only bool, starred_only bool) ([]*Item, error) { var args []interface{} query := `SELECT item.id, item.title, item.url, item.description, - item.read_state, item.publish_date, + item.read_state, item.starred, item.publish_date, feed.url, feed.title FROM item,feed WHERE item.feed_id=feed.id ` @@ -82,6 +83,11 @@ func Filter(max_id int64, feed_id int64, unread_only bool) ([]*Item, error) { query = query + " AND item.read_state=0 " } + if starred_only { + query = query + " AND item.starred=1 " + } + + query = query + "ORDER BY item.id DESC LIMIT 15" // log.Println(query) // log.Println(args...) @@ -102,7 +108,7 @@ func Filter(max_id int64, feed_id int64, unread_only bool) ([]*Item, error) { items := make([]*Item, 0) for rows.Next() { i := new(Item) - err := rows.Scan(&i.Id, &i.Title, &i.Url, &i.Description, &i.ReadState, &i.PublishDate, &i.FeedUrl, &i.FeedTitle) + err := rows.Scan(&i.Id, &i.Title, &i.Url, &i.Description, &i.ReadState, &i.Starred, &i.PublishDate, &i.FeedUrl, &i.FeedTitle) if err != nil { log.Println(err) return nil, err diff --git a/static/login.html b/static/login.html index d97c831..ab3e781 100644 --- a/static/login.html +++ b/static/login.html @@ -3,11 +3,6 @@ neko rss mode - - - - - @@ -19,7 +14,6 @@

password

- diff --git a/static/ui.js b/static/ui.js index 96e285d..6f44db0 100644 --- a/static/ui.js +++ b/static/ui.js @@ -224,9 +224,6 @@ var ItemCollection = Backbone.Collection.extend({ App.loading = true; url = '/stream/'; - if(App.get('starredFilter')) { - url = url + 'starred/'; - } if(App.tag != undefined) { url = url + 'tag/' + App.tag + '/'; } @@ -234,11 +231,12 @@ var ItemCollection = Backbone.Collection.extend({ if(App.get('searchFilter')) { url = url + '&q=' + App.get('searchFilter'); } - if(App.get('feedFilter')) { url = url + '&feed_url=' + App.get('feedFilter').get('url'); } - + if(App.get('starredFilter')) { + url = url + '&starred=1'; + } if(App.items.last()) { url = url + '&max_id=' + App.items.last().get('_id'); } diff --git a/web/web.go b/web/web.go index 2cb9669..1f01241 100644 --- a/web/web.go +++ b/web/web.go @@ -37,8 +37,13 @@ func streamHandler(w http.ResponseWriter, r *http.Request) { unread_only = false } + starred_only := false + if r.FormValue("starred") != "" { + starred_only = true + } + var items []*item.Item - items, err := item.Filter(int64(max_id), feed_id, unread_only) + items, err := item.Filter(int64(max_id), feed_id, unread_only, starred_only) if err != nil { log.Println(err) } -- cgit v1.2.3