From ff4248b09e1bcd48bb6346df123d5de68cf20e8d Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Fri, 3 Nov 2023 08:33:35 +0300 Subject: [PATCH] add wip UI/backend stuff to filter feed tree --- classes/Pref_Feeds.php | 13 +++------- index.php | 1 + js/App.js | 3 +++ js/Feeds.js | 55 +++++++++++++++++++++++++++++++++++++++++- 4 files changed, 62 insertions(+), 10 deletions(-) diff --git a/classes/Pref_Feeds.php b/classes/Pref_Feeds.php index 60da4f18c..36c9bcbc5 100644 --- a/classes/Pref_Feeds.php +++ b/classes/Pref_Feeds.php @@ -39,12 +39,7 @@ class Pref_Feeds extends Handler_Protected { /** * @return array> */ - private function get_category_items(int $cat_id): array { - - if (clean($_REQUEST['mode'] ?? 0) != 2) - $search = $_SESSION["prefs_feed_search"] ?? ""; - else - $search = ""; + private function get_category_items(int $cat_id, string $search): array { // first one is set by API $show_empty_cats = self::_param_to_bool($_REQUEST['force_show_empty'] ?? false) || @@ -64,7 +59,7 @@ class Pref_Feeds extends Handler_Protected { 'id' => 'CAT:' . $feed_category->id, 'bare_id' => (int)$feed_category->id, 'name' => $feed_category->title, - 'items' => $this->get_category_items($feed_category->id), + 'items' => $this->get_category_items($feed_category->id, $search), 'checkbox' => false, 'type' => 'category', 'unread' => -1, @@ -121,7 +116,7 @@ class Pref_Feeds extends Handler_Protected { if (clean($_REQUEST['mode'] ?? 0) != 2) $search = $_SESSION["prefs_feed_search"] ?? ""; else - $search = ""; + $search = $_REQUEST['search'] ?? ''; $root = array(); $root['id'] = 'root'; @@ -226,7 +221,7 @@ class Pref_Feeds extends Handler_Protected { 'bare_id' => (int) $feed_category->id, 'auxcounter' => -1, 'name' => $feed_category->title, - 'items' => $this->get_category_items($feed_category->id), + 'items' => $this->get_category_items($feed_category->id, $search), 'checkbox' => false, 'type' => 'category', 'unread' => -1, diff --git a/index.php b/index.php index b7c039d7a..e9f85264e 100644 --- a/index.php +++ b/index.php @@ -263,6 +263,7 @@
+
diff --git a/js/App.js b/js/App.js index 9d3f6a47d..de653e306 100644 --- a/js/App.js +++ b/js/App.js @@ -1270,6 +1270,9 @@ const App = { case "qmcSearch": Feeds.search(); break; + case "qmcFilterFeeds": + Feeds.filter(); + break; case "qmcAddFeed": CommonDialogs.subscribeToFeed(); break; diff --git a/js/Feeds.js b/js/Feeds.js index a6eecaf81..2cc5586b3 100644 --- a/js/Feeds.js +++ b/js/Feeds.js @@ -23,6 +23,7 @@ const Feeds = { infscroll_in_progress: 0, infscroll_disabled: 0, _infscroll_timeout: false, + _filter_query: false, // TODO: figure out the UI for this _search_query: false, last_search_query: [], _viewfeed_wait_timeout: false, @@ -154,6 +155,10 @@ const Feeds = { toggle: function() { Element.toggle("feeds-holder"); }, + cancelFilter: function() { + this._filter_query = ""; + this.reload(); + }, cancelSearch: function() { this._search_query = ""; this.reloadCurrent(); @@ -178,8 +183,14 @@ const Feeds = { dijit.byId("feedTree").destroyRecursive(); } + let query = {op: 'Pref_Feeds', method: 'getfeedtree', mode: 2}; + + if (this._filter_query) { + query = Object.assign(query, this._filter_query); + } + const store = new dojo.data.ItemFileWriteStore({ - url: "backend.php?op=Pref_Feeds&method=getfeedtree&mode=2" + url: "backend.php?" + dojo.objectToQuery(query) }); // noinspection JSUnresolvedFunction @@ -682,6 +693,48 @@ const Feeds = { } }); + }, + filter: function() { + const dialog = new fox.SingleUseDialog({ + content: ` +
+
+
+ +
+
+ + +
+ `, + title: __("Search feeds"), + execute: function () { + if (this.validate()) { + Feeds._filter_query = this.attr('value'); + + this.hide(); + Feeds.reload(); + } + }, + }); + + const tmph = dojo.connect(dialog, 'onShow', function () { + dojo.disconnect(tmph); + + if (Feeds._filter_query && Feeds._filter_query.search) { + dijit.byId('filter_query') + .attr('value', Feeds._filter_query.search); + } + }); + + dialog.show(); + }, updateRandom: function() { console.log("in update_random_feed");