fix unread count

This commit is contained in:
Jeremie Panzer
2013-03-22 11:42:25 +01:00
parent 25f0871195
commit bb3431a510
7 changed files with 50 additions and 45 deletions

View File

@@ -52,8 +52,15 @@ public class StartupBean {
salt)); salt));
userService.save(user); userService.save(user);
Feed feed = new Feed("http://feed.dilbert.com/dilbert/daily_strip"); Feed dilbert = new Feed(
feedService.save(feed); "http://feed.dilbert.com/dilbert/daily_strip");
feedService.save(dilbert);
Feed engadget = new Feed("http://www.engadget.com/rss.xml");
feedService.save(engadget);
Feed frandroid = new Feed("http://feeds.feedburner.com/frandroid");
feedService.save(frandroid);
FeedCategory newsCategory = new FeedCategory(); FeedCategory newsCategory = new FeedCategory();
newsCategory.setName("News"); newsCategory.setName("News");
@@ -66,13 +73,32 @@ public class StartupBean {
comicsCategory.setParent(newsCategory); comicsCategory.setParent(newsCategory);
feedCategoryService.save(comicsCategory); feedCategoryService.save(comicsCategory);
FeedCategory techCategory = new FeedCategory();
techCategory.setName("Tech");
techCategory.setUser(user);
techCategory.setParent(newsCategory);
feedCategoryService.save(techCategory);
FeedSubscription sub = new FeedSubscription(); FeedSubscription sub = new FeedSubscription();
sub.setCategory(comicsCategory); sub.setCategory(comicsCategory);
sub.setFeed(feed); sub.setFeed(dilbert);
sub.setTitle("Dilbert - Strips"); sub.setTitle("Dilbert - Strips");
sub.setUser(user); sub.setUser(user);
feedSubscriptionService.save(sub); feedSubscriptionService.save(sub);
FeedSubscription sub2 = new FeedSubscription();
sub2.setCategory(techCategory);
sub2.setFeed(engadget);
sub2.setTitle("Engadget");
sub2.setUser(user);
feedSubscriptionService.save(sub2);
FeedSubscription sub3 = new FeedSubscription();
sub3.setFeed(frandroid);
sub3.setTitle("Frandroid");
sub3.setUser(user);
feedSubscriptionService.save(sub3);
} }
} }

View File

