add wip UI/backend stuff to filter feed tree

This commit is contained in:
Andrew Dolgov 2023-11-03 08:33:35 +03:00
parent 0b7d021f8e
commit ff4248b09e
No known key found for this signature in database
GPG Key ID: 1A56B4FA25D4AF2A
4 changed files with 62 additions and 10 deletions

View File

@ -39,12 +39,7 @@ class Pref_Feeds extends Handler_Protected {
/**
* @return array<int, array<string, bool|int|string>>
*/
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,

View File

@ -263,6 +263,7 @@
<div dojoType="dijit.MenuItem" onclick="App.onActionSelected('qmcPrefs')"><?= __('Preferences...') ?></div>
<div dojoType="dijit.MenuItem" onclick="App.onActionSelected('qmcSearch')"><?= __('Search...') ?></div>
<div dojoType="dijit.MenuItem" onclick="App.onActionSelected('qmcFilterFeeds')"><?= __('Search feeds...') ?></div>
<div dojoType="dijit.MenuItem" disabled="1"><?= __('Feed actions:') ?></div>
<div dojoType="dijit.MenuItem" onclick="App.onActionSelected('qmcAddFeed')"><?= __('Subscribe to feed...') ?></div>
<div dojoType="dijit.MenuItem" onclick="App.onActionSelected('qmcEditFeed')"><?= __('Edit this feed...') ?></div>

View File

@ -1270,6 +1270,9 @@ const App = {
case "qmcSearch":
Feeds.search();
break;
case "qmcFilterFeeds":
Feeds.filter();
break;
case "qmcAddFeed":
CommonDialogs.subscribeToFeed();
break;

View File

@ -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: `
<form onsubmit='return false'>
<section>
<fieldset>
<input dojoType='dijit.form.ValidationTextBox' id='filter_query'
style='font-size : 16px; width : 540px;'
placeHolder="${__("Show feeds matching...")}"
name='search' type='search' value=''>
</fieldset>
</section>
<footer>
${App.FormFields.submit_tag(App.FormFields.icon("search") + " " + __('Search'), {onclick: "App.dialogOf(this).execute()"})}
${App.FormFields.cancel_dialog_tag(__('Cancel'))}
</footer>
</form>
`,
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");