Index: openacs-4/contrib/packages/project-manager/tcl/task-procs.tcl
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/project-manager/tcl/Attic/task-procs.tcl,v
diff -u -r1.4.2.24 -r1.4.2.25
--- openacs-4/contrib/packages/project-manager/tcl/task-procs.tcl 8 Oct 2004 21:25:04 -0000 1.4.2.24
+++ openacs-4/contrib/packages/project-manager/tcl/task-procs.tcl 26 Oct 2004 01:22:27 -0000 1.4.2.25
@@ -13,7 +13,24 @@
namespace eval pm::task {}
+ad_proc -public pm::task::name {
+ {-task_item_id:required}
+} {
+ Returns the name of the task
+
+ @author Jade Rubick (jader@bread.com)
+ @creation-date 2004-10-25
+
+ @param task_item_id
+ @return
+
+ @error -1
+} {
+ return [db_string get_name { } -default "-1"]
+}
+
+
ad_proc -public pm::task::options_list {
{-edit_p "f"}
-project_item_id
@@ -81,7 +98,7 @@
SELECT
r.item_id,
r.title as task_title
- FROM
+ FROM
pm_tasks_revisionsx r,
cr_items i,
pm_tasks_active t
@@ -147,6 +164,173 @@
}
+ad_proc -public pm::task::options_list_html {
+ {-edit_p "f"}
+ -project_item_id
+ {-task_item_id ""}
+ {-dependency_task_id ""}
+ {-dependency_task_ids ""}
+ {-number "0"}
+ {-depends_on_new ""}
+ {-current_number "0"}
+} {
+ Returns a list of options suiteable for HTML.
+ Contains a list of possible tasks that this task can
+ depend upon, or selected. These tasks are limited to just the
+ one project.
+
+
+
+ There is one special case that we handle: if you are creating new
+ tasks (not editing), you can have them depend on each other.
+ So if you create two tasks at the same time, you may want task
+ 2 to depend on task 1. Instead of a task_item_id, we then
+ specify a value of this form:
+
+
+ numX
+
+
+ where X represents the number of the new task, ranging from 1
+ to n.
+
+
+
+ To be more efficient when creating multiple tasks at the same
+ time, we should cache the database calls.
+
+ @author Jade Rubick (jader@bread.com)
+ @creation-date 2004-05-13
+
+ @param edit_p Is this for a task being edited? Or a new task?
+
+ @param project_item_id The project we're finding tasks from
+
+ @param task_item_id The task ID. This is used because we do not
+ want a task to depend on itself, so it is excluded from the list.
+
+ @param dependency_task_ids For edited tasks, the current task_ids
+ that it depends on. Used because sometimes it can be closed, and
+ it wouldn't otherwise appear on the list. This is a list.
+
+ @param dependency_task_id For edited tasks, the current task that
+ it depends on, used for setting the default option in HTML.
+
+ @param number When the list is returned, it includes entries for
+ number new tasks, in the numX format described in these docs.
+
+ @param depends_on_new When you're using a process, you want the
+ dependency to be on other new tasks. The format for this should
+ be num1 num2, etc.. So we make the default if this parameter is set.
+
+ @param current_number The current number. Used for new tasks. It
+ prevents allowing dependencies on the task being created.
+
+ @return
+
+ @error
+} {
+
+ # get tasks this task can depend on
+
+ if {[exists_and_not_null dependency_task_ids]} {
+
+ set union_clause "
+ UNION
+ SELECT
+ r.item_id,
+ r.title as task_title
+ FROM
+ pm_tasks_revisionsx r,
+ cr_items i,
+ pm_tasks_active t
+ WHERE
+ r.parent_id = :project_item_id and
+ r.revision_id = i.live_revision and
+ i.item_id = t.task_id
+ and t.task_id in ([join $dependency_task_ids ","])"
+ } else {
+ set union_clause ""
+ }
+
+ set keys [list]
+
+ db_foreach get_dependency_tasks { } {
+ set options($task_title) $item_id
+ lappend keys $task_title
+ }
+
+ set keys [lsort $keys]
+
+ # ---------------------------------------------------------------
+ # Start setting up the output.
+ # These are for new tasks, the already created tasks are added to
+ # the list later.
+ # ---------------------------------------------------------------
+
+ set dependency_options_full " "
+
+ if {[string is false $edit_p]} {
+
+ # now set up dependency options
+
+ for {set j 1} {$j <= $number} {incr j} {
+
+ if {[string equal $depends_on_new $j]} {
+ set selected "selected=\"selected\" "
+ } else {
+ set selected ""
+ }
+
+ if {![string equal $current_number $j]} {
+ append dependency_options_full " "
+ }
+ }
+ }
+
+ # -------------------------------------------------
+ # Now add the tasks that are already in the project
+ # -------------------------------------------------
+
+
+ if {[string is true $edit_p]} {
+ foreach key $keys {
+
+ # for editing tasks, we skip ourselves (because depending on
+ # ourselves just sometimes isn't an option)
+ if {![string equal $task_item_id $options($key)]} {
+
+ if {[string equal $options($key) $dependency_task_id]} {
+ set selected "selected=\"selected\" "
+ } else {
+ set selected ""
+ }
+
+ # check for case when there is a quote in the name of
+ # a task. We have to filter this out, or we get an
+ # error. -- not sure what this comment is for -- JR
+
+
+ append dependency_options_full " "
+ }
+ }
+ } else {
+
+ foreach key $keys {
+
+ # check for case when there is a quote in the name of a
+ # task. We have to filter this out, or we get an error. --
+ # not sure what this comment is for -- JR
+
+ append dependency_options_full " "
+ }
+ }
+
+
+ return $dependency_options_full
+}
+
+
ad_proc -public pm::task::dependency_delete_all {
-task_item_id:required
@@ -156,13 +340,14 @@
@author Jade Rubick (jader@bread.com)
@creation-date 2004-02-23
- @param task_item_id The task we wish to remove the dependencies from
+ @param task_item_id The task we wish to remove the dependencies from.
@return
@error
} {
- db_dml delete_deps "delete from pm_task_dependency where task_id = :task_item_id"
+ db_dml delete_deps { }
+
return 1
}
@@ -214,16 +399,7 @@
@error
} {
- set project_tasks [db_list get_tasks "
- SELECT
- task.item_id as t_item_id
- FROM
- cr_items task,
- cr_items project
- WHERE
- task.parent_id = project.item_id and
- project.item_id = :project_item_id
- "]
+ set project_tasks [db_list get_tasks { }]
# we do not allow tasks to depend on items outside of their
# project. So if it's not in the list of tasks for that project,
@@ -239,15 +415,7 @@
if {$loop_limit > 0} {
set dep_list [list]
- db_foreach get_dependencies "
- SElECT
- d.task_id as dep_task,
- d.parent_task_id as dep_task_parent
- FROM
- pm_task_dependency d
- WHERE
- d.task_id in ([join $project_tasks ", "])
- " {
+ db_foreach get_dependencies { } {
lappend dep_list d-$dep_task-$dep_task_parent
}
@@ -266,12 +434,11 @@
}
-
- if {[string equal $valid_p "TRUE"]} {
+ if {[string is true $valid_p]} {
# after it passes
set dependency_id [db_nextval pm_task_dependency_seq]
- db_dml insert_dep "insert into pm_task_dependency (dependency_id, task_id, parent_task_id, dependency_type) values (:dependency_id, :task_item_id, :parent_id, 'finish_before_start')"
+ db_dml insert_dep { }
} else {
ns_log Notice "Task dependency for $task_item_id on $parent_id was not added due to looping or being outside of the current project"
@@ -457,8 +624,6 @@
-estimated_hours_work:required
-estimated_hours_work_min:required
-estimated_hours_work_max:required
- -actual_hours_worked:required
- {-status_id}
-update_user:required
-update_ip:required
-package_id:required
@@ -491,10 +656,6 @@
@param estimated_hours_work_max
- @param actual_hours_worked The number of hours worked to date
-
- @param status_id The code representing the status
-
@param update_user The user updating the task
@param update_ip The IP address of the request
@@ -505,56 +666,42 @@
@error
} {
- if {![exists_and_not_null status_id]} {
- set status_id [pm::task::current_status \
- -task_item_id $task_item_id]
- }
-
# simple sanity check for min and max estimated hours
if {$estimated_hours_work_min > $estimated_hours_work_max} {
set temp $estimated_hours_work_max
set estimated_hours_work_max $estimated_hours_work_min
set estimated_hours_work_min $temp
}
- set return_val [db_exec_plsql new_task_revision { *SQL }]
+ if {$percent_complete >= 100} {
- # we have to update all logged hours to make sure the hours are
- # updated whenever the project is changed.
+ set status_id [pm::task::default_status_closed]
- set logger_project [pm::project::get_logger_project -project_item_id $project_item_id]
+ } elseif {$percent_complete < 100} {
- db_dml update_logger_entries {
- UPDATE
- logger_entries
- SET
- project_id = :logger_project
- WHERE
- entry_id in
- (select logger_entry from pm_task_logger_proj_map where task_item_id = :task_item_id)
+ set status_id [pm::task::default_status_open]
}
- # if the we've done 100% of the work, then we close the task
- if {$percent_complete >= 100} {
- pm::task::close \
- -task_item_id $task_item_id \
- -comment "$comment" \
- -comment_type $comment_type
- } else {
- # does not need comment because that's done later
- pm::task::open \
- -task_item_id $task_item_id
+ set actual_hours_worked [pm::task::update_hours \
+ -task_item_id $task_item_id]
- }
+ set return_val [db_exec_plsql new_task_revision { *SQL }]
+ # we have to update all logged hours to make sure the hours are
+ # set to the correct project whenever the project is changed.
+
+ set logger_project [pm::project::get_logger_project -project_item_id $project_item_id]
+
+ db_dml update_logger_entries { }
+
return $return_val
}
ad_proc -public pm::task::new {
-project_id:required
- -title:required
+ {-title "Subject missing"}
{-description ""}
{-mime_type "text/plain"}
{-end_date ""}
@@ -564,10 +711,25 @@
{-estimated_hours_work_max "0"}
{-creation_date ""}
{-status_id ""}
+ {-process_instance_id ""}
-creation_user:required
-creation_ip:required
-package_id:required
} {
+ Creates a new task.
+
+ @param process_instance_id If a process was used to create the
+ task, then it is linked in to that process instance, so we can
+ things like display only tasks that are a part of a process.
+
+ @author Jade Rubick (jader@bread.com)
+ @creation-date who knows?
+
+ @return new task_item_id
+
+ @error
+
+} {
if {![exists_and_not_null status_id]} {
set status_id [pm::task::default_status_open]
}
@@ -578,9 +740,15 @@
set estimated_hours_work_min $temp
}
- set return_val [db_exec_plsql new_task_item { *SQL }]
+ set task_revision [db_exec_plsql new_task_item { *SQL }]
+ set task_item_id [pm::task::get_item_id \
+ -task_id $task_revision]
- return $return_val
+ if {$percent_complete >= 100} {
+ pm::task::close -task_item_id $task_item_id
+ }
+
+ return $task_item_id
}
@@ -739,7 +907,7 @@
select sum(le.value) from logger_entries le where entry_id in (select logger_entry from pm_task_logger_proj_map where task_item_id = :task_item_id) and le.variable_id = '[logger::variable::get_default_variable_id]'
" -default "0"]
- if {[string equal $update_tasks_p "t"]} {
+ if {[string is true $update_tasks_p]} {
db_dml update_current_task "
UPDATE
@@ -865,10 +1033,9 @@
ad_proc -public pm::task::open {
- -task_item_id:required
+ {-task_item_id:required}
} {
- Opens a task, and sends notifications, unless it was already
- open. If it was already open, does nothing.
+ Opens a task.
@author Jade Rubick (jader@bread.com)
@creation-date 2004-04-22
@@ -879,137 +1046,15 @@
@error
} {
- # find out what the status of the task was, and while we're at it,
- # get other interesting information about the task, in case we
- # want to close it. Then we can put this info in the email.
-
- db_1row get_status "
- SELECT
- t.status,
- s.status_type,
- s.description as status_description,
- r.title as task_title,
- r.estimated_hours_work,
- r.estimated_hours_work_min,
- r.estimated_hours_work_max,
- to_char(r.earliest_start, 'YYYY-MM-DD HH24:MI:SS') as earliest_start_ansi,
- to_char(r.earliest_finish, 'YYYY-MM-DD HH24:MI:SS') as earliest_finish_ansi,
- to_char(r.latest_start, 'YYYY-MM-DD HH24:MI:SS') as latest_start_ansi,
- to_char(r.latest_finish, 'YYYY-MM-DD HH24:MI:SS') as latest_finish_ansi,
- r.description as task_description,
- r.mime_type,
- project_revision.title as project_name
- FROM
- pm_tasks t,
- cr_items task_item,
- pm_task_status s,
- pm_tasks_revisionsx r,
- cr_items project_item,
- cr_revisions project_revision
- WHERE
- r.parent_id = project_item.item_id and
- t.task_id = task_item.item_id and
- task_item.live_revision = r.revision_id and
- project_item.live_revision = project_revision.revision_id and
- r.item_id = t.task_id and
- t.status = s.status_id and
- t.task_id = :task_item_id"
-
- if {[string equal $status_type "o"]} {
-
- # this is already open
- return
-
- }
-
- # set the new status
-
set status_code [pm::task::default_status_open]
- db_dml update_status "
- UPDATE
- pm_tasks
- SET
- status = :status_code
- WHERE
- task_id = :task_item_id"
-
- # send out an email notification
-
- set earliest_start [lc_time_fmt $earliest_start_ansi "%x"]
- set earliest_finish [lc_time_fmt $earliest_finish_ansi "%x"]
- set latest_start [lc_time_fmt $latest_start_ansi "%x"]
- set latest_finish [lc_time_fmt $latest_finish_ansi "%x"]
-
- set assignees [pm::task::assignee_email_list -task_item_id $task_item_id]
-
- if {[llength $assignees] > 0} {
-
- set to_address $assignees
-
- set user_id [ad_conn user_id]
-
- set from_address [db_string get_from_email "select email from parties where party_id = :user_id" -default "nobody@nowhere.com"]
-
- set task_url [pm::task::get_url $task_item_id]
-
- set subject "Task Reopened (was $status_description): $task_title"
-
- set notification_text "Task reopened, was $status_description\n\n"
-
- set task_description [ad_html_text_convert -from $mime_type -to "text/html" -- $task_description]
-
- append notification_text "
-