2013-03-21 16:22:58 +01:00
|
|
|
var module = angular.module('commafeed.controllers', []);
|
|
|
|
|
|
2013-03-22 09:29:30 +01:00
|
|
|
module.run(function($rootScope) {
|
2013-03-23 17:17:27 +01:00
|
|
|
$rootScope.$on('emitMark', function(event, args) {
|
|
|
|
|
// args.entry - the entry
|
|
|
|
|
$rootScope.$broadcast('mark', args);
|
2013-03-22 09:29:30 +01:00
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
2013-03-22 20:51:22 +01:00
|
|
|
module.controller('CategoryTreeCtrl', function($scope, $routeParams, $location,
|
|
|
|
|
CategoryService) {
|
2013-03-21 23:10:05 +01:00
|
|
|
|
2013-03-22 23:54:52 +01:00
|
|
|
$scope.$on('$routeChangeSuccess', function() {
|
|
|
|
|
$scope.selectedType = $routeParams._type;
|
|
|
|
|
$scope.selectedId = $routeParams._id;
|
|
|
|
|
});
|
2013-03-21 23:10:05 +01:00
|
|
|
|
2013-03-22 20:51:22 +01:00
|
|
|
$scope.root = CategoryService.get();
|
|
|
|
|
|
|
|
|
|
var unreadCount = function(category) {
|
|
|
|
|
var count = 0;
|
|
|
|
|
if (category.children) {
|
|
|
|
|
for ( var i = 0; i < category.children.length; i++) {
|
|
|
|
|
count = count + unreadCount(category.children[i]);
|
2013-03-22 07:31:15 +01:00
|
|
|
}
|
2013-03-22 20:51:22 +01:00
|
|
|
}
|
|
|
|
|
if (category.feeds) {
|
|
|
|
|
for ( var i = 0; i < category.feeds.length; i++) {
|
|
|
|
|
var feed = category.feeds[i];
|
|
|
|
|
count = count + feed.unread;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return count;
|
|
|
|
|
}
|
2013-03-22 07:31:15 +01:00
|
|
|
|
2013-03-22 20:51:22 +01:00
|
|
|
$scope.formatCategoryName = function(category) {
|
|
|
|
|
var count = unreadCount(category);
|
|
|
|
|
var label = category.name;
|
|
|
|
|
if (count > 0) {
|
|
|
|
|
label = label + " (" + count + ")";
|
|
|
|
|
}
|
|
|
|
|
return label;
|
|
|
|
|
}
|
2013-03-21 16:22:58 +01:00
|
|
|
|
2013-03-22 20:51:22 +01:00
|
|
|
$scope.formatFeedName = function(feed) {
|
|
|
|
|
var label = feed.name;
|
|
|
|
|
if (feed.unread > 0) {
|
|
|
|
|
label = label + " (" + feed.unread + ")";
|
|
|
|
|
}
|
|
|
|
|
return label;
|
|
|
|
|
}
|
2013-03-22 09:29:30 +01:00
|
|
|
|
2013-03-22 20:51:22 +01:00
|
|
|
$scope.feedClicked = function(id) {
|
|
|
|
|
$location.path('/feeds/view/feed/' + id);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
$scope.categoryClicked = function(id) {
|
|
|
|
|
$location.path('/feeds/view/category/' + id);
|
|
|
|
|
};
|
|
|
|
|
|
2013-03-23 17:17:27 +01:00
|
|
|
var mark = function(node, entry) {
|
2013-03-22 22:20:17 +01:00
|
|
|
if (node.children) {
|
|
|
|
|
for ( var i = 0; i < node.children.length; i++) {
|
2013-03-23 17:17:27 +01:00
|
|
|
mark(node.children[i], entry);
|
2013-03-22 20:51:22 +01:00
|
|
|
}
|
2013-03-22 22:20:17 +01:00
|
|
|
}
|
|
|
|
|
if (node.feeds) {
|
|
|
|
|
for ( var i = 0; i < node.feeds.length; i++) {
|
|
|
|
|
var feed = node.feeds[i];
|
|
|
|
|
if (feed.id == entry.feedId) {
|
2013-03-23 17:17:27 +01:00
|
|
|
var c = entry.read ? -1 : 1;
|
2013-03-22 22:20:17 +01:00
|
|
|
feed.unread = feed.unread + c;
|
2013-03-22 09:29:30 +01:00
|
|
|
}
|
2013-03-22 20:51:22 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
};
|
2013-03-22 09:29:30 +01:00
|
|
|
|
2013-03-23 17:17:27 +01:00
|
|
|
$scope.$on('mark', function(event, args) {
|
|
|
|
|
mark($scope.root, args.entry)
|
2013-03-22 20:51:22 +01:00
|
|
|
});
|
|
|
|
|
});
|
2013-03-21 16:22:58 +01:00
|
|
|
|
2013-03-22 20:51:22 +01:00
|
|
|
module.controller('FeedListCtrl', function($scope, $routeParams, $http,
|
|
|
|
|
EntryService) {
|
2013-03-21 16:22:58 +01:00
|
|
|
|
2013-03-22 09:29:30 +01:00
|
|
|
$scope.selectedType = $routeParams._type;
|
|
|
|
|
$scope.selectedId = $routeParams._id;
|
|
|
|
|
|
2013-03-23 17:56:19 +01:00
|
|
|
$scope.readType = 'all';
|
2013-03-22 20:51:22 +01:00
|
|
|
|
2013-03-23 17:56:19 +01:00
|
|
|
$scope.refreshList = function() {
|
|
|
|
|
$scope.entryList = EntryService.get({
|
|
|
|
|
_type : $scope.selectedType,
|
|
|
|
|
_id : $scope.selectedId,
|
|
|
|
|
_readtype : $scope.readType
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
$scope.refreshList();
|
|
|
|
|
|
2013-03-23 17:17:27 +01:00
|
|
|
$scope.mark = function(entry, read) {
|
2013-03-22 09:29:30 +01:00
|
|
|
if (entry.read != read) {
|
2013-03-23 17:17:27 +01:00
|
|
|
entry.read = read;
|
|
|
|
|
$scope.$emit('emitMark', {
|
|
|
|
|
entry : entry
|
|
|
|
|
});
|
|
|
|
|
EntryService.mark({
|
|
|
|
|
_type : 'entry',
|
|
|
|
|
_id : entry.id,
|
|
|
|
|
_readtype : read
|
2013-03-22 09:29:30 +01:00
|
|
|
});
|
|
|
|
|
}
|
2013-03-21 19:51:00 +01:00
|
|
|
};
|
2013-03-21 16:22:58 +01:00
|
|
|
});
|