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

View File

@@ -6,6 +6,11 @@
margin-bottom: 0px;
}
.horizontal-align {
padding-top: 5px;
line-height: 20px
}
.welcome .header {
margin: 20px 0 40px 0;
}

View File

@@ -1,17 +1,9 @@
<li>
<div ng-mouseenter="hovered=node" ng-mouseleave="hovered=null" class="pointer" ui-if="showLabel">
<div class="dropdown pull-right">
<a data-toggle="dropdown" class="pull-right">
<i ng-class="{'icon-chevron-down': hovered==node && node.id != 'all'}" class="icon"></i>
</a>
<ul class="dropdown-menu">
<li>
<a ng-click="renameCategory(node)">Rename</a>
</li>
<li>
<a ng-click="deleteCategory(node)">Delete</a>
</li>
</ul>
<div class="pull-right" ng-click="showCategoryDetails(node)">
<i ng-class="{'icon-chevron-right': hovered==node}" class="icon"></i>
</div>
</div>
<span class="fldr">
<i ng-class="{'icon-caret-right': !node.expanded, 'icon-caret-down': node.expanded}" ng-click="toggleCategory(node)" ng-show="showChildren"></i>
@@ -32,22 +24,12 @@
<li ng-repeat="feed in node.feeds" ng-mouseenter="hovered=feed"
ng-mouseleave="hovered=null" ng-show="settingsService.settings.showRead == true || feed.unread > 0"
ng-class="{error: feed.message && feed.errorCount > 10}">
<div class="dropdown pull-right">
<a data-toggle="dropdown" class="pull-right">
<i ng-class="{'icon-chevron-down': hovered==feed}" class="icon"></i>
</a>
<ul class="dropdown-menu">
<li>
<a ng-click="renameFeed(feed)">Rename</a>
</li>
<li>
<a ng-click="unsubscribe(feed)">Unsubscribe</a>
</li>
</ul>
<div class="pull-right" ng-click="showFeedDetails(feed)">
<i ng-class="{'icon-chevron-right': hovered==feed}" class="icon pointer"></i>
</div>
<a ng-click="feedClicked(feed.id)" class="feed-link"
ng-class="{selected: (feed.id == selectedId && selectedType == 'feed'), unread: feed.unread }">
<favicon url="feed.feedUrl" />
<favicon url="feed.feedLink" />
{{formatFeedName(feed)}}
</a>
</li>

View File

