From 6d0dc451e45effc8cbb6953a766b111036d893ce Mon Sep 17 00:00:00 2001 From: Frédéric Guillot Date: Wed, 4 Jul 2018 22:05:19 -0700 Subject: Add search form --- daemon/routes.go | 2 + locale/translations.go | 11 +++- locale/translations/fr_FR.json | 7 ++- sql/sql.go | 2 +- storage/entry_pagination_builder.go | 8 +++ template/common.go | 25 +++++--- template/html/common/entry_pagination.html | 4 +- template/html/common/layout.html | 9 +++ template/html/common/pagination.html | 4 +- template/html/search_entries.html | 30 ++++++++++ template/views.go | 34 ++++++++++- ui/entry_search.go | 95 ++++++++++++++++++++++++++++++ ui/pagination.go | 1 + ui/search_entries.go | 66 +++++++++++++++++++++ ui/static/bin.go | 2 +- ui/static/css.go | 10 ++-- ui/static/css/black.css | 5 ++ ui/static/css/common.css | 46 ++++++++++++++- ui/static/js.go | 18 +++--- ui/static/js/app.js | 53 ++++++++++++----- 20 files changed, 383 insertions(+), 49 deletions(-) create mode 100644 template/html/search_entries.html create mode 100644 ui/entry_search.go create mode 100644 ui/search_entries.go diff --git a/daemon/routes.go b/daemon/routes.go index 6f52437..56ee6b9 100644 --- a/daemon/routes.go +++ b/daemon/routes.go @@ -95,6 +95,8 @@ func routes(cfg *config.Config, store *storage.Storage, feedHandler *feed.Handle uiRouter.HandleFunc("/unread", uiController.ShowUnreadPage).Name("unread").Methods("GET") uiRouter.HandleFunc("/history", uiController.ShowHistoryPage).Name("history").Methods("GET") uiRouter.HandleFunc("/starred", uiController.ShowStarredPage).Name("starred").Methods("GET") + uiRouter.HandleFunc("/search", uiController.ShowSearchEntries).Name("searchEntries").Methods("GET") + uiRouter.HandleFunc("/search/entry/{entryID}", uiController.ShowSearchEntry).Name("searchEntry").Methods("GET") uiRouter.HandleFunc("/feed/{feedID}/refresh", uiController.RefreshFeed).Name("refreshFeed").Methods("GET") uiRouter.HandleFunc("/feed/{feedID}/edit", uiController.EditFeed).Name("editFeed").Methods("GET") uiRouter.HandleFunc("/feed/{feedID}/remove", uiController.RemoveFeed).Name("removeFeed").Methods("POST") diff --git a/locale/translations.go b/locale/translations.go index aff5b7c..a14f70e 100755 --- a/locale/translations.go +++ b/locale/translations.go @@ -1,5 +1,5 @@ // Code generated by go generate; DO NOT EDIT. -// 2018-07-04 14:42:27.494264089 -0700 PDT m=+0.053526807 +// 2018-07-04 22:00:22.177727933 -0700 PDT m=+0.039621734 package locale @@ -491,7 +491,12 @@ var translations = map[string]string{ "Feed Password": "Mot de passe du flux", "You are not authorized to access this resource (invalid username/password)": "Vous n'êtes pas autorisé à accéder à cette ressource (nom d'utilisateur / mot de passe incorrect)", "Unable to fetch this resource (Status Code = %d)": "Impossible de récupérer cette ressource (code=%d)", - "Resource not found (404), this feed doesn't exists anymore, check the feed URL": "Page introuvable (404), cet abonnement n'existe plus, vérifiez l'adresse du flux" + "Resource not found (404), this feed doesn't exists anymore, check the feed URL": "Page introuvable (404), cet abonnement n'existe plus, vérifiez l'adresse du flux", + "Search Results": "Résultats de la recherche", + "There is no result for this search.": "Il n'y a aucun résultat pour cette recherche.", + "Search...": "Recherche...", + "Set focus on search form": "Mettre le focus sur le champ de recherche", + "Search": "Recherche" } `, "nl_NL": `{ @@ -1166,7 +1171,7 @@ var translations = map[string]string{ var translationsChecksums = map[string]string{ "de_DE": "eddbb2c3224169a6533eed6f917af95b8d9bee58c3b3d61951260face7edd768", "en_US": "6fe95384260941e8a5a3c695a655a932e0a8a6a572c1e45cb2b1ae8baa01b897", - "fr_FR": "7a451a1d09e051a847f554937e07a6af24b92f1da7f46da8c0ef2d4cc31bcec6", + "fr_FR": "343a148eed375a593023c30597ef7280d18222756c5062e6a85e1006c7b12d14", "nl_NL": "05cca4936bd3b0fa44057c4dab64acdef3aed32fbb682393f254cfe2f686ef1f", "pl_PL": "2295f35a98c8f60cfc6bab241d26b224c06979cc9ca3740bb89c63c7596a0431", "zh_CN": "f5fb0a9b7336c51e74d727a2fb294bab3514e3002376da7fd904e0d7caed1a1c", diff --git a/locale/translations/fr_FR.json b/locale/translations/fr_FR.json index 5270b91..534432c 100644 --- a/locale/translations/fr_FR.json +++ b/locale/translations/fr_FR.json @@ -235,5 +235,10 @@ "Feed Password": "Mot de passe du flux", "You are not authorized to access this resource (invalid username/password)": "Vous n'êtes pas autorisé à accéder à cette ressource (nom d'utilisateur / mot de passe incorrect)", "Unable to fetch this resource (Status Code = %d)": "Impossible de récupérer cette ressource (code=%d)", - "Resource not found (404), this feed doesn't exists anymore, check the feed URL": "Page introuvable (404), cet abonnement n'existe plus, vérifiez l'adresse du flux" + "Resource not found (404), this feed doesn't exists anymore, check the feed URL": "Page introuvable (404), cet abonnement n'existe plus, vérifiez l'adresse du flux", + "Search Results": "Résultats de la recherche", + "There is no result for this search.": "Il n'y a aucun résultat pour cette recherche.", + "Search...": "Recherche...", + "Set focus on search form": "Mettre le focus sur le champ de recherche", + "Search": "Recherche" } diff --git a/sql/sql.go b/sql/sql.go index fae19aa..c7967a1 100644 --- a/sql/sql.go +++ b/sql/sql.go @@ -1,5 +1,5 @@ // Code generated by go generate; DO NOT EDIT. -// 2018-07-04 14:42:27.443758746 -0700 PDT m=+0.003021464 +// 2018-07-04 22:00:22.141197828 -0700 PDT m=+0.003091629 package sql diff --git a/storage/entry_pagination_builder.go b/storage/entry_pagination_builder.go index 72fae8d..e443b00 100644 --- a/storage/entry_pagination_builder.go +++ b/storage/entry_pagination_builder.go @@ -23,6 +23,14 @@ type EntryPaginationBuilder struct { direction string } +// WithSearchQuery adds full-text search query to the condition. +func (e *EntryPaginationBuilder) WithSearchQuery(query string) { + if query != "" { + e.conditions = append(e.conditions, fmt.Sprintf("e.document_vectors @@ plainto_tsquery($%d)", len(e.args)+1)) + e.args = append(e.args, query) + } +} + // WithStarred adds starred to the condition. func (e *EntryPaginationBuilder) WithStarred() { e.conditions = append(e.conditions, "e.starred is true") diff --git a/template/common.go b/template/common.go index 1c0f5e2..be12839 100644 --- a/template/common.go +++ b/template/common.go @@ -1,5 +1,5 @@ // Code generated by go generate; DO NOT EDIT. -// 2018-06-21 15:46:05.07724268 +0200 CEST m=+0.035251547 +// 2018-07-04 22:00:22.176755806 -0700 PDT m=+0.038649607 package template @@ -8,7 +8,7 @@ var templateCommonMap = map[string]string{