From c30533045a6ed9a3edeb555e482132c6b2a76412 Mon Sep 17 00:00:00 2001 From: Tai Groot Date: Wed, 28 Oct 2020 21:44:00 -0700 Subject: [PATCH] feat: allows for searching by tag (note: requires #149) --- src/App.vue | 32 +++++++++++++++++++++++++++++ src/components/SearchInput.vue | 1 + src/components/Service.vue | 2 +- src/components/services/Generic.vue | 12 ++++++++++- src/components/services/PiHole.vue | 10 ++++++++- 5 files changed, 54 insertions(+), 3 deletions(-) diff --git a/src/App.vue b/src/App.vue index d97df0c..8793c5c 100644 --- a/src/App.vue +++ b/src/App.vue @@ -40,6 +40,7 @@ @@ -90,6 +92,7 @@ @@ -210,6 +213,35 @@ export default { console.warning("fail to open service"); } }, + filterTag: function (filter) { + this.showMenu = true; + this.$nextTick(() => { + document.getElementById("searchBox").focus(); + }); + this.filter = filter; + + if (!filter) { + this.services = this.config.services; + return; + } + + const searchResultItems = []; + for (const group of this.config.services) { + for (const item of group.items) { + if (this.matchesFilter(item)) { + searchResultItems.push(item); + } + } + } + + this.services = [ + { + name: filter, + icon: "fas fa-search", + items: searchResultItems, + }, + ]; + }, filterServices: function (filter) { this.filter = filter; diff --git a/src/components/SearchInput.vue b/src/components/SearchInput.vue index 9419db3..c4bef47 100644 --- a/src/components/SearchInput.vue +++ b/src/components/SearchInput.vue @@ -2,6 +2,7 @@ -
+
#{{ item.tag }}
@@ -51,6 +56,9 @@ export default { response.json() ); }, + filterTag: function () { + this.$emit("filter", this.item.tag.toLowerCase()); + }, }, };