@@ -169,6 +169,136 @@ function($scope, $timeout, $stateParams, $window, $location, $state, $route, Cat
});
}]);
module.controller('FeedDetailsCtrl', ['$scope', '$state', '$stateParams', 'FeedService', 'CategoryService', '$dialog',
function($scope, $state, $stateParams, FeedService, CategoryService, $dialog) {
$scope.CategoryService = CategoryService;
$scope.sub = FeedService.get({
id : $stateParams._id
});
$scope.back = function() {
$state.transitionTo('feeds.view', {
_id: $stateParams._id,
_type: 'feed'
});
};
$scope.unsubscribe = function() {
var sub = $scope.sub;
var title = 'Unsubscribe';
var msg = 'Unsubscribe from ' + sub.name + ' ?';
var btns = [ {
result : 'cancel',
label : 'Cancel'
}, {
result : 'ok',
label : 'OK',
cssClass : 'btn-primary'
} ];
$dialog.messageBox(title, msg, btns).open().then(
function(result) {
if (result == 'ok') {
var data = {
id : sub.id
};
FeedService.unsubscribe(data,
function() {
CategoryService.init();
});
$state.transitionTo('feeds.view', {
_id: 'all',
_type: 'category'
});
}
});
};
$scope.save = function() {
var sub = $scope.sub;
FeedService.modify({
id : sub.id,
name : sub.name,
categoryId : sub.categoryId
}, function() {
CategoryService.init();
$state.transitionTo('feeds.view', {
_id: 'all',
_type: 'category'
});
});
};
}]);
module.controller('CategoryDetailsCtrl', ['$scope', '$state', '$stateParams', 'FeedService', 'CategoryService', '$dialog',
function($scope, $state, $stateParams, FeedService, CategoryService, $dialog) {
$scope.CategoryService = CategoryService;
CategoryService.get(function() {
for(var i = 0; i < CategoryService.flatCategories.length; i++){
var cat = CategoryService.flatCategories[i];
if (cat.id == $stateParams._id) {
$scope.category = angular.copy(cat);
$scope.category.name = $scope.category.origName;
break;
}
}
});
$scope.back = function() {
$state.transitionTo('feeds.view', {
_id: $stateParams._id,
_type: 'category'
});
};
$scope.deleteCategory = function() {
var category = $scope.category;
var title = 'Delete category';
var msg = 'Delete category ' + category.name + ' ?';
var btns = [ {
result : 'cancel',
label : 'Cancel'
}, {
result : 'ok',
label : 'OK',
cssClass : 'btn-primary'
} ];
$dialog.messageBox(title, msg, btns).open().then(
function(result) {
if (result == 'ok') {
CategoryService.remove({
id : category.id
}, function() {
CategoryService.init();
});
$state.transitionTo('feeds.view', {
_id: 'all',
_type: 'category'
});
}
});
};
$scope.save = function() {
var cat = $scope.category;
CategoryService.modify({
id : cat.id,
name : cat.name,
parentId : cat.parentId
}, function() {
CategoryService.init();
$state.transitionTo('feeds.view', {
_id: 'all',
_type: 'category'
});
});
};
}]);
module.controller('ToolbarCtrl', ['$scope', '$http', '$state', '$stateParams',
'$route', '$location', 'SettingsService', 'EntryService', 'ProfileService', 'AnalyticsService', 'ServerService', 'FeedService',
function($scope, $http, $state, $stateParams, $route, $location,

View File

@@ -112,32 +112,6 @@ module.directive('category', [ function() {
function($scope, $state, $dialog, FeedService, CategoryService,
SettingsService) {
$scope.settingsService = SettingsService;
$scope.unsubscribe = function(subscription) {
var title = 'Unsubscribe';
var msg = 'Unsubscribe from ' + subscription.name
+ ' ?';
var btns = [ {
result : 'cancel',
label : 'Cancel'
}, {
result : 'ok',
label : 'OK',
cssClass : 'btn-primary'
} ];
$dialog.messageBox(title, msg, btns).open().then(
function(result) {
if (result == 'ok') {
var data = {
id : subscription.id
};
FeedService.unsubscribe(data,
function() {
CategoryService.init();
});
}
});
};
$scope.formatCategoryName = function(category) {
var count = $scope.unreadCount({
@@ -181,52 +155,17 @@ module.directive('category', [ function() {
});
}
};
$scope.renameFeed = function(feed) {
var name = window.prompt('Rename feed : ', feed.name);
if (name && name != feed.name) {
feed.name = name;
FeedService.rename({
id : feed.id,
name : name
});
}
$scope.showFeedDetails = function(feed) {
$state.transitionTo('feeds.feed_details', {
_id: feed.id
});
};
$scope.renameCategory = function(category) {
var name = window.prompt('Rename category: ',
category.name);
if (name && name != category.name) {
category.name = name;
CategoryService.rename({
id : category.id,
name : name
});
}
};
$scope.deleteCategory = function(category) {
var title = 'Delete category';
var msg = 'Delete category ' + category.name + ' ?';
var btns = [ {
result : 'cancel',
label : 'Cancel'
}, {
result : 'ok',
label : 'OK',
cssClass : 'btn-primary'
} ];
$dialog.messageBox(title, msg, btns).open().then(
function(result) {
if (result == 'ok') {
CategoryService.remove({
id : category.id
}, function() {
CategoryService.init();
});
}
});
$scope.showCategoryDetails = function(category) {
$state.transitionTo('feeds.category_details', {
_id: category.id
});
};
$scope.toggleCategory = function(category) {

View File

@@ -23,6 +23,16 @@ function($routeProvider, $stateProvider, $urlRouterProvider) {
templateUrl : 'templates/feeds.view.html',
controller : 'FeedListCtrl'
});
$stateProvider.state('feeds.feed_details', {
url : '/details/feed/:_id',
templateUrl : 'templates/feeds.feed_details.html',
controller : 'FeedDetailsCtrl'
});
$stateProvider.state('feeds.category_details', {
url : '/details/category/:_id',
templateUrl : 'templates/feeds.category_details.html',
controller : 'CategoryDetailsCtrl'
});
$stateProvider.state('feeds.help', {
url : '/help',
templateUrl : 'templates/feeds.help.html',

View File

@@ -80,14 +80,15 @@ function($resource, $http) {
_method : 'unsubscribe'
}
},
rename : {
modify : {
method : 'POST',
params : {
_method : 'rename'
_method : 'modify'
}
}
};
var res = $resource('rest/feed/:_method', {}, actions);
res.get = $resource('rest/feed/get/:id').get;
return res;
}]);
@@ -102,7 +103,8 @@ function($resource, $http) {
}
array.push({
id : category.id,
name : name
name : name,
origName: category.name
});
if (category.children) {
for ( var i = 0; i < category.children.length; i++) {
@@ -142,10 +144,10 @@ function($resource, $http) {
_method : 'delete'
}
},
rename : {
modify : {
method : 'POST',
params : {
_method : 'rename'
_method : 'modify'
}
},
collapse : {

View File

@@ -0,0 +1,38 @@
<div>
<div class="page-header">
<h3>Category details</h3>
</div>
<form name="form" class="form-horizontal" ng-submit="save()">
<div class="control-group" ng-class="{error : !form.name.$valid}">
<label class="control-label">Name</label>
<div class="controls">
<input type="text" name="name" ng-model="category.name" class="input-block-level" required></input>
<span class="help-block" ng-show="!form.name.$valid">Required</span>
</div>
</div>
<div class="control-group" ng-class="{error : !form.category.$valid}">
<label class="control-label">Parent category</label>
<div class="controls">
<select name="category" class="input-block-level" ng-model="cat.parentId"
ng-options="cat.id as cat.name for cat in CategoryService.flatCategories">
</select>
<span class="help-block" ng-show="!form.category.$valid">Required</span>
</div>
</div>
<div class="control-group">
<label class="control-label">Feed URL</label>
<div class="controls horizontal-align">
<a href="{{'rest/category/entriesAsFeed?id=' + cat.id}}" target="_blank">{{'rest/category/entriesAsFeed?id=' + cat.id}}</a>
</div>
</div>
<div class="form-actions">
<button type="submit" class="btn btn-primary">Save</button>
<button type="button" class="btn" ng-click="back()">Cancel</button>
<button type="button" class="btn btn-danger" ng-click="unsubscribe()">Unsubscribe</button>
</div>
</form>
</div>

View File

@@ -0,0 +1,51 @@
<div>
<div class="page-header">
<h3>Feed details</h3>
</div>
<form name="form" class="form-horizontal" ng-submit="save()">
<div class="control-group">
<label class="control-label">URL</label>
<div class="controls horizontal-align">
<a href="{{sub.feedUrl}}" target="_blank">{{sub.feedUrl}}</a>
</div>
</div>
<div class="control-group" ng-class="{error : !form.name.$valid}">
<label class="control-label">Name</label>
<div class="controls">
<input type="text" name="name" ng-model="sub.name" class="input-block-level" required></input>
<span class="help-block" ng-show="!form.name.$valid">Required</span>
</div>
</div>
<div class="control-group" ng-class="{error : !form.category.$valid}">
<label class="control-label">Category</label>
<div class="controls">
<select name="category" class="input-block-level" ng-model="sub.categoryId"
ng-options="cat.id as cat.name for cat in CategoryService.flatCategories">
</select>
<span class="help-block" ng-show="!form.category.$valid">Required</span>
</div>
</div>
<div class="control-group">
<label class="control-label">Last refresh</label>
<div class="controls horizontal-align">
<span>{{sub.lastRefresh|date:'medium'}}</span>
</div>
</div>
<div class="control-group">
<label class="control-label">Feed URL</label>
<div class="controls horizontal-align">
<a href="{{'rest/feed/entriesAsFeed?id=' + sub.id}}" target="_blank">{{'rest/feed/entriesAsFeed?id=' + sub.id}}</a>
</div>
</div>
<div class="form-actions">
<button type="submit" class="btn btn-primary">Save</button>
<button type="button" class="btn" ng-click="back()">Cancel</button>
<button type="button" class="btn btn-danger" ng-click="unsubscribe()">Unsubscribe</button>
</div>
</form>
</div>

View File

@@ -13,7 +13,7 @@
<i ng-class="{'icon-star icon-star-yellow': entry.starred, 'icon-star-empty': !entry.starred}"
class="pointer"></i>
</span>
<favicon url="entry.feedUrl" />
<favicon url="entry.feedLink" />
{{entry.feedName}}
</span>
<span class="entry-date">{{entry.date | date: 'yyyy-MM-dd HH:mm'}}</span>