wip: filter async testing

This commit is contained in:
Andrew Dolgov 2015-09-09 16:56:04 +03:00
parent a0dbc45acd
commit a007c18dff
2 changed files with 87 additions and 31 deletions

View File

@ -43,8 +43,11 @@ class Pref_Filters extends Handler_Protected {
return;
}
function testFilterDo() {
require_once "include/rssfuncs.php";
$offset = (int) db_escape_string($_REQUEST["offset"]);
function testFilter() {
$filter = array();
$filter["enabled"] = true;
@ -94,24 +97,14 @@ class Pref_Filters extends Handler_Protected {
}
}
$found = 0;
$offset = 0;
$limit = 30;
$started = time();
print __("Articles matching this filter:");
require_once "include/rssfuncs.php";
print "<div class=\"filterTestHolder\">";
print "<table width=\"100%\" cellspacing=\"0\" id=\"prefErrorFeedList\">";
$glue = $filter['match_any_rule'] ? " OR " : " AND ";
$scope_qpart = join($glue, $scope_qparts);
if (!$scope_qpart) $scope_qpart = "true";
while ($found < $limit && $offset < $limit * 10 && time() - $started < ini_get("max_execution_time") * 0.7) {
$rv = array();
//while ($found < $limit && $offset < $limit * 1000 && time() - $started < ini_get("max_execution_time") * 0.7) {
$result = db_query("SELECT ttrss_entries.id,
ttrss_entries.title,
@ -130,7 +123,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 $limit OFFSET $offset");
ORDER BY date_entered DESC LIMIT 30 OFFSET $offset");
while ($line = db_fetch_assoc($result)) {
@ -149,14 +142,10 @@ class Pref_Filters extends Handler_Protected {
if ($line["feed_title"]) $feed_title = "(" . $line["feed_title"] . ")";
print "<tr>";
print "<td width='5%' align='center'><input dojoType=\"dijit.form.CheckBox\"
checked=\"1\" disabled=\"1\" type=\"checkbox\"></td>";
print "<td>";
$line = "<td width='5%' align='center'><input dojoType=\"dijit.form.CheckBox\"
checked=\"1\" disabled=\"1\" type=\"checkbox\"></td><td>";
/*foreach ($filter['rules'] as $rule) {
$reg_exp = $rule['reg_exp'];
$reg_exp = str_replace('/', '\/', $rule["reg_exp"]);
$line["title"] = preg_replace("/($reg_exp)/i",
@ -166,25 +155,38 @@ class Pref_Filters extends Handler_Protected {
"<span class=\"highlight\">$1</span>", $content_preview);
}*/
print $line["title"];
print "<div class='small' style='float : right'>" . $feed_title . "</div>";
print "<div class=\"insensitive\">" . $content_preview . "</div>";
print " " . mb_substr($line["date_entered"], 0, 16);
$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);
print "</td></tr>";
$line .= "</td></tr>";
$found++;
array_push($rv, $line);
}
}
$offset += $limit;
}
//$offset += $limit;
//}
if ($found == 0) {
/*if ($found == 0) {
print "<tr><td align='center'>" .
__("No recent articles matching this filter have been found.");
}
}*/
print json_encode($rv);
}
function testFilter() {
if (isset($_REQUEST["offset"])) return $this->testFilterDo();
//print __("Articles matching this filter:");
print "<div><img 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\">";
print "</table></div>";
print "<div style='text-align : center'>";

View File

@ -146,6 +146,7 @@ function editFilter(id) {
id: "filterEditDlg",
title: __("Edit Filter"),
style: "width: 600px",
test: function() {
var query = "backend.php?" + dojo.formToQuery("filter_edit_form") + "&savemode=test";
@ -156,8 +157,61 @@ function editFilter(id) {
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();
},
selectRules: function(select) {