mostly implement async filter test dialog

master
Andrew Dolgov 9 years ago
parent a007c18dff
commit 261226a3a5

@ -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 = "<td width='5%' align='center'><input dojoType=\"dijit.form.CheckBox\"
$tmp = "<tr><td width='5%' align='center'><input dojoType=\"dijit.form.CheckBox\"
checked=\"1\" disabled=\"1\" type=\"checkbox\"></td><td>";
/*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",
"<span class=\"highlight\">$1</span>", $content_preview);
}*/
}
$tmp .= "<strong>" . $line["title"] . "</strong>";
$tmp .= "<div class='small' style='float : right'>" . $feed_title . "</div>";
$tmp .= "<div class=\"insensitive\">" . $content_preview . "</div>";
$tmp .= " " . mb_substr($line["date_entered"], 0, 16);
$tmp .= "</td></tr>";
$line .= $line["title"];
$line .= "<div class='small' style='float : right'>" . $feed_title . "</div>";
$line .= "<div class=\"insensitive\">" . $content_preview . "</div>";
$line .= " " . mb_substr($line["date_entered"], 0, 16);
array_push($rv, $tmp);
$line .= "</td></tr>";
/*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 "<div><img src='images/indicator_tiny.gif'>&nbsp;<span id='prefFilterProgressMsg'>Looking for articles...</span></div>";
print "<div><img id='prefFilterLoadingIndicator' src='images/indicator_tiny.gif'>&nbsp;<span id='prefFilterProgressMsg'>Looking for articles...</span></div>";
print "<br/><div class=\"filterTestHolder\">";
print "<table width=\"100%\" cellspacing=\"0\" id=\"prefFilterTestResultList\">";

@ -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 = "<tr><td align='center'>No recent articles matching this filter have been found.</td></tr>";
$("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) {

Loading…
Cancel
Save