]> git.wh0rd.org Git - tt-rss.git/commitdiff
sort feedlist by unread articles (closes #66)
authorAndrew Dolgov <fox@madoka.spb.ru>
Mon, 5 Jun 2006 08:33:19 +0000 (09:33 +0100)
committerAndrew Dolgov <fox@madoka.spb.ru>
Mon, 5 Jun 2006 08:33:19 +0000 (09:33 +0100)
backend.php
functions.js
functions.php
schema/ttrss_schema_mysql.sql
schema/ttrss_schema_pgsql.sql
schema/upgrade-1.1.5-1.1.7-mysql.sql
schema/upgrade-1.1.5-1.1.7-pgsql.sql

index abc0988adff6ff5abc829f403f1e5c70d0e6e734..dafb0b95b199e0f901ba3617b1669bce97aada39 100644 (file)
 //                     }
 
                        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.*,
index 3b6339b82e92fa688e19097cd21234b69122aaae..7ed20d53264220f3bc5f53738592597e382e92bb 100644 (file)
@@ -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);
                }
        
index 3d6078b14b39b0401ffacf1a51ee4305aaf617cd..6bcebe598dcb3c113a299b428b671898c8fe11a7 100644 (file)
                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>";
        }
 
index e1d61009c4dc4f71315634ca82d96f64061cad58..1e51df31c16380a4593ac9f17381c1eaa79d1aa0 100644 (file)
@@ -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),
index 1726ecc8e9fb0896e4596e726af86557816b7c46..042e650fd5e9e3c28ed01795a1b1b6b46801aacf 100644 (file)
@@ -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,
index bfccc3358f78115db982681092c9f9de23f08d34..a7fb99024bcfc89caba1c1050956a3b1f1d4d404 100644 (file)
@@ -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');
 
index 4a2237a3f778f73c98ee535970b9c1787559a899..4c7c78f9d78765c09abee0de14808a9b1169e642 100644 (file)
@@ -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');