forked from Archives/Athou_commafeed
unread count sync
This commit is contained in:
@@ -15,10 +15,12 @@
|
||||
<script src="vendor/jquery/jquery-1.9.1.min.js"></script>
|
||||
<script src="vendor/bootstrap/js/bootstrap.min.js"></script>
|
||||
<script src="vendor/angular/angular.min.js"></script>
|
||||
<script src="vendor/angular/angular-resource.min.js"></script>
|
||||
<script src="vendor/angular-ui/angular-ui.min.js"></script>
|
||||
<script src="vendor/angular-ui-bootstrap/ui-bootstrap-tpls-0.2.0.min.js"></script>
|
||||
<script src="js/main.js"></script>
|
||||
<script src="js/controllers.js"></script>
|
||||
<script src="js/directives.js"></script>
|
||||
<script src="js/services.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
@@ -1,10 +1,18 @@
|
||||
var module = angular.module('commafeed.controllers', []);
|
||||
|
||||
module.run(function($rootScope) {
|
||||
$rootScope.$on('emitMarkAsRead', function(event, args) {
|
||||
$rootScope.$broadcast('markAsRead', args);
|
||||
});
|
||||
});
|
||||
|
||||
module.controller('CategoryTreeCtrl',
|
||||
function($scope, $routeParams, $location) {
|
||||
function($scope, $routeParams, $location, CategoryService) {
|
||||
|
||||
$scope.selectedType = $routeParams._type;
|
||||
$scope.selectedId = $routeParams._id;
|
||||
|
||||
$scope.root2 = CategoryService.get();
|
||||
|
||||
$scope.root = {
|
||||
children : [ {
|
||||
@@ -75,31 +83,70 @@ module.controller('CategoryTreeCtrl',
|
||||
$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) {
|
||||
|
||||
$scope.entries = [ {
|
||||
id : '1',
|
||||
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',
|
||||
read : false,
|
||||
starred : false,
|
||||
} ];
|
||||
$scope.selectedType = $routeParams._type;
|
||||
$scope.selectedId = $routeParams._id;
|
||||
|
||||
$scope.entryList = {
|
||||
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,
|
||||
} ]
|
||||
};
|
||||
|
||||
$scope.markAsRead = function(entry) {
|
||||
var read = entry.read;
|
||||
entry.read = true;
|
||||
if (entry.read != read) {
|
||||
$scope.$emit('emitMarkAsRead', {
|
||||
entry : entry,
|
||||
read : true
|
||||
});
|
||||
}
|
||||
};
|
||||
});
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
var app = angular.module('commafeed', [ 'ui', 'ui.bootstrap', 'commafeed.directives', 'commafeed.controllers' ]);
|
||||
var app = angular
|
||||
.module('commafeed', [ 'ui', 'ui.bootstrap', 'commafeed.directives',
|
||||
'commafeed.controllers', 'commafeed.services' ]);
|
||||
|
||||
app.config([ '$routeProvider', function($routeProvider) {
|
||||
$routeProvider.when('/feeds/view/:_type/:_id', {
|
||||
|
||||
13
src/main/webapp/js/services.js
Normal file
13
src/main/webapp/js/services.js
Normal file
@@ -0,0 +1,13 @@
|
||||
var module = angular.module('commafeed.services', [ 'ngResource' ]);
|
||||
|
||||
module.factory('CategoryService', [ '$resource', '$http',
|
||||
function($resource, $http) {
|
||||
|
||||
var actions = {
|
||||
'get' : {
|
||||
method : 'GET'
|
||||
}
|
||||
}
|
||||
res = $resource('subscriptions', {}, actions);
|
||||
return res
|
||||
} ]);
|
||||
@@ -13,12 +13,13 @@
|
||||
</div>
|
||||
</div>
|
||||
<div class="span10" ng-controller="FeedListCtrl">
|
||||
<span>{{entryList.name}}</span><span ng-show="selectedType == 'category'">»</span>
|
||||
<div class="accordion" id="feed-accordion">
|
||||
<div class="accordion-group" ng-repeat="entry in entries">
|
||||
<div class="accordion-group" ng-repeat="entry in entryList.entries">
|
||||
<div class="accordion-heading">
|
||||
<a class="accordion-toggle" data-toggle="collapse" ng-click="markAsRead(entry)" ng-class="{unread: entry.read == false}"
|
||||
data-parent="#feed-accordion" href="{{'#feed-body' + $index}}">
|
||||
{{entry.title}}
|
||||
<span ng-show="selectedType == 'category'">{{entry.feedName}} - </span>{{entry.title}}
|
||||
</a>
|
||||
</div>
|
||||
<div id="{{'feed-body' + $index}}" class="accordion-body collapse">
|
||||
|
||||
10
src/main/webapp/vendor/angular/angular-resource.min.js
vendored
Normal file
10
src/main/webapp/vendor/angular/angular-resource.min.js
vendored
Normal file
@@ -0,0 +1,10 @@
|
||||
/*
|
||||
AngularJS v1.0.5
|
||||
(c) 2010-2012 Google, Inc. http://angularjs.org
|
||||
License: MIT
|
||||
*/
|
||||
(function(C,d,w){'use strict';d.module("ngResource",["ng"]).factory("$resource",["$http","$parse",function(x,y){function s(b,e){return encodeURIComponent(b).replace(/%40/gi,"@").replace(/%3A/gi,":").replace(/%24/g,"$").replace(/%2C/gi,",").replace(e?null:/%20/g,"+")}function t(b,e){this.template=b+="#";this.defaults=e||{};var a=this.urlParams={};h(b.split(/\W/),function(f){f&&RegExp("(^|[^\\\\]):"+f+"\\W").test(b)&&(a[f]=!0)});this.template=b.replace(/\\:/g,":")}function u(b,e,a){function f(m,a){var b=
|
||||
{},a=o({},e,a);h(a,function(a,z){var c;a.charAt&&a.charAt(0)=="@"?(c=a.substr(1),c=y(c)(m)):c=a;b[z]=c});return b}function g(a){v(a||{},this)}var k=new t(b),a=o({},A,a);h(a,function(a,b){a.method=d.uppercase(a.method);var e=a.method=="POST"||a.method=="PUT"||a.method=="PATCH";g[b]=function(b,c,d,B){var j={},i,l=p,q=null;switch(arguments.length){case 4:q=B,l=d;case 3:case 2:if(r(c)){if(r(b)){l=b;q=c;break}l=c;q=d}else{j=b;i=c;l=d;break}case 1:r(b)?l=b:e?i=b:j=b;break;case 0:break;default:throw"Expected between 0-4 arguments [params, data, success, error], got "+
|
||||
arguments.length+" arguments.";}var n=this instanceof g?this:a.isArray?[]:new g(i);x({method:a.method,url:k.url(o({},f(i,a.params||{}),j)),data:i}).then(function(b){var c=b.data;if(c)a.isArray?(n.length=0,h(c,function(a){n.push(new g(a))})):v(c,n);(l||p)(n,b.headers)},q);return n};g.prototype["$"+b]=function(a,d,h){var m=f(this),j=p,i;switch(arguments.length){case 3:m=a;j=d;i=h;break;case 2:case 1:r(a)?(j=a,i=d):(m=a,j=d||p);case 0:break;default:throw"Expected between 1-3 arguments [params, success, error], got "+
|
||||
arguments.length+" arguments.";}g[b].call(this,m,e?this:w,j,i)}});g.bind=function(d){return u(b,o({},e,d),a)};return g}var A={get:{method:"GET"},save:{method:"POST"},query:{method:"GET",isArray:!0},remove:{method:"DELETE"},"delete":{method:"DELETE"}},p=d.noop,h=d.forEach,o=d.extend,v=d.copy,r=d.isFunction;t.prototype={url:function(b){var e=this,a=this.template,f,g,b=b||{};h(this.urlParams,function(h,c){f=b.hasOwnProperty(c)?b[c]:e.defaults[c];d.isDefined(f)&&f!==null?(g=s(f,!0).replace(/%26/gi,"&").replace(/%3D/gi,
|
||||
"=").replace(/%2B/gi,"+"),a=a.replace(RegExp(":"+c+"(\\W)","g"),g+"$1")):a=a.replace(RegExp("(/?):"+c+"(\\W)","g"),function(a,b,c){return c.charAt(0)=="/"?c:b+c})});var a=a.replace(/\/?#$/,""),k=[];h(b,function(a,b){e.urlParams[b]||k.push(s(b)+"="+s(a))});k.sort();a=a.replace(/\/*$/,"");return a+(k.length?"?"+k.join("&"):"")}};return u}])})(window,window.angular);
|
||||
Reference in New Issue
Block a user