refactored tree, no more dropdown for feed editing

This commit is contained in:
Athou
2013-04-30 16:17:34 +02:00
parent bfde9241eb
commit 2d40c4292c
16 changed files with 444 additions and 121 deletions

View File

@@ -15,6 +15,7 @@ import com.google.common.collect.Lists;
public class Category implements Serializable {
private String id;
private String parentId;
private String name;
private List<Category> children = Lists.newArrayList();
private List<Subscription> feeds = Lists.newArrayList();
@@ -28,6 +29,14 @@ public class Category implements Serializable {
this.id = id;
}
public String getParentId() {
return parentId;
}
public void setParentId(String parentId) {
this.parentId = parentId;
}
public String getName() {
return name;
}

View File

@@ -41,7 +41,8 @@ public class Entry implements Serializable {
entry.setFeedName(status.getSubscription().getTitle());
entry.setFeedId(String.valueOf(status.getSubscription().getId()));
entry.setFeedUrl(status.getSubscription().getFeed().getLink());
entry.setFeedUrl(status.getSubscription().getFeed().getUrl());
entry.setFeedLink(status.getSubscription().getFeed().getLink());
return entry;
}
@@ -87,9 +88,12 @@ public class Entry implements Serializable {
@ApiProperty("feed name")
private String feedName;
@ApiProperty("feed url")
@ApiProperty("this entry's feed url")
private String feedUrl;
@ApiProperty("this entry's website url")
private String feedLink;
@ApiProperty("entry url")
private String url;
@@ -203,4 +207,12 @@ public class Entry implements Serializable {
this.guid = guid;
}
public String getFeedLink() {
return feedLink;
}
public void setFeedLink(String feedLink) {
this.feedLink = feedLink;
}
}

View File

@@ -1,11 +1,14 @@
package com.commafeed.frontend.model;
import java.io.Serializable;
import java.util.Date;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlRootElement;
import com.commafeed.backend.model.FeedCategory;
import com.commafeed.backend.model.FeedSubscription;
import com.wordnik.swagger.annotations.ApiClass;
import com.wordnik.swagger.annotations.ApiProperty;
@@ -15,6 +18,23 @@ import com.wordnik.swagger.annotations.ApiProperty;
@ApiClass("User information")
public class Subscription implements Serializable {
public static Subscription build(FeedSubscription subscription,
long unreadCount) {
FeedCategory category = subscription.getCategory();
Subscription sub = new Subscription();
sub.setId(subscription.getId());
sub.setName(subscription.getTitle());
sub.setMessage(subscription.getFeed().getMessage());
sub.setErrorCount(subscription.getFeed().getErrorCount());
sub.setFeedUrl(subscription.getFeed().getUrl());
sub.setFeedLink(subscription.getFeed().getLink());
sub.setLastRefresh(subscription.getFeed().getLastUpdated());
sub.setUnread(unreadCount);
sub.setCategoryId(category == null ? null : String.valueOf(category
.getId()));
return sub;
}
@ApiProperty(value = "subscription id", required = true)
private Long id;
@@ -27,12 +47,21 @@ public class Subscription implements Serializable {
@ApiProperty(value = "error count", required = true)
private int errorCount;
@ApiProperty(value = "last time the feed was refreshed", required = true)
private Date lastRefresh;
@ApiProperty(value = "this subscription's feed url", required = true)
private String feedUrl;
@ApiProperty(value = "this subscription's website url", required = true)
private String feedLink;
@ApiProperty(value = "unread count", required = true)
private long unread;
@ApiProperty(value = "category id")
private String categoryId;
public Long getId() {
return id;
}
@@ -81,4 +110,28 @@ public class Subscription implements Serializable {
this.errorCount = errorCount;
}
public String getFeedLink() {
return feedLink;
}
public void setFeedLink(String feedLink) {
this.feedLink = feedLink;
}
public Date getLastRefresh() {
return lastRefresh;
}
public void setLastRefresh(Date lastRefresh) {
this.lastRefresh = lastRefresh;
}
public String getCategoryId() {
return categoryId;
}
public void setCategoryId(String categoryId) {
this.categoryId = categoryId;
}
}

View File

@@ -12,15 +12,18 @@ import com.wordnik.swagger.annotations.ApiProperty;
@SuppressWarnings("serial")
@XmlRootElement
@XmlAccessorType(XmlAccessType.FIELD)
@ApiClass("Rename Request")
public class RenameRequest implements Serializable {
@ApiClass("Category modification request")
public class CategoryModificationRequest implements Serializable {
@ApiProperty(value = "id", required = true)
private Long id;
@ApiProperty(value = "mark as read or unread")
@ApiProperty(value = "new name")
private String name;
@ApiProperty(value = "new parent category id")
private String parentId;
public Long getId() {
return id;
}
@@ -37,4 +40,12 @@ public class RenameRequest implements Serializable {
this.name = name;
}
public String getParentId() {
return parentId;
}
public void setParentId(String parentId) {
this.parentId = parentId;
}
}

View File

@@ -0,0 +1,51 @@
package com.commafeed.frontend.model.request;
import java.io.Serializable;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlRootElement;
import com.wordnik.swagger.annotations.ApiClass;
import com.wordnik.swagger.annotations.ApiProperty;
@SuppressWarnings("serial")
@XmlRootElement
@XmlAccessorType(XmlAccessType.FIELD)
@ApiClass("Feed modification request")
public class FeedModificationRequest implements Serializable {
@ApiProperty(value = "id", required = true)
private Long id;
@ApiProperty(value = "new name")
private String name;
@ApiProperty(value = "new parent category id")
private String categoryId;
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 String getCategoryId() {
return categoryId;
}
public void setCategoryId(String categoryId) {
this.categoryId = categoryId;
}
}

View File

@@ -32,10 +32,10 @@ import com.commafeed.frontend.model.Entries;
import com.commafeed.frontend.model.Entry;
import com.commafeed.frontend.model.Subscription;
import com.commafeed.frontend.model.request.AddCategoryRequest;
import com.commafeed.frontend.model.request.CategoryModificationRequest;
import com.commafeed.frontend.model.request.CollapseRequest;
import com.commafeed.frontend.model.request.IDRequest;
import com.commafeed.frontend.model.request.MarkRequest;
import com.commafeed.frontend.model.request.RenameRequest;
import com.commafeed.frontend.rest.Enums.ReadType;
import com.google.common.base.Preconditions;
import com.google.common.collect.Lists;
@@ -218,9 +218,10 @@ public class CategoryREST extends AbstractResourceREST {
}
@POST
@Path("/rename")
@Path("/modify")
@ApiOperation(value = "Rename a category", notes = "Rename an existing feed category")
public Response renameCategory(@ApiParam(required = true) RenameRequest req) {
public Response modifyCategory(
@ApiParam(required = true) CategoryModificationRequest req) {
Preconditions.checkNotNull(req);
Preconditions.checkNotNull(req.getId());
Preconditions.checkArgument(StringUtils.isNotBlank(req.getName()));
@@ -228,6 +229,16 @@ public class CategoryREST extends AbstractResourceREST {
FeedCategory category = feedCategoryDAO
.findById(getUser(), req.getId());
category.setName(req.getName());
FeedCategory parent = null;
if (req.getParentId() != null
&& !CategoryREST.ALL.equals(req.getParentId())
&& !StringUtils.equals(req.getParentId(),
String.valueOf(req.getId()))) {
parent = feedCategoryDAO.findById(getUser(),
Long.valueOf(req.getParentId()));
}
category.setParent(parent);
feedCategoryDAO.update(category);
return Response.ok(Status.OK).build();
@@ -281,6 +292,9 @@ public class CategoryREST extends AbstractResourceREST {
subscriptions, unreadCount);
child.setId(String.valueOf(c.getId()));
child.setName(c.getName());
if (c.getParent() != null && c.getParent().getId() != null) {
child.setParentId(String.valueOf(c.getParent().getId()));
}
child.setExpanded(!c.isCollapsed());
category.getChildren().add(child);
}
@@ -296,14 +310,9 @@ public class CategoryREST extends AbstractResourceREST {
if ((id == null && subscription.getCategory() == null)
|| (subscription.getCategory() != null && ObjectUtils
.equals(subscription.getCategory().getId(), id))) {
Subscription sub = new Subscription();
sub.setId(subscription.getId());
sub.setName(subscription.getTitle());
sub.setMessage(subscription.getFeed().getMessage());
sub.setErrorCount(subscription.getFeed().getErrorCount());
sub.setFeedUrl(subscription.getFeed().getLink());
Long size = unreadCount.get(subscription.getId());
sub.setUnread(size == null ? 0 : size);
long unread = size == null ? 0 : size;
Subscription sub = Subscription.build(subscription, unread);
category.getFeeds().add(sub);
}
}

View File

@@ -10,6 +10,7 @@ import javax.ws.rs.DefaultValue;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.WebApplicationException;
@@ -34,9 +35,10 @@ import com.commafeed.backend.model.UserSettings.ReadingOrder;
import com.commafeed.frontend.model.Entries;
import com.commafeed.frontend.model.Entry;
import com.commafeed.frontend.model.FeedInfo;
import com.commafeed.frontend.model.Subscription;
import com.commafeed.frontend.model.request.IDRequest;
import com.commafeed.frontend.model.request.MarkRequest;
import com.commafeed.frontend.model.request.RenameRequest;
import com.commafeed.frontend.model.request.FeedModificationRequest;
import com.commafeed.frontend.model.request.SubscribeRequest;
import com.commafeed.frontend.rest.Enums.ReadType;
import com.google.common.base.Preconditions;
@@ -191,6 +193,17 @@ public class FeedREST extends AbstractResourceREST {
return Response.ok(Status.OK).build();
}
@GET
@Path("/get/{id}")
@ApiOperation(value = "", notes = "")
public Subscription get(
@ApiParam(value = "user id", required = true) @PathParam("id") Long id) {
Preconditions.checkNotNull(id);
FeedSubscription sub = feedSubscriptionDAO.findById(getUser(), id);
return Subscription.build(sub, 0);
}
@POST
@Path("/subscribe")
@ApiOperation(value = "Subscribe to a feed", notes = "Subscribe to a feed")
@@ -237,10 +250,10 @@ public class FeedREST extends AbstractResourceREST {
}
@POST
@Path("/rename")
@ApiOperation(value = "Rename a subscription", notes = "Rename a feed subscription")
public Response rename(
@ApiParam(value = "subscription id", required = true) RenameRequest req) {
@Path("/modify")
@ApiOperation(value = "Modify a subscription", notes = "Modify a feed subscription")
public Response modify(
@ApiParam(value = "subscription id", required = true) FeedModificationRequest req) {
Preconditions.checkNotNull(req);
Preconditions.checkNotNull(req.getId());
Preconditions.checkNotNull(req.getName());
@@ -248,6 +261,14 @@ public class FeedREST extends AbstractResourceREST {
FeedSubscription subscription = feedSubscriptionDAO.findById(getUser(),
req.getId());
subscription.setTitle(req.getName());
FeedCategory parent = null;
if (req.getCategoryId() != null
&& !CategoryREST.ALL.equals(req.getCategoryId())) {
parent = feedCategoryDAO.findById(getUser(),
Long.valueOf(req.getCategoryId()));
}
subscription.setCategory(parent);
feedSubscriptionDAO.update(subscription);
return Response.ok(Status.OK).build();