forked from Archives/Athou_commafeed
toggle between unread and all entries
This commit is contained in:
@@ -46,12 +46,11 @@ public class FeedEntryService extends GenericDAO<FeedEntry, Long> {
|
||||
return typedQuery.getResultList();
|
||||
}
|
||||
|
||||
public List<FeedEntry> getAllEntries(Feed feed, User user) {
|
||||
public List<FeedEntry> getAllEntries(Feed feed) {
|
||||
String query = "select e from FeedEntry e where e.feed=:feed";
|
||||
TypedQuery<FeedEntry> typedQuery = em.createQuery(query,
|
||||
FeedEntry.class);
|
||||
typedQuery.setParameter("feed", feed);
|
||||
typedQuery.setParameter("user", user);
|
||||
return typedQuery.getResultList();
|
||||
}
|
||||
|
||||
|
||||
@@ -30,11 +30,13 @@ public class EntriesREST extends AbstractREST {
|
||||
@PathParam("id") String id, @PathParam("readType") String readType) {
|
||||
|
||||
Entries entries = new Entries();
|
||||
boolean unreadOnly = "unread".equals(readType);
|
||||
|
||||
if ("feed".equals(type)) {
|
||||
FeedSubscription subscription = feedSubscriptionService
|
||||
.findById(Long.valueOf(id));
|
||||
entries.setName(subscription.getTitle());
|
||||
entries.getEntries().addAll(buildEntries(subscription));
|
||||
entries.getEntries().addAll(buildEntries(subscription, unreadOnly));
|
||||
|
||||
} else {
|
||||
FeedCategory feedCategory = "all".equals(id) ? null
|
||||
@@ -45,7 +47,8 @@ public class EntriesREST extends AbstractREST {
|
||||
|
||||
entries.setName("all".equals(id) ? "All" : feedCategory.getName());
|
||||
for (FeedSubscription subscription : subscriptions) {
|
||||
entries.getEntries().addAll(buildEntries(subscription));
|
||||
entries.getEntries().addAll(
|
||||
buildEntries(subscription, unreadOnly));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -59,9 +62,17 @@ public class EntriesREST extends AbstractREST {
|
||||
return entries;
|
||||
}
|
||||
|
||||
private List<Entry> buildEntries(FeedSubscription subscription) {
|
||||
List<FeedEntry> feedEntries = feedEntryService.getUnreadEntries(
|
||||
subscription.getFeed(), getUser());
|
||||
private List<Entry> buildEntries(FeedSubscription subscription,
|
||||
boolean unreadOnly) {
|
||||
List<FeedEntry> feedEntries = null;
|
||||
|
||||
if (unreadOnly) {
|
||||
feedEntries = feedEntryService.getUnreadEntries(
|
||||
subscription.getFeed(), getUser());
|
||||
} else {
|
||||
feedEntries = feedEntryService.getAllEntries(
|
||||
subscription.getFeed());
|
||||
}
|
||||
|
||||
List<Entry> entries = Lists.newArrayList();
|
||||
for (FeedEntry feedEntry : feedEntries) {
|
||||
|
||||
@@ -86,12 +86,18 @@ module.controller('FeedListCtrl', function($scope, $routeParams, $http,
|
||||
$scope.selectedType = $routeParams._type;
|
||||
$scope.selectedId = $routeParams._id;
|
||||
|
||||
$scope.entryList = EntryService.get({
|
||||
_type : $scope.selectedType,
|
||||
_id : $scope.selectedId,
|
||||
_readtype : 'unread'
|
||||
})
|
||||
$scope.readType = 'all';
|
||||
|
||||
$scope.refreshList = function() {
|
||||
$scope.entryList = EntryService.get({
|
||||
_type : $scope.selectedType,
|
||||
_id : $scope.selectedId,
|
||||
_readtype : $scope.readType
|
||||
});
|
||||
};
|
||||
|
||||
$scope.refreshList();
|
||||
|
||||
$scope.mark = function(entry, read) {
|
||||
if (entry.read != read) {
|
||||
entry.read = read;
|
||||
|
||||
@@ -1,4 +1,14 @@
|
||||
<div ng-controller="FeedListCtrl">
|
||||
|
||||
|
||||
<div class="toolbar">
|
||||
<div class="btn-group" data-toggle="buttons-radio">
|
||||
<button type="button" class="btn" ng-model="readType" btn-radio="'all'" ng-click="refreshList()">All</button>
|
||||
<button type="button" class="btn" ng-model="readType" btn-radio="'unread'" ng-click="refreshList()">Unread only</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
<span>{{entryList.name}}</span><span
|
||||
ng-show="selectedType == 'category'"> »</span>
|
||||
<div class="accordion" id="feed-accordion">
|
||||
|
||||
Reference in New Issue
Block a user