mirror of
https://github.com/Athou/commafeed.git
synced 2026-03-21 21:37:29 +00:00
use backend to populate data
This commit is contained in:
@@ -6,86 +6,92 @@ module.run(function($rootScope) {
|
||||
});
|
||||
});
|
||||
|
||||
module.controller('CategoryTreeCtrl',
|
||||
function($scope, $routeParams, $location, CategoryService) {
|
||||
|
||||
$scope.selectedType = $routeParams._type;
|
||||
$scope.selectedId = $routeParams._id;
|
||||
|
||||
$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]);
|
||||
}
|
||||
}
|
||||
if (category.feeds) {
|
||||
for ( var i = 0; i < category.feeds.length; i++) {
|
||||
var feed = category.feeds[i];
|
||||
count = count + feed.unread;
|
||||
}
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
$scope.formatCategoryName = function(category) {
|
||||
var count = 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) {
|
||||
$location.path('/feeds/view/feed/' + id);
|
||||
};
|
||||
|
||||
$scope.categoryClicked = function(id) {
|
||||
$location.path('/feeds/view/category/' + id);
|
||||
};
|
||||
|
||||
var markAsRead = function(children, entry, read) {
|
||||
for ( var i = 0; i < children.length; i++) {
|
||||
var child = children[i];
|
||||
if (child.children) {
|
||||
markAsRead(child.children, entry, read);
|
||||
}
|
||||
if (child.feeds) {
|
||||
for ( var j = 0; j < child.feeds.length; j++) {
|
||||
var feed = child.feeds[j];
|
||||
console.log(entry.feedId)
|
||||
if (feed.id == entry.feedId) {
|
||||
var c = read ? -1 : 1;
|
||||
console.log(c)
|
||||
feed.unread = feed.unread + c;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
$scope.$on('markAsRead', function(event, args) {
|
||||
markAsRead($scope.root.children, args.entry, args.read)
|
||||
});
|
||||
});
|
||||
|
||||
module.controller('FeedListCtrl', function($scope, $routeParams, $http) {
|
||||
module.controller('CategoryTreeCtrl', function($scope, $routeParams, $location,
|
||||
CategoryService) {
|
||||
|
||||
$scope.selectedType = $routeParams._type;
|
||||
$scope.selectedId = $routeParams._id;
|
||||
|
||||
$scope.entryList = {
|
||||
$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]);
|
||||
}
|
||||
}
|
||||
if (category.feeds) {
|
||||
for ( var i = 0; i < category.feeds.length; i++) {
|
||||
var feed = category.feeds[i];
|
||||
count = count + feed.unread;
|
||||
}
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
$scope.formatCategoryName = function(category) {
|
||||
var count = 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) {
|
||||
$location.path('/feeds/view/feed/' + id);
|
||||
};
|
||||
|
||||
$scope.categoryClicked = function(id) {
|
||||
$location.path('/feeds/view/category/' + id);
|
||||
};
|
||||
|
||||
var markAsRead = function(children, entry, read) {
|
||||
for ( var i = 0; i < children.length; i++) {
|
||||
var child = children[i];
|
||||
if (child.children) {
|
||||
markAsRead(child.children, entry, read);
|
||||
}
|
||||
if (child.feeds) {
|
||||
for ( var j = 0; j < child.feeds.length; j++) {
|
||||
var feed = child.feeds[j];
|
||||
if (feed.id == entry.feedId) {
|
||||
var c = read ? -1 : 1;
|
||||
feed.unread = feed.unread + c;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
$scope.$on('markAsRead', function(event, args) {
|
||||
console.log(args.entry)
|
||||
markAsRead($scope.root.children, args.entry, args.read)
|
||||
});
|
||||
});
|
||||
|
||||
module.controller('FeedListCtrl', function($scope, $routeParams, $http,
|
||||
EntryService) {
|
||||
|
||||
$scope.selectedType = $routeParams._type;
|
||||
$scope.selectedId = $routeParams._id;
|
||||
|
||||
$scope.entryList = EntryService.getUnread({
|
||||
_type : $scope.selectedType,
|
||||
_id : $scope.selectedId,
|
||||
_readtype : 'unread'
|
||||
})
|
||||
|
||||
$scope.entryList2 = {
|
||||
name : 'aaa',
|
||||
entries : [ {
|
||||
id : '1',
|
||||
|
||||
Reference in New Issue
Block a user