@@ -32,7 +32,7 @@ public class FeedEntryService extends GenericDAO<FeedEntry, String> {
} }
public List<FeedEntry> getUnreadEntries(Feed feed, User user) { public List<FeedEntry> getUnreadEntries(Feed feed, User user) {
String query = "select entry from FeedEntry entry where entry.feed = :feed and not in (select status.entry from FeedEntryStatus status where status.user = :user and status.read = true)"; String query = "select e from FeedEntry e where e.feed=:feed and not exists (select s from FeedEntryStatus s where s.entry = e and s.user =:user and s.read = true)";
TypedQuery<FeedEntry> typedQuery = em.createQuery(query, TypedQuery<FeedEntry> typedQuery = em.createQuery(query,
FeedEntry.class); FeedEntry.class);
typedQuery.setParameter("feed", feed); typedQuery.setParameter("feed", feed);

View File

@@ -8,6 +8,8 @@ import com.commafeed.frontend.utils.ModelFactory.MF;
import com.commafeed.model.FeedCategory; import com.commafeed.model.FeedCategory;
import com.commafeed.model.FeedSubscription; import com.commafeed.model.FeedSubscription;
import com.commafeed.model.User; import com.commafeed.model.User;
import com.uaihebert.factory.EasyCriteriaFactory;
import com.uaihebert.model.EasyCriteria;
@Stateless @Stateless
public class FeedSubscriptionService extends GenericDAO<FeedSubscription, Long> { public class FeedSubscriptionService extends GenericDAO<FeedSubscription, Long> {
@@ -15,4 +17,12 @@ public class FeedSubscriptionService extends GenericDAO<FeedSubscription, Long>
public List<FeedSubscription> findAll(User user) { public List<FeedSubscription> findAll(User user) {
return findByField(MF.i(MF.p(FeedCategory.class).getUser()), user); return findByField(MF.i(MF.p(FeedCategory.class).getUser()), user);
} }
public List<FeedSubscription> findWithoutCategories(User user) {
EasyCriteria<FeedSubscription> criteria = EasyCriteriaFactory.createQueryCriteria(em, getType());
criteria.andEquals("user", user);
criteria.andEquals("category", null);
return criteria.getResultList();
}
} }

View File

@@ -45,7 +45,7 @@ public class CommaFeedSession extends AuthenticatedWebSession {
@Override @Override
public boolean authenticate(String userName, String password) { public boolean authenticate(String userName, String password) {
User user = userService.login(userName, password); User user = userService.login(userName, password);
setUser(user); this.user = user;
return user != null; return user != null;
} }

View File

@@ -11,7 +11,6 @@ import com.commafeed.backend.dao.FeedEntryService;
import com.commafeed.backend.dao.FeedSubscriptionService; import com.commafeed.backend.dao.FeedSubscriptionService;
import com.commafeed.frontend.CommaFeedSession; import com.commafeed.frontend.CommaFeedSession;
import com.commafeed.frontend.pages.JSONPage; import com.commafeed.frontend.pages.JSONPage;
import com.commafeed.frontend.utils.ModelFactory.MF;
import com.commafeed.model.FeedCategory; import com.commafeed.model.FeedCategory;
import com.commafeed.model.FeedSubscription; import com.commafeed.model.FeedSubscription;
import com.commafeed.model.User; import com.commafeed.model.User;
@@ -24,21 +23,19 @@ public class FeedSubscriptionsREST extends JSONPage {
FeedSubscriptionService feedSubscriptionService; FeedSubscriptionService feedSubscriptionService;
@Inject @Inject
FeedCategoryService FeedCategoryService; FeedCategoryService feedCategoryService;
@Inject @Inject
FeedEntryService feedEntryService; FeedEntryService feedEntryService;
User user = CommaFeedSession.get().getUser();
@Override @Override
protected Object getObject() { protected Object getObject() {
List<FeedCategory> categories = FeedCategoryService.findAll(user); User user = CommaFeedSession.get().getUser();
List<FeedCategory> categories = feedCategoryService.findAll(user);
Category root = new Category(); Category root = new Category();
addChildren(categories, root); addChildren(categories, root);
for (FeedSubscription subscription : feedSubscriptionService for (FeedSubscription subscription : feedSubscriptionService
.findByField(MF.i(MF.p(FeedSubscription.class).getCategory()), .findWithoutCategories(user)) {
null)) {
Subscription sub = new Subscription(); Subscription sub = new Subscription();
sub.setId(subscription.getId()); sub.setId(subscription.getId());
sub.setName(subscription.getTitle()); sub.setName(subscription.getTitle());
@@ -65,7 +62,8 @@ public class FeedSubscriptionsREST extends JSONPage {
sub.setId(subscription.getId()); sub.setId(subscription.getId());
sub.setName(subscription.getTitle()); sub.setName(subscription.getTitle());
int size = feedEntryService.getUnreadEntries( int size = feedEntryService.getUnreadEntries(
subscription.getFeed(), user).size(); subscription.getFeed(),
CommaFeedSession.get().getUser()).size();
sub.setUnread(size); sub.setUnread(size);
child.getFeeds().add(sub); child.getFeeds().add(sub);
} }

View File

@@ -1,4 +1,4 @@
<span> <input type="checkbox" checked="checked" /> <li> <input type="checkbox" checked="checked" />
<label ng-click="categoryClick({id: node.id})" <label ng-click="categoryClick({id: node.id})"
ng-class="{selected: (node.id == selectedId && selectedType == 'category')}">{{formatCategoryName({category:node})}} ng-class="{selected: (node.id == selectedId && selectedType == 'category')}">{{formatCategoryName({category:node})}}
</label> </label>
@@ -9,4 +9,4 @@
</a> </a>
</li> </li>
</ul> </ul>
</span> </li>

View File

@@ -12,36 +12,7 @@ module.controller('CategoryTreeCtrl',
$scope.selectedType = $routeParams._type; $scope.selectedType = $routeParams._type;
$scope.selectedId = $routeParams._id; $scope.selectedId = $routeParams._id;
$scope.root2 = CategoryService.get(); $scope.root = CategoryService.get();
$scope.root = {
children : [ {
id : "1",
name : "News",
feeds : [ {
id : "2",
name : "Cyanide & Happiness",
unread : 34
} ],
children : [ {
id : "2",
name : "Comics",
feeds : [ {
id : "1",
name : "Dilbert",
unread : 4
} ]
} ]
}, {
id : '3',
name : "Blogs",
feeds : [ {
id : "3",
name : "Engadget",
unread : 0
} ]
} ]
};
var unreadCount = function(category) { var unreadCount = function(category) {
var count = 0; var count = 0;