fix label issues

This commit is contained in:
Athou
2013-03-22 07:31:15 +01:00
parent 42f9b38f68
commit 905bea4a1a
4 changed files with 27 additions and 9 deletions

View File

@@ -5,7 +5,7 @@
<ul> <ul>
<li ng-repeat="feed in node.feeds"> <li ng-repeat="feed in node.feeds">
<a ng-click="feedClick({id: feed.id})" <a ng-click="feedClick({id: feed.id})"
ng-class="{selected: (feed.id == selectedId && selectedType == 'feed')}">{{feed.name}} ng-class="{selected: (feed.id == selectedId && selectedType == 'feed')}">{{formatFeedName({feed:feed})}}
</a> </a>
</li> </li>
</ul> </ul>

View File

@@ -37,12 +37,14 @@ module.controller('CategoryTreeCtrl',
var unreadCount = function(category) { var unreadCount = function(category) {
var count = 0; var count = 0;
console.log(category) if (category.children) {
for ( var child in category.children) { for ( var i = 0; i < category.children.length; i++) {
count = count + unreadCount(child); count = count + unreadCount(category.children[i]);
}
} }
for ( var feed in category.feeds) { if (category.feeds) {
if (feed.unread) { for ( var i = 0; i < category.feeds.length; i++) {
var feed = category.feeds[i];
count = count + feed.unread; count = count + feed.unread;
} }
} }
@@ -58,6 +60,15 @@ module.controller('CategoryTreeCtrl',
return label; return label;
} }
$scope.formatFeedName = function(feed) {
console.log('cc')
var label = feed.name;
if (feed.unread > 0) {
label = label + " (" + feed.unread + ")";
}
return label;
}
$scope.feedClicked = function(id) { $scope.feedClicked = function(id) {
$location.path('/feeds/view/feed/' + id); $location.path('/feeds/view/feed/' + id);
}; };

View File

@@ -8,7 +8,8 @@ module.directive('category', function($compile) {
selectedId: '=', selectedId: '=',
feedClick: '&', feedClick: '&',
categoryClick: '&', categoryClick: '&',
formatCategoryName: '&' formatCategoryName: '&',
formatFeedName: '&'
}, },
restrict : 'E', restrict : 'E',
replace: true, replace: true,
@@ -16,7 +17,10 @@ module.directive('category', function($compile) {
link: function(scope, element) { link: function(scope, element) {
if (scope.node.children) { if (scope.node.children) {
var ul = element.find('ul'); var ul = element.find('ul');
ul.prepend('<category ng-repeat="child in node.children" node="child" feed-click="feedClick({id:id})" category-click="categoryClick({id:id})" selected-type="selectedType" selected-id="selectedId" format-category-name="formatCategoryName({category:category})"></category>'); ul.prepend('<category ng-repeat="child in node.children" node="child" feed-click="feedClick({id:id})" \
category-click="categoryClick({id:id})" selected-type="selectedType" selected-id="selectedId" \
format-category-name="formatCategoryName({category:category})" format-feed-name="formatFeedName({feed:feed})">\
</category>');
$compile(ul.contents())(scope); $compile(ul.contents())(scope);
} }
} }

View File

@@ -4,7 +4,10 @@
<div class="css-treeview"> <div class="css-treeview">
<ul> <ul>
<li ng-repeat="node in root.children"> <li ng-repeat="node in root.children">
<category node="node" feed-click="feedClicked(id)" category-click="categoryClicked(id)" selected-type="selectedType" selected-id="selectedId" format-category-name="formatCategoryName(category)"></category> <category node="node" feed-click="feedClicked(id)" category-click="categoryClicked(id)"
selected-type="selectedType" selected-id="selectedId"
format-category-name="formatCategoryName(category)" format-feed-name="formatFeedName(feed)">
</category>
</li> </li>
</ul> </ul>
</div> </div>