From 31da4db14fdda364b1c72460a81e3ccce67ff7e8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Guillot?= Date: Sun, 29 Apr 2018 17:43:40 -0700 Subject: [PATCH] Do not show save link if no integration is configured --- storage/integration.go | 15 +++ template/common.go | 34 +++--- .../{starred.html => bookmark_entries.html} | 2 +- template/html/category_entries.html | 2 +- template/html/common/item_meta.html | 30 ++--- template/html/entry.html | 20 ++-- template/html/feed_entries.html | 2 +- .../{history.html => history_entries.html} | 2 +- .../html/{unread.html => unread_entries.html} | 2 +- template/views.go | 108 +++++++++--------- ui/bookmark_entries.go | 3 +- ui/category_entries.go | 1 + ui/{entry_starred.go => entry_bookmark.go} | 1 + ui/entry_category.go | 1 + ui/entry_feed.go | 1 + ui/entry_read.go | 1 + ui/entry_unread.go | 1 + ui/feed_entries.go | 1 + ui/history_entries.go | 3 +- ui/unread_entries.go | 3 +- 20 files changed, 133 insertions(+), 100 deletions(-) rename template/html/{starred.html => bookmark_entries.html} (97%) rename template/html/{history.html => history_entries.html} (97%) rename template/html/{unread.html => unread_entries.html} (97%) rename ui/{entry_starred.go => entry_bookmark.go} (97%) diff --git a/storage/integration.go b/storage/integration.go index 5a60d857..6a389de9 100644 --- a/storage/integration.go +++ b/storage/integration.go @@ -176,3 +176,18 @@ func (s *Storage) CreateIntegration(userID int64) error { return nil } + +// HasSaveEntry returns true if the given user can save articles to third-parties. +func (s *Storage) HasSaveEntry(userID int64) (result bool) { + query := ` + SELECT true FROM integrations + WHERE user_id=$1 AND + (pinboard_enabled='t' OR instapaper_enabled='t' OR wallabag_enabled='t' OR nunux_keeper_enabled='t') + ` + + if err := s.db.QueryRow(query, userID).Scan(&result); err != nil { + result = false + } + + return result +} diff --git a/template/common.go b/template/common.go index 62645ef0..f573ba15 100644 --- a/template/common.go +++ b/template/common.go @@ -1,5 +1,5 @@ // Code generated by go generate; DO NOT EDIT. -// 2018-04-29 16:22:00.539326448 -0700 PDT m=+0.023616542 +// 2018-04-29 17:36:50.459886967 -0700 PDT m=+0.024552529 package template @@ -32,18 +32,25 @@ var templateCommonMap = map[string]string{
  • -
  • - {{ t "Save" }} -
  • + {{ if .hasSaveEntry }} +
  • + {{ t "Save" }} +
  • + {{ end }}
  • {{ t "Original" }}
  • + {{ if .entry.CommentsURL }} +
  • + {{ t "Comments" }} +
  • + {{ end }}
  • {{ if eq .entry.Status "read" }}✘ {{ t "Unread" }}{{ else }}✔ {{ t "Read" }}{{ end }}
  • - {{ if .entry.CommentsURL }} -
  • - {{ t "Comments" }} -
  • - {{ end }} {{ end }}`, @@ -220,7 +222,7 @@ var templateCommonMap = map[string]string{ var templateCommonMapChecksums = map[string]string{ "entry_pagination": "f1465fa70f585ae8043b200ec9de5bf437ffbb0c19fb7aefc015c3555614ee27", - "item_meta": "c14b5b36076e087346def2ebcef4876ed5e8165218f40dc017db44e754c22d03", + "item_meta": "6cff8ae243f19dac936e523867d2975f70aa749b2a461ae63f6ebbca94cf7419", "layout": "c7565e2cf904612e236bc1d7167c6c124ffe5d27348608eb5c2336606f266896", "pagination": "6ff462c2b2a53bc5448b651da017f40a39f1d4f16cef4b2f09784f0797286924", } diff --git a/template/html/starred.html b/template/html/bookmark_entries.html similarity index 97% rename from template/html/starred.html rename to template/html/bookmark_entries.html index e2a24071..afd81921 100644 --- a/template/html/starred.html +++ b/template/html/bookmark_entries.html @@ -20,7 +20,7 @@ {{ .Feed.Category.Title }} - {{ template "item_meta" dict "user" $.user "entry" . }} + {{ template "item_meta" dict "user" $.user "entry" . "hasSaveEntry" $.hasSaveEntry }} {{ end }} diff --git a/template/html/category_entries.html b/template/html/category_entries.html index 8910f224..41d3c402 100644 --- a/template/html/category_entries.html +++ b/template/html/category_entries.html @@ -27,7 +27,7 @@ {{ .Feed.Category.Title }} - {{ template "item_meta" dict "user" $.user "entry" . }} + {{ template "item_meta" dict "user" $.user "entry" . "hasSaveEntry" $.hasSaveEntry }} {{ end }} diff --git a/template/html/common/item_meta.html b/template/html/common/item_meta.html index 7d83c152..7c43ef55 100644 --- a/template/html/common/item_meta.html +++ b/template/html/common/item_meta.html @@ -7,18 +7,25 @@
  • -
  • - {{ t "Save" }} -
  • + {{ if .hasSaveEntry }} +
  • + {{ t "Save" }} +
  • + {{ end }}
  • {{ t "Original" }}
  • + {{ if .entry.CommentsURL }} +
  • + {{ t "Comments" }} +
  • + {{ end }}
  • {{ if eq .entry.Status "read" }}✘ {{ t "Unread" }}{{ else }}✔ {{ t "Read" }}{{ end }}
  • - {{ if .entry.CommentsURL }} -
  • - {{ t "Comments" }} -
  • - {{ end }} {{ end }} \ No newline at end of file diff --git a/template/html/entry.html b/template/html/entry.html index 55d03908..cc061aa5 100644 --- a/template/html/entry.html +++ b/template/html/entry.html @@ -18,15 +18,17 @@ data-value="{{ if .Starred }}star{{ else }}unstar{{ end }}" >{{ if .entry.Starred }}★ {{ t "Unstar" }}{{ else }}☆ {{ t "Star" }}{{ end }} -
  • - {{ t "Save" }} -
  • + {{ if .hasSaveEntry }} +
  • + {{ t "Save" }} +
  • + {{ end }}
  • {{ .Feed.Category.Title }} - {{ template "item_meta" dict "user" $.user "entry" . }} + {{ template "item_meta" dict "user" $.user "entry" . "hasSaveEntry" $.hasSaveEntry }} {{ end }} diff --git a/template/html/history.html b/template/html/history_entries.html similarity index 97% rename from template/html/history.html rename to template/html/history_entries.html index 3b806da6..ed82dae3 100644 --- a/template/html/history.html +++ b/template/html/history_entries.html @@ -27,7 +27,7 @@ {{ .Feed.Category.Title }} - {{ template "item_meta" dict "user" $.user "entry" . }} + {{ template "item_meta" dict "user" $.user "entry" . "hasSaveEntry" $.hasSaveEntry }} {{ end }} diff --git a/template/html/unread.html b/template/html/unread_entries.html similarity index 97% rename from template/html/unread.html rename to template/html/unread_entries.html index c8e0a8ec..b23049e3 100644 --- a/template/html/unread.html +++ b/template/html/unread_entries.html @@ -30,7 +30,7 @@ {{ .Feed.Category.Title }} - {{ template "item_meta" dict "user" $.user "entry" . }} + {{ template "item_meta" dict "user" $.user "entry" . "hasSaveEntry" $.hasSaveEntry }} {{ end }} diff --git a/template/views.go b/template/views.go index 712dc60b..3c2167ab 100644 --- a/template/views.go +++ b/template/views.go @@ -1,5 +1,5 @@ // Code generated by go generate; DO NOT EDIT. -// 2018-04-29 16:22:00.531039167 -0700 PDT m=+0.015329261 +// 2018-04-29 17:36:50.450844913 -0700 PDT m=+0.015510475 package template @@ -91,6 +91,37 @@ var templateViewsMap = map[string]string{ {{ end }} +{{ end }} +`, + "bookmark_entries": `{{ define "title"}}{{ t "Favorites" }} ({{ .total }}){{ end }} + +{{ define "content"}} + + +{{ if not .entries }} +

    {{ t "There is no bookmark at the moment." }}

    +{{ else }} +
    + {{ range .entries }} +
    +
    + + {{ if ne .Feed.Icon.IconID 0 }} + + {{ end }} + {{ .Title }} + + {{ .Feed.Category.Title }} +
    + {{ template "item_meta" dict "user" $.user "entry" . "hasSaveEntry" $.hasSaveEntry }} +
    + {{ end }} +
    + {{ template "pagination" .pagination }} +{{ end }} + {{ end }} `, "categories": `{{ define "title"}}{{ t "Categories" }} ({{ .total }}){{ end }} @@ -179,7 +210,7 @@ var templateViewsMap = map[string]string{ {{ .Feed.Category.Title }} - {{ template "item_meta" dict "user" $.user "entry" . }} + {{ template "item_meta" dict "user" $.user "entry" . "hasSaveEntry" $.hasSaveEntry }} {{ end }} @@ -483,15 +514,17 @@ var templateViewsMap = map[string]string{ data-value="{{ if .Starred }}star{{ else }}unstar{{ end }}" >{{ if .entry.Starred }}★ {{ t "Unstar" }}{{ else }}☆ {{ t "Star" }}{{ end }}
  • -
  • - {{ t "Save" }} -
  • + {{ if .hasSaveEntry }} +
  • + {{ t "Save" }} +
  • + {{ end }}
  • {{ .Feed.Category.Title }} - {{ template "item_meta" dict "user" $.user "entry" . }} + {{ template "item_meta" dict "user" $.user "entry" . "hasSaveEntry" $.hasSaveEntry }} {{ end }} @@ -705,7 +738,7 @@ var templateViewsMap = map[string]string{ {{ end }} `, - "history": `{{ define "title"}}{{ t "History" }} ({{ .total }}){{ end }} + "history_entries": `{{ define "title"}}{{ t "History" }} ({{ .total }}){{ end }} {{ define "content"}}