Notes, edits, tigers, oh my!

git-svn-id: https://samskivert.googlecode.com/svn/trunk@898 6335cc39-0255-0410-8fd6-9bcaacd3b74c
This commit is contained in:
mdb
2002-11-08 21:49:18 +00:00
parent aa4c37541a
commit 2de6a6923b
10 changed files with 404 additions and 58 deletions
@@ -1,5 +1,5 @@
//
// $Id: Task.java,v 1.1 2002/11/08 09:14:21 mdb Exp $
// $Id: Task.java,v 1.2 2002/11/08 21:49:17 mdb Exp $
package com.samskivert.twodue.data;
@@ -31,5 +31,5 @@ public class Task
public Date completion;
public transient ArrayList notes;
public String notes;
}
@@ -1,5 +1,5 @@
//
// $Id: TaskRepository.java,v 1.1 2002/11/08 09:14:21 mdb Exp $
// $Id: TaskRepository.java,v 1.2 2002/11/08 21:49:17 mdb Exp $
package com.samskivert.twodue.data;
@@ -75,6 +75,7 @@ public class TaskRepository extends JORARepository
task.complexity = complexity;
task.priority = priority;
task.creator = creator;
task.notes = "";
createTask(task);
return task;
}
@@ -102,18 +103,24 @@ public class TaskRepository extends JORARepository
/**
* Loads up the specified task.
*
* @return the requested task or null if no tasks exists with that id.
*/
public Task loadTask (int taskId)
public Task loadTask (final int taskId)
throws PersistenceException
{
return (Task)execute(new Operation () {
public Object invoke (Connection conn, DatabaseLiaison liaison)
throws PersistenceException, SQLException
{
String query = "where COMPLETOR IS NULL AND OWNER IS NULL " +
"ORDER BY CATEGORY, PRIORITY";
Cursor tc = _ttable.select(query);
return tc.toArrayList();
String query = "where TASK_ID = " + taskId;
Cursor ec = _ttable.select(query);
Task task = (Task)ec.next();
if (task != null) {
// call next() again to cause the cursor to close itself
ec.next();
}
return task;
}
});
}
@@ -0,0 +1,89 @@
//
// $Id: detail.java,v 1.1 2002/11/08 21:49:17 mdb Exp $
package com.samskivert.twodue.logic;
import java.util.StringTokenizer;
import javax.servlet.http.HttpServletRequest;
import com.samskivert.servlet.user.User;
import com.samskivert.servlet.util.ParameterUtil;
import com.samskivert.util.StringUtil;
import com.samskivert.velocity.InvocationContext;
import com.samskivert.twodue.Log;
import com.samskivert.twodue.TwoDueApp;
import com.samskivert.twodue.data.Task;
/**
* Displays the details of a single task.
*/
public class detail extends UserLogic
{
public void invoke (InvocationContext ctx, TwoDueApp app, User user)
throws Exception
{
HttpServletRequest req = ctx.getRequest();
int taskId = ParameterUtil.requireIntParameter(
ctx.getRequest(), "task", "task.error.missing_taskid");
// we use this to determine whether to show "complete" buttons for
// tasks
ctx.put("username", user.username);
// load up the task in question
Task task = app.getRepository().loadTask(taskId);
if (task == null) {
ctx.put("error", "task.error.no_such_task");
} else {
// format the notes and stuff those in the context
ctx.put("notes", formatNotes(task.notes));
// stick the task in the context
ctx.put("task", task);
}
}
protected String formatNotes (String notes)
{
if (StringUtil.blank(notes)) {
return notes;
}
StringBuffer fnotes = new StringBuffer();
StringTokenizer tok = new StringTokenizer(notes, "\n", true);
boolean excepting = false, eatnewline = false;
while (tok.hasMoreTokens()) {
String line = tok.nextToken();
boolean sawexcept = false;
if (line.indexOf("Exception:") != -1) {
sawexcept = true;
fnotes.append("<pre>\n");
}
if (line.equals("\n")) {
if (!eatnewline) {
fnotes.append("<p>\n");
} else {
eatnewline = false;
}
// no further processing on newlines
continue;
} else {
fnotes.append(line).append("\n");
eatnewline = true;
}
if (excepting && line.indexOf(" at ") == -1) {
excepting = false;
fnotes.append("</pre>");
}
if (sawexcept) {
excepting = true;
}
}
return fnotes.toString();
}
}
@@ -0,0 +1,109 @@
//
// $Id: edit.java,v 1.1 2002/11/08 21:49:17 mdb Exp $
package com.samskivert.twodue.logic;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import javax.servlet.http.HttpServletRequest;
import com.samskivert.util.QuickSort;
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;
/**
* Allows a single task to be edited.
*/
public class edit extends UserLogic
{
public void invoke (InvocationContext ctx, TwoDueApp app, User user)
throws Exception
{
HttpServletRequest req = ctx.getRequest();
int taskId = ParameterUtil.requireIntParameter(
ctx.getRequest(), "task", "task.error.missing_taskid");
// load up the task in question
Task task = app.getRepository().loadTask(taskId);
if (task == null) {
ctx.put("error", "edit.error.no_such_task");
} else {
// stick the task in the context
ctx.put("task", task);
}
// if they've submitted the form, we update the task database
if (ParameterUtil.parameterEquals(
ctx.getRequest(), "action", "update")) {
// extract our fields
task.summary = ParameterUtil.requireParameter(
ctx.getRequest(), "summary", "task.error.missing_summary");
// remove extra spaces introduced by our friend the textarea
task.summary = task.summary.trim();
task.category = ParameterUtil.requireParameter(
ctx.getRequest(), "category",
"task.error.missing_category");
task.complexity = ParameterUtil.requireParameter(
ctx.getRequest(), "complexity",
"task.error.missing_complexity");
task.priority = ParameterUtil.requireIntParameter(
ctx.getRequest(), "priority",
"task.error.invalid_priority");
task.creator = ParameterUtil.requireParameter(
ctx.getRequest(), "creator",
"task.error.missing_creator");
// preserve the null-status of non-owned tasks
String owner = ParameterUtil.getParameter(
ctx.getRequest(), "owner", true);
task.owner = (StringUtil.blank(owner)) ? null : owner;
app.getRepository().updateTask(task);
ctx.put("error", "edit.message.task_updated");
} else if (ParameterUtil.parameterEquals(
ctx.getRequest(), "action", "reopen")) {
// clear out the completor and completion dates
task.completor = null;
task.completion = null;
app.getRepository().updateTask(task);
ctx.put("error", "edit.message.task_reopened");
} else if (ParameterUtil.parameterEquals(
ctx.getRequest(), "action", "addnote")) {
// extract our fields
String note = ParameterUtil.requireParameter(
ctx.getRequest(), "note", "edit.error.missing_note");
// prefix the note with a creator identifier
note = "[" + user.username + "] " + note.trim();
if (StringUtil.blank(task.notes)) {
task.notes = note;
} else {
task.notes += "\n\n" + note;
}
app.getRepository().updateTask(task);
ctx.put("error", "edit.message.note_added");
} else if (ParameterUtil.parameterEquals(
ctx.getRequest(), "action", "editnotes")) {
task.notes = ParameterUtil.getParameter(
ctx.getRequest(), "notes", false).trim();
app.getRepository().updateTask(task);
ctx.put("error", "edit.message.notes_updated");
}
}
}
@@ -1,5 +1,5 @@
//
// $Id: index.java,v 1.1 2002/11/08 09:14:21 mdb Exp $
// $Id: index.java,v 1.2 2002/11/08 21:49:17 mdb Exp $
package com.samskivert.twodue.logic;
@@ -47,19 +47,18 @@ public class index extends UserLogic
// set the creator from the username of the calling user
Task task = new Task();
task.creator = user.username;
task.notes = ""; // no notes to start
// parse our fields
task.summary = ParameterUtil.requireParameter(
ctx.getRequest(), "summary", "index.error.missing_summary");
ctx.getRequest(), "summary", "task.error.missing_summary");
task.category = ParameterUtil.requireParameter(
ctx.getRequest(), "category",
"index.error.missing_category");
ctx.getRequest(), "category", "task.error.missing_category");
task.complexity = ParameterUtil.requireParameter(
ctx.getRequest(), "complexity",
"index.error.missing_complexity");
"task.error.missing_complexity");
task.priority = ParameterUtil.requireIntParameter(
ctx.getRequest(), "priority",
"index.error.invalid_priority");
ctx.getRequest(), "priority", "task.error.invalid_priority");
// insert the task into the repository
app.getRepository().createTask(task);
@@ -72,7 +71,7 @@ public class index extends UserLogic
} else if (ParameterUtil.parameterEquals(
ctx.getRequest(), "action", "complete")) {
int taskId = ParameterUtil.requireIntParameter(
ctx.getRequest(), "task", "index.error.missing_taskid");
ctx.getRequest(), "task", "task.error.missing_taskid");
app.getRepository().completeTask(taskId, user.username);
// let the user know we updated the database
@@ -81,7 +80,7 @@ public class index extends UserLogic
} else if (ParameterUtil.parameterEquals(
ctx.getRequest(), "action", "claim")) {
int taskId = ParameterUtil.requireIntParameter(
ctx.getRequest(), "task", "index.error.missing_taskid");
ctx.getRequest(), "task", "task.error.missing_taskid");
app.getRepository().claimTask(taskId, user.username);
// let the user know we updated the database
+6 -1
View File
@@ -1,5 +1,5 @@
/**
* $Id: tasks-schema.sql,v 1.1 2002/11/08 09:14:21 mdb Exp $
* $Id: tasks-schema.sql,v 1.2 2002/11/08 21:49:18 mdb Exp $
*
* Schema for the Two Due tasks and notes table.
*/
@@ -61,6 +61,11 @@ CREATE TABLE TASKS
*/
COMPLETION DATE,
/**
* Free form notes associated with this task.
*/
NOTES TEXT NOT NULL,
/**
* Defines our table keys.
*/