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) {
|
|
|
|
|
$rootScope.$on('emitMarkAsRead', function(event, args) {
|
|
|
|
|
$rootScope.$broadcast('markAsRead', args);
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
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 20:51:22 +01:00
|
|
|
$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-22 22:20:17 +01:00
|
|
|
var markAsRead = function(node, entry, read) {
|
|
|
|
|
if (node.children) {
|
|
|
|
|
for ( var i = 0; i < node.children.length; i++) {
|
|
|
|
|
markAsRead(node.children[i], entry, read);
|
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) {
|
|
|
|
|
var c = read ? -1 : 1;
|
|
|
|
|
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-22 20:51:22 +01:00
|
|
|
$scope.$on('markAsRead', function(event, args) {
|
2013-03-22 22:20:17 +01:00
|
|
|
markAsRead($scope.root, args.entry, args.read)
|
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-22 20:51:22 +01:00
|
|
|
$scope.entryList = EntryService.getUnread({
|
|
|
|
|
_type : $scope.selectedType,
|
|
|
|
|
_id : $scope.selectedId,
|
|
|
|
|
_readtype : 'unread'
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
$scope.entryList2 = {
|
2013-03-22 09:29:30 +01:00
|
|
|
name : 'aaa',
|
|
|
|
|
entries : [ {
|
|
|
|
|
id : '1',
|
|
|
|
|
title : 'my title',
|
|
|
|
|
content : 'my content',
|
|
|
|
|
date : 'my date',
|
|
|
|
|
feedId : '1',
|
|
|
|
|
feedName : 'my feed',
|
|
|
|
|
url : 'my url',
|
|
|
|
|
read : false,
|
|
|
|
|
starred : false,
|
|
|
|
|
}, {
|
|
|
|
|
id : '2',
|
|
|
|
|
title : 'my other title',
|
|
|
|
|
content : 'my other content',
|
|
|
|
|
date : 'my other date',
|
|
|
|
|
feedId : '2',
|
|
|
|
|
feedName : 'my other feed',
|
|
|
|
|
url : 'my other url',
|
|
|
|
|
read : false,
|
|
|
|
|
starred : false,
|
|
|
|
|
} ]
|
|
|
|
|
};
|
2013-03-21 19:51:00 +01:00
|
|
|
|
|
|
|
|
$scope.markAsRead = function(entry) {
|
2013-03-22 09:29:30 +01:00
|
|
|
var read = entry.read;
|
2013-03-21 19:51:00 +01:00
|
|
|
entry.read = true;
|
2013-03-22 09:29:30 +01:00
|
|
|
if (entry.read != read) {
|
|
|
|
|
$scope.$emit('emitMarkAsRead', {
|
|
|
|
|
entry : entry,
|
|
|
|
|
read : true
|
|
|
|
|
});
|
|
|
|
|
}
|
2013-03-21 19:51:00 +01:00
|
|
|
};
|
2013-03-21 16:22:58 +01:00
|
|
|
});
|