use backend to populate data

This commit is contained in:
Athou
2013-03-22 20:51:22 +01:00
parent c6ec3c9517
commit f3ff02b476
14 changed files with 239 additions and 126 deletions

View File

@@ -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',

View File

@@ -1,6 +1,6 @@
var app = angular
.module('commafeed', [ 'ui', 'ui.bootstrap', 'commafeed.directives',
'commafeed.controllers', 'commafeed.services' ]);
'commafeed.controllers', 'commafeed.services', 'ngSanitize' ]);
app.config([ '$routeProvider', function($routeProvider) {
$routeProvider.when('/feeds/view/:_type/:_id', {

View File

@@ -2,7 +2,6 @@ var module = angular.module('commafeed.services', [ 'ngResource' ]);
module.factory('CategoryService', [ '$resource', '$http',
function($resource, $http) {
var actions = {
'get' : {
method : 'GET'
@@ -10,4 +9,20 @@ module.factory('CategoryService', [ '$resource', '$http',
}
res = $resource('subscriptions', {}, actions);
return res
} ]);
module.factory('EntryService', [ '$resource', '$http',
function($resource, $http) {
var actions = {
'getUnread' : {
method : 'GET',
params : {
_type : 'category',
_id : '1',
_readtype : 'unread',
}
}
}
res = $resource('entries/:_type/:_id/:_readtype', {}, actions);
return res
} ]);