]> git.wh0rd.org Git - tt-rss.git/commitdiff
add special indication for categories having unread items in child categories
authorAndrew Dolgov <fox@madoka.volgo-balt.ru>
Mon, 13 Aug 2012 15:52:34 +0000 (19:52 +0400)
committerAndrew Dolgov <fox@madoka.volgo-balt.ru>
Mon, 13 Aug 2012 15:52:34 +0000 (19:52 +0400)
classes/pref_feeds.php
include/functions.php
js/FeedTree.js
js/feedlist.js

index a6760b9e1464068556eecab12ace0e102055ffb0..c87b0e549c696d30f0eadbb2ccdd41c69d314192 100644 (file)
@@ -50,6 +50,7 @@ class Pref_Feeds extends Protected_Handler {
                        $cat['hidden'] = sql_bool_to_bool($line['collapsed']);
                        $cat['type'] = 'category';
                        $cat['unread'] = 0;
+                       $cat['child_unread'] = 0;
 
                        $cat['items'] = $this->get_category_items($line['id']);
 
@@ -167,6 +168,7 @@ class Pref_Feeds extends Protected_Handler {
                                $cat['hidden'] = sql_bool_to_bool($line['collapsed']);
                                $cat['type'] = 'category';
                                $cat['unread'] = 0;
+                               $cat['child_unread'] = 0;
 
                                $cat['items'] = $this->get_category_items($line['id']);
 
@@ -189,6 +191,7 @@ class Pref_Feeds extends Protected_Handler {
                        $cat['type'] = 'category';
                        $cat['checkbox'] = false;
                        $cat['unread'] = 0;
+                       $cat['child_unread'] = 0;
 
                        $feed_result = db_query($this->link, "SELECT id, title,last_error,
                                ".SUBSTRING_FOR_DATE."(last_updated,1,19) AS last_updated
index 009955c999f371221ee8ae1dcbced7f6d760162a..b2319e6e1efabcad01d2897be89443af7306de32 100644 (file)
 
                array_push($ret_arr, $cv);
 
-               $result = db_query($link, "SELECT id AS cat_id, value AS unread
+               $result = db_query($link, "SELECT id AS cat_id, value AS unread,
+                       (SELECT COUNT(id) FROM ttrss_feed_categories AS c2
+                               WHERE c2.parent_cat = ttrss_feed_categories.id) AS num_children
                        FROM ttrss_feed_categories, ttrss_cat_counters_cache
                        WHERE ttrss_cat_counters_cache.feed_id = id AND
                        ttrss_feed_categories.owner_uid = " . $_SESSION["uid"]);
                while ($line = db_fetch_assoc($result)) {
                        $line["cat_id"] = (int) $line["cat_id"];
 
+                       if ($line["num_children"] > 0) {
+                               $child_counter = getCategoryUnreadRecursive($link, $line["cat_id"], $_SESSION["uid"]);
+                       } else {
+                               $child_counter = 0;
+                       }
+
                        $cv = array("id" => $line["cat_id"], "kind" => "cat",
+                               "child_counter" => $child_counter,
                                "counter" => $line["unread"]);
 
                        array_push($ret_arr, $cv);
                return $ret_arr;
        }
 
+       // only accepts real cats (>= 0)
+       function getCategoryUnreadRecursive($link, $cat, $owner_uid = false) {
+               if (!$owner_uid) $owner_uid = $_SESSION["uid"];
+
+               $result = db_query($link, "SELECT id FROM ttrss_feed_categories WHERE parent_cat = '$cat'
+                               AND owner_uid = $owner_uid");
+
+               $unread = 0;
+
+               while ($line = db_fetch_assoc($result)) {
+                       $unread += getCategoryUnread($link, $line["id"], $owner_uid);
+                       $unread += getCategoryUnreadRecursive($link, $line["id"], $owner_uid);
+               }
+
+               return $unread;
+       }
+
        function getCategoryUnread($link, $cat, $owner_uid = false) {
 
                if (!$owner_uid) $owner_uid = $_SESSION["uid"];
index 30e625015d27b47dbe50543c1df8f31659b5e5aa..b39e728623531d02f35f58f0b10516ba5e215b88 100644 (file)
@@ -120,6 +120,14 @@ dojo.declare("fox.FeedTree", dijit.Tree, {
                        dojo.place(span, tnode.iconNode, 'replace');
                }
 
+               if (id.match("CAT:") && bare_id > 0) {
+                       param = dojo.doc.createElement('span');
+                       param.className = 'feedParam';
+                       param.innerHTML = "";
+                       dojo.place(param, tnode.labelNode, 'after');
+                       tnode._paramNode = param;
+               }
+
                if (id.match("FEED:") && bare_id > 0) {
                        var menu = new dijit.Menu();
                        menu.row_id = bare_id;
@@ -183,11 +191,15 @@ dojo.declare("fox.FeedTree", dijit.Tree, {
                name = name.replace(/&lt;/g, "<");
                name = name.replace(/&gt;/g, ">");
 
+               var label;
+
                if (item.unread > 0) {
-                       return name + " (" + item.unread + ")";
+                       label = name + " (" + item.unread + ")";
                } else {
-                       return name;
+                       label = name;
                }
+
+               return label;
        },
        selectFeed: function(feed, is_cat) {
                if (is_cat)
@@ -443,4 +455,15 @@ dojo.declare("fox.FeedTree", dijit.Tree, {
                        return false;
                }
        },
+       setCatParam: function(cat, value) {
+               var treeNode = this._itemNodesMap['CAT:' + cat];
+
+               if (treeNode && treeNode[0] && treeNode[0]._paramNode) {
+                       if (value > 0)
+                               treeNode[0]._paramNode.innerHTML = '+' + value;
+                       else
+                               treeNode[0]._paramNode.innerHTML = "";
+               }
+               this.model.setFeedValue(cat, true, 'child_unread', value);
+       },
 });
index 13cdc2694da5dbba0258d8e6b1cccb8b2daa005f..18d4a97704e7fc47031618e5636940d6a94c523c 100644 (file)
@@ -286,6 +286,7 @@ function parse_counters(elems, scheduled_call) {
                        var error = elems[l].error;
                        var has_img = elems[l].has_img;
                        var updated = elems[l].updated;
+                       var child_unread = parseInt(elems[l].child_counter);
 
                        if (id == "global-unread") {
                                global_unread = ctr;
@@ -322,6 +323,8 @@ function parse_counters(elems, scheduled_call) {
                                                setFeedIcon(id, false, 'images/blank_icon.gif');
                                        }
                                }
+                       } else {
+                               setCatParam(id, child_unread);
                        }
                }
 
@@ -411,6 +414,19 @@ function setFeedValue(feed, is_cat, key, value) {
        }
 }
 
+function setCatParam(cat, value) {
+       try {
+               var tree = dijit.byId("feedTree");
+
+               if (tree && tree.model)
+                       return tree.setCatParam(cat, value);
+
+       } catch (e) {
+               //
+       }
+}
+
+
 function selectFeed(feed, is_cat) {
        try {
                var tree = dijit.byId("feedTree");