toggle between unread and all entries

This commit is contained in:
Athou
2013-03-23 17:56:19 +01:00
parent 84e4751e07
commit 1871fa1169
4 changed files with 38 additions and 12 deletions

View File

@@ -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();
}

View File

@@ -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) {

View File

@@ -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;

View File

@@ -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'"> &#187;</span>
<div class="accordion" id="feed-accordion">