forked from Archives/Athou_commafeed
added complete tree
This commit is contained in:
@@ -3,26 +3,66 @@ package com.commafeed.backend.dao;
|
||||
import java.util.List;
|
||||
|
||||
import javax.ejb.Stateless;
|
||||
import javax.inject.Inject;
|
||||
import javax.persistence.TypedQuery;
|
||||
|
||||
import org.apache.commons.lang.ObjectUtils;
|
||||
|
||||
import com.commafeed.frontend.utils.ModelFactory.MF;
|
||||
import com.commafeed.model.FeedCategory;
|
||||
import com.commafeed.model.FeedSubscription;
|
||||
import com.commafeed.model.User;
|
||||
import com.google.common.collect.Lists;
|
||||
import com.uaihebert.factory.EasyCriteriaFactory;
|
||||
import com.uaihebert.model.EasyCriteria;
|
||||
|
||||
@Stateless
|
||||
public class FeedSubscriptionService extends GenericDAO<FeedSubscription, Long> {
|
||||
|
||||
@Inject
|
||||
FeedCategoryService feedCategoryService;
|
||||
|
||||
public List<FeedSubscription> findAll(User user) {
|
||||
return findByField(MF.i(MF.p(FeedCategory.class).getUser()), user);
|
||||
}
|
||||
|
||||
|
||||
public List<FeedSubscription> findWithoutCategories(User user) {
|
||||
EasyCriteria<FeedSubscription> criteria = EasyCriteriaFactory.createQueryCriteria(em, getType());
|
||||
EasyCriteria<FeedSubscription> criteria = EasyCriteriaFactory
|
||||
.createQueryCriteria(em, getType());
|
||||
criteria.andEquals("user", user);
|
||||
criteria.andEquals("category", null);
|
||||
return criteria.getResultList();
|
||||
|
||||
|
||||
}
|
||||
|
||||
public List<FeedSubscription> findWithCategory(User user,
|
||||
FeedCategory category) {
|
||||
|
||||
List<FeedCategory> categories = Lists.newArrayList();
|
||||
for (FeedCategory c : feedCategoryService.findAll(user)) {
|
||||
if (isChild(c, category)) {
|
||||
categories.add(c);
|
||||
}
|
||||
}
|
||||
|
||||
String query = "select s from FeedSubscription s where s.user=:user and s.category in :categories";
|
||||
TypedQuery<FeedSubscription> typedQuery = em.createQuery(query,
|
||||
FeedSubscription.class);
|
||||
typedQuery.setParameter("user", user);
|
||||
typedQuery.setParameter("categories", categories);
|
||||
return typedQuery.getResultList();
|
||||
}
|
||||
|
||||
private boolean isChild(FeedCategory c, FeedCategory category) {
|
||||
boolean isChild = false;
|
||||
while (c != null) {
|
||||
if (ObjectUtils.equals(c.getId(), category.getId())) {
|
||||
isChild = true;
|
||||
break;
|
||||
}
|
||||
c = c.getParent();
|
||||
}
|
||||
return isChild;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,22 +1,27 @@
|
||||
package com.commafeed.frontend.rest;
|
||||
|
||||
import java.text.DateFormat;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
import org.apache.wicket.request.mapper.parameter.PageParameters;
|
||||
|
||||
import com.commafeed.backend.dao.FeedCategoryService;
|
||||
import com.commafeed.backend.dao.FeedEntryService;
|
||||
import com.commafeed.backend.dao.FeedEntryStatusService;
|
||||
import com.commafeed.backend.dao.FeedSubscriptionService;
|
||||
import com.commafeed.frontend.rest.model.Entries;
|
||||
import com.commafeed.frontend.rest.model.Entry;
|
||||
import com.commafeed.frontend.utils.ModelFactory.MF;
|
||||
import com.commafeed.model.FeedCategory;
|
||||
import com.commafeed.model.FeedEntry;
|
||||
import com.commafeed.model.FeedEntryStatus;
|
||||
import com.commafeed.model.FeedSubscription;
|
||||
import com.google.common.collect.Iterables;
|
||||
import com.google.common.collect.Lists;
|
||||
|
||||
public class FeedEntriesREST extends JSONPage {
|
||||
|
||||
@@ -33,6 +38,9 @@ public class FeedEntriesREST extends JSONPage {
|
||||
@Inject
|
||||
FeedSubscriptionService feedSubscriptionService;
|
||||
|
||||
@Inject
|
||||
FeedCategoryService feedCategoryService;
|
||||
|
||||
public FeedEntriesREST(PageParameters pageParameters) {
|
||||
super(pageParameters);
|
||||
}
|
||||
@@ -50,23 +58,52 @@ public class FeedEntriesREST extends JSONPage {
|
||||
if ("feed".equals(type)) {
|
||||
FeedSubscription subscription = feedSubscriptionService
|
||||
.findById(Long.valueOf(id));
|
||||
List<FeedEntry> feedEntries = feedEntryService.getUnreadEntries(
|
||||
subscription.getFeed(), getUser());
|
||||
|
||||
entries.setName(subscription.getTitle());
|
||||
for (FeedEntry feedEntry : feedEntries) {
|
||||
|
||||
List<FeedEntryStatus> feedEntryStatus = feedEntryStatusService.findByField(MF.i(MF.p(FeedEntryStatus.class).getEntry()), feedEntry);
|
||||
|
||||
Entry entry = buildEntry(feedEntry);
|
||||
entry.setFeedName(subscription.getTitle());
|
||||
entry.setFeedId(String.valueOf(subscription.getId()));
|
||||
entry.setRead(feedEntryStatus.isEmpty() ? false : Iterables.getFirst(feedEntryStatus, null).isRead());
|
||||
entry.setStarred(feedEntryStatus.isEmpty() ? false : Iterables.getFirst(feedEntryStatus, null).isStarred());
|
||||
entries.getEntries().add(entry);
|
||||
entries.getEntries().addAll(buildEntries(subscription));
|
||||
|
||||
} else {
|
||||
FeedCategory feedCategory = feedCategoryService.findById("all"
|
||||
.equals(id) ? null : Long.valueOf(id));
|
||||
Collection<FeedSubscription> subscriptions = "all".equals(id) ? feedSubscriptionService
|
||||
.findAll(getUser()) : feedSubscriptionService
|
||||
.findWithCategory(getUser(), feedCategory);
|
||||
|
||||
entries.setName("all".equals(id) ? "All" : feedCategory.getName());
|
||||
for (FeedSubscription subscription : subscriptions) {
|
||||
entries.getEntries().addAll(buildEntries(subscription));
|
||||
}
|
||||
}
|
||||
|
||||
Collections.sort(entries.getEntries(), new Comparator<Entry>() {
|
||||
|
||||
@Override
|
||||
public int compare(Entry e1, Entry e2) {
|
||||
return e2.getDate().compareTo(e1.getDate());
|
||||
}
|
||||
});
|
||||
return entries;
|
||||
}
|
||||
|
||||
private List<Entry> buildEntries(FeedSubscription subscription) {
|
||||
List<FeedEntry> feedEntries = feedEntryService.getUnreadEntries(
|
||||
subscription.getFeed(), getUser());
|
||||
|
||||
List<Entry> entries = Lists.newArrayList();
|
||||
for (FeedEntry feedEntry : feedEntries) {
|
||||
|
||||
List<FeedEntryStatus> feedEntryStatus = feedEntryStatusService
|
||||
.findByField(MF.i(MF.p(FeedEntryStatus.class).getEntry()),
|
||||
feedEntry);
|
||||
|
||||
Entry entry = buildEntry(feedEntry);
|
||||
entry.setFeedName(subscription.getTitle());
|
||||
entry.setFeedId(String.valueOf(subscription.getId()));
|
||||
entry.setRead(feedEntryStatus.isEmpty() ? false : Iterables
|
||||
.getFirst(feedEntryStatus, null).isRead());
|
||||
entry.setStarred(feedEntryStatus.isEmpty() ? false : Iterables
|
||||
.getFirst(feedEntryStatus, null).isStarred());
|
||||
entries.add(entry);
|
||||
}
|
||||
return entries;
|
||||
}
|
||||
|
||||
@@ -75,8 +112,7 @@ public class FeedEntriesREST extends JSONPage {
|
||||
entry.setId(feedEntry.getGuid());
|
||||
entry.setTitle(feedEntry.getTitle());
|
||||
entry.setContent(feedEntry.getContent());
|
||||
entry.setDate(DateFormat.getDateInstance(DateFormat.SHORT, getLocale())
|
||||
.format(feedEntry.getUpdated()));
|
||||
entry.setDate(feedEntry.getUpdated());
|
||||
entry.setUrl(feedEntry.getUrl());
|
||||
|
||||
return entry;
|
||||
|
||||
@@ -10,9 +10,10 @@ import org.apache.wicket.request.mapper.parameter.PageParameters;
|
||||
import com.commafeed.backend.dao.FeedCategoryService;
|
||||
import com.commafeed.backend.dao.FeedEntryService;
|
||||
import com.commafeed.backend.dao.FeedSubscriptionService;
|
||||
import com.commafeed.frontend.rest.model.Category;
|
||||
import com.commafeed.frontend.rest.model.Subscription;
|
||||
import com.commafeed.model.FeedCategory;
|
||||
import com.commafeed.model.FeedSubscription;
|
||||
import com.google.common.collect.Lists;
|
||||
|
||||
@SuppressWarnings("serial")
|
||||
public class FeedSubscriptionsREST extends JSONPage {
|
||||
@@ -28,7 +29,6 @@ public class FeedSubscriptionsREST extends JSONPage {
|
||||
|
||||
public FeedSubscriptionsREST(PageParameters pageParameters) {
|
||||
super(pageParameters);
|
||||
// TODO Auto-generated constructor stub
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -36,6 +36,8 @@ public class FeedSubscriptionsREST extends JSONPage {
|
||||
List<FeedCategory> categories = feedCategoryService.findAll(getUser());
|
||||
Category root = new Category();
|
||||
addChildren(categories, root);
|
||||
root.setId("all");
|
||||
root.setName("All");
|
||||
for (FeedSubscription subscription : feedSubscriptionService
|
||||
.findWithoutCategories(getUser())) {
|
||||
Subscription sub = new Subscription();
|
||||
@@ -53,9 +55,10 @@ public class FeedSubscriptionsREST extends JSONPage {
|
||||
for (FeedCategory category : categories) {
|
||||
if ((category.getParent() == null && current.getId() == null)
|
||||
|| (category.getParent() != null && (ObjectUtils.equals(
|
||||
category.getParent().getId(), current.getId())))) {
|
||||
String.valueOf(category.getParent().getId()),
|
||||
current.getId())))) {
|
||||
Category child = new Category();
|
||||
child.setId(category.getId());
|
||||
child.setId(String.valueOf(category.getId()));
|
||||
child.setName(category.getName());
|
||||
addChildren(categories, child);
|
||||
for (FeedSubscription subscription : category
|
||||
@@ -72,76 +75,4 @@ public class FeedSubscriptionsREST extends JSONPage {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static class Category {
|
||||
private Long id;
|
||||
private String name;
|
||||
private List<Category> children = Lists.newArrayList();
|
||||
private List<Subscription> feeds = Lists.newArrayList();
|
||||
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(Long id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public List<Category> getChildren() {
|
||||
return children;
|
||||
}
|
||||
|
||||
public void setChildren(List<Category> children) {
|
||||
this.children = children;
|
||||
}
|
||||
|
||||
public List<Subscription> getFeeds() {
|
||||
return feeds;
|
||||
}
|
||||
|
||||
public void setFeeds(List<Subscription> feeds) {
|
||||
this.feeds = feeds;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static class Subscription {
|
||||
private Long id;
|
||||
private String name;
|
||||
private int unread;
|
||||
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(Long id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public int getUnread() {
|
||||
return unread;
|
||||
}
|
||||
|
||||
public void setUnread(int unread) {
|
||||
this.unread = unread;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -7,13 +7,15 @@ import org.apache.wicket.request.mapper.parameter.PageParameters;
|
||||
import com.commafeed.frontend.CommaFeedSession;
|
||||
import com.commafeed.model.User;
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.GsonBuilder;
|
||||
|
||||
@SuppressWarnings("serial")
|
||||
public abstract class JSONPage extends WebPage {
|
||||
|
||||
public JSONPage(PageParameters pageParameters) {
|
||||
Gson gson = new GsonBuilder().setDateFormat("yyyy-MM-dd").create();
|
||||
getRequestCycle().scheduleRequestHandlerAfterCurrent(
|
||||
new TextRequestHandler("application/json", "UTF-8", new Gson()
|
||||
new TextRequestHandler("application/json", "UTF-8", gson
|
||||
.toJson(getObject(pageParameters))));
|
||||
}
|
||||
|
||||
|
||||
@@ -2,20 +2,19 @@ package com.commafeed.frontend.rest.model;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.commafeed.frontend.rest.FeedSubscriptionsREST.Subscription;
|
||||
import com.google.common.collect.Lists;
|
||||
|
||||
public class Category {
|
||||
private Long id;
|
||||
private String id;
|
||||
private String name;
|
||||
private List<Category> children = Lists.newArrayList();
|
||||
private List<Subscription> feeds = Lists.newArrayList();
|
||||
|
||||
public Long getId() {
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(Long id) {
|
||||
public void setId(String id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,10 +1,12 @@
|
||||
package com.commafeed.frontend.rest.model;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
public class Entry {
|
||||
private String id;
|
||||
private String title;
|
||||
private String content;
|
||||
private String date;
|
||||
private Date date;
|
||||
private String feedId;
|
||||
private String feedName;
|
||||
private String url;
|
||||
@@ -35,11 +37,11 @@ public class Entry {
|
||||
this.content = content;
|
||||
}
|
||||
|
||||
public String getDate() {
|
||||
public Date getDate() {
|
||||
return date;
|
||||
}
|
||||
|
||||
public void setDate(String date) {
|
||||
public void setDate(Date date) {
|
||||
this.date = date;
|
||||
}
|
||||
|
||||
|
||||
@@ -15,14 +15,12 @@ module.directive('category', function($compile) {
|
||||
replace: true,
|
||||
templateUrl: 'directives/category.html',
|
||||
link: function(scope, element) {
|
||||
if (scope.node.children) {
|
||||
var ul = element.find('ul');
|
||||
ul.prepend('<category ng-repeat="child in node.children" node="child" feed-click="feedClick({id:id})" \
|
||||
category-click="categoryClick({id:id})" selected-type="selectedType" selected-id="selectedId" \
|
||||
format-category-name="formatCategoryName({category:category})" format-feed-name="formatFeedName({feed:feed})">\
|
||||
</category>');
|
||||
$compile(ul.contents())(scope);
|
||||
}
|
||||
var ul = element.find('ul');
|
||||
ul.prepend('<category ng-repeat="child in node.children" node="child" feed-click="feedClick({id:id})" \
|
||||
category-click="categoryClick({id:id})" selected-type="selectedType" selected-id="selectedId" \
|
||||
format-category-name="formatCategoryName({category:category})" format-feed-name="formatFeedName({feed:feed})">\
|
||||
</category>');
|
||||
$compile(ul.contents())(scope);
|
||||
}
|
||||
};
|
||||
});
|
||||
@@ -3,23 +3,28 @@
|
||||
<div class="span2" ng-controller="CategoryTreeCtrl">
|
||||
<div class="css-treeview">
|
||||
<ul>
|
||||
<li ng-repeat="node in root.children">
|
||||
<category node="node" feed-click="feedClicked(id)" category-click="categoryClicked(id)"
|
||||
<category node="root" feed-click="feedClicked(id)" category-click="categoryClicked(id)"
|
||||
selected-type="selectedType" selected-id="selectedId"
|
||||
format-category-name="formatCategoryName(category)" format-feed-name="formatFeedName(feed)">
|
||||
</category>
|
||||
</li>
|
||||
<!-- <li ng-repeat="node in root.children"> -->
|
||||
<!-- <category node="node" feed-click="feedClicked(id)" category-click="categoryClicked(id)" -->
|
||||
<!-- selected-type="selectedType" selected-id="selectedId" -->
|
||||
<!-- format-category-name="formatCategoryName(category)" format-feed-name="formatFeedName(feed)"> -->
|
||||
<!-- </category> -->
|
||||
<!-- </li> -->
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
<div class="span10" ng-controller="FeedListCtrl">
|
||||
<span>{{entryList.name}}</span><span ng-show="selectedType == 'category'">»</span>
|
||||
<span>{{entryList.name}}</span><span ng-show="selectedType == 'category'"> »</span>
|
||||
<div class="accordion" id="feed-accordion">
|
||||
<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}}">
|
||||
<span ng-show="selectedType == 'category'">{{entry.feedName}} - </span>{{entry.title}}
|
||||
<span class="pull-right">{{entry.date}}</span>
|
||||
</a>
|
||||
</div>
|
||||
<div id="{{'feed-body' + $index}}" class="accordion-body collapse">
|
||||
|
||||
Reference in New Issue
Block a user