Files
commafeed/src/main/webapp/js/controllers.js

96 lines
2.0 KiB
JavaScript
Raw Normal View History

2013-03-21 16:22:58 +01:00
var module = angular.module('commafeed.controllers', []);
module.controller('CategoryTreeCtrl',
function($scope, $routeParams, $location) {
$scope.selectedType = $routeParams._type;
$scope.selectedId = $routeParams._id;
$scope.root = {
children : [ {
id : "1",
name : "News",
feeds : [ {
id : "2",
2013-03-21 23:10:05 +01:00
name : "Cyanide & Happiness",
unread : 34
2013-03-21 16:22:58 +01:00
} ],
children : [ {
id : "2",
name : "Comics",
feeds : [ {
id : "1",
2013-03-21 23:10:05 +01:00
name : "Dilbert",
unread : 4
2013-03-21 16:22:58 +01:00
} ]
} ]
}, {
id : '3',
name : "Blogs",
feeds : [ {
id : "3",
2013-03-21 23:10:05 +01:00
name : "Engadget",
unread : 0
2013-03-21 16:22:58 +01:00
} ]
} ]
};
2013-03-21 23:10:05 +01:00
var unreadCount = function(category) {
var count = 0;
console.log(category)
for ( var child in category.children) {
count = count + unreadCount(child);
}
for ( var feed in category.feeds) {
if (feed.unread) {
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;
}
2013-03-21 16:22:58 +01:00
$scope.feedClicked = function(id) {
$location.path('/feeds/view/feed/' + id);
};
$scope.categoryClicked = function(id) {
$location.path('/feeds/view/category/' + id);
};
});
module.controller('FeedListCtrl', function($scope, $routeParams, $http) {
$scope.entries = [ {
id : '1',
2013-03-21 19:51:00 +01:00
title : 'my title',
content : 'my content',
date : 'my date',
feed : 'my feed',
url : 'my url',
read : false,
starred : false,
}, {
id : '1',
title : 'my title',
content : 'my content',
date : 'my date',
feed : 'my feed',
url : 'my url',
2013-03-21 16:22:58 +01:00
read : false,
starred : false,
} ];
2013-03-21 19:51:00 +01:00
$scope.markAsRead = function(entry) {
entry.read = true;
};
2013-03-21 16:22:58 +01:00
});