git-svn-id: https://samskivert.googlecode.com/svn/trunk@1317 6335cc39-0255-0410-8fd6-9bcaacd3b74c

This commit is contained in:
mdb
2003-11-15 22:55:32 +00:00
parent c8d6a29c89
commit 5202d2a61e
13 changed files with 507 additions and 134 deletions
@@ -1,5 +1,5 @@
//
// $Id: TwoDueApp.java,v 1.1 2002/11/08 09:14:21 mdb Exp $
// $Id: TwoDueApp.java,v 1.2 2003/11/15 22:55:32 mdb Exp $
package com.samskivert.twodue;
@@ -14,6 +14,7 @@ import com.samskivert.jdbc.StaticConnectionProvider;
import com.samskivert.servlet.JDBCTableSiteIdentifier;
import com.samskivert.servlet.SiteIdentifier;
import com.samskivert.servlet.user.UserManager;
import com.samskivert.util.ConfigUtil;
import com.samskivert.util.ServiceUnavailableException;
import com.samskivert.velocity.Application;
@@ -51,9 +52,8 @@ public class TwoDueApp extends Application
// create a static connection provider
_conprov = new StaticConnectionProvider(CONN_CONFIG);
// initialize the user manager
Properties props = new Properties();
props.put("login_url", "/register/login.wm?from=%R");
// load up our configuration properties
Properties props = ConfigUtil.loadProperties("user.properties");
_usermgr = new UserManager(props, _conprov);
// initialize the task repository
@@ -0,0 +1,171 @@
//
// $Id: bycategory.java,v 1.1 2003/11/15 22:55:32 mdb Exp $
package com.samskivert.twodue.logic;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.Iterator;
import javax.servlet.http.HttpServletRequest;
import com.samskivert.util.StringUtil;
import com.samskivert.servlet.RedirectException;
import com.samskivert.servlet.user.User;
import com.samskivert.servlet.util.ParameterUtil;
import com.samskivert.velocity.InvocationContext;
import com.samskivert.twodue.Log;
import com.samskivert.twodue.TwoDueApp;
import com.samskivert.twodue.data.Task;
/**
* Displays a summary of unclaimed tasks by category.
*/
public class bycategory extends UserLogic
{
public void invoke (InvocationContext ctx, TwoDueApp app, User user)
throws Exception
{
HttpServletRequest req = ctx.getRequest();
// display any message we've been asked to display
String msg = ParameterUtil.getParameter(req, "message", true);
if (!StringUtil.blank(msg)) {
ctx.put("error", msg);
}
// we use this to determine whether to show "complete" buttons for
// tasks
ctx.put("username", user.username);
ArrayList tasks = null;
String query = ParameterUtil.getParameter(req, "query", false);
if (StringUtil.blank(query)) {
tasks = app.getRepository().loadTasks();
} else {
ctx.put("query", query);
tasks = app.getRepository().findTasks(query);
}
// sort the tasks by priority, then complexity
Collections.sort(tasks, OPEN_PARATOR);
CatList[] xtasks = categorize(tasks, new Categorizer() {
public String category (Task task) {
return task.category;
}
});
ctx.put("xtasks", xtasks);
ctx.put("xcats", new CategoryTool());
// figure out where to start the second column
int total = 0, current = 0;
for (int ii = 0; ii < xtasks.length; ii++) {
total += xtasks[ii].tasks.size();
}
for (int ii = 0; ii < xtasks.length; ii++) {
current += xtasks[ii].tasks.size();
if (current >= total/2) {
ctx.put("break", ii);
break;
}
}
if (!StringUtil.blank(query) && xtasks.length == 0) {
ctx.put("error", "index.error.no_matching_tasks");
}
}
protected static class CatList
implements Comparable
{
public String name;
public ArrayList tasks;
public int compareTo (Object other)
{
return name.compareTo(((CatList)other).name);
}
}
protected static interface Categorizer
{
public String category (Task task);
}
protected CatList[] categorize (ArrayList tasks, Categorizer catter)
{
if (tasks == null) {
return new CatList[0];
}
ArrayList cats = new ArrayList();
HashMap cmap = new HashMap();
int tcount = tasks.size();
for (int ii = 0; ii < tcount; ii++) {
Task task = (Task)tasks.get(ii);
String category = catter.category(task);
CatList clist = (CatList)cmap.get(category);
if (clist == null) {
clist = new CatList();
clist.name = category;
clist.tasks = new ArrayList();
cats.add(clist);
cmap.put(category, clist);
}
clist.tasks.add(task);
}
CatList[] ctasks = new CatList[cats.size()];
cats.toArray(ctasks);
return ctasks;
}
protected static final Comparator OPEN_PARATOR = new Comparator() {
public int compare (Object o1, Object o2) {
Task t1 = (Task)o1, t2 = (Task)o2;
// sort first by category, then reverse priority, then by complexity
if (t1.category.equals(t2.category)) {
if (t1.priority == t2.priority) {
return t1.getComplexityValue() - t2.getComplexityValue();
} else {
return t2.priority - t1.priority;
}
} else {
return t1.category.compareTo(t2.category);
}
}
};
protected static final Comparator OWNED_PARATOR = new Comparator() {
public int compare (Object o1, Object o2) {
Task t1 = (Task)o1, t2 = (Task)o2;
// sort by complexity
return t1.getComplexityValue() - t2.getComplexityValue();
}
};
// used to easy category generation in UI
public static class CategoryTool
{
public boolean checkCategory (String category)
{
if (category.equals(_category)) {
return false;
} else {
_category = category;
return true;
}
}
public void clear ()
{
_category = null;
}
protected String _category;
}
}
@@ -1,5 +1,5 @@
//
// $Id: index.java,v 1.10 2003/05/21 02:40:13 mdb Exp $
// $Id: index.java,v 1.11 2003/11/15 22:55:32 mdb Exp $
package com.samskivert.twodue.logic;
@@ -94,40 +94,10 @@ public class index extends UserLogic
ctx.put("error", "index.message.task_claimed");
}
// load up outstanding tasks and break them down by complexity
String expand = ParameterUtil.getParameter(req, "expand", false);
ctx.put("expand", expand);
ArrayList tasks = null;
String query = ParameterUtil.getParameter(req, "query", false);
if (StringUtil.blank(query)) {
tasks = app.getRepository().loadTasks();
} else {
ctx.put("query", query);
tasks = app.getRepository().findTasks(query);
// force expand to all
expand = "all";
}
// sort the tasks by priority, then complexity
Collections.sort(tasks, OPEN_PARATOR);
CatList[] xtasks = categorize(tasks, expand, new Categorizer() {
public String category (Task task) {
return task.getPriorityName();
}
});
ctx.put("xtasks", xtasks);
ctx.put("xcats", new CategoryTool());
if (!StringUtil.blank(query) && xtasks.length == 0) {
ctx.put("error", "index.error.no_matching_tasks");
}
// load up owned tasks and break them down by owner
tasks = app.getRepository().loadOwnedTasks();
ArrayList tasks = app.getRepository().loadOwnedTasks();
Collections.sort(tasks, OWNED_PARATOR);
CatList[] otasks = categorize(tasks, null, new Categorizer() {
CatList[] otasks = categorize(tasks, new Categorizer() {
public String category (Task task) {
return task.owner;
}
@@ -154,7 +124,6 @@ public class index extends UserLogic
{
public String name;
public ArrayList tasks;
public int pruned;
public int compareTo (Object other)
{
return name.compareTo(((CatList)other).name);
@@ -166,8 +135,7 @@ public class index extends UserLogic
public String category (Task task);
}
protected CatList[] categorize (
ArrayList tasks, String expand, Categorizer catter)
protected CatList[] categorize (ArrayList tasks, Categorizer catter)
{
if (tasks == null) {
return new CatList[0];
@@ -187,13 +155,7 @@ public class index extends UserLogic
cats.add(clist);
cmap.put(category, clist);
}
if (expand == null || clist.tasks.size() < 2 ||
expand.equals("all") ||
(task.priority > 15) || expand.equals(category)) {
clist.tasks.add(task);
} else {
clist.pruned++;
}
clist.tasks.add(task);
}
CatList[] ctasks = new CatList[cats.size()];
@@ -0,0 +1,154 @@
//
// $Id: tasks.java,v 1.1 2003/11/15 22:55:32 mdb Exp $
package com.samskivert.twodue.logic;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.Iterator;
import javax.servlet.http.HttpServletRequest;
import com.samskivert.util.StringUtil;
import com.samskivert.servlet.RedirectException;
import com.samskivert.servlet.user.User;
import com.samskivert.servlet.util.ParameterUtil;
import com.samskivert.velocity.InvocationContext;
import com.samskivert.twodue.Log;
import com.samskivert.twodue.TwoDueApp;
import com.samskivert.twodue.data.Task;
/**
* Displays a summary of unclaimed tasks.
*/
public class tasks extends UserLogic
{
public void invoke (InvocationContext ctx, TwoDueApp app, User user)
throws Exception
{
HttpServletRequest req = ctx.getRequest();
// display any message we've been asked to display
String msg = ParameterUtil.getParameter(req, "message", true);
if (!StringUtil.blank(msg)) {
ctx.put("error", msg);
}
// we use this to determine whether to show "complete" buttons for
// tasks
ctx.put("username", user.username);
ArrayList tasks = null;
String query = ParameterUtil.getParameter(req, "query", false);
if (StringUtil.blank(query)) {
tasks = app.getRepository().loadTasks();
} else {
ctx.put("query", query);
tasks = app.getRepository().findTasks(query);
}
// sort the tasks by priority, then complexity
Collections.sort(tasks, OPEN_PARATOR);
CatList[] xtasks = categorize(tasks, new Categorizer() {
public String category (Task task) {
return task.getPriorityName();
}
});
ctx.put("xtasks", xtasks);
ctx.put("xcats", new CategoryTool());
if (!StringUtil.blank(query) && xtasks.length == 0) {
ctx.put("error", "index.error.no_matching_tasks");
}
}
protected static class CatList
implements Comparable
{
public String name;
public ArrayList tasks;
public int compareTo (Object other)
{
return name.compareTo(((CatList)other).name);
}
}
protected static interface Categorizer
{
public String category (Task task);
}
protected CatList[] categorize (ArrayList tasks, Categorizer catter)
{
if (tasks == null) {
return new CatList[0];
}
ArrayList cats = new ArrayList();
HashMap cmap = new HashMap();
int tcount = tasks.size();
for (int ii = 0; ii < tcount; ii++) {
Task task = (Task)tasks.get(ii);
String category = catter.category(task);
CatList clist = (CatList)cmap.get(category);
if (clist == null) {
clist = new CatList();
clist.name = category;
clist.tasks = new ArrayList();
cats.add(clist);
cmap.put(category, clist);
}
clist.tasks.add(task);
}
CatList[] ctasks = new CatList[cats.size()];
cats.toArray(ctasks);
return ctasks;
}
protected static final Comparator OPEN_PARATOR = new Comparator() {
public int compare (Object o1, Object o2) {
Task t1 = (Task)o1, t2 = (Task)o2;
// sort first by reverse priority, then by complexity
if (t1.priority == t2.priority) {
return t1.getComplexityValue() - t2.getComplexityValue();
} else {
return t2.priority - t1.priority;
}
}
};
protected static final Comparator OWNED_PARATOR = new Comparator() {
public int compare (Object o1, Object o2) {
Task t1 = (Task)o1, t2 = (Task)o2;
// sort by complexity
return t1.getComplexityValue() - t2.getComplexityValue();
}
};
// used to easy category generation in UI
public static class CategoryTool
{
public boolean checkCategory (String category)
{
if (category.equals(_category)) {
return false;
} else {
_category = category;
return true;
}
}
public void clear ()
{
_category = null;
}
protected String _category;
}
}