forked from Archives/Athou_commafeed
ability to subscribe to a feed
This commit is contained in:
@@ -8,14 +8,14 @@ module.run(function($rootScope) {
|
||||
});
|
||||
|
||||
module.controller('CategoryTreeCtrl', function($scope, $routeParams, $location,
|
||||
CategoryService) {
|
||||
SubscriptionService) {
|
||||
|
||||
$scope.$on('$routeChangeSuccess', function() {
|
||||
$scope.selectedType = $routeParams._type;
|
||||
$scope.selectedId = $routeParams._id;
|
||||
});
|
||||
|
||||
$scope.root = CategoryService.get();
|
||||
$scope.SubscriptionService = SubscriptionService;
|
||||
|
||||
var unreadCount = function(category) {
|
||||
var count = 0;
|
||||
@@ -76,7 +76,7 @@ module.controller('CategoryTreeCtrl', function($scope, $routeParams, $location,
|
||||
};
|
||||
|
||||
$scope.$on('mark', function(event, args) {
|
||||
mark($scope.root, args.entry)
|
||||
mark($scope.SubscriptionService.subscriptions, args.entry)
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@@ -1,5 +1,40 @@
|
||||
var module = angular.module('commafeed.directives', []);
|
||||
|
||||
module.directive('subscribe', function() {
|
||||
return {
|
||||
scope : {},
|
||||
restrict : 'E',
|
||||
replace : true,
|
||||
templateUrl : 'directives/subscribe.html',
|
||||
controller : function($scope, SubscriptionService) {
|
||||
$scope.opts = {
|
||||
backdropFade : true,
|
||||
dialogFade : true
|
||||
};
|
||||
|
||||
$scope.isOpen = false;
|
||||
$scope.sub = {};
|
||||
|
||||
$scope.SubscriptionService = SubscriptionService;
|
||||
|
||||
$scope.open = function() {
|
||||
$scope.sub = {};
|
||||
$scope.isOpen = true;
|
||||
};
|
||||
|
||||
$scope.close = function() {
|
||||
$scope.isOpen = false;
|
||||
};
|
||||
|
||||
$scope.save = function() {
|
||||
SubscriptionService.subscribe($scope.sub, function() {
|
||||
$scope.close();
|
||||
});
|
||||
};
|
||||
}
|
||||
};
|
||||
});
|
||||
|
||||
module.directive('category', function($compile) {
|
||||
return {
|
||||
scope: {
|
||||
|
||||
@@ -1,8 +1,63 @@
|
||||
var module = angular.module('commafeed.services', [ 'ngResource' ]);
|
||||
|
||||
module.factory('CategoryService', [ '$resource', '$http',
|
||||
module.factory('SubscriptionService', [ '$resource', '$http',
|
||||
function($resource, $http) {
|
||||
return $resource('rest/subscriptions');
|
||||
|
||||
var flatten = function(category, parentName, array) {
|
||||
if(!array) array = [];
|
||||
array.push({
|
||||
id : category.id,
|
||||
name : category.name + (parentName ? (' (in ' + parentName + ')') : '')
|
||||
});
|
||||
if (category.children) {
|
||||
for ( var i = 0; i < category.children.length; i++) {
|
||||
flatten(category.children[i], category.name, array);
|
||||
}
|
||||
}
|
||||
return array;
|
||||
}
|
||||
var actions = {
|
||||
get : {
|
||||
method : 'GET',
|
||||
params : {
|
||||
_method : ''
|
||||
}
|
||||
},
|
||||
subscribe : {
|
||||
method : 'POST',
|
||||
params : {
|
||||
_method : 'subscribe'
|
||||
}
|
||||
},
|
||||
unsubscribe : {
|
||||
method : 'GET',
|
||||
params : {
|
||||
_method : 'unsubscribe'
|
||||
}
|
||||
}
|
||||
};
|
||||
var s = {};
|
||||
s.subscriptions = {};
|
||||
s.flatCategories = {};
|
||||
|
||||
var res = $resource('rest/subscriptions/:_method', {}, actions);
|
||||
s.init = function() {
|
||||
s.subscriptions = res.get(function(){
|
||||
s.flatCategories = flatten(s.subscriptions);
|
||||
});
|
||||
};
|
||||
s.subscribe = function(sub) {
|
||||
res.subscribe(sub);
|
||||
s.init();
|
||||
};
|
||||
s.unsubscribe = function(id) {
|
||||
res.unsubscribe({
|
||||
id : id
|
||||
});
|
||||
s.init();
|
||||
};
|
||||
s.init();
|
||||
return s;
|
||||
} ]);
|
||||
|
||||
module.factory('EntryService', [
|
||||
|
||||
Reference in New Issue
Block a user