diff --git a/src/main/java/com/commafeed/backend/model/FeedCategory.java b/src/main/java/com/commafeed/backend/model/FeedCategory.java index e670c0a8..d09b035f 100644 --- a/src/main/java/com/commafeed/backend/model/FeedCategory.java +++ b/src/main/java/com/commafeed/backend/model/FeedCategory.java @@ -30,6 +30,8 @@ public class FeedCategory extends AbstractModel { @OneToMany(mappedBy = "category") private Set subscriptions; + private boolean collapsed; + public String getName() { return name; } @@ -73,4 +75,12 @@ public class FeedCategory extends AbstractModel { this.children = children; } + public boolean isCollapsed() { + return collapsed; + } + + public void setCollapsed(boolean collapsed) { + this.collapsed = collapsed; + } + } diff --git a/src/main/java/com/commafeed/frontend/model/Category.java b/src/main/java/com/commafeed/frontend/model/Category.java index 99d180ec..6cea0a9b 100644 --- a/src/main/java/com/commafeed/frontend/model/Category.java +++ b/src/main/java/com/commafeed/frontend/model/Category.java @@ -7,11 +7,12 @@ import com.google.common.collect.Lists; @SuppressWarnings("serial") public class Category implements Serializable { - + private String id; private String name; private List children = Lists.newArrayList(); private List feeds = Lists.newArrayList(); + private boolean expanded; public String getId() { return id; @@ -45,4 +46,11 @@ public class Category implements Serializable { this.feeds = feeds; } + public boolean isExpanded() { + return expanded; + } + + public void setExpanded(boolean expanded) { + this.expanded = expanded; + } } \ No newline at end of file diff --git a/src/main/java/com/commafeed/frontend/rest/resources/SubscriptionsREST.java b/src/main/java/com/commafeed/frontend/rest/resources/SubscriptionsREST.java index 1d690482..566f4b5e 100644 --- a/src/main/java/com/commafeed/frontend/rest/resources/SubscriptionsREST.java +++ b/src/main/java/com/commafeed/frontend/rest/resources/SubscriptionsREST.java @@ -60,6 +60,20 @@ public class SubscriptionsREST extends AbstractREST { return Response.ok(Status.OK).build(); } + @GET + @Path("collapse") + public Response collapse(@QueryParam("id") String id, + @QueryParam("collapse") boolean collapse) { + Preconditions.checkNotNull(id); + if (!"all".equals(id)) { + FeedCategory category = feedCategoryService.findById(getUser(), + Long.valueOf(id)); + category.setCollapsed(collapse); + feedCategoryService.update(category); + } + return Response.ok(Status.OK).build(); + } + @POST @Path("import") @Consumes(MediaType.MULTIPART_FORM_DATA) @@ -100,6 +114,7 @@ public class SubscriptionsREST extends AbstractREST { List subscriptions) { Category category = new Category(); category.setId(String.valueOf(id)); + category.setExpanded(true); for (FeedCategory c : categories) { if ((id == null && c.getParent() == null) @@ -109,6 +124,7 @@ public class SubscriptionsREST extends AbstractREST { subscriptions); child.setId(String.valueOf(c.getId())); child.setName(c.getName()); + child.setExpanded(!c.isCollapsed()); category.getChildren().add(child); } } diff --git a/src/main/webapp/directives/category.html b/src/main/webapp/directives/category.html index 3336dadc..55914e8c 100644 --- a/src/main/webapp/directives/category.html +++ b/src/main/webapp/directives/category.html @@ -1,4 +1,4 @@ -
  • +
  • diff --git a/src/main/webapp/js/directives.js b/src/main/webapp/js/directives.js index 7508922d..e2ce332f 100644 --- a/src/main/webapp/js/directives.js +++ b/src/main/webapp/js/directives.js @@ -90,7 +90,15 @@ module.directive('category', function($compile) { .unsubscribe(subscription.id); } }); - } + }; + + $scope.toggleCategory = function(category) { + console.log(category.expanded) + SubscriptionService.collapse({ + id : category.id, + collapse : !category.expanded + }); + }; } }; }); diff --git a/src/main/webapp/js/services.js b/src/main/webapp/js/services.js index ff160e76..2066a3d2 100644 --- a/src/main/webapp/js/services.js +++ b/src/main/webapp/js/services.js @@ -38,6 +38,12 @@ module.factory('SubscriptionService', [ params : { _method : 'unsubscribe' } + }, + collapse : { + method : 'GET', + params : { + _method : 'collapse' + } } }; var s = {}; @@ -84,6 +90,7 @@ module.factory('SubscriptionService', [ id : id }); }; + s.collapse = res.collapse; s.init(); return s; } ]);