angular prototype

This commit is contained in:
Jeremie Panzer
2013-03-21 16:22:58 +01:00
parent a5ac6b9c44
commit 0161de1f13
19 changed files with 508 additions and 6 deletions

View File

@@ -5,6 +5,9 @@ import javax.ejb.Singleton;
import javax.ejb.Startup;
import javax.inject.Inject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.commafeed.backend.dao.FeedCategoryService;
import com.commafeed.backend.dao.FeedService;
import com.commafeed.backend.dao.FeedSubscriptionService;
@@ -19,6 +22,8 @@ import com.commafeed.model.User;
@Singleton
public class StartupBean {
private static Logger log = LoggerFactory.getLogger(StartupBean.class);
@Inject
FeedService feedService;
@@ -38,6 +43,7 @@ public class StartupBean {
private void init() {
if (userService.getCount() == 0) {
log.info("Populating database with default values");
User user = new User();
byte[] salt = encryptionService.generateSalt();
user.setName("admin");

View File

@@ -28,7 +28,8 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.commafeed.frontend.components.auth.LoginPage;
import com.commafeed.frontend.pages.feed.FeedViewPage;
import com.commafeed.frontend.pages.feed.FeedSubscriptionsPage;
import com.commafeed.frontend.pages.home.HomePage;
import com.commafeed.frontend.utils.exception.DisplayExceptionPage;
import de.agilecoders.wicket.Bootstrap;
@@ -44,7 +45,7 @@ public class CommaFeedApplication extends AuthenticatedWebApplication {
super.init();
mountPage("login", LoginPage.class);
mountPage("feeds", FeedViewPage.class);
mountPage("/subscriptions/all", FeedSubscriptionsPage.class);
setupInjection();
@@ -84,7 +85,7 @@ public class CommaFeedApplication extends AuthenticatedWebApplication {
@Override
public Class<? extends Page> getHomePage() {
return FeedViewPage.class;
return HomePage.class;
}
protected void setupInjection() {

View File

@@ -0,0 +1,27 @@
package com.commafeed.frontend.pages;
import org.apache.wicket.authroles.authorization.strategies.role.annotations.AuthorizeInstantiation;
import org.apache.wicket.markup.html.WebPage;
import org.apache.wicket.request.handler.TextRequestHandler;
import org.apache.wicket.request.mapper.parameter.PageParameters;
import com.commafeed.frontend.components.auth.Role;
import com.google.gson.Gson;
@SuppressWarnings("serial")
@AuthorizeInstantiation(Role.USER)
public abstract class JSONPage extends WebPage {
public JSONPage() {
this(new PageParameters());
}
public JSONPage(PageParameters pageParameters) {
getRequestCycle().scheduleRequestHandlerAfterCurrent(
new TextRequestHandler("application/json", "UTF-8", new Gson()
.toJson(getObject())));
}
protected abstract Object getObject();
}

View File

@@ -0,0 +1,139 @@
package com.commafeed.frontend.pages.feed;
import java.util.List;
import javax.inject.Inject;
import org.apache.commons.lang.ObjectUtils;
import com.commafeed.backend.dao.FeedCategoryService;
import com.commafeed.backend.dao.FeedSubscriptionService;
import com.commafeed.frontend.CommaFeedSession;
import com.commafeed.frontend.pages.JSONPage;
import com.commafeed.frontend.utils.ModelFactory.MF;
import com.commafeed.model.FeedCategory;
import com.commafeed.model.FeedSubscription;
import com.commafeed.model.User;
import com.google.common.collect.Lists;
@SuppressWarnings("serial")
public class FeedSubscriptionsPage extends JSONPage {
@Inject
FeedSubscriptionService feedSubscriptionService;
@Inject
FeedCategoryService FeedCategoryService;
@Override
protected Object getObject() {
User user = CommaFeedSession.get().getUser();
List<FeedCategory> categories = FeedCategoryService.findAll(user);
Category root = new Category();
addChildren(categories, root);
for (FeedSubscription subscription : feedSubscriptionService
.findByField(MF.i(MF.p(FeedSubscription.class).getCategory()),
null)) {
Subscription sub = new Subscription();
sub.setId(subscription.getId());
sub.setName(subscription.getTitle());
sub.setUnread(77);
}
return root;
}
private void addChildren(List<FeedCategory> categories, Category current) {
for (FeedCategory category : categories) {
if ((category.getParent() == null && current.getId() == null)
|| (category.getParent() != null && (ObjectUtils.equals(
category.getParent().getId(), current.getId())))) {
Category child = new Category();
child.setId(category.getId());
child.setName(category.getName());
addChildren(categories, child);
for (FeedSubscription subscription : category
.getSubscriptions()) {
Subscription sub = new Subscription();
sub.setId(subscription.getId());
sub.setName(subscription.getTitle());
sub.setUnread(77);
}
current.getChildren().add(child);
}
}
}
public static class Category {
private Long id;
private String name;
private List<Category> children = Lists.newArrayList();
private List<Subscription> feeds = Lists.newArrayList();
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 List<Category> getChildren() {
return children;
}
public void setChildren(List<Category> children) {
this.children = children;
}
public List<Subscription> getFeeds() {
return feeds;
}
public void setFeeds(List<Subscription> feeds) {
this.feeds = feeds;
}
}
public static class Subscription {
private Long id;
private String name;
private int unread;
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 int getUnread() {
return unread;
}
public void setUnread(int unread) {
this.unread = unread;
}
}
}

View File

@@ -7,8 +7,8 @@ import javax.inject.Inject;
import org.apache.wicket.Component;
import org.apache.wicket.ajax.AjaxRequestTarget;
import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.model.IModel;
import org.apache.wicket.model.LoadableDetachableModel;
import org.apache.wicket.model.Model;
import com.commafeed.backend.dao.FeedCategoryService;
@@ -20,6 +20,7 @@ import com.commafeed.frontend.pages.BasePage;
import com.commafeed.frontend.utils.ModelFactory.MF;
import com.commafeed.frontend.utils.stateless.StatelessAjaxLink;
import com.commafeed.model.FeedCategory;
import com.commafeed.model.FeedEntryStatus;
import com.commafeed.model.FeedSubscription;
import com.google.common.base.Predicate;
import com.google.common.collect.Collections2;
@@ -36,7 +37,7 @@ public class FeedViewPage extends BasePage {
public FeedViewPage() {
add(newTree("tree"));
add(new Label("entries", Model.of("")));
add(newFeedsPanel("entries"));
}
private Component newTree(String markupId) {
@@ -113,4 +114,16 @@ public class FeedViewPage extends BasePage {
}
};
}
private Component newFeedsPanel(String markupId) {
new LoadableDetachableModel<List<FeedEntryStatus>>() {
@Override
protected List<FeedEntryStatus> load() {
return null;
}
};
return null;
}
}

View File

@@ -0,0 +1,17 @@
<!DOCTYPE html>
<html xmlns:wicket="http://wicket.apache.org">
<body>
<wicket:panel>
<div class="accordion-group" wicket:id="entry">
<div class="accordion-heading">
<a class="accordion-toggle" data-toggle="collapse" wicket:id="link"
data-parent="#accordion2" href="#collapseOne"> Collapsible
Group Item #1 </a>
</div>
<div id="collapseOne" class="accordion-body collapse in" wicket:id="body">
<div class="accordion-inner" wicket:id="content">Anim pariatur cliche...</div>
</div>
</div>
</wicket:panel>
</body>
</html>

View File

@@ -0,0 +1,54 @@
package com.commafeed.frontend.pages.feed.components;
import java.util.List;
import org.apache.wicket.AttributeModifier;
import org.apache.wicket.markup.ComponentTag;
import org.apache.wicket.markup.html.WebMarkupContainer;
import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.html.list.ListItem;
import org.apache.wicket.markup.html.list.ListView;
import org.apache.wicket.markup.html.panel.GenericPanel;
import org.apache.wicket.model.IModel;
import com.commafeed.model.FeedEntryStatus;
import de.agilecoders.wicket.markup.html.bootstrap.behavior.CssClassNameAppender;
import de.agilecoders.wicket.util.Components;
@SuppressWarnings("serial")
public class FeedsPanel extends GenericPanel<List<FeedEntryStatus>> {
private AttributeModifier dataParentModifier;
public FeedsPanel(String id, IModel<List<FeedEntryStatus>> model) {
super(id, model);
add(new CssClassNameAppender("accordion"));
dataParentModifier = new AttributeModifier("data-parent", getMarkupId());
ListView<FeedEntryStatus> listView = new ListView<FeedEntryStatus>(
"entry", model) {
@Override
protected void populateItem(ListItem<FeedEntryStatus> item) {
FeedEntryStatus status = item.getModelObject();
WebMarkupContainer link = new WebMarkupContainer("link");
link.add(dataParentModifier);
WebMarkupContainer body = new WebMarkupContainer("body");
body.add(new Label("content", status.getEntry().getContent())
.setEscapeModelStrings(false));
link.add(new AttributeModifier("href", "#" + body.getMarkupId()));
}
};
add(listView);
}
@Override
protected void onComponentTag(ComponentTag tag) {
super.onComponentTag(tag);
Components.assertTag(this, tag, "div");
}
}

View File

@@ -0,0 +1,10 @@
<!DOCTYPE html>
<html xmlns:wicket="http://wicket.apache.org">
<body>
<wicket:extend>
<div ng-app="commafeed">
<ng:view></ng:view>
</div>
</wicket:extend>
</body>
</html>

View File

@@ -1,8 +1,34 @@
package com.commafeed.frontend.pages.home;
import org.apache.wicket.markup.head.CssHeaderItem;
import org.apache.wicket.markup.head.IHeaderResponse;
import org.apache.wicket.markup.head.JavaScriptHeaderItem;
import org.apache.wicket.request.Url;
import org.apache.wicket.request.resource.UrlResourceReference;
import com.commafeed.frontend.pages.BasePage;
import com.commafeed.frontend.references.angular.AngularReference;
import com.commafeed.frontend.references.csstree.CssTreeViewReference;
@SuppressWarnings("serial")
public class HomePage extends BasePage {
@Override
public void renderHead(IHeaderResponse response) {
super.renderHead(response);
AngularReference.render(response);
CssTreeViewReference.render(response);
response.render(CssHeaderItem.forReference(new UrlResourceReference(Url
.parse("css/app.css"))));
response.render(JavaScriptHeaderItem
.forReference(new UrlResourceReference(Url.parse("js/main.js"))));
response.render(JavaScriptHeaderItem
.forReference(new UrlResourceReference(Url
.parse("js/directives.js"))));
response.render(JavaScriptHeaderItem
.forReference(new UrlResourceReference(Url
.parse("js/controllers.js"))));
}
}

View File

@@ -0,0 +1,20 @@
package com.commafeed.frontend.references.angular;
import org.apache.wicket.markup.head.IHeaderResponse;
import org.apache.wicket.markup.head.JavaScriptHeaderItem;
import de.agilecoders.wicket.webjars.request.resource.WebjarsJavaScriptResourceReference;
@SuppressWarnings("serial")
public class AngularReference extends WebjarsJavaScriptResourceReference {
private static AngularReference instance = new AngularReference();
public AngularReference() {
super("angularjs/current/angular.min.js");
}
public static void render(IHeaderResponse response) {
response.render(JavaScriptHeaderItem.forReference(instance));
}
}

View File

@@ -0,0 +1,55 @@
package com.commafeed.model;
import java.io.Serializable;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;
@Entity
@Table(name = "USERS")
@SuppressWarnings("serial")
public class UserSettings implements Serializable {
public enum ReadingMode {
ALL, UNREAD
}
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
private User user;
@Enumerated(EnumType.STRING)
private ReadingMode readingMode;
public ReadingMode getReadingMode() {
return readingMode;
}
public void setReadingMode(ReadingMode readingMode) {
this.readingMode = readingMode;
}
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public User getUser() {
return user;
}
public void setUser(User user) {
this.user = user;
}
}