From fa83a6a9031e8cbbf221d6c8748764cf856c2940 Mon Sep 17 00:00:00 2001 From: Athou Date: Mon, 25 Mar 2013 21:01:29 +0100 Subject: [PATCH] mark all as read --- .../backend/dao/FeedEntryService.java | 2 +- .../commafeed/backend/feeds/FeedTimer.java | 3 +- .../frontend/rest/resources/EntriesREST.java | 48 +++++++++++++------ src/main/webapp/css/app.css | 24 +++++++++- src/main/webapp/directives/toolbar.html | 2 +- src/main/webapp/js/controllers.js | 6 +-- src/main/webapp/js/directives.js | 13 ++++- src/main/webapp/js/services.js | 5 +- src/main/webapp/templates/feeds.html | 5 +- 9 files changed, 81 insertions(+), 27 deletions(-) diff --git a/src/main/java/com/commafeed/backend/dao/FeedEntryService.java b/src/main/java/com/commafeed/backend/dao/FeedEntryService.java index 506e1a62..a0d11868 100644 --- a/src/main/java/com/commafeed/backend/dao/FeedEntryService.java +++ b/src/main/java/com/commafeed/backend/dao/FeedEntryService.java @@ -40,7 +40,7 @@ public class FeedEntryService extends GenericDAO { } private TypedQuery unreadQuery(Feed feed, User user) { - 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)"; + 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 typedQuery = em.createQuery(query, FeedEntry.class); typedQuery.setParameter("feed", feed); diff --git a/src/main/java/com/commafeed/backend/feeds/FeedTimer.java b/src/main/java/com/commafeed/backend/feeds/FeedTimer.java index d5d50a73..d5e55c22 100644 --- a/src/main/java/com/commafeed/backend/feeds/FeedTimer.java +++ b/src/main/java/com/commafeed/backend/feeds/FeedTimer.java @@ -3,6 +3,7 @@ package com.commafeed.backend.feeds; import java.util.Calendar; import java.util.Map; import java.util.concurrent.Future; +import java.util.concurrent.TimeUnit; import javax.ejb.Schedule; import javax.ejb.Singleton; @@ -46,7 +47,7 @@ public class FeedTimer { for (String key : futures.keySet()) { Future future = futures.get(key); try { - Feed feed = future.get(); + Feed feed = future.get(1, TimeUnit.MINUTES); feedEntryService .updateEntries(feed.getUrl(), feed.getEntries()); } catch (Exception e) { diff --git a/src/main/java/com/commafeed/frontend/rest/resources/EntriesREST.java b/src/main/java/com/commafeed/frontend/rest/resources/EntriesREST.java index 7d23b85d..b9107a77 100644 --- a/src/main/java/com/commafeed/frontend/rest/resources/EntriesREST.java +++ b/src/main/java/com/commafeed/frontend/rest/resources/EntriesREST.java @@ -8,11 +8,11 @@ import java.util.List; import javax.ws.rs.DefaultValue; import javax.ws.rs.GET; import javax.ws.rs.Path; -import javax.ws.rs.PathParam; import javax.ws.rs.QueryParam; import org.apache.commons.lang.ObjectUtils; +import com.commafeed.backend.model.Feed; import com.commafeed.backend.model.FeedCategory; import com.commafeed.backend.model.FeedEntry; import com.commafeed.backend.model.FeedEntryStatus; @@ -30,7 +30,7 @@ public class EntriesREST extends AbstractREST { private static final String ALL = "all"; public enum Type { - category, feed; + category, feed, entry; } public enum ReadType { @@ -132,22 +132,42 @@ public class EntriesREST extends AbstractREST { return entry; } - @Path("mark/{type}/{id}/{read}") + @Path("mark") @GET - public void mark(@PathParam("type") String type, - @PathParam("id") String id, @PathParam("read") boolean read) { - if ("entry".equals(type)) { + public void mark(@QueryParam("type") Type type, + @QueryParam("id") String id, @QueryParam("read") boolean read) { + Preconditions.checkNotNull(type); + Preconditions.checkNotNull(id); + Preconditions.checkNotNull(read); + + if (type == Type.entry) { FeedEntry entry = feedEntryService.findById(Long.valueOf(id)); - FeedEntryStatus status = feedEntryStatusService.getStatus( - getUser(), entry); - if (status == null) { - status = new FeedEntryStatus(); - status.setUser(getUser()); - status.setEntry(entry); + markEntry(entry, read); + } else if (type == Type.feed) { + List entries = null; + Feed feed = feedSubscriptionService.findById(Long.valueOf(id)) + .getFeed(); + if (read) { + entries = feedEntryService.getUnreadEntries(feed, getUser()); + } else { + entries = feedEntryService.getAllEntries(feed); + } + for (FeedEntry entry : entries) { + markEntry(entry, read); } - status.setRead(read); - feedEntryStatusService.saveOrUpdate(status); } } + private void markEntry(FeedEntry entry, boolean read) { + FeedEntryStatus status = feedEntryStatusService.getStatus(getUser(), + entry); + if (status == null) { + status = new FeedEntryStatus(); + status.setUser(getUser()); + status.setEntry(entry); + } + status.setRead(read); + feedEntryStatusService.saveOrUpdate(status); + } + } diff --git a/src/main/webapp/css/app.css b/src/main/webapp/css/app.css index 25763966..3d6983ef 100644 --- a/src/main/webapp/css/app.css +++ b/src/main/webapp/css/app.css @@ -27,14 +27,34 @@ } /* entry list*/ -.entry { +#feed-accordion .entry { border-bottom: 1px solid #CCCCCC; } -.entry:hover { +.no-entries { + text-align: center; + font-weight: bold; + margin-top: 80px; +} + +.entry .entry-heading a { + padding: 6px 0px; background-color: #EBEBEB; } +.entry .entry-heading a.collapsed { + background-color: #FFF; +} + +.entry .entry-heading a.collapsed:hover { + background-color: #EBEBEB; +} + +.entry .entry-heading a ~.collapsed { + background-color: #EBEBEB; + padding: 6px 0px; +} + .entry a { color: black; display: block; diff --git a/src/main/webapp/directives/toolbar.html b/src/main/webapp/directives/toolbar.html index 96b73c74..d3f43fc2 100644 --- a/src/main/webapp/directives/toolbar.html +++ b/src/main/webapp/directives/toolbar.html @@ -7,7 +7,7 @@ - +
diff --git a/src/main/webapp/js/controllers.js b/src/main/webapp/js/controllers.js index 72f6c415..cc8d2817 100644 --- a/src/main/webapp/js/controllers.js +++ b/src/main/webapp/js/controllers.js @@ -152,9 +152,9 @@ module.controller('FeedListCtrl', function($scope, $routeParams, $http, entry : entry }); EntryService.mark({ - _type : 'entry', - _id : entry.id, - _readtype : read + type : 'entry', + id : entry.id, + read : read }); } }; diff --git a/src/main/webapp/js/directives.js b/src/main/webapp/js/directives.js index 68863502..e8490834 100644 --- a/src/main/webapp/js/directives.js +++ b/src/main/webapp/js/directives.js @@ -89,7 +89,7 @@ module.directive('category', function($compile) { }; }); -module.directive('toolbar', function(SettingsService) { +module.directive('toolbar', function($routeParams, $route, SettingsService, EntryService, SubscriptionService) { return { scope : {}, restrict : 'E', @@ -99,6 +99,17 @@ module.directive('toolbar', function(SettingsService) { $scope.settings = SettingsService.settings; $scope.refresh = function() { $route.reload(); + }, + $scope.markAllAsRead = function() { + EntryService.mark({ + type: $routeParams._type, + id: $routeParams._id, + read: true, + }, function() { + SubscriptionService.init(function() { + $route.reload(); + }); + }); } }, link : function($scope, element) { diff --git a/src/main/webapp/js/services.js b/src/main/webapp/js/services.js index d1010607..56489fab 100644 --- a/src/main/webapp/js/services.js +++ b/src/main/webapp/js/services.js @@ -41,9 +41,10 @@ module.factory('SubscriptionService', [ '$resource', '$http', s.flatCategories = {}; var res = $resource('rest/subscriptions/:_method', {}, actions); - s.init = function() { - s.subscriptions = res.get(function(){ + s.init = function(callback) { + s.subscriptions = res.get(function(data) { s.flatCategories = flatten(s.subscriptions); + callback(data); }); }; s.subscribe = function(sub, callback) { diff --git a/src/main/webapp/templates/feeds.html b/src/main/webapp/templates/feeds.html index 7dab4a9d..5bf39948 100644 --- a/src/main/webapp/templates/feeds.html +++ b/src/main/webapp/templates/feeds.html @@ -2,10 +2,10 @@ {{readType}} {{entryList.name}} » -
\ No newline at end of file