From 261226a3a50c598fcf385c336246e8a97934329c Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Wed, 9 Sep 2015 22:09:03 +0300 Subject: [PATCH] mostly implement async filter test dialog --- classes/pref/filters.php | 29 ++++--- js/prefs.js | 158 +++++++++++++++++++++++---------------- 2 files changed, 113 insertions(+), 74 deletions(-) mode change 100644 => 100755 classes/pref/filters.php mode change 100644 => 100755 js/prefs.js diff --git a/classes/pref/filters.php b/classes/pref/filters.php old mode 100644 new mode 100755 index ec0c3862a..6170f7a08 --- a/classes/pref/filters.php +++ b/classes/pref/filters.php @@ -47,6 +47,7 @@ class Pref_Filters extends Handler_Protected { require_once "include/rssfuncs.php"; $offset = (int) db_escape_string($_REQUEST["offset"]); + $limit = (int) db_escape_string($_REQUEST["limit"]); $filter = array(); @@ -112,6 +113,7 @@ class Pref_Filters extends Handler_Protected { ttrss_feeds.title AS feed_title, ttrss_feed_categories.id AS cat_id, content, + date_entered, link, author, tag_cache @@ -123,7 +125,7 @@ class Pref_Filters extends Handler_Protected { ref_id = ttrss_entries.id AND ($scope_qpart) AND ttrss_user_entries.owner_uid = " . $_SESSION["uid"] . " - ORDER BY date_entered DESC LIMIT 30 OFFSET $offset"); + ORDER BY date_entered DESC LIMIT $limit OFFSET $offset"); while ($line = db_fetch_assoc($result)) { @@ -142,10 +144,10 @@ class Pref_Filters extends Handler_Protected { if ($line["feed_title"]) $feed_title = "(" . $line["feed_title"] . ")"; - $line = ""; - /*foreach ($filter['rules'] as $rule) { + foreach ($filter['rules'] as $rule) { $reg_exp = str_replace('/', '\/', $rule["reg_exp"]); $line["title"] = preg_replace("/($reg_exp)/i", @@ -153,16 +155,21 @@ class Pref_Filters extends Handler_Protected { $content_preview = preg_replace("/($reg_exp)/i", "$1", $content_preview); - }*/ + } - $line .= $line["title"]; - $line .= "
" . $feed_title . "
"; - $line .= "
" . $content_preview . "
"; - $line .= " " . mb_substr($line["date_entered"], 0, 16); + $tmp .= "" . $line["title"] . ""; + $tmp .= "
" . $feed_title . "
"; + $tmp .= "
" . $content_preview . "
"; + $tmp .= " " . mb_substr($line["date_entered"], 0, 16); + $tmp .= ""; - $line .= ""; + array_push($rv, $tmp); + + /*array_push($rv, array("title" => $line["title"], + "content" => $content_preview, + "date" => $line["date_entered"], + "feed" => $line["feed_title"])); */ - array_push($rv, $line); } } @@ -183,7 +190,7 @@ class Pref_Filters extends Handler_Protected { //print __("Articles matching this filter:"); - print "
 Looking for articles...
"; + print "
 Looking for articles...
"; print "
"; print ""; diff --git a/js/prefs.js b/js/prefs.js old mode 100644 new mode 100755 index 797e0e071..ac6ac2066 --- a/js/prefs.js +++ b/js/prefs.js @@ -131,6 +131,100 @@ function editUser(id, event) { } +function editFilterTest(query) { + try { + + if (dijit.byId("filterTestDlg")) + dijit.byId("filterTestDlg").destroyRecursive(); + + var test_dlg = new dijit.Dialog({ + id: "filterTestDlg", + title: "Test Filter", + style: "width: 600px", + results: 0, + limit: 100, + max_offset: 10000, + getTestResults: function(query, offset) { + var updquery = query + "&offset=" + offset + "&limit=" + test_dlg.limit; + + console.log("getTestResults:" + offset); + + new Ajax.Request("backend.php", { + parameters: updquery, + onComplete: function (transport) { + try { + var result = JSON.parse(transport.responseText); + + if (result && dijit.byId("filterTestDlg") && dijit.byId("filterTestDlg").open) { + test_dlg.results += result.size(); + + console.log("got results:" + result.size()); + + $("prefFilterProgressMsg").innerHTML = __("Looking for articles (%d processed, %f found)...") + .replace("%f", test_dlg.results) + .replace("%d", offset); + + console.log(offset + " " + test_dlg.max_offset); + + for (var i = 0; i < result.size(); i++) { + var tmp = new Element("table"); + tmp.innerHTML = result[i]; + dojo.parser.parse(tmp); + + $("prefFilterTestResultList").innerHTML += tmp.innerHTML; + } + + if (test_dlg.results < 30 && offset < test_dlg.max_offset) { + + // get the next batch + window.setTimeout(function () { + test_dlg.getTestResults(query, offset + test_dlg.limit); + }, 0); + + } else { + // all done + + Element.hide("prefFilterLoadingIndicator"); + + if (test_dlg.results == 0) { + $("prefFilterTestResultList").innerHTML = ""; + $("prefFilterProgressMsg").innerHTML = "Articles matching this filter:"; + } else { + $("prefFilterProgressMsg").innerHTML = __("Found %d articles matching this filter:") + .replace("%d", test_dlg.results); + } + + } + + } else if (!result) { + console.log("getTestResults: can't parse results object"); + + Element.hide("prefFilterLoadingIndicator"); + + notify_error("Error while trying to get filter test results."); + + } else { + console.log("getTestResults: dialog closed, bailing out."); + } + } catch (e) { + exception_error("editFilterTest/inner", e); + } + + } }); + }, + href: query}); + + dojo.connect(test_dlg, "onLoad", null, function(e) { + test_dlg.getTestResults(query, 0); + }); + + test_dlg.show(); + + } catch (e) { + exception_error("editFilterTest", e); + } +} + function editFilter(id) { try { @@ -150,69 +244,7 @@ function editFilter(id) { test: function() { var query = "backend.php?" + dojo.formToQuery("filter_edit_form") + "&savemode=test"; - if (dijit.byId("filterTestDlg")) - dijit.byId("filterTestDlg").destroyRecursive(); - - var test_dlg = new dijit.Dialog({ - id: "filterTestDlg", - title: "Test Filter", - style: "width: 600px", - results: 0, - max_offset: 10000, - getTestResults: function(query, offset) { - var updquery = query + "&offset=" + offset; - - console.log("getTestResults:" + offset); - //console.log(updquery); - - new Ajax.Request("backend.php", { - parameters: updquery, - onComplete: function (transport) { - - console.log(transport.responseText); - - var result = JSON.parse(transport.responseText); - - console.log("R:" + result); - - //console.log("<<< " + transport.responseText); - - if (result && dijit.byId("filterTestDlg") && dijit.byId("filterTestDlg").open) { - test_dlg.results += result.size(); - - $("prefFilterProgressMsg").innerHTML = __("Looking for articles (%d)...".replace("%d", offset)); - - console.log(offset + " " + test_dlg.max_offset); - - for (var i = 0; i < result.size(); i++) { - $("prefFilterTestResultList").innerHTML += result[i]; - } - - if (test_dlg.results < 30 && offset < test_dlg.max_offset) { - window.setTimeout(function() { - //console.log("blaargh"); - - test_dlg.getTestResults(query, offset + 30); - }, 0); - } else { - - // all done - - } - - } else { - console.log("can't parse results object / dialog closed"); - } - - } }); - }, - href: query}); - - dojo.connect(test_dlg, "onShow", null, function(e) { - test_dlg.getTestResults(query, 0); - }); - - test_dlg.show(); + editFilterTest(query); }, selectRules: function(select) { $$("#filterDlg_Matches input[type=checkbox]").each(function(e) {
No recent articles matching this filter have been found.