implement filtering by category (closes #386)

This commit is contained in:
Andrew Dolgov 2011-12-27 12:52:33 +04:00
parent b69a09ea07
commit ba975b2ec7
10 changed files with 144 additions and 20 deletions

View File

@ -462,8 +462,16 @@ class Dlg extends Protected_Handler {
print "<hr/>";
print __("in") . " ";
print "<span id='filterDlg_feeds'>";
print_feed_select($this->link, "feed_id", $active_feed_id,
'dojoType="dijit.form.FilteringSelect"');
print "</span>";
print "<span id='filterDlg_cats' style='display : none'>";
print_feed_cat_select($this->link, "cat_id", $active_cat_id,
'dojoType="dijit.form.FilteringSelect"');
print "</span>";
print "</div>";
@ -505,7 +513,11 @@ class Dlg extends Protected_Handler {
<label for=\"enabled\">".__('Enabled')."</label><hr/>";
print "<input dojoType=\"dijit.form.CheckBox\" type=\"checkbox\" name=\"inverse\" id=\"inverse\">
<label for=\"inverse\">".__('Inverse match')."</label>";
<label for=\"inverse\">".__('Inverse match')."</label><hr/>";
print "<input dojoType=\"dijit.form.CheckBox\" type=\"checkbox\" name=\"cat_filter\" id=\"cat_filter\" onchange=\"filterDlgCheckCat(this)\">
<label for=\"cat_filter\">".__('Apply to category')."</label><hr/>";
print "</div>";

View File

@ -8,7 +8,8 @@ class Pref_Filters extends Protected_Handler {
}
function filter_test($filter_type, $reg_exp,
$action_id, $action_param, $filter_param, $inverse, $feed_id) {
$action_id, $action_param, $filter_param, $inverse, $feed_id, $cat_id,
$cat_filter) {
$result = db_query($this->link, "SELECT name FROM ttrss_filter_types WHERE
id = " . $filter_type);
@ -34,8 +35,8 @@ class Pref_Filters extends Protected_Handler {
$feed_title = getFeedTitle($this->link, $feed);
$qfh_ret = queryFeedHeadlines($this->link, $feed,
30, "", false, false, false,
$qfh_ret = queryFeedHeadlines($this->link, $cat_filter ? $cat_id : $feed,
30, "", $cat_filter, false, false,
false, "date_entered DESC", 0, $_SESSION["uid"], $filter);
$result = $qfh_ret[0];
@ -100,17 +101,21 @@ class Pref_Filters extends Protected_Handler {
ttrss_filter_types.description AS filter_type_descr,
enabled,
inverse,
cat_filter,
feed_id,
ttrss_filters.cat_id,
action_id,
filter_param,
filter_type,
ttrss_filter_actions.description AS action_description,
ttrss_feeds.title AS feed_title,
ttrss_feed_categories.title AS cat_title,
ttrss_filter_actions.name AS action_name,
ttrss_filters.action_param AS action_param
FROM
ttrss_filter_types,ttrss_filter_actions,ttrss_filters LEFT JOIN
ttrss_feeds ON (ttrss_filters.feed_id = ttrss_feeds.id)
ttrss_feeds ON (ttrss_filters.feed_id = ttrss_feeds.id) LEFT JOIN
ttrss_feed_categories ON (ttrss_filters.cat_id = ttrss_feed_categories.id)
WHERE
filter_type = ttrss_filter_types.id AND
ttrss_filter_actions.id = action_id AND
@ -169,7 +174,13 @@ class Pref_Filters extends Protected_Handler {
$filter['inverse'] = sql_bool_to_bool($line['inverse']);
$filter['checkbox'] = false;
if ($line['feed_id'])
if (sql_bool_to_bool($line['cat_filter']))
if ($line['cat_id'] != 0) {
$filter['feed'] = $line['cat_title'];
} else {
$filter['feed'] = __('Uncategorized');
}
else if ($line['feed_id'])
$filter['feed'] = $line['feed_title'];
array_push($cat['items'], $filter);
@ -197,12 +208,14 @@ class Pref_Filters extends Protected_Handler {
$reg_exp = htmlspecialchars(db_fetch_result($result, 0, "reg_exp"));
$filter_type = db_fetch_result($result, 0, "filter_type");
$feed_id = db_fetch_result($result, 0, "feed_id");
$cat_id = db_fetch_result($result, 0, "cat_id");
$action_id = db_fetch_result($result, 0, "action_id");
$action_param = db_fetch_result($result, 0, "action_param");
$filter_param = db_fetch_result($result, 0, "filter_param");
$enabled = sql_bool_to_bool(db_fetch_result($result, 0, "enabled"));
$inverse = sql_bool_to_bool(db_fetch_result($result, 0, "inverse"));
$cat_filter = sql_bool_to_bool(db_fetch_result($result, 0, "cat_filter"));
print "<form id=\"filter_edit_form\" onsubmit='return false'>";
@ -257,8 +270,21 @@ class Pref_Filters extends Protected_Handler {
print "<hr/>";
print __("in") . " ";
$hidden = $cat_filter ? "style='display:none'" : "";
print "<span id='filterDlg_feeds' $hidden>";
print_feed_select($this->link, "feed_id", $feed_id,
'dojoType="dijit.form.FilteringSelect"');
print "</span>";
$hidden = $cat_filter ? "" : "style='display:none'";
print "<span id='filterDlg_cats' $hidden>";
print_feed_cat_select($this->link, "cat_id", $cat_id,
'dojoType="dijit.form.FilteringSelect"');
print "</span>";
print "</div>";
@ -323,7 +349,16 @@ class Pref_Filters extends Protected_Handler {
}
print "<input dojoType=\"dijit.form.CheckBox\" type=\"checkbox\" name=\"inverse\" id=\"inverse\" $checked>
<label for=\"inverse\">".__('Inverse match')."</label>";
<label for=\"inverse\">".__('Inverse match')."</label><hr/>";
if ($cat_filter) {
$checked = "checked=\"1\"";
} else {
$checked = "";
}
print "<input dojoType=\"dijit.form.CheckBox\" type=\"checkbox\" name=\"cat_filter\" id=\"cat_filter\" onchange=\"filterDlgCheckCat(this)\" $checked>
<label for=\"cat_filter\">".__('Apply to category')."</label><hr/>";
print "</div>";
print "</div>";
@ -363,6 +398,8 @@ class Pref_Filters extends Protected_Handler {
$action_param_label = db_escape_string($_REQUEST["action_param_label"]);
$enabled = checkbox_to_sql_bool(db_escape_string($_REQUEST["enabled"]));
$inverse = checkbox_to_sql_bool(db_escape_string($_REQUEST["inverse"]));
$cat_filter = checkbox_to_sql_bool(db_escape_string($_REQUEST["cat_filter"]));
$cat_id = db_escape_string($_REQUEST['cat_id']);
# for the time being, no other filters use params anyway...
$filter_param = db_escape_string($_REQUEST["filter_date_modifier"]);
@ -373,6 +410,12 @@ class Pref_Filters extends Protected_Handler {
$feed_id = sprintf("'%s'", db_escape_string($feed_id));
}
if (!$cat_id) {
$cat_id = 'NULL';
} else {
$cat_id = sprintf("'%d'", db_escape_string($cat_id));
}
/* When processing 'assign label' filters, action_param_label dropbox
* overrides action_param */
@ -388,10 +431,12 @@ class Pref_Filters extends Protected_Handler {
$result = db_query($this->link, "UPDATE ttrss_filters SET
reg_exp = '$reg_exp',
feed_id = $feed_id,
cat_id = $cat_id,
action_id = '$action_id',
filter_type = '$filter_type',
enabled = $enabled,
inverse = $inverse,
cat_filter = $cat_filter,
action_param = '$action_param',
filter_param = '$filter_param'
WHERE id = '$filter_id' AND owner_uid = " . $_SESSION["uid"]);
@ -399,7 +444,8 @@ class Pref_Filters extends Protected_Handler {
$this->filter_test($filter_type, $reg_exp,
$action_id, $action_param, $filter_param, sql_bool_to_bool($inverse),
(int) $_REQUEST["feed_id"]);
(int) $_REQUEST["feed_id"], (int) $_REQUEST['cat_id'],
sql_bool_to_bool($cat_filter));
print "<div align='center'>";
print "<button dojoType=\"dijit.form.Button\"
@ -429,10 +475,12 @@ class Pref_Filters extends Protected_Handler {
$regexp = db_escape_string(trim($_REQUEST["reg_exp"]));
$filter_type = db_escape_string(trim($_REQUEST["filter_type"]));
$feed_id = db_escape_string($_REQUEST["feed_id"]);
$cat_id = db_escape_string($_REQUEST["cat_id"]);
$action_id = db_escape_string($_REQUEST["action_id"]);
$action_param = db_escape_string($_REQUEST["action_param"]);
$action_param_label = db_escape_string($_REQUEST["action_param_label"]);
$inverse = checkbox_to_sql_bool(db_escape_string($_REQUEST["inverse"]));
$cat_filter = checkbox_to_sql_bool(db_escape_string($_REQUEST["cat_filter"]));
# for the time being, no other filters use params anyway...
$filter_param = db_escape_string($_REQUEST["filter_date_modifier"]);
@ -445,6 +493,12 @@ class Pref_Filters extends Protected_Handler {
$feed_id = sprintf("'%s'", db_escape_string($feed_id));
}
if (!$cat_id) {
$cat_id = 'NULL';
} else {
$cat_id = sprintf("'%d'", db_escape_string($cat_id));
}
/* When processing 'assign label' filters, action_param_label dropbox
* overrides action_param */
@ -459,11 +513,11 @@ class Pref_Filters extends Protected_Handler {
if ($savemode != "test") {
$result = db_query($this->link,
"INSERT INTO ttrss_filters (reg_exp,filter_type,owner_uid,feed_id,
action_id, action_param, inverse, filter_param)
action_id, action_param, inverse, filter_param, cat_id, cat_filter)
VALUES
('$regexp', '$filter_type','".$_SESSION["uid"]."',
$feed_id, '$action_id', '$action_param', $inverse,
'$filter_param')");
'$filter_param', $cat_id, '$cat_filter')");
if (db_affected_rows($this->link, $result) != 0) {
print T_sprintf("Created filter <b>%s</b>", htmlspecialchars($regexp));
@ -473,7 +527,8 @@ class Pref_Filters extends Protected_Handler {
$this->filter_test($filter_type, $regexp,
$action_id, $action_param, $filter_param, sql_bool_to_bool($inverse),
(int) $_REQUEST["feed_id"]);
(int) $_REQUEST["feed_id"], (int) $_REQUEST['cat_id'],
sql_bool_to_bool($cat_filter));
print "<div align='center'>";
print "<button dojoType=\"dijit.form.Button\"

View File

@ -3488,15 +3488,23 @@
inverse,
action_param,
filter_param
FROM ttrss_filters,ttrss_filter_types,ttrss_filter_actions WHERE
FROM ttrss_filters
LEFT JOIN ttrss_feeds ON (ttrss_feeds.id = '$feed'),
ttrss_filter_types,ttrss_filter_actions
WHERE
enabled = true AND
$ftype_query_part
owner_uid = $owner_uid AND
ttrss_filters.owner_uid = $owner_uid AND
ttrss_filter_types.id = filter_type AND
ttrss_filter_actions.id = action_id AND
(feed_id IS NULL OR feed_id = '$feed') ORDER BY reg_exp");
((cat_filter = true AND ttrss_feeds.cat_id = ttrss_filters.cat_id) OR
(cat_filter = true AND ttrss_feeds.cat_id IS NULL AND
ttrss_filters.cat_id IS NULL) OR
(cat_filter = false AND (feed_id IS NULL OR feed_id = '$feed')))
ORDER BY reg_exp");
while ($line = db_fetch_assoc($result)) {
if (!$filters[$line["name"]]) $filters[$line["name"]] = array();
$filter["reg_exp"] = $line["reg_exp"];
$filter["action"] = $line["action"];

View File

@ -6,7 +6,7 @@
} else {
define('EXPECTED_CONFIG_VERSION', 25);
define('SCHEMA_VERSION', 86);
define('SCHEMA_VERSION', 87);
require_once "config.php";
require_once "sanity_config.php";

View File

@ -26,13 +26,13 @@ dojo.declare("fox.PrefFilterTree", lib.CheckBoxTree, {
var inverse = this.model.store.getValue(item, 'inverse');
if (feed)
label += " (" + __("Feed:") + " " + feed + ")";
label += " (" + __("in") + " " + feed + ")";
if (inverse)
label += " (" + __("Inverse") + ")";
/* if (item.param)
label = "<span class=\"labelFixedLength\">" + label +
label = "<span class=\"labelFixedLength\">" + label +
"</span>" + item.param[0]; */
return label;
@ -45,7 +45,7 @@ dojo.declare("fox.PrefFilterTree", lib.CheckBoxTree, {
return (enabled != false) ? "dijitTreeLabel labelFixedLength" : "dijitTreeLabel labelFixedLength Disabled";
},
getRowClass: function (item, opened) {
return (!item.error || item.error == '') ? "dijitTreeRow" :
return (!item.error || item.error == '') ? "dijitTreeRow" :
"dijitTreeRow Error";
},
});

View File

@ -565,6 +565,21 @@ function fatalError(code, msg, ext_info) {
}
}
function filterDlgCheckCat(sender) {
try {
if (sender.checked) {
Element.show('filterDlg_cats');
Element.hide('filterDlg_feeds');
} else {
Element.show('filterDlg_feeds');
Element.hide('filterDlg_cats');
}
} catch (e) {
exception_error("filterDlgCheckCat", e);
}
}
function filterDlgCheckType(sender) {
try {

View File

@ -233,6 +233,8 @@ create table ttrss_filters (id integer not null primary key auto_increment,
filter_param varchar(250) not null default '',
inverse bool not null default false,
enabled bool not null default true,
cat_filter bool not null default false,
cat_id integer default null,
action_id integer not null default 1,
action_param varchar(250) not null default '',
index (filter_type),
@ -241,6 +243,8 @@ create table ttrss_filters (id integer not null primary key auto_increment,
foreign key (owner_uid) references ttrss_users(id) ON DELETE CASCADE,
index (feed_id),
foreign key (feed_id) references ttrss_feeds(id) ON DELETE CASCADE,
index (cat_id),
foreign key (cat_id) references ttrss_feed_categories(id) ON DELETE CASCADE,
index (action_id),
foreign key (action_id) references ttrss_filter_actions(id) ON DELETE CASCADE) ENGINE=InnoDB DEFAULT CHARSET=UTF8;
@ -255,7 +259,7 @@ create table ttrss_tags (id integer primary key auto_increment,
create table ttrss_version (schema_version int not null) ENGINE=InnoDB DEFAULT CHARSET=UTF8;
insert into ttrss_version values (86);
insert into ttrss_version values (87);
create table ttrss_enclosures (id integer primary key auto_increment,
content_url text not null,

View File

@ -213,6 +213,8 @@ create table ttrss_filters (id serial not null primary key,
filter_param varchar(250) not null default '',
enabled boolean not null default true,
inverse boolean not null default false,
cat_filter boolean not null default false,
cat_id integer references ttrss_feed_categories(id) on delete cascade default null,
action_id integer not null default 1 references ttrss_filter_actions(id) on delete cascade,
action_param varchar(250) not null default '');
@ -226,7 +228,7 @@ create index ttrss_tags_post_int_id_idx on ttrss_tags(post_int_id);
create table ttrss_version (schema_version int not null);
insert into ttrss_version values (86);
insert into ttrss_version values (87);
create table ttrss_enclosures (id serial not null primary key,
content_url text not null,

View File

@ -0,0 +1,14 @@
begin;
alter table ttrss_filters add column cat_filter bool;
update ttrss_filters set cat_filter = true;
alter table ttrss_filters change cat_filter cat_filter bool not null;
alter table ttrss_filters alter column cat_filter set default false;
alter table ttrss_filters add column cat_id integer;
alter table ttrss_filters add FOREIGN KEY (cat_id) REFERENCES ttrss_feed_categories(id) ON DELETE CASCADE;
update ttrss_version set schema_version = 87;
commit;

View File

@ -0,0 +1,14 @@
begin;
alter table ttrss_filters add column cat_filter boolean;
update ttrss_filters set cat_filter = false;
alter table ttrss_filters alter column cat_filter set not null;
alter table ttrss_filters alter column cat_filter set default false;
alter table ttrss_filters add column cat_id integer;
alter table ttrss_filters add constraint "$5" FOREIGN KEY (cat_id) REFERENCES ttrss_feed_categories(id) ON DELETE CASCADE;
update ttrss_version set schema_version = 87;
commit;