Added support for simple queries.

git-svn-id: https://samskivert.googlecode.com/svn/trunk@903 6335cc39-0255-0410-8fd6-9bcaacd3b74c
This commit is contained in:
mdb
2002-11-09 01:40:01 +00:00
parent 9d4b641278
commit ee37ff3a93
4 changed files with 53 additions and 8 deletions
@@ -1,5 +1,5 @@
//
// $Id: TaskRepository.java,v 1.2 2002/11/08 21:49:17 mdb Exp $
// $Id: TaskRepository.java,v 1.3 2002/11/09 01:40:01 mdb Exp $
package com.samskivert.twodue.data;
@@ -136,6 +136,19 @@ public class TaskRepository extends JORARepository
"ORDER BY PRIORITY DESC");
}
/**
* Loads up and returns all unowned, uncompleted tasks, whose summary
* or category contain the specified string, ordered by priority.
*/
public ArrayList findTasks (String query)
throws PersistenceException
{
return loadTasks("where COMPLETOR IS NULL AND OWNER IS NULL " +
" AND (SUMMARY LIKE '%" + query +
"%' OR CATEGORY LIKE '%" + query + "%') " +
"ORDER BY PRIORITY DESC");
}
/**
* Loads up all owned tasks, ordered by priority.
*/
@@ -1,5 +1,5 @@
//
// $Id: index.java,v 1.2 2002/11/08 21:49:17 mdb Exp $
// $Id: index.java,v 1.3 2002/11/09 01:40:01 mdb Exp $
package com.samskivert.twodue.logic;
@@ -89,7 +89,15 @@ public class index extends UserLogic
// load up outstanding tasks and break them down by complexity
String expand = ParameterUtil.getParameter(req, "expand", false);
ArrayList tasks = app.getRepository().loadTasks();
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);
}
CatList[] xtasks = categorize(tasks, expand, new Categorizer() {
public String category (Task task) {
return task.complexity;
@@ -97,6 +105,10 @@ public class index extends UserLogic
});
ctx.put("xtasks", xtasks);
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();
CatList[] otasks = categorize(tasks, null, new Categorizer() {
@@ -131,6 +143,10 @@ public class index extends UserLogic
protected CatList[] categorize (
ArrayList tasks, String expand, Categorizer catter)
{
if (tasks == null) {
return new CatList[0];
}
HashMap cmap = new HashMap();
int tcount = tasks.size();
for (int ii = 0; ii < tcount; ii++) {
@@ -144,7 +160,7 @@ public class index extends UserLogic
cmap.put(category, clist);
}
if (expand == null || clist.tasks.size() < 2 ||
(expand.equals(category))) {
expand.equals("all") || expand.equals(category)) {
clist.tasks.add(task);
} else {
clist.pruned++;