moved some functions to category directive scope

This commit is contained in:
Athou
2013-04-24 13:11:34 +02:00
parent edb345da9c
commit cde844b4a5
4 changed files with 46 additions and 56 deletions

View File

@@ -16,19 +16,16 @@
<span class="fldr" ng-click="toggleCategory(node)"> <span class="fldr" ng-click="toggleCategory(node)">
<i ng-class="{'icon-caret-right': !node.expanded, 'icon-caret-down': node.expanded}"></i> <i ng-class="{'icon-caret-right': !node.expanded, 'icon-caret-down': node.expanded}"></i>
</span> </span>
<span ng-click="categoryClick({id: node.id})"> <span ng-click="categoryClicked(node.id)">
<span ng-class="{selected: (node.id == selectedId && selectedType == 'category'), unread: unreadCount({category:node})}">{{formatCategoryName({category:node})}} <span ng-class="{selected: (node.id == selectedId && selectedType == 'category'), unread: unreadCount({category:node})}">{{formatCategoryName(node)}}
</span> </span>
</span> </span>
</div> </div>
<ul ng-show="node.expanded" class="indent"> <ul ng-show="node.expanded" class="indent">
<recursive> <recursive>
<category ng-repeat="child in node.children" ng-show="settingsService.settings.showRead == true || unreadCount({category:node}) > 0" <category ng-repeat="child in node.children" ng-show="settingsService.settings.showRead == true || unreadCount({category:node}) > 0"
node="child" feed-click="feedClick({id:id})" node="child" selected-type="selectedType"
category-click="categoryClick({id:id})" selected-type="selectedType"
selected-id="selectedId" selected-id="selectedId"
format-category-name="formatCategoryName({category:category})"
format-feed-name="formatFeedName({feed:feed})"
unread-count="unreadCount({category:category})"> unread-count="unreadCount({category:category})">
</category> </category>
</recursive> </recursive>
@@ -48,10 +45,10 @@
</li> </li>
</ul> </ul>
</div> </div>
<a ng-click="feedClick({id: feed.id})" class="feed-link" <a ng-click="feedClicked(feed.id)" class="feed-link"
ng-class="{selected: (feed.id == selectedId && selectedType == 'feed'), unread: feed.unread }"> ng-class="{selected: (feed.id == selectedId && selectedType == 'feed'), unread: feed.unread }">
<favicon url="feed.feedUrl" /> <favicon url="feed.feedUrl" />
{{formatFeedName({feed:feed})}} {{formatFeedName(feed)}}
</a> </a>
</li> </li>
</ul> </ul>

View File

@@ -138,45 +138,6 @@ function($scope, $timeout, $stateParams, $window, $location, $state, $route, Cat
$window.document.title = label; $window.document.title = label;
}); });
$scope.formatCategoryName = function(category) {
var count = $scope.unreadCount(category);
var label = category.name;
if (count > 0) {
label = label + ' (' + count + ')';
}
return label;
};
$scope.formatFeedName = function(feed) {
var label = feed.name;
if (feed.unread > 0) {
label = label + ' (' + feed.unread + ')';
}
return label;
};
$scope.feedClicked = function(id) {
if ($scope.selectedType == 'feed' && id == $scope.selectedId) {
$scope.$emit('emitReload');
} else {
$state.transitionTo('feeds.view', {
_type : 'feed',
_id : id
});
}
};
$scope.categoryClicked = function(id) {
if ($scope.selectedType == 'category' && id == $scope.selectedId) {
$scope.$emit('emitReload');
} else {
$state.transitionTo('feeds.view', {
_type : 'category',
_id : id
});
}
};
var mark = function(node, entry) { var mark = function(node, entry) {
var i; var i;
if (node.children) { if (node.children) {

View File

@@ -71,22 +71,18 @@ module.directive('recursive', ['$compile', function($compile) {
}; };
}]); }]);
module.directive('category', ['$compile', function($compile) { module.directive('category', [function() {
return { return {
scope : { scope : {
node : '=', node : '=',
selectedType : '=', selectedType : '=',
selectedId : '=', selectedId : '=',
feedClick : '&',
categoryClick : '&',
unreadCount : '&', unreadCount : '&',
formatCategoryName : '&',
formatFeedName : '&'
}, },
restrict : 'E', restrict : 'E',
replace : true, replace : true,
templateUrl : 'directives/category.html', templateUrl : 'directives/category.html',
controller : function($scope, $dialog, FeedService, CategoryService, controller : function($scope, $state, $dialog, FeedService, CategoryService,
SettingsService) { SettingsService) {
$scope.settingsService = SettingsService; $scope.settingsService = SettingsService;
$scope.unsubscribe = function(subscription) { $scope.unsubscribe = function(subscription) {
@@ -114,6 +110,45 @@ module.directive('category', ['$compile', function($compile) {
}); });
}; };
$scope.formatCategoryName = function(category) {
var count = $scope.unreadCount({category:category});
var label = category.name;
if (count > 0) {
label = label + ' (' + count + ')';
}
return label;
};
$scope.formatFeedName = function(feed) {
var label = feed.name;
if (feed.unread > 0) {
label = label + ' (' + feed.unread + ')';
}
return label;
};
$scope.feedClicked = function(id) {
if ($scope.selectedType == 'feed' && id == $scope.selectedId) {
$scope.$emit('emitReload');
} else {
$state.transitionTo('feeds.view', {
_type : 'feed',
_id : id
});
}
};
$scope.categoryClicked = function(id) {
if ($scope.selectedType == 'category' && id == $scope.selectedId) {
$scope.$emit('emitReload');
} else {
$state.transitionTo('feeds.view', {
_type : 'category',
_id : id
});
}
};
$scope.renameFeed = function(feed) { $scope.renameFeed = function(feed) {
var name = window.prompt('Rename feed : ', feed.name); var name = window.prompt('Rename feed : ', feed.name);
if (name && name != feed.name) { if (name && name != feed.name) {

View File

@@ -1,10 +1,7 @@
<div class="css-treeview" ng-controller="CategoryTreeCtrl"> <div class="css-treeview" ng-controller="CategoryTreeCtrl">
<ul> <ul>
<category node="CategoryService.subscriptions" <category node="CategoryService.subscriptions"
feed-click="feedClicked(id)" category-click="categoryClicked(id)"
selected-type="selectedType" selected-id="selectedId" selected-type="selectedType" selected-id="selectedId"
format-category-name="formatCategoryName(category)"
format-feed-name="formatFeedName(feed)"
unread-count="unreadCount(category)"> </category> unread-count="unreadCount(category)"> </category>
</ul> </ul>
</div> </div>