sort feedlist by unread articles (closes #66)

master
Andrew Dolgov 19 years ago
parent b2caf812fb
commit c9268ed599

@ -241,9 +241,17 @@
// }
if (get_pref($link, 'ENABLE_FEED_CATS')) {
$order_by_qpart = "category,title";
if (get_pref($link, "FEEDS_SORT_BY_UNREAD")) {
$order_by_qpart = "category,unread DESC,title";
} else {
$order_by_qpart = "category,title";
}
} else {
$order_by_qpart = "title";
if (get_pref($link, "FEEDS_SORT_BY_UNREAD")) {
$order_by_qpart = "unread DESC,title";
} else {
$order_by_qpart = "title";
}
}
$result = db_query($link, "SELECT ttrss_feeds.*,

@ -581,6 +581,10 @@ function all_counters_callback() {
if (runtime) {
getMainContext().parse_runtime_info(runtime);
}
if (getInitParam("feeds_sort_by_unread")) {
resort_feedlist();
}
} catch (e) {
exception_error("all_counters_callback", e);
@ -588,6 +592,75 @@ function all_counters_callback() {
}
}
function get_feed_entry_unread(doc, elem) {
var id = elem.id.replace("FEEDR-", "");
if (id <= 0) {
return -1;
}
try {
return parseInt(doc.getElementById("FEEDU-" + id).innerHTML);
} catch (e) {
return -1;
}
}
function resort_category(doc, node) {
debug("resort_category: " + node);
if (node.hasChildNodes() && node.firstChild.nextSibling != false) {
for (i = 0; i < node.childNodes.length; i++) {
if (node.childNodes[i].nodeName != "LI") { continue; }
if (get_feed_entry_unread(doc, node.childNodes[i]) < 0) {
continue;
}
for (j = i+1; j < node.childNodes.length; j++) {
if (node.childNodes[j].nodeName != "LI") { continue; }
var tmp_val = get_feed_entry_unread(doc, node.childNodes[i]);
var cur_val = get_feed_entry_unread(doc, node.childNodes[j]);
if (cur_val > tmp_val) {
tempnode_i = node.childNodes[i].cloneNode(true);
tempnode_j = node.childNodes[j].cloneNode(true);
node.replaceChild(tempnode_i, node.childNodes[j]);
node.replaceChild(tempnode_j, node.childNodes[i]);
}
}
}
}
}
function resort_feedlist() {
debug("resort_feedlist");
var fd = getFeedsContext().document;
if (fd.getElementById("feedCatHolder")) {
var feeds = fd.getElementById("feedList");
var child = feeds.firstChild;
while (child) {
if (child.id == "feedCatHolder") {
resort_category(fd, child.firstChild);
}
child = child.nextSibling;
}
} else {
resort_category(fd, fd.getElementById("feedList"));
}
}
function update_all_counters(feed) {
if (xmlhttp_ready(xmlhttp_rpc)) {
var query = "backend.php?op=rpc&subop=getAllCounters";
@ -1147,7 +1220,7 @@ function debug(msg) {
var c = ctx.document.getElementById('debug_output');
if (c && c.style.display == "block") {
while (c.lastChild != 'undefined' && c.childNodes.length > 20) {
while (c.lastChild != 'undefined' && c.childNodes.length > 100) {
c.removeChild(c.lastChild);
}

@ -1718,6 +1718,9 @@
print "<param key=\"hide_read_feeds\" value=\"" .
sprintf("%d", get_pref($link, "HIDE_READ_FEEDS")) . "\"/>";
print "<param key=\"feeds_sort_by_unread\" value=\"" .
sprintf("%d", get_pref($link, "FEEDS_SORT_BY_UNREAD")) . "\"/>";
print "</init-params>";
}

@ -247,6 +247,8 @@ insert into ttrss_prefs (pref_name,type_id,def_value,short_desc,section_id) valu
insert into ttrss_prefs (pref_name,type_id,def_value,short_desc,section_id,help_text) values('ON_CATCHUP_SHOW_NEXT_FEED', 1, 'false', 'On catchup show next feed',2,
'When "Mark as read" button is clicked in toolbar, automatically open next feed with unread articles.');
insert into ttrss_prefs (pref_name,type_id,def_value,short_desc,section_id) values('FEEDS_SORT_BY_UNREAD', 1, 'false', 'Sort feeds by unread articles count',2);
create table ttrss_user_prefs (
owner_uid integer not null,
pref_name varchar(250),

@ -227,6 +227,8 @@ insert into ttrss_prefs (pref_name,type_id,def_value,short_desc,section_id) valu
insert into ttrss_prefs (pref_name,type_id,def_value,short_desc,section_id,help_text) values('ON_CATCHUP_SHOW_NEXT_FEED', 1, 'false', 'On catchup show next feed',2,
'When "Mark as read" button is clicked in toolbar, automatically open next feed with unread articles.');
insert into ttrss_prefs (pref_name,type_id,def_value,short_desc,section_id) values('FEEDS_SORT_BY_UNREAD', 1, 'false', 'Sort feeds by unread articles count',2);
create table ttrss_user_prefs (
owner_uid integer not null references ttrss_users(id) ON DELETE CASCADE,
pref_name varchar(250) not null references ttrss_prefs(pref_name) ON DELETE CASCADE,

@ -3,6 +3,8 @@ insert into ttrss_themes (theme_name, theme_path) values ('Old-skool', 'compat')
insert into ttrss_prefs (pref_name,type_id,def_value,short_desc,section_id,help_text) values('ON_CATCHUP_SHOW_NEXT_FEED', 1, 'false', 'On catchup show next feed',2,
'When "Mark as read" button is clicked in toolbar, automatically open next feed with unread articles.');
insert into ttrss_prefs (pref_name,type_id,def_value,short_desc,section_id) values('FEEDS_SORT_BY_UNREAD', 1, 'false', 'Sort feeds by unread articles count',2);
insert into ttrss_filter_actions (id,name,description) values (3, 'mark',
'Set starred');

@ -5,6 +5,8 @@ insert into ttrss_themes (theme_name, theme_path) values ('Old-skool', 'compat')
insert into ttrss_prefs (pref_name,type_id,def_value,short_desc,section_id,help_text) values('ON_CATCHUP_SHOW_NEXT_FEED', 1, 'false', 'On catchup show next feed',2,
'When "Mark as read" button is clicked in toolbar, automatically open next feed with unread articles.');
insert into ttrss_prefs (pref_name,type_id,def_value,short_desc,section_id) values('FEEDS_SORT_BY_UNREAD', 1, 'false', 'Sort feeds by unread articles count',2);
insert into ttrss_filter_actions (id,name,description) values (3, 'mark',
'Set starred');

Loading…
Cancel
Save