From: Andrew Dolgov Date: Wed, 9 Sep 2015 19:09:03 +0000 (+0300) Subject: mostly implement async filter test dialog X-Git-Tag: 16.3~116 X-Git-Url: https://git.wh0rd.org/?a=commitdiff_plain;h=261226a3a50c598fcf385c336246e8a97934329c;p=tt-rss.git mostly implement async filter test dialog --- diff --git a/classes/pref/filters.php b/classes/pref/filters.php old mode 100644 new mode 100755 index ec0c3862..6170f7a0 --- 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); - }*/ + } + + $tmp .= "" . $line["title"] . ""; + $tmp .= "
" . $feed_title . "
"; + $tmp .= "
" . $content_preview . "
"; + $tmp .= " " . mb_substr($line["date_entered"], 0, 16); + $tmp .= ""; - $line .= $line["title"]; - $line .= "
" . $feed_title . "
"; - $line .= "
" . $content_preview . "
"; - $line .= " " . mb_substr($line["date_entered"], 0, 16); + array_push($rv, $tmp); - $line .= ""; + /*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 797e0e07..ac6ac206 --- a/js/prefs.js +++ b/js/prefs.js @@ -131,88 +131,120 @@ function editUser(id, event) { } -function editFilter(id) { +function editFilterTest(query) { try { - var query = "backend.php?op=pref-filters&method=edit&id=" + param_escape(id); - - if (dijit.byId("feedEditDlg")) - dijit.byId("feedEditDlg").destroyRecursive(); - - if (dijit.byId("filterEditDlg")) - dijit.byId("filterEditDlg").destroyRecursive(); + if (dijit.byId("filterTestDlg")) + dijit.byId("filterTestDlg").destroyRecursive(); - dialog = new dijit.Dialog({ - id: "filterEditDlg", - title: __("Edit Filter"), + 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; - test: function() { - var query = "backend.php?" + dojo.formToQuery("filter_edit_form") + "&savemode=test"; + console.log("getTestResults:" + offset); - if (dijit.byId("filterTestDlg")) - dijit.byId("filterTestDlg").destroyRecursive(); + new Ajax.Request("backend.php", { + parameters: updquery, + onComplete: function (transport) { + try { + var result = JSON.parse(transport.responseText); - 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; + if (result && dijit.byId("filterTestDlg") && dijit.byId("filterTestDlg").open) { + test_dlg.results += result.size(); - console.log("getTestResults:" + offset); - //console.log(updquery); + console.log("got results:" + result.size()); - new Ajax.Request("backend.php", { - parameters: updquery, - onComplete: function (transport) { + $("prefFilterProgressMsg").innerHTML = __("Looking for articles (%d processed, %f found)...") + .replace("%f", test_dlg.results) + .replace("%d", offset); - console.log(transport.responseText); + console.log(offset + " " + test_dlg.max_offset); - var result = JSON.parse(transport.responseText); + for (var i = 0; i < result.size(); i++) { + var tmp = new Element("table"); + tmp.innerHTML = result[i]; + dojo.parser.parse(tmp); - console.log("R:" + result); + $("prefFilterTestResultList").innerHTML += tmp.innerHTML; + } - //console.log("<<< " + transport.responseText); + if (test_dlg.results < 30 && offset < test_dlg.max_offset) { - if (result && dijit.byId("filterTestDlg") && dijit.byId("filterTestDlg").open) { - test_dlg.results += result.size(); + // get the next batch + window.setTimeout(function () { + test_dlg.getTestResults(query, offset + test_dlg.limit); + }, 0); - $("prefFilterProgressMsg").innerHTML = __("Looking for articles (%d)...".replace("%d", offset)); + } else { + // all done - console.log(offset + " " + test_dlg.max_offset); + Element.hide("prefFilterLoadingIndicator"); - for (var i = 0; i < result.size(); i++) { - $("prefFilterTestResultList").innerHTML += result[i]; + 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); } - if (test_dlg.results < 30 && offset < test_dlg.max_offset) { - window.setTimeout(function() { - //console.log("blaargh"); + } - test_dlg.getTestResults(query, offset + 30); - }, 0); - } else { + } else if (!result) { + console.log("getTestResults: can't parse results object"); - // all done + Element.hide("prefFilterLoadingIndicator"); - } + notify_error("Error while trying to get filter test results."); - } else { - console.log("can't parse results object / dialog closed"); - } + } else { + console.log("getTestResults: dialog closed, bailing out."); + } + } catch (e) { + exception_error("editFilterTest/inner", e); + } - } }); - }, - href: query}); + } }); + }, + href: query}); - dojo.connect(test_dlg, "onShow", null, function(e) { - test_dlg.getTestResults(query, 0); - }); + 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 { + + var query = "backend.php?op=pref-filters&method=edit&id=" + param_escape(id); + + if (dijit.byId("feedEditDlg")) + dijit.byId("feedEditDlg").destroyRecursive(); + + if (dijit.byId("filterEditDlg")) + dijit.byId("filterEditDlg").destroyRecursive(); + + dialog = new dijit.Dialog({ + id: "filterEditDlg", + title: __("Edit Filter"), + style: "width: 600px", + + test: function() { + var query = "backend.php?" + dojo.formToQuery("filter_edit_form") + "&savemode=test"; - 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.