From 2356ddad28d50aacc8bbb3e020792d3b92f2fb4d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Guillot?= Date: Sat, 2 Dec 2017 19:32:14 -0800 Subject: [PATCH] Add Pinboard integration --- integration/pinboard/pinboard.go | 45 +++++++++++ locale/translations.go | 13 ++- locale/translations/fr_FR.json | 9 ++- model/integration.go | 14 ++++ reader/http/client.go | 53 +++++++----- server/routes.go | 2 + server/static/bin.go | 2 +- server/static/css.go | 6 +- server/static/css/common.css | 10 ++- server/static/js.go | 11 ++- server/static/js/app.js | 37 +++++++++ server/template/common.go | 2 +- server/template/html/category_entries.html | 9 +++ server/template/html/create_user.html | 2 +- server/template/html/edit_user.html | 2 +- server/template/html/entry.html | 9 +++ server/template/html/feed_entries.html | 9 +++ server/template/html/history.html | 9 +++ server/template/html/integrations.html | 27 +++++++ server/template/html/unread.html | 9 +++ server/template/views.go | 94 +++++++++++++++++++--- server/ui/controller/integrations.go | 87 +++++++++++++++++++- server/ui/form/integration.go | 37 +++++++++ sql/schema_version_5.sql | 8 ++ sql/sql.go | 12 ++- storage/integration.go | 78 ++++++++++++++++++ storage/migration.go | 2 +- storage/user.go | 1 + 28 files changed, 550 insertions(+), 49 deletions(-) create mode 100644 integration/pinboard/pinboard.go create mode 100644 model/integration.go create mode 100644 server/ui/form/integration.go create mode 100644 sql/schema_version_5.sql create mode 100644 storage/integration.go diff --git a/integration/pinboard/pinboard.go b/integration/pinboard/pinboard.go new file mode 100644 index 00000000..41794836 --- /dev/null +++ b/integration/pinboard/pinboard.go @@ -0,0 +1,45 @@ +// Copyright 2017 Frédéric Guillot. All rights reserved. +// Use of this source code is governed by the Apache 2.0 +// license that can be found in the LICENSE file. + +package pinboard + +import ( + "fmt" + "net/url" + + "github.com/miniflux/miniflux2/reader/http" +) + +// Client represents a Pinboard token. +type Client struct { + authToken string +} + +// AddBookmark sends a link to Pinboard. +func (c *Client) AddBookmark(link, title, tags string, markAsUnread bool) error { + toRead := "no" + if markAsUnread { + toRead = "yes" + } + + values := url.Values{} + values.Add("auth_token", c.authToken) + values.Add("url", link) + values.Add("description", title) + values.Add("tags", tags) + values.Add("toread", toRead) + + client := http.NewClient("https://api.pinboard.in/v1/posts/add?" + values.Encode()) + response, err := client.Get() + if response.HasServerFailure() { + return fmt.Errorf("unable to send bookmark to pinboard, status=%d", response.StatusCode) + } + + return err +} + +// NewClient returns a new Pinboard client. +func NewClient(authToken string) *Client { + return &Client{authToken: authToken} +} diff --git a/locale/translations.go b/locale/translations.go index 95530182..49c241c0 100644 --- a/locale/translations.go +++ b/locale/translations.go @@ -1,5 +1,5 @@ // Code generated by go generate; DO NOT EDIT. -// 2017-12-02 16:12:47.287568844 -0800 PST m=+0.033078160 +// 2017-12-02 19:31:37.042505019 -0800 PST m=+0.027446145 package locale @@ -153,12 +153,19 @@ var translations = map[string]string{ "Invalid theme.": "Le thème est invalide.", "Entry Sorting": "Ordre des éléments", "Older entries first": "Ancien éléments en premier", - "Recent entries first": "Éléments récents en premier" + "Recent entries first": "Éléments récents en premier", + "Saving...": "Enregistrement...", + "Done!": "Terminé !", + "Save this article": "Sauvegarder cet article", + "Mark bookmark as unread": "Marquer le lien comme non lu", + "Pinboard Tags": "Libellés de Pinboard", + "Pinboard API Token": "Jeton de sécurité de l'API de Pinboard", + "Enable Pinboard": "Activer Pinboard" } `, } var translationsChecksums = map[string]string{ "en_US": "6fe95384260941e8a5a3c695a655a932e0a8a6a572c1e45cb2b1ae8baa01b897", - "fr_FR": "5c054c06fa687f05fd4f6041b002207fe1fe304d6c0c0d094b8caa61a5071ba5", + "fr_FR": "fce31dfc3b8d45ee1c5d0c7aca4449553a8228a2428491e5cf5cf9e507dddb31", } diff --git a/locale/translations/fr_FR.json b/locale/translations/fr_FR.json index 08f07292..c349a99d 100644 --- a/locale/translations/fr_FR.json +++ b/locale/translations/fr_FR.json @@ -137,5 +137,12 @@ "Invalid theme.": "Le thème est invalide.", "Entry Sorting": "Ordre des éléments", "Older entries first": "Ancien éléments en premier", - "Recent entries first": "Éléments récents en premier" + "Recent entries first": "Éléments récents en premier", + "Saving...": "Enregistrement...", + "Done!": "Terminé !", + "Save this article": "Sauvegarder cet article", + "Mark bookmark as unread": "Marquer le lien comme non lu", + "Pinboard Tags": "Libellés de Pinboard", + "Pinboard API Token": "Jeton de sécurité de l'API de Pinboard", + "Enable Pinboard": "Activer Pinboard" } diff --git a/model/integration.go b/model/integration.go new file mode 100644 index 00000000..91a45958 --- /dev/null +++ b/model/integration.go @@ -0,0 +1,14 @@ +// Copyright 2017 Frédéric Guillot. All rights reserved. +// Use of this source code is governed by the Apache 2.0 +// license that can be found in the LICENSE file. + +package model + +// Integration represents user integration settings. +type Integration struct { + UserID int64 + PinboardEnabled bool + PinboardToken string + PinboardTags string + PinboardMarkAsUnread bool +} diff --git a/reader/http/client.go b/reader/http/client.go index de0558cf..3b4488f9 100644 --- a/reader/http/client.go +++ b/reader/http/client.go @@ -23,22 +23,17 @@ type Client struct { url string etagHeader string lastModifiedHeader string + username string + password string Insecure bool } // Get execute a GET HTTP request. -func (h *Client) Get() (*Response, error) { - defer helper.ExecutionTime(time.Now(), fmt.Sprintf("[HttpClient:Get] url=%s", h.url)) - u, _ := url.Parse(h.url) +func (c *Client) Get() (*Response, error) { + defer helper.ExecutionTime(time.Now(), fmt.Sprintf("[HttpClient:Get] url=%s", c.url)) - req := &http.Request{ - URL: u, - Method: http.MethodGet, - Header: h.buildHeaders(), - } - - client := h.buildClient() - resp, err := client.Do(req) + client := c.buildClient() + resp, err := client.Do(c.buildRequest()) if err != nil { return nil, err } @@ -53,7 +48,7 @@ func (h *Client) Get() (*Response, error) { } log.Println("[HttpClient:Get]", - "OriginalURL:", h.url, + "OriginalURL:", c.url, "StatusCode:", response.StatusCode, "ETag:", response.ETag, "LastModified:", response.LastModified, @@ -63,9 +58,24 @@ func (h *Client) Get() (*Response, error) { return response, err } -func (h *Client) buildClient() http.Client { +func (c *Client) buildRequest() *http.Request { + link, _ := url.Parse(c.url) + request := &http.Request{ + URL: link, + Method: http.MethodGet, + Header: c.buildHeaders(), + } + + if c.username != "" && c.password != "" { + request.SetBasicAuth(c.username, c.password) + } + + return request +} + +func (c *Client) buildClient() http.Client { client := http.Client{Timeout: time.Duration(requestTimeout * time.Second)} - if h.Insecure { + if c.Insecure { client.Transport = &http.Transport{ TLSClientConfig: &tls.Config{InsecureSkipVerify: true}, } @@ -74,16 +84,16 @@ func (h *Client) buildClient() http.Client { return client } -func (h *Client) buildHeaders() http.Header { +func (c *Client) buildHeaders() http.Header { headers := make(http.Header) headers.Add("User-Agent", userAgent) - if h.etagHeader != "" { - headers.Add("If-None-Match", h.etagHeader) + if c.etagHeader != "" { + headers.Add("If-None-Match", c.etagHeader) } - if h.lastModifiedHeader != "" { - headers.Add("If-Modified-Since", h.lastModifiedHeader) + if c.lastModifiedHeader != "" { + headers.Add("If-Modified-Since", c.lastModifiedHeader) } return headers @@ -94,6 +104,11 @@ func NewClient(url string) *Client { return &Client{url: url, Insecure: false} } +// NewClientWithCredentials returns a new HTTP client that require authentication. +func NewClientWithCredentials(url, username, password string) *Client { + return &Client{url: url, Insecure: false, username: username, password: password} +} + // NewClientWithCacheHeaders returns a new HTTP client that send cache headers. func NewClientWithCacheHeaders(url, etagHeader, lastModifiedHeader string) *Client { return &Client{url: url, etagHeader: etagHeader, lastModifiedHeader: lastModifiedHeader, Insecure: false} diff --git a/server/routes.go b/server/routes.go index 903f24c4..5cb1e998 100644 --- a/server/routes.go +++ b/server/routes.go @@ -91,6 +91,7 @@ func getRoutes(cfg *config.Config, store *storage.Storage, feedHandler *feed.Han router.Handle("/category/{categoryID}/entry/{entryID}", uiHandler.Use(uiController.ShowCategoryEntry)).Name("categoryEntry").Methods("GET") router.Handle("/entry/status", uiHandler.Use(uiController.UpdateEntriesStatus)).Name("updateEntriesStatus").Methods("POST") + router.Handle("/entry/save/{entryID}", uiHandler.Use(uiController.SaveEntry)).Name("saveEntry").Methods("POST") router.Handle("/categories", uiHandler.Use(uiController.ShowCategories)).Name("categories").Methods("GET") router.Handle("/category/create", uiHandler.Use(uiController.CreateCategory)).Name("createCategory").Methods("GET") @@ -117,6 +118,7 @@ func getRoutes(cfg *config.Config, store *storage.Storage, feedHandler *feed.Han router.Handle("/bookmarklet", uiHandler.Use(uiController.Bookmarklet)).Name("bookmarklet").Methods("GET") router.Handle("/integrations", uiHandler.Use(uiController.ShowIntegrations)).Name("integrations").Methods("GET") + router.Handle("/integration", uiHandler.Use(uiController.UpdateIntegration)).Name("updateIntegration").Methods("POST") router.Handle("/sessions", uiHandler.Use(uiController.ShowSessions)).Name("sessions").Methods("GET") router.Handle("/sessions/{sessionID}/remove", uiHandler.Use(uiController.RemoveSession)).Name("removeSession").Methods("POST") diff --git a/server/static/bin.go b/server/static/bin.go index 21cd59fb..ab92ae30 100644 --- a/server/static/bin.go +++ b/server/static/bin.go @@ -1,5 +1,5 @@ // Code generated by go generate; DO NOT EDIT. -// 2017-12-02 16:12:47.261744369 -0800 PST m=+0.007253685 +// 2017-12-02 19:31:37.021832102 -0800 PST m=+0.006773228 package static diff --git a/server/static/css.go b/server/static/css.go index d30f2758..243ba82c 100644 --- a/server/static/css.go +++ b/server/static/css.go @@ -1,14 +1,14 @@ // Code generated by go generate; DO NOT EDIT. -// 2017-12-02 16:12:47.265273764 -0800 PST m=+0.010783080 +// 2017-12-02 19:31:37.024320147 -0800 PST m=+0.009261273 package static var Stylesheets = map[string]string{ "black": `body{background:#222;color:#efefef}h1,h2,h3{color:#aaa}a{color:#aaa}a:focus,a:hover{color:#ddd}.header li{border-color:#333}.header a{color:#ddd;font-weight:400}.header .active a{font-weight:400;color:#9b9494}.header a:focus,.header a:hover{color:rgba(82,168,236,.85)}.page-header h1{border-color:#333}.logo a:hover span{color:#555}table,th,td{border:1px solid #555}th{background:#333;color:#aaa;font-weight:400}tr:hover{background-color:#333;color:#aaa}input[type=url],input[type=password],input[type=text]{border:1px solid #555;background:#333;color:#ccc}input[type=url]:focus,input[type=password]:focus,input[type=text]:focus{color:#efefef;border-color:rgba(82,168,236,.8);box-shadow:0 0 8px rgba(82,168,236,.6)}.button-primary{border-color:#444;background:#333;color:#efefef}.button-primary:hover,.button-primary:focus{border-color:#888;background:#555}.alert,.alert-success,.alert-error,.alert-info,.alert-normal{color:#efefef;background-color:#333;border-color:#444}.panel{background:#333;border-color:#555}.unread-counter{color:#bbb}.category{color:#efefef;background-color:#333;border-color:#444}.category a{color:#999}.category a:hover,.category a:focus{color:#aaa}.pagination a{color:#aaa}.pagination-bottom{border-color:#333}.item{border-color:#666;padding:4px}.item.current-item{border-width:2px;border-color:rgba(82,168,236,.8);box-shadow:0 0 8px rgba(82,168,236,.6)}.item-title a{font-weight:400}.item-status-read .item-title a{color:#666}.item-status-read .item-title a:focus,.item-status-read .item-title a:hover{color:rgba(82,168,236,.6)}.item-meta a:hover,.item-meta a:focus{color:#aaa}.item-meta li:after{color:#ddd}.entry header{border-color:#333}.entry header h1 a{color:#bbb}.entry-content,.entry-content p,ul{color:#999}.entry-content pre,.entry-content code{color:#fff;background:#555;border-color:#888}.entry-enclosure{border-color:#333}`, - "common": `*{margin:0;padding:0;box-sizing:border-box}body{font-family:helvetica neue,Helvetica,Arial,sans-serif;text-rendering:optimizeLegibility}main{padding-left:5px;padding-right:5px}a{color:#36c}a:focus{outline:0;color:red;text-decoration:none;border:1px dotted #aaa}a:hover{color:#333;text-decoration:none}.header{margin-top:10px;margin-bottom:20px}.header nav ul{display:none}.header li{cursor:pointer;padding-left:10px;line-height:2.1em;font-size:1.2em;border-bottom:1px dotted #ddd}.header li:hover a{color:#888}.header a{font-size:.9em;color:#444;text-decoration:none;border:0}.header .active a{font-weight:600}.header a:hover,.header a:focus{color:#888}.page-header{margin-bottom:25px}.page-header h1{font-weight:500;border-bottom:1px dotted #ddd}.page-header ul{margin-left:25px}.page-header li{list-style-type:circle;line-height:1.8em}.logo{cursor:pointer;text-align:center}.logo a{color:#000;letter-spacing:1px}.logo a:hover{color:#396}.logo a span{color:#396}.logo a:hover span{color:#000}@media(min-width:600px){body{margin:auto;max-width:750px}.logo{text-align:left;float:left;margin-right:15px}.header nav ul{display:block}.header li{display:inline;padding:0;padding-right:15px;line-height:normal;border:0;font-size:1em}.page-header ul{margin-left:0}.page-header li{display:inline;padding-right:15px}}table{width:100%;border-collapse:collapse}table,th,td{border:1px solid #ddd}th,td{padding:5px;text-align:left}td{vertical-align:top}th{background:#fcfcfc}tr:hover{background-color:#f9f9f9}.column-40{width:40%}.column-25{width:25%}.column-20{width:20%}label{cursor:pointer;display:block}.radio-group{line-height:1.9em}div.radio-group label{display:inline-block}select{margin-bottom:15px}input[type=url],input[type=password],input[type=text]{border:1px solid #ccc;padding:3px;line-height:20px;width:250px;font-size:99%;margin-bottom:10px;margin-top:5px;-webkit-appearance:none}input[type=url]:focus,input[type=password]:focus,input[type=text]:focus{color:#000;border-color:rgba(82,168,236,.8);outline:0;box-shadow:0 0 8px rgba(82,168,236,.6)}::-moz-placeholder,::-ms-input-placeholder,::-webkit-input-placeholder{color:#ddd;padding-top:2px}.form-help{font-size:.9em;color:brown;margin-bottom:15px}a.button{text-decoration:none}.button{display:inline-block;-webkit-appearance:none;-moz-appearance:none;font-size:1.1em;cursor:pointer;padding:3px 10px;border:1px solid;border-radius:unset}.button-primary{border-color:#3079ed;background:#4d90fe;color:#fff}.button-primary:hover,.button-primary:focus{border-color:#2f5bb7;background:#357ae8}.button-danger{border-color:#b0281a;background:#d14836;color:#fff}.button-danger:hover,.button-danger:focus{color:#fff;background:#c53727}.button:disabled{color:#ccc;background:#f7f7f7;border-color:#ccc}.buttons{margin-top:10px;margin-bottom:20px}.alert{padding:8px 35px 8px 14px;margin-bottom:20px;color:#c09853;background-color:#fcf8e3;border:1px solid #fbeed5;border-radius:4px;overflow:auto}.alert h3{margin-top:0;margin-bottom:15px}.alert-success{color:#468847;background-color:#dff0d8;border-color:#d6e9c6}.alert-error{color:#b94a48;background-color:#f2dede;border-color:#eed3d7}.alert-error a{color:#b94a48}.alert-info{color:#3a87ad;background-color:#d9edf7;border-color:#bce8f1}.panel{color:#333;background-color:#f0f0f0;border:1px solid #ddd;border-radius:5px;padding:10px;margin-bottom:15px}.panel h3{font-weight:500;margin-top:0;margin-bottom:20px}.panel ul{margin-left:30px}.login-form{margin:50px auto 0;max-width:280px}.unread-counter{font-size:.8em;font-weight:300;color:#666}.category{font-size:.75em;background-color:#fffcd7;border:1px solid #d5d458;border-radius:5px;margin-left:.25em;padding:1px .4em;white-space:nowrap}.category a{color:#555;text-decoration:none}.category a:hover,.category a:focus{color:#000}.pagination{font-size:1.1em;display:flex;align-items:center;padding-top:8px}.pagination-bottom{border-top:1px dotted #ddd;margin-bottom:15px;margin-top:50px}.pagination>div{flex:1}.pagination-next{text-align:right}.pagination-prev:before{content:"« "}.pagination-next:after{content:" »"}.pagination a{color:#333}.pagination a:hover,.pagination a:focus{text-decoration:none}.item{border:1px dotted #ddd;margin-bottom:20px;padding:5px;overflow:hidden}.item.current-item{border:3px solid #bce;padding:3px}.item-title a{text-decoration:none;font-weight:600}.item-status-read .item-title a{color:#777}.item-meta{color:#777;font-size:.8em}.item-meta a{color:#777;text-decoration:none}.item-meta a:hover,.item-meta a:focus{color:#333}.item-meta ul{margin-top:5px}.item-meta li{display:inline}.item-meta li:after{content:"|";color:#aaa}.item-meta li:last-child:after{content:""}.hide-read-items .item-status-read{display:none}.entry header{padding-bottom:5px;border-bottom:1px dotted #ddd}.entry header h1{font-size:2em;line-height:1.25em;margin:30px 0}.entry header h1 a{text-decoration:none;color:#333}.entry header h1 a:hover,.entry header h1 a:focus{color:#666}.entry-meta{font-size:.95em;margin:0 0 20px;color:#666;overflow-wrap:break-word}.entry-website img{vertical-align:top}.entry-website a{color:#666;vertical-align:top;text-decoration:none}.entry-website a:hover,.entry-website a:focus{text-decoration:underline}.entry-date{font-size:.65em;font-style:italic;color:#555}.entry-content{padding-top:15px;font-size:1.2em;font-weight:300;font-family:Georgia,times new roman,Times,serif;color:#555;line-height:1.4em;overflow-wrap:break-word}.entry-content h1,h2,h3,h4,h5,h6{margin-top:15px;margin-bottom:10px}.entry-content iframe,.entry-content video,.entry-content img{max-width:100%}.entry-content figure img{border:1px solid #000}.entry-content figcaption{font-size:.75em;text-transform:uppercase;color:#777}.entry-content p{margin-top:10px;margin-bottom:15px}.entry-content a{overflow-wrap:break-word}.entry-content a:visited{color:purple}.entry-content dt{font-weight:500;margin-top:15px;color:#555}.entry-content dd{margin-left:15px;margin-top:5px;padding-left:20px;border-left:3px solid #ddd;color:#777;font-weight:300;line-height:1.4em}.entry-content blockquote{border-left:4px solid #ddd;padding-left:25px;margin-left:20px;margin-top:20px;margin-bottom:20px;color:#888;line-height:1.4em;font-family:Georgia,serif}.entry-content blockquote+p{color:#555;font-style:italic;font-weight:200}.entry-content q{color:purple;font-family:Georgia,serif;font-style:italic}.entry-content q:before{content:"“"}.entry-content q:after{content:"”"}.entry-content pre{padding:5px;background:#f0f0f0;border:1px solid #ddd;overflow:scroll;overflow-wrap:initial}.entry-content table{table-layout:fixed;max-width:100%}.entry-content ul,.entry-content ol{margin-left:30px}.entry-content ul{list-style-type:square}.entry-enclosures h3{font-weight:500}.entry-enclosure{border:1px dotted #ddd;padding:5px;margin-top:10px;max-width:100%}.entry-enclosure-download{font-size:.85em}.enclosure-video video,.enclosure-image img{max-width:100%}.confirm{font-weight:500;color:#ed2d04}.confirm a{color:#ed2d04}.loading{font-style:italic}.bookmarklet{border:1px dashed #ccc;border-radius:5px;padding:15px;margin:15px;text-align:center}.bookmarklet a{font-weight:600;text-decoration:none;font-size:1.2em}`, + "common": `*{margin:0;padding:0;box-sizing:border-box}body{font-family:helvetica neue,Helvetica,Arial,sans-serif;text-rendering:optimizeLegibility}main{padding-left:5px;padding-right:5px}a{color:#36c}a:focus{outline:0;color:red;text-decoration:none;border:1px dotted #aaa}a:hover{color:#333;text-decoration:none}.header{margin-top:10px;margin-bottom:20px}.header nav ul{display:none}.header li{cursor:pointer;padding-left:10px;line-height:2.1em;font-size:1.2em;border-bottom:1px dotted #ddd}.header li:hover a{color:#888}.header a{font-size:.9em;color:#444;text-decoration:none;border:0}.header .active a{font-weight:600}.header a:hover,.header a:focus{color:#888}.page-header{margin-bottom:25px}.page-header h1{font-weight:500;border-bottom:1px dotted #ddd}.page-header ul{margin-left:25px}.page-header li{list-style-type:circle;line-height:1.8em}.logo{cursor:pointer;text-align:center}.logo a{color:#000;letter-spacing:1px}.logo a:hover{color:#396}.logo a span{color:#396}.logo a:hover span{color:#000}@media(min-width:600px){body{margin:auto;max-width:750px}.logo{text-align:left;float:left;margin-right:15px}.header nav ul{display:block}.header li{display:inline;padding:0;padding-right:15px;line-height:normal;border:0;font-size:1em}.page-header ul{margin-left:0}.page-header li{display:inline;padding-right:15px}}table{width:100%;border-collapse:collapse}table,th,td{border:1px solid #ddd}th,td{padding:5px;text-align:left}td{vertical-align:top}th{background:#fcfcfc}tr:hover{background-color:#f9f9f9}.column-40{width:40%}.column-25{width:25%}.column-20{width:20%}label{cursor:pointer;display:block}.radio-group{line-height:1.9em}div.radio-group label{display:inline-block}select{margin-bottom:15px}input[type=url],input[type=password],input[type=text]{border:1px solid #ccc;padding:3px;line-height:20px;width:250px;font-size:99%;margin-bottom:10px;margin-top:5px;-webkit-appearance:none}input[type=url]:focus,input[type=password]:focus,input[type=text]:focus{color:#000;border-color:rgba(82,168,236,.8);outline:0;box-shadow:0 0 8px rgba(82,168,236,.6)}input[type=checkbox]{margin-bottom:10px}::-moz-placeholder,::-ms-input-placeholder,::-webkit-input-placeholder{color:#ddd;padding-top:2px}.form-help{font-size:.9em;color:brown;margin-bottom:15px}a.button{text-decoration:none}.button{display:inline-block;-webkit-appearance:none;-moz-appearance:none;font-size:1.1em;cursor:pointer;padding:3px 10px;border:1px solid;border-radius:unset}.button-primary{border-color:#3079ed;background:#4d90fe;color:#fff}.button-primary:hover,.button-primary:focus{border-color:#2f5bb7;background:#357ae8}.button-danger{border-color:#b0281a;background:#d14836;color:#fff}.button-danger:hover,.button-danger:focus{color:#fff;background:#c53727}.button:disabled{color:#ccc;background:#f7f7f7;border-color:#ccc}.buttons{margin-top:10px;margin-bottom:20px}.alert{padding:8px 35px 8px 14px;margin-bottom:20px;color:#c09853;background-color:#fcf8e3;border:1px solid #fbeed5;border-radius:4px;overflow:auto}.alert h3{margin-top:0;margin-bottom:15px}.alert-success{color:#468847;background-color:#dff0d8;border-color:#d6e9c6}.alert-error{color:#b94a48;background-color:#f2dede;border-color:#eed3d7}.alert-error a{color:#b94a48}.alert-info{color:#3a87ad;background-color:#d9edf7;border-color:#bce8f1}.panel{color:#333;background-color:#fcfcfc;border:1px solid #ddd;border-radius:5px;padding:10px;margin-bottom:15px}.panel h3{font-weight:500;margin-top:0;margin-bottom:20px}.panel ul{margin-left:30px}.login-form{margin:50px auto 0;max-width:280px}.unread-counter{font-size:.8em;font-weight:300;color:#666}.category{font-size:.75em;background-color:#fffcd7;border:1px solid #d5d458;border-radius:5px;margin-left:.25em;padding:1px .4em;white-space:nowrap}.category a{color:#555;text-decoration:none}.category a:hover,.category a:focus{color:#000}.pagination{font-size:1.1em;display:flex;align-items:center;padding-top:8px}.pagination-bottom{border-top:1px dotted #ddd;margin-bottom:15px;margin-top:50px}.pagination>div{flex:1}.pagination-next{text-align:right}.pagination-prev:before{content:"« "}.pagination-next:after{content:" »"}.pagination a{color:#333}.pagination a:hover,.pagination a:focus{text-decoration:none}.item{border:1px dotted #ddd;margin-bottom:20px;padding:5px;overflow:hidden}.item.current-item{border:3px solid #bce;padding:3px}.item-title a{text-decoration:none;font-weight:600}.item-status-read .item-title a{color:#777}.item-meta{color:#777;font-size:.8em}.item-meta a{color:#777;text-decoration:none}.item-meta a:hover,.item-meta a:focus{color:#333}.item-meta ul{margin-top:5px}.item-meta li{display:inline}.item-meta li:after{content:"|";color:#aaa}.item-meta li:last-child:after{content:""}.hide-read-items .item-status-read{display:none}.entry header{padding-bottom:5px;border-bottom:1px dotted #ddd}.entry header h1{font-size:2em;line-height:1.25em;margin:30px 0}.entry header h1 a{text-decoration:none;color:#333}.entry header h1 a:hover,.entry header h1 a:focus{color:#666}.entry-actions{margin-bottom:20px}.entry-meta{font-size:.95em;margin:0 0 20px;color:#666;overflow-wrap:break-word}.entry-website img{vertical-align:top}.entry-website a{color:#666;vertical-align:top;text-decoration:none}.entry-website a:hover,.entry-website a:focus{text-decoration:underline}.entry-date{font-size:.65em;font-style:italic;color:#555}.entry-content{padding-top:15px;font-size:1.2em;font-weight:300;font-family:Georgia,times new roman,Times,serif;color:#555;line-height:1.4em;overflow-wrap:break-word}.entry-content h1,h2,h3,h4,h5,h6{margin-top:15px;margin-bottom:10px}.entry-content iframe,.entry-content video,.entry-content img{max-width:100%}.entry-content figure img{border:1px solid #000}.entry-content figcaption{font-size:.75em;text-transform:uppercase;color:#777}.entry-content p{margin-top:10px;margin-bottom:15px}.entry-content a{overflow-wrap:break-word}.entry-content a:visited{color:purple}.entry-content dt{font-weight:500;margin-top:15px;color:#555}.entry-content dd{margin-left:15px;margin-top:5px;padding-left:20px;border-left:3px solid #ddd;color:#777;font-weight:300;line-height:1.4em}.entry-content blockquote{border-left:4px solid #ddd;padding-left:25px;margin-left:20px;margin-top:20px;margin-bottom:20px;color:#888;line-height:1.4em;font-family:Georgia,serif}.entry-content blockquote+p{color:#555;font-style:italic;font-weight:200}.entry-content q{color:purple;font-family:Georgia,serif;font-style:italic}.entry-content q:before{content:"“"}.entry-content q:after{content:"”"}.entry-content pre{padding:5px;background:#f0f0f0;border:1px solid #ddd;overflow:scroll;overflow-wrap:initial}.entry-content table{table-layout:fixed;max-width:100%}.entry-content ul,.entry-content ol{margin-left:30px}.entry-content ul{list-style-type:square}.entry-enclosures h3{font-weight:500}.entry-enclosure{border:1px dotted #ddd;padding:5px;margin-top:10px;max-width:100%}.entry-enclosure-download{font-size:.85em}.enclosure-video video,.enclosure-image img{max-width:100%}.confirm{font-weight:500;color:#ed2d04}.confirm a{color:#ed2d04}.loading{font-style:italic}.bookmarklet{border:1px dashed #ccc;border-radius:5px;padding:15px;margin:15px;text-align:center}.bookmarklet a{font-weight:600;text-decoration:none;font-size:1.2em}`, } var StylesheetsChecksums = map[string]string{ "black": "38e7fee92187a036ce37f3c15fde2deff59a55c5ab693c7b8578af79d6a117d2", - "common": "921e622bf833cb8a843766b4bf71263e4cf8cc4a0c8678692b363a2d3b44f465", + "common": "af622cd4416dd93c3192a00c0123a37bd1880ef19d0e9f519e55c86533b10043", } diff --git a/server/static/css/common.css b/server/static/css/common.css index 411ab8f5..b1b523da 100644 --- a/server/static/css/common.css +++ b/server/static/css/common.css @@ -222,6 +222,10 @@ input[type="text"]:focus { box-shadow: 0 0 8px rgba(82, 168, 236, 0.6); } +input[type="checkbox"] { + margin-bottom: 10px; +} + ::-moz-placeholder, ::-ms-input-placeholder, ::-webkit-input-placeholder { @@ -327,7 +331,7 @@ a.button { /* Panel */ .panel { color: #333; - background-color: #f0f0f0; + background-color: #fcfcfc; border: 1px solid #ddd; border-radius: 5px; padding: 10px; @@ -497,6 +501,10 @@ a.button { color: #666; } +.entry-actions { + margin-bottom: 20px; +} + .entry-meta { font-size: 0.95em; margin: 0 0 20px; diff --git a/server/static/js.go b/server/static/js.go index a0c535a7..a5a795f2 100644 --- a/server/static/js.go +++ b/server/static/js.go @@ -1,5 +1,5 @@ // Code generated by go generate; DO NOT EDIT. -// 2017-12-02 16:12:47.268772139 -0800 PST m=+0.014281455 +// 2017-12-02 19:31:37.026479459 -0800 PST m=+0.011420585 package static @@ -42,13 +42,16 @@ getCsrfToken(){let element=document.querySelector("meta[name=X-CSRF-Token]");if( return "";} execute(){fetch(new Request(this.url,this.options)).then((response)=>{if(this.callback){this.callback(response);}});}} class EntryHandler{static updateEntriesStatus(entryIDs,status){let url=document.body.dataset.entriesStatusUrl;let request=new RequestBuilder(url);request.withBody({entry_ids:entryIDs,status:status});request.execute();} -static toggleEntryStatus(element){let entryID=parseInt(element.dataset.id,10);let statuses={read:"unread",unread:"read"};for(let currentStatus in statuses){let newStatus=statuses[currentStatus];if(element.classList.contains("item-status-"+currentStatus)){element.classList.remove("item-status-"+currentStatus);element.classList.add("item-status-"+newStatus);this.updateEntriesStatus([entryID],newStatus);break;}}}} +static toggleEntryStatus(element){let entryID=parseInt(element.dataset.id,10);let statuses={read:"unread",unread:"read"};for(let currentStatus in statuses){let newStatus=statuses[currentStatus];if(element.classList.contains("item-status-"+currentStatus)){element.classList.remove("item-status-"+currentStatus);element.classList.add("item-status-"+newStatus);this.updateEntriesStatus([entryID],newStatus);break;}}} +static saveEntry(element){if(element.dataset.completed){return;} +element.innerHTML=element.dataset.labelLoading;let request=new RequestBuilder(element.dataset.saveUrl);request.withCallback(()=>{element.innerHTML=element.dataset.labelDone;element.dataset.completed=true;});request.execute();}} class ConfirmHandler{remove(url){let request=new RequestBuilder(url);request.withCallback(()=>window.location.reload());request.execute();} handle(event){let questionElement=document.createElement("span");let linkElement=event.target;let containerElement=linkElement.parentNode;linkElement.style.display="none";let yesElement=document.createElement("a");yesElement.href="#";yesElement.appendChild(document.createTextNode(linkElement.dataset.labelYes));yesElement.onclick=(event)=>{event.preventDefault();let loadingElement=document.createElement("span");loadingElement.className="loading";loadingElement.appendChild(document.createTextNode(linkElement.dataset.labelLoading));questionElement.remove();containerElement.appendChild(loadingElement);this.remove(linkElement.dataset.url);};let noElement=document.createElement("a");noElement.href="#";noElement.appendChild(document.createTextNode(linkElement.dataset.labelNo));noElement.onclick=(event)=>{event.preventDefault();linkElement.style.display="inline";questionElement.remove();};questionElement.className="confirm";questionElement.appendChild(document.createTextNode(linkElement.dataset.labelQuestion+" "));questionElement.appendChild(yesElement);questionElement.appendChild(document.createTextNode(", "));questionElement.appendChild(noElement);containerElement.appendChild(questionElement);}} class MenuHandler{clickMenuListItem(event){let element=event.target;if(element.tagName==="A"){window.location.href=element.getAttribute("href");}else{window.location.href=element.querySelector("a").getAttribute("href");}} toggleMainMenu(){let menu=document.querySelector(".header nav ul");if(DomHelper.isVisible(menu)){menu.style.display="none";}else{menu.style.display="block";}}} class NavHandler{markPageAsRead(){let items=DomHelper.getVisibleElements(".items .item");let entryIDs=[];items.forEach((element)=>{element.classList.add("item-status-read");entryIDs.push(parseInt(element.dataset.id,10));});if(entryIDs.length>0){EntryHandler.updateEntriesStatus(entryIDs,"read");} this.goToPage("next");} +saveEntry(){if(this.isListView()){let currentItem=document.querySelector(".current-item");if(currentItem!==null){let saveLink=currentItem.querySelector("a[data-save-entry]");if(saveLink){EntryHandler.saveEntry(saveLink);}}}else{let saveLink=document.querySelector("a[data-save-entry]");if(saveLink){EntryHandler.saveEntry(saveLink);}}} toggleEntryStatus(){let currentItem=document.querySelector(".current-item");if(currentItem!==null){EntryHandler.toggleEntryStatus(currentItem);this.goToNextListItem();}} openOriginalLink(){let entryLink=document.querySelector(".entry h1 a");if(entryLink!==null){DomHelper.openNewTab(entryLink.getAttribute("href"));return;} let currentItemOriginalLink=document.querySelector(".current-item a[data-original-link]");if(currentItemOriginalLink!==null){DomHelper.openNewTab(currentItemOriginalLink.getAttribute("href"));}} @@ -65,9 +68,9 @@ if(document.querySelector(".current-item")===null){items[0].classList.add("curre for(let i=0;inavHandler.goToPage("unread"));keyboardHandler.on("g h",()=>navHandler.goToPage("history"));keyboardHandler.on("g f",()=>navHandler.goToPage("feeds"));keyboardHandler.on("g c",()=>navHandler.goToPage("categories"));keyboardHandler.on("g s",()=>navHandler.goToPage("settings"));keyboardHandler.on("ArrowLeft",()=>navHandler.goToPrevious());keyboardHandler.on("ArrowRight",()=>navHandler.goToNext());keyboardHandler.on("j",()=>navHandler.goToPrevious());keyboardHandler.on("p",()=>navHandler.goToPrevious());keyboardHandler.on("k",()=>navHandler.goToNext());keyboardHandler.on("n",()=>navHandler.goToNext());keyboardHandler.on("h",()=>navHandler.goToPage("previous"));keyboardHandler.on("l",()=>navHandler.goToPage("next"));keyboardHandler.on("o",()=>navHandler.openSelectedItem());keyboardHandler.on("v",()=>navHandler.openOriginalLink());keyboardHandler.on("m",()=>navHandler.toggleEntryStatus());keyboardHandler.on("A",()=>navHandler.markPageAsRead());keyboardHandler.listen();let mouseHandler=new MouseHandler();mouseHandler.onClick("a[data-on-click=markPageAsRead]",()=>navHandler.markPageAsRead());mouseHandler.onClick("a[data-confirm]",(event)=>{(new ConfirmHandler()).handle(event);});if(document.documentElement.clientWidth<600){let menuHandler=new MenuHandler();mouseHandler.onClick(".logo",()=>menuHandler.toggleMainMenu());mouseHandler.onClick(".header nav li",(event)=>menuHandler.clickMenuListItem(event));}});})();`, +document.addEventListener("DOMContentLoaded",function(){FormHandler.handleSubmitButtons();let touchHandler=new TouchHandler();touchHandler.listen();let navHandler=new NavHandler();let keyboardHandler=new KeyboardHandler();keyboardHandler.on("g u",()=>navHandler.goToPage("unread"));keyboardHandler.on("g h",()=>navHandler.goToPage("history"));keyboardHandler.on("g f",()=>navHandler.goToPage("feeds"));keyboardHandler.on("g c",()=>navHandler.goToPage("categories"));keyboardHandler.on("g s",()=>navHandler.goToPage("settings"));keyboardHandler.on("ArrowLeft",()=>navHandler.goToPrevious());keyboardHandler.on("ArrowRight",()=>navHandler.goToNext());keyboardHandler.on("j",()=>navHandler.goToPrevious());keyboardHandler.on("p",()=>navHandler.goToPrevious());keyboardHandler.on("k",()=>navHandler.goToNext());keyboardHandler.on("n",()=>navHandler.goToNext());keyboardHandler.on("h",()=>navHandler.goToPage("previous"));keyboardHandler.on("l",()=>navHandler.goToPage("next"));keyboardHandler.on("o",()=>navHandler.openSelectedItem());keyboardHandler.on("v",()=>navHandler.openOriginalLink());keyboardHandler.on("m",()=>navHandler.toggleEntryStatus());keyboardHandler.on("A",()=>navHandler.markPageAsRead());keyboardHandler.on("s",()=>navHandler.saveEntry());keyboardHandler.listen();let mouseHandler=new MouseHandler();mouseHandler.onClick("a[data-save-entry]",(event)=>{event.preventDefault();EntryHandler.saveEntry(event.target);});mouseHandler.onClick("a[data-on-click=markPageAsRead]",()=>navHandler.markPageAsRead());mouseHandler.onClick("a[data-confirm]",(event)=>{(new ConfirmHandler()).handle(event);});if(document.documentElement.clientWidth<600){let menuHandler=new MenuHandler();mouseHandler.onClick(".logo",()=>menuHandler.toggleMainMenu());mouseHandler.onClick(".header nav li",(event)=>menuHandler.clickMenuListItem(event));}});})();`, } var JavascriptChecksums = map[string]string{ - "app": "e1a955eaf7c0672da771ddbb87090bd7831197c46c5508349aa87a955f7814f6", + "app": "ce9791d6752f8b09f6163907e5ba01092f76595d6f99d611858216d6533f4655", } diff --git a/server/static/js/app.js b/server/static/js/app.js index 40611eca..0fd65a5f 100644 --- a/server/static/js/app.js +++ b/server/static/js/app.js @@ -298,6 +298,21 @@ class EntryHandler { } } } + + static saveEntry(element) { + if (element.dataset.completed) { + return; + } + + element.innerHTML = element.dataset.labelLoading; + + let request = new RequestBuilder(element.dataset.saveUrl); + request.withCallback(() => { + element.innerHTML = element.dataset.labelDone; + element.dataset.completed = true; + }); + request.execute(); + } } class ConfirmHandler { @@ -386,6 +401,23 @@ class NavHandler { this.goToPage("next"); } + saveEntry() { + if (this.isListView()) { + let currentItem = document.querySelector(".current-item"); + if (currentItem !== null) { + let saveLink = currentItem.querySelector("a[data-save-entry]"); + if (saveLink) { + EntryHandler.saveEntry(saveLink); + } + } + } else { + let saveLink = document.querySelector("a[data-save-entry]"); + if (saveLink) { + EntryHandler.saveEntry(saveLink); + } + } + } + toggleEntryStatus() { let currentItem = document.querySelector(".current-item"); if (currentItem !== null) { @@ -520,9 +552,14 @@ document.addEventListener("DOMContentLoaded", function() { keyboardHandler.on("v", () => navHandler.openOriginalLink()); keyboardHandler.on("m", () => navHandler.toggleEntryStatus()); keyboardHandler.on("A", () => navHandler.markPageAsRead()); + keyboardHandler.on("s", () => navHandler.saveEntry()); keyboardHandler.listen(); let mouseHandler = new MouseHandler(); + mouseHandler.onClick("a[data-save-entry]", (event) => { + event.preventDefault(); + EntryHandler.saveEntry(event.target); + }); mouseHandler.onClick("a[data-on-click=markPageAsRead]", () => navHandler.markPageAsRead()); mouseHandler.onClick("a[data-confirm]", (event) => { (new ConfirmHandler()).handle(event); diff --git a/server/template/common.go b/server/template/common.go index 461f8e5e..e7fa6fcb 100644 --- a/server/template/common.go +++ b/server/template/common.go @@ -1,5 +1,5 @@ // Code generated by go generate; DO NOT EDIT. -// 2017-12-02 16:12:47.286110197 -0800 PST m=+0.031619513 +// 2017-12-02 19:31:37.041375649 -0800 PST m=+0.026316775 package template diff --git a/server/template/html/category_entries.html b/server/template/html/category_entries.html index 77d27255..d86b1037 100644 --- a/server/template/html/category_entries.html +++ b/server/template/html/category_entries.html @@ -35,6 +35,15 @@
  • +
  • + {{ t "Save" }} +
  • {{ t "Original" }}
  • diff --git a/server/template/html/create_user.html b/server/template/html/create_user.html index 225dfaa1..8faab49e 100644 --- a/server/template/html/create_user.html +++ b/server/template/html/create_user.html @@ -35,7 +35,7 @@ - +
    {{ t "or" }} {{ t "cancel" }} diff --git a/server/template/html/edit_user.html b/server/template/html/edit_user.html index dbbd852e..66119434 100644 --- a/server/template/html/edit_user.html +++ b/server/template/html/edit_user.html @@ -38,7 +38,7 @@ - +
    {{ t "or" }} {{ t "cancel" }} diff --git a/server/template/html/entry.html b/server/template/html/entry.html index 7c190d3b..06e01842 100644 --- a/server/template/html/entry.html +++ b/server/template/html/entry.html @@ -6,6 +6,15 @@

    {{ .entry.Title }}

    +
    + {{ t "Save" }} +