Index: openacs-4/contrib/packages/simulation/lib/simulations-task-count.adp =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/simulation/lib/Attic/simulations-task-count.adp,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/simulation/lib/simulations-task-count.adp 4 Mar 2004 12:09:43 -0000 1.1 @@ -0,0 +1 @@ +

Index: openacs-4/contrib/packages/simulation/lib/simulations-task-count.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/simulation/lib/Attic/simulations-task-count.tcl,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/simulation/lib/simulations-task-count.tcl 4 Mar 2004 12:09:43 -0000 1.1 @@ -0,0 +1,44 @@ +simulation::include_contract { + Displays a list of simulations with task counts for admins. + + @author Joel Aufrecht + @creation-date 2003-11-12 + @cvs-id $Id: simulations-task-count.tcl,v 1.1 2004/03/04 12:09:43 peterm Exp $ +} + +set user_id [ad_conn user_id] + +template::list::create \ + -name simulations \ + -multirow simulations \ + -no_data "You don't have any tasks." \ + -elements { + pretty_name { + label "Simulation" + link_url_col simulation_url + } + number_of_tasks { + label "Number of tasks" + html {align center} + } + } + +db_multirow -extend { simulation_url } simulations simulations { + select q.* from + (select w.workflow_id, + w.pretty_name, + (select count(*) + from workflow_case_role_user_map wcrum, + workflow_case_assigned_actions wcaa, + workflow_cases wc + where wcrum.case_id = wcaa.case_id + and wcrum.role_id = wcaa.role_id + and wcaa.case_id = wc.case_id + and wc.workflow_id = w.workflow_id + and wcrum.user_id = :user_id + ) as number_of_tasks + from workflows w) q + where q.number_of_tasks > 0 +} { + set simulation_url [export_vars -base tasks-bulk { workflow_id }] +} Index: openacs-4/contrib/packages/simulation/lib/tasks.adp =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/simulation/lib/Attic/tasks.adp,v diff -u -r1.2 -r1.3 --- openacs-4/contrib/packages/simulation/lib/tasks.adp 6 Jan 2004 09:51:25 -0000 1.2 +++ openacs-4/contrib/packages/simulation/lib/tasks.adp 4 Mar 2004 12:09:43 -0000 1.3 @@ -2,5 +2,6 @@ This case has been completed. +

Index: openacs-4/contrib/packages/simulation/lib/tasks.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/simulation/lib/Attic/tasks.tcl,v diff -u -r1.13 -r1.14 --- openacs-4/contrib/packages/simulation/lib/tasks.tcl 23 Jan 2004 15:35:18 -0000 1.13 +++ openacs-4/contrib/packages/simulation/lib/tasks.tcl 4 Mar 2004 12:09:43 -0000 1.14 @@ -14,12 +14,19 @@ role_id { default_value "" } + workflow_id { + default_value "" + } } if { [empty_string_p $case_id] } { unset case_id } +if { [empty_string_p $user_id] } { + set user_id [ad_conn user_id] +} + set package_id [ad_conn package_id] set adminplayer_p [permission::permission_p -object_id $package_id -privilege sim_adminplayer] @@ -60,11 +67,83 @@ } } +set bulk_actions "" +set role_values "" +set task_values "" +set bulk_p 0 +if { ![empty_string_p $workflow_id] } { + # We are listing tasks across cases in a workflow. + # Enable the role filter. + + set role_values [db_list_of_lists select_roles { + select wr.pretty_name, + wr.role_id + from workflow_roles wr + where wr.workflow_id = :workflow_id + and exists (select 1 + from workflow_case_role_user_map wcrum, + workflow_case_assigned_actions wcaa + where wcrum.case_id = wcaa.case_id + and wcrum.role_id = wcaa.role_id + and wcrum.role_id = wr.role_id + and wcrum.user_id = :user_id + ) + }] + + if { [llength $role_values] <= 1 } { + # Don't display a filter with one option + set role_values {} + } + + set task_values [db_list_of_lists select_tasks { + select wa.pretty_name, + wa.action_id + from workflow_actions wa + where wa.workflow_id = :workflow_id + and exists (select 1 + from workflow_case_role_user_map wcrum, + workflow_case_assigned_actions wcaa + where wcrum.case_id = wcaa.case_id + and wcrum.role_id = wcaa.role_id + and wcaa.action_id = wa.action_id + and wcrum.user_id = :user_id + ) + }] + + if { [llength $task_values] <= 1 } { + # Don't display a filter with one option + set task_values {} + } + + set bulk_actions { + "Respond" task-detail "Take action on selected tasks" + } + set bulk_p 1 +} + template::list::create \ -name tasks \ -multirow tasks \ -no_data "You don't have any tasks." \ - -elements $elements + -key "enabled_action_id" \ + -elements $elements \ + -filters { + role_id { + label "Role" + values $role_values + hide_p {[ad_decode [llength $role_values] 0 t f]} + } + task_id { + label "Task" + values $task_values + hide_p {[ad_decode [llength $task_values] 0 t f]} + } + workflow_id { + hide_p t + } + } \ + -bulk_actions $bulk_actions \ + -bulk_action_export_vars { bulk_p } # NOTE: Our "pick case and role" design of simplay doesn't work if a child workflow uses per_user mapping # because the role in the child workflow will then no longer match any role in the top case. @@ -88,6 +167,7 @@ and sc.sim_case_id = topwc.object_id and w.workflow_id = topwc.workflow_id and wr.role_id = wcaa.role_id + [ad_decode [exists_and_not_null workflow_id] 1 "and w.workflow_id = :workflow_id" ""] [ad_decode [exists_and_not_null role_id] 1 "and wcaa.role_id = :role_id" ""] [ad_decode [exists_and_not_null case_id] 1 "and wcaa.case_id = :case_id" "and exists (select 1 from workflow_case_role_user_map @@ -96,7 +176,5 @@ and user_id = :user_id)"] order by wa.sort_order " { - set task_url [export_vars -base "[apm_package_url_from_id $package_id]simplay/task-detail" { enabled_action_id case_id role_id }] + set task_url [export_vars -base "[apm_package_url_from_id $package_id]simplay/task-detail" { enabled_action_id case_id role_id bulk_p }] } - - Index: openacs-4/contrib/packages/simulation/tcl/template-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/simulation/tcl/Attic/template-procs.tcl,v diff -u -r1.65 -r1.66 --- openacs-4/contrib/packages/simulation/tcl/template-procs.tcl 27 Jan 2004 09:58:43 -0000 1.65 +++ openacs-4/contrib/packages/simulation/tcl/template-procs.tcl 4 Mar 2004 12:09:43 -0000 1.66 @@ -577,6 +577,10 @@ lappend invite_email_list [list $email $user_name] } } + # Always enroll the admin creating the simulation + set admin_user_id [ad_conn user_id] + acs_user::get -user_id $admin_user_id -array admin_user + lappend enroll_user_list [list $admin_user_id $admin_user(email) $admin_user(name)] # Enroll users foreach user $enroll_user_list { @@ -834,6 +838,7 @@ }] foreach case_id $current_cases { cast_users_in_case \ + -workflow_id $workflow_id \ -case_id $case_id \ -roles_array roles \ -role_names_array role_short_name \ @@ -858,6 +863,7 @@ -workflow_short_name $workflow_short_name] cast_users_in_case \ + -workflow_id $workflow_id \ -case_id $case_id \ -roles_array roles \ -role_names_array role_short_name \ @@ -868,6 +874,7 @@ } ad_proc -private simulation::template::cast_users_in_case { + {-workflow_id:required} {-case_id:required} {-roles_array:required} {-role_names_array} @@ -886,6 +893,8 @@ upvar $users_var users_to_cast upvar $users_not_in_groups_var users_to_cast_not_in_groups + set admin_user_id [admin_user_id -workflow_id $workflow_id] + # Loop over each role in the case and decide which users to assign it array unset row array set row [list] @@ -930,7 +939,9 @@ # There is a role group with at least one user that hasn't been cast. # Cast a random user from that group set user_id [lindex $group_members($group_id) 0] - lappend assignees $user_id + if { ![string equal $user_id $admin_user_id] } { + lappend assignees $user_id + } # Remove the user from the group member list set group_members($group_id) [lreplace $group_members($group_id) 0 0] @@ -946,8 +957,10 @@ if { [llength $users_to_cast_not_in_groups] > 0 } { # Fill the role with a user not in any of the role groups set user_id [lindex $users_to_cast_not_in_groups 0] - lappend assignees $user_id - + if { ![string equal $user_id $admin_user_id] } { + lappend assignees $user_id + } + # Remove user from the not-in-group list set users_to_cast_not_in_groups [lreplace $users_to_cast_not_in_groups 0 0] @@ -958,7 +971,7 @@ } else { # No more users to cast, resort to the logged in user (admin) - lappend assignees [ad_conn user_id] + lappend assignees $admin_user_id # Don't add the admin more than once break } @@ -969,13 +982,29 @@ set row($role_short_name($role_id)) $assignees } + ns_log Notice "pm debug row = [array get row]" + # Do all the user-role assignments in the case workflow::case::role::assign \ -case_id $case_id \ -array row \ } +ad_proc -private simulation::template::admin_user_id { + {-workflow_id:required} +} { + When starting a simulation, get the user if of the simulation admin. The simulation + admin is the creator of the simulation. + @author Peter Marklund +} { + return [db_string select_creation_user { + select creation_user + from acs_objects + where object_id = :workflow_id + }] +} + #---------------------------------------------------------------------- # Simple workflow wrappers #---------------------------------------------------------------------- Index: openacs-4/contrib/packages/simulation/www/simplay/index.adp =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/simulation/www/simplay/Attic/index.adp,v diff -u -r1.22 -r1.23 --- openacs-4/contrib/packages/simulation/www/simplay/index.adp 22 Jan 2004 15:47:23 -0000 1.22 +++ openacs-4/contrib/packages/simulation/www/simplay/index.adp 4 Mar 2004 12:09:44 -0000 1.23 @@ -17,9 +17,10 @@

-

All Tasks

+

Your Tasks

- -

+ +

+

Index: openacs-4/contrib/packages/simulation/www/simplay/message.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/simulation/www/simplay/Attic/message.tcl,v diff -u -r1.24 -r1.25 --- openacs-4/contrib/packages/simulation/www/simplay/message.tcl 30 Jan 2004 11:23:25 -0000 1.24 +++ openacs-4/contrib/packages/simulation/www/simplay/message.tcl 4 Mar 2004 12:09:44 -0000 1.25 @@ -26,10 +26,7 @@ set to_role_options [list] foreach one_role_id [workflow::role::get_ids -workflow_id $workflow_id] { - # A role cannot send message to himself - if { ![exists_and_equal role_id $one_role_id] } { lappend to_role_options [list [workflow::role::get_element -role_id $one_role_id -element pretty_name] $one_role_id] - } } set attachment_options [simulation::case::attachment_options -case_id $case_id -role_id $role_id] Index: openacs-4/contrib/packages/simulation/www/simplay/task-detail.adp =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/simulation/www/simplay/Attic/task-detail.adp,v diff -u -r1.9 -r1.10 --- openacs-4/contrib/packages/simulation/www/simplay/task-detail.adp 30 Jan 2004 10:57:08 -0000 1.9 +++ openacs-4/contrib/packages/simulation/www/simplay/task-detail.adp 4 Mar 2004 12:09:44 -0000 1.10 @@ -1,9 +1,28 @@ - + + + + + + @case_id@ + @page_title;noquote@ @context;noquote@ @focus;noquote@ - @case_id@ + +

+ You are doing a bulk response to @common_actions_count@ tasks. +

+ + +

+ Note: Ignoring @ignored_actions_count@ tasks that don't have the task + name "@action.pretty_name@". Please back up your browser if you + want to change the selection of tasks. +

+
+
+

@action.description@

Index: openacs-4/contrib/packages/simulation/www/simplay/task-detail.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/simulation/www/simplay/Attic/task-detail.tcl,v diff -u -r1.19 -r1.20 --- openacs-4/contrib/packages/simulation/www/simplay/task-detail.tcl 30 Jan 2004 11:23:25 -0000 1.19 +++ openacs-4/contrib/packages/simulation/www/simplay/task-detail.tcl 4 Mar 2004 12:09:44 -0000 1.20 @@ -2,31 +2,102 @@ Details for a task. If there is a recipient_role a message is created. If there is not recipient role we upload a document instead. } { - case_id:integer - role_id:integer - enabled_action_id:integer + {enabled_action_id:integer,multiple ""} + {enabled_action_ids ""} item_id:optional + {bulk_p 0} + {return_url ""} } -simulation::case::assert_user_may_play_role -case_id $case_id -role_id $role_id +# FIXME: I am exporting the enabled_action_id list as the string variable enabled_action_ids in +# the forms as I can't export multiples. Here I'm recreating the list again. This is convoluted. +if { ![empty_string_p $enabled_action_ids] } { + set enabled_action_id [split $enabled_action_ids] +} -workflow::case::enabled_action_get -enabled_action_id $enabled_action_id -array enabled_action -set action_id $enabled_action(action_id) -simulation::action::get -action_id $action_id -array action +if { [llength $enabled_action_id] > 1 } { + set bulk_p 1 +} +if { !$bulk_p } { + workflow::case::enabled_action_get -enabled_action_id $enabled_action_id -array enabled_action + + set action_id $enabled_action(action_id) + set case_id $enabled_action(case_id) + simulation::action::get -action_id $action_id -array action + set role_id $action(assigned_role_id) + + simulation::case::assert_user_may_play_role -case_id $case_id -role_id $action(assigned_role_id) + + set common_enabled_action_ids [list [list $enabled_action_id $case_id]] + + if { [empty_string_p $return_url] } { + set return_url [export_vars -base tasks { case_id role_id }] + } + +} else { + # Only admin users can neglect to provide case_id and role_id + permission::require_permission -object_id [ad_conn package_id] -privilege sim_adminplayer + + # If we are taking action on more than one task, extract the subset of the tasks that + # have the same action_id + set common_action_id "" + set common_enabled_action_ids [list] + set ignored_enabled_action_ids [list] + set task_list [db_list_of_lists select_tasks " + select wcea.enabled_action_id, + wcea.action_id, + wcea.case_id + from workflow_case_enabled_actions wcea + where wcea.enabled_action_id in ('[join $enabled_action_id "', '"]') + "] + foreach task $task_list { + set one_enabled_action_id [lindex $task 0] + set one_action_id [lindex $task 1] + set one_case_id [lindex $task 2] + + if { [empty_string_p $common_action_id] } { + set common_action_id $one_action_id + set case_id $one_case_id + } + + if { [string equal $common_action_id $one_action_id] } { + lappend common_enabled_action_ids [list $one_enabled_action_id $one_case_id] + } else { + lappend ignored_enabled_action_ids $one_enabled_action_id + } + } + + set common_actions_count [llength $common_enabled_action_ids] + set ignored_actions_count [llength $ignored_enabled_action_ids] + + set action_id $common_action_id + + simulation::action::get -action_id $action_id -array action + + if { [empty_string_p $return_url] } { + set return_url [export_vars -base tasks-bulk { {workflow_id $action(workflow_id)} }] + } +} + set page_title $action(pretty_name) set context [list [list . "SimPlay"] [list [export_vars -base case { case_id role_id }] "Case"] [list [export_vars -base tasks { case_id role_id }] "Tasks"] $page_title] +set documents_pre_form "" if { ![empty_string_p $action(recipients)] } { # We have recipient roles - use message form - if { ![empty_string_p $action(assigned_role_id)] } { - set attachment_options [simulation::case::attachment_options -case_id $case_id -role_id $action(assigned_role_id)] + if { !$bulk_p } { + if { ![empty_string_p $action(assigned_role_id)] } { + set attachment_options [simulation::case::attachment_options -case_id $case_id -role_id $action(assigned_role_id)] + } + } else { + set attachment_options {} } set form_id action - ad_form -name $form_id -edit_buttons { { Send ok } } -export { case_id role_id enabled_action_id } \ + ad_form -name $form_id -edit_buttons { { Send ok } } -export { case_id role_id {enabled_action_ids $enabled_action_id} bulk_p} \ -form { {pretty_name:text(inform) {label "Task"} @@ -77,27 +148,32 @@ set body_text [template::util::richtext::get_property "contents" $body] set body_mime_type [template::util::richtext::get_property "format" $body] - + db_transaction { - set entry_id [workflow::case::action::execute \ + foreach one_action $common_enabled_action_ids { + set enabled_action_id [lindex $one_action 0] + set case_id [lindex $one_action 1] + + set entry_id [workflow::case::action::execute \ -enabled_action_id $enabled_action_id \ -comment $body_text \ -comment_mime_type $body_mime_type] - foreach recipient_id $action(recipients) { - simulation::message::new \ - -from_role_id $action(assigned_role_id) \ - -to_role_id $recipient_id \ - -case_id $case_id \ - -subject $subject \ - -body $body_text \ - -body_mime_type $body_mime_type \ - -attachments $attachments \ - -entry_id $entry_id - } + foreach recipient_id $action(recipients) { + simulation::message::new \ + -from_role_id $action(assigned_role_id) \ + -to_role_id $recipient_id \ + -case_id $case_id \ + -subject $subject \ + -body $body_text \ + -body_mime_type $body_mime_type \ + -attachments $attachments \ + -entry_id $entry_id + } + } } - ad_returnredirect [export_vars -base tasks { case_id role_id }] + ad_returnredirect $return_url ad_script_abort } @@ -109,7 +185,7 @@ set form_id document - ad_form -name $form_id -export { case_id role_id workflow_id enabled_action_id } -html {enctype multipart/form-data} \ + ad_form -name $form_id -export { case_id role_id workflow_id {enabled_action_ids $enabled_action_id} bulk_p} -html {enctype multipart/form-data} \ -form [concat {{pretty_name:text(inform) {label "Task"}}} [simulation::ui::forms::document_upload::form_block]] \ -on_request { set pretty_name $action(pretty_name) @@ -118,19 +194,23 @@ } -on_submit { db_transaction { - set entry_id [workflow::case::action::execute \ + foreach one_action $common_enabled_action_ids { + set case_id [lindex $one_action 1] + + set entry_id [workflow::case::action::execute \ -case_id $case_id \ -action_id $action_id \ -comment "Document [lindex $document_file 0] uploaded" \ -comment_mime_type "text/plain"] - simulation::ui::forms::document_upload::insert_document \ - $case_id $role_id $item_id $document_file $title $entry_id + simulation::ui::forms::document_upload::insert_document \ + $case_id $action(assigned_role_id) $item_id $document_file $title $entry_id + } } - ad_returnredirect [export_vars -base tasks { case_id role_id }] + ad_returnredirect $return_url + ad_script_abort } set focus "document.document_file" } - Index: openacs-4/contrib/packages/simulation/www/simplay/tasks-bulk.adp =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/simulation/www/simplay/Attic/tasks-bulk.adp,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/simulation/www/simplay/tasks-bulk.adp 4 Mar 2004 12:09:44 -0000 1.1 @@ -0,0 +1,10 @@ + + @page_title;noquote@ + @context;noquote@ + + + +

+ If you are using the respond button to respond to multiple tasks + then all checked tasks must share the same task name. +

\ No newline at end of file Index: openacs-4/contrib/packages/simulation/www/simplay/tasks-bulk.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/simulation/www/simplay/Attic/tasks-bulk.tcl,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/simulation/www/simplay/tasks-bulk.tcl 4 Mar 2004 12:09:44 -0000 1.1 @@ -0,0 +1,16 @@ +ad_page_contract { + This page shows all tasks that an admin has in a certain simulation and + allows the admin to take action on the tasks in bulk. + + @author Peter Marklund +} { + workflow_id:integer + role_id:optional +} + +permission::require_permission -object_id [ad_conn package_id] -privilege sim_adminplayer + +simulation::template::get -workflow_id $workflow_id -array simulation + +set page_title "Your Tasks in Simulation $simulation(pretty_name)" +set context [list [list . "SimPlay"] $page_title] Index: openacs-4/packages/simulation/lib/simulations-task-count.adp =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/simulation/lib/simulations-task-count.adp,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/simulation/lib/simulations-task-count.adp 4 Mar 2004 12:09:43 -0000 1.1 @@ -0,0 +1 @@ +

Index: openacs-4/packages/simulation/lib/simulations-task-count.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/simulation/lib/simulations-task-count.tcl,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/simulation/lib/simulations-task-count.tcl 4 Mar 2004 12:09:43 -0000 1.1 @@ -0,0 +1,44 @@ +simulation::include_contract { + Displays a list of simulations with task counts for admins. + + @author Joel Aufrecht + @creation-date 2003-11-12 + @cvs-id $Id: simulations-task-count.tcl,v 1.1 2004/03/04 12:09:43 peterm Exp $ +} + +set user_id [ad_conn user_id] + +template::list::create \ + -name simulations \ + -multirow simulations \ + -no_data "You don't have any tasks." \ + -elements { + pretty_name { + label "Simulation" + link_url_col simulation_url + } + number_of_tasks { + label "Number of tasks" + html {align center} + } + } + +db_multirow -extend { simulation_url } simulations simulations { + select q.* from + (select w.workflow_id, + w.pretty_name, + (select count(*) + from workflow_case_role_user_map wcrum, + workflow_case_assigned_actions wcaa, + workflow_cases wc + where wcrum.case_id = wcaa.case_id + and wcrum.role_id = wcaa.role_id + and wcaa.case_id = wc.case_id + and wc.workflow_id = w.workflow_id + and wcrum.user_id = :user_id + ) as number_of_tasks + from workflows w) q + where q.number_of_tasks > 0 +} { + set simulation_url [export_vars -base tasks-bulk { workflow_id }] +} Index: openacs-4/packages/simulation/lib/tasks.adp =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/simulation/lib/tasks.adp,v diff -u -r1.2 -r1.3 --- openacs-4/packages/simulation/lib/tasks.adp 6 Jan 2004 09:51:25 -0000 1.2 +++ openacs-4/packages/simulation/lib/tasks.adp 4 Mar 2004 12:09:43 -0000 1.3 @@ -2,5 +2,6 @@ This case has been completed. +

Index: openacs-4/packages/simulation/lib/tasks.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/simulation/lib/tasks.tcl,v diff -u -r1.13 -r1.14 --- openacs-4/packages/simulation/lib/tasks.tcl 23 Jan 2004 15:35:18 -0000 1.13 +++ openacs-4/packages/simulation/lib/tasks.tcl 4 Mar 2004 12:09:43 -0000 1.14 @@ -14,12 +14,19 @@ role_id { default_value "" } + workflow_id { + default_value "" + } } if { [empty_string_p $case_id] } { unset case_id } +if { [empty_string_p $user_id] } { + set user_id [ad_conn user_id] +} + set package_id [ad_conn package_id] set adminplayer_p [permission::permission_p -object_id $package_id -privilege sim_adminplayer] @@ -60,11 +67,83 @@ } } +set bulk_actions "" +set role_values "" +set task_values "" +set bulk_p 0 +if { ![empty_string_p $workflow_id] } { + # We are listing tasks across cases in a workflow. + # Enable the role filter. + + set role_values [db_list_of_lists select_roles { + select wr.pretty_name, + wr.role_id + from workflow_roles wr + where wr.workflow_id = :workflow_id + and exists (select 1 + from workflow_case_role_user_map wcrum, + workflow_case_assigned_actions wcaa + where wcrum.case_id = wcaa.case_id + and wcrum.role_id = wcaa.role_id + and wcrum.role_id = wr.role_id + and wcrum.user_id = :user_id + ) + }] + + if { [llength $role_values] <= 1 } { + # Don't display a filter with one option + set role_values {} + } + + set task_values [db_list_of_lists select_tasks { + select wa.pretty_name, + wa.action_id + from workflow_actions wa + where wa.workflow_id = :workflow_id + and exists (select 1 + from workflow_case_role_user_map wcrum, + workflow_case_assigned_actions wcaa + where wcrum.case_id = wcaa.case_id + and wcrum.role_id = wcaa.role_id + and wcaa.action_id = wa.action_id + and wcrum.user_id = :user_id + ) + }] + + if { [llength $task_values] <= 1 } { + # Don't display a filter with one option + set task_values {} + } + + set bulk_actions { + "Respond" task-detail "Take action on selected tasks" + } + set bulk_p 1 +} + template::list::create \ -name tasks \ -multirow tasks \ -no_data "You don't have any tasks." \ - -elements $elements + -key "enabled_action_id" \ + -elements $elements \ + -filters { + role_id { + label "Role" + values $role_values + hide_p {[ad_decode [llength $role_values] 0 t f]} + } + task_id { + label "Task" + values $task_values + hide_p {[ad_decode [llength $task_values] 0 t f]} + } + workflow_id { + hide_p t + } + } \ + -bulk_actions $bulk_actions \ + -bulk_action_export_vars { bulk_p } # NOTE: Our "pick case and role" design of simplay doesn't work if a child workflow uses per_user mapping # because the role in the child workflow will then no longer match any role in the top case. @@ -88,6 +167,7 @@ and sc.sim_case_id = topwc.object_id and w.workflow_id = topwc.workflow_id and wr.role_id = wcaa.role_id + [ad_decode [exists_and_not_null workflow_id] 1 "and w.workflow_id = :workflow_id" ""] [ad_decode [exists_and_not_null role_id] 1 "and wcaa.role_id = :role_id" ""] [ad_decode [exists_and_not_null case_id] 1 "and wcaa.case_id = :case_id" "and exists (select 1 from workflow_case_role_user_map @@ -96,7 +176,5 @@ and user_id = :user_id)"] order by wa.sort_order " { - set task_url [export_vars -base "[apm_package_url_from_id $package_id]simplay/task-detail" { enabled_action_id case_id role_id }] + set task_url [export_vars -base "[apm_package_url_from_id $package_id]simplay/task-detail" { enabled_action_id case_id role_id bulk_p }] } - - Index: openacs-4/packages/simulation/tcl/template-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/simulation/tcl/template-procs.tcl,v diff -u -r1.65 -r1.66 --- openacs-4/packages/simulation/tcl/template-procs.tcl 27 Jan 2004 09:58:43 -0000 1.65 +++ openacs-4/packages/simulation/tcl/template-procs.tcl 4 Mar 2004 12:09:43 -0000 1.66 @@ -577,6 +577,10 @@ lappend invite_email_list [list $email $user_name] } } + # Always enroll the admin creating the simulation + set admin_user_id [ad_conn user_id] + acs_user::get -user_id $admin_user_id -array admin_user + lappend enroll_user_list [list $admin_user_id $admin_user(email) $admin_user(name)] # Enroll users foreach user $enroll_user_list { @@ -834,6 +838,7 @@ }] foreach case_id $current_cases { cast_users_in_case \ + -workflow_id $workflow_id \ -case_id $case_id \ -roles_array roles \ -role_names_array role_short_name \ @@ -858,6 +863,7 @@ -workflow_short_name $workflow_short_name] cast_users_in_case \ + -workflow_id $workflow_id \ -case_id $case_id \ -roles_array roles \ -role_names_array role_short_name \ @@ -868,6 +874,7 @@ } ad_proc -private simulation::template::cast_users_in_case { + {-workflow_id:required} {-case_id:required} {-roles_array:required} {-role_names_array} @@ -886,6 +893,8 @@ upvar $users_var users_to_cast upvar $users_not_in_groups_var users_to_cast_not_in_groups + set admin_user_id [admin_user_id -workflow_id $workflow_id] + # Loop over each role in the case and decide which users to assign it array unset row array set row [list] @@ -930,7 +939,9 @@ # There is a role group with at least one user that hasn't been cast. # Cast a random user from that group set user_id [lindex $group_members($group_id) 0] - lappend assignees $user_id + if { ![string equal $user_id $admin_user_id] } { + lappend assignees $user_id + } # Remove the user from the group member list set group_members($group_id) [lreplace $group_members($group_id) 0 0] @@ -946,8 +957,10 @@ if { [llength $users_to_cast_not_in_groups] > 0 } { # Fill the role with a user not in any of the role groups set user_id [lindex $users_to_cast_not_in_groups 0] - lappend assignees $user_id - + if { ![string equal $user_id $admin_user_id] } { + lappend assignees $user_id + } + # Remove user from the not-in-group list set users_to_cast_not_in_groups [lreplace $users_to_cast_not_in_groups 0 0] @@ -958,7 +971,7 @@ } else { # No more users to cast, resort to the logged in user (admin) - lappend assignees [ad_conn user_id] + lappend assignees $admin_user_id # Don't add the admin more than once break } @@ -969,13 +982,29 @@ set row($role_short_name($role_id)) $assignees } + ns_log Notice "pm debug row = [array get row]" + # Do all the user-role assignments in the case workflow::case::role::assign \ -case_id $case_id \ -array row \ } +ad_proc -private simulation::template::admin_user_id { + {-workflow_id:required} +} { + When starting a simulation, get the user if of the simulation admin. The simulation + admin is the creator of the simulation. + @author Peter Marklund +} { + return [db_string select_creation_user { + select creation_user + from acs_objects + where object_id = :workflow_id + }] +} + #---------------------------------------------------------------------- # Simple workflow wrappers #---------------------------------------------------------------------- Index: openacs-4/packages/simulation/www/simplay/index.adp =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/simulation/www/simplay/index.adp,v diff -u -r1.22 -r1.23 --- openacs-4/packages/simulation/www/simplay/index.adp 22 Jan 2004 15:47:23 -0000 1.22 +++ openacs-4/packages/simulation/www/simplay/index.adp 4 Mar 2004 12:09:44 -0000 1.23 @@ -17,9 +17,10 @@

-

All Tasks

+

Your Tasks

- -

+ +

+

Index: openacs-4/packages/simulation/www/simplay/message.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/simulation/www/simplay/message.tcl,v diff -u -r1.24 -r1.25 --- openacs-4/packages/simulation/www/simplay/message.tcl 30 Jan 2004 11:23:25 -0000 1.24 +++ openacs-4/packages/simulation/www/simplay/message.tcl 4 Mar 2004 12:09:44 -0000 1.25 @@ -26,10 +26,7 @@ set to_role_options [list] foreach one_role_id [workflow::role::get_ids -workflow_id $workflow_id] { - # A role cannot send message to himself - if { ![exists_and_equal role_id $one_role_id] } { lappend to_role_options [list [workflow::role::get_element -role_id $one_role_id -element pretty_name] $one_role_id] - } } set attachment_options [simulation::case::attachment_options -case_id $case_id -role_id $role_id] Index: openacs-4/packages/simulation/www/simplay/task-detail.adp =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/simulation/www/simplay/task-detail.adp,v diff -u -r1.9 -r1.10 --- openacs-4/packages/simulation/www/simplay/task-detail.adp 30 Jan 2004 10:57:08 -0000 1.9 +++ openacs-4/packages/simulation/www/simplay/task-detail.adp 4 Mar 2004 12:09:44 -0000 1.10 @@ -1,9 +1,28 @@ - + + + + + + @case_id@ + @page_title;noquote@ @context;noquote@ @focus;noquote@ - @case_id@ + +

+ You are doing a bulk response to @common_actions_count@ tasks. +

+ + +

+ Note: Ignoring @ignored_actions_count@ tasks that don't have the task + name "@action.pretty_name@". Please back up your browser if you + want to change the selection of tasks. +

+
+
+

@action.description@

Index: openacs-4/packages/simulation/www/simplay/task-detail.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/simulation/www/simplay/task-detail.tcl,v diff -u -r1.19 -r1.20 --- openacs-4/packages/simulation/www/simplay/task-detail.tcl 30 Jan 2004 11:23:25 -0000 1.19 +++ openacs-4/packages/simulation/www/simplay/task-detail.tcl 4 Mar 2004 12:09:44 -0000 1.20 @@ -2,31 +2,102 @@ Details for a task. If there is a recipient_role a message is created. If there is not recipient role we upload a document instead. } { - case_id:integer - role_id:integer - enabled_action_id:integer + {enabled_action_id:integer,multiple ""} + {enabled_action_ids ""} item_id:optional + {bulk_p 0} + {return_url ""} } -simulation::case::assert_user_may_play_role -case_id $case_id -role_id $role_id +# FIXME: I am exporting the enabled_action_id list as the string variable enabled_action_ids in +# the forms as I can't export multiples. Here I'm recreating the list again. This is convoluted. +if { ![empty_string_p $enabled_action_ids] } { + set enabled_action_id [split $enabled_action_ids] +} -workflow::case::enabled_action_get -enabled_action_id $enabled_action_id -array enabled_action -set action_id $enabled_action(action_id) -simulation::action::get -action_id $action_id -array action +if { [llength $enabled_action_id] > 1 } { + set bulk_p 1 +} +if { !$bulk_p } { + workflow::case::enabled_action_get -enabled_action_id $enabled_action_id -array enabled_action + + set action_id $enabled_action(action_id) + set case_id $enabled_action(case_id) + simulation::action::get -action_id $action_id -array action + set role_id $action(assigned_role_id) + + simulation::case::assert_user_may_play_role -case_id $case_id -role_id $action(assigned_role_id) + + set common_enabled_action_ids [list [list $enabled_action_id $case_id]] + + if { [empty_string_p $return_url] } { + set return_url [export_vars -base tasks { case_id role_id }] + } + +} else { + # Only admin users can neglect to provide case_id and role_id + permission::require_permission -object_id [ad_conn package_id] -privilege sim_adminplayer + + # If we are taking action on more than one task, extract the subset of the tasks that + # have the same action_id + set common_action_id "" + set common_enabled_action_ids [list] + set ignored_enabled_action_ids [list] + set task_list [db_list_of_lists select_tasks " + select wcea.enabled_action_id, + wcea.action_id, + wcea.case_id + from workflow_case_enabled_actions wcea + where wcea.enabled_action_id in ('[join $enabled_action_id "', '"]') + "] + foreach task $task_list { + set one_enabled_action_id [lindex $task 0] + set one_action_id [lindex $task 1] + set one_case_id [lindex $task 2] + + if { [empty_string_p $common_action_id] } { + set common_action_id $one_action_id + set case_id $one_case_id + } + + if { [string equal $common_action_id $one_action_id] } { + lappend common_enabled_action_ids [list $one_enabled_action_id $one_case_id] + } else { + lappend ignored_enabled_action_ids $one_enabled_action_id + } + } + + set common_actions_count [llength $common_enabled_action_ids] + set ignored_actions_count [llength $ignored_enabled_action_ids] + + set action_id $common_action_id + + simulation::action::get -action_id $action_id -array action + + if { [empty_string_p $return_url] } { + set return_url [export_vars -base tasks-bulk { {workflow_id $action(workflow_id)} }] + } +} + set page_title $action(pretty_name) set context [list [list . "SimPlay"] [list [export_vars -base case { case_id role_id }] "Case"] [list [export_vars -base tasks { case_id role_id }] "Tasks"] $page_title] +set documents_pre_form "" if { ![empty_string_p $action(recipients)] } { # We have recipient roles - use message form - if { ![empty_string_p $action(assigned_role_id)] } { - set attachment_options [simulation::case::attachment_options -case_id $case_id -role_id $action(assigned_role_id)] + if { !$bulk_p } { + if { ![empty_string_p $action(assigned_role_id)] } { + set attachment_options [simulation::case::attachment_options -case_id $case_id -role_id $action(assigned_role_id)] + } + } else { + set attachment_options {} } set form_id action - ad_form -name $form_id -edit_buttons { { Send ok } } -export { case_id role_id enabled_action_id } \ + ad_form -name $form_id -edit_buttons { { Send ok } } -export { case_id role_id {enabled_action_ids $enabled_action_id} bulk_p} \ -form { {pretty_name:text(inform) {label "Task"} @@ -77,27 +148,32 @@ set body_text [template::util::richtext::get_property "contents" $body] set body_mime_type [template::util::richtext::get_property "format" $body] - + db_transaction { - set entry_id [workflow::case::action::execute \ + foreach one_action $common_enabled_action_ids { + set enabled_action_id [lindex $one_action 0] + set case_id [lindex $one_action 1] + + set entry_id [workflow::case::action::execute \ -enabled_action_id $enabled_action_id \ -comment $body_text \ -comment_mime_type $body_mime_type] - foreach recipient_id $action(recipients) { - simulation::message::new \ - -from_role_id $action(assigned_role_id) \ - -to_role_id $recipient_id \ - -case_id $case_id \ - -subject $subject \ - -body $body_text \ - -body_mime_type $body_mime_type \ - -attachments $attachments \ - -entry_id $entry_id - } + foreach recipient_id $action(recipients) { + simulation::message::new \ + -from_role_id $action(assigned_role_id) \ + -to_role_id $recipient_id \ + -case_id $case_id \ + -subject $subject \ + -body $body_text \ + -body_mime_type $body_mime_type \ + -attachments $attachments \ + -entry_id $entry_id + } + } } - ad_returnredirect [export_vars -base tasks { case_id role_id }] + ad_returnredirect $return_url ad_script_abort } @@ -109,7 +185,7 @@ set form_id document - ad_form -name $form_id -export { case_id role_id workflow_id enabled_action_id } -html {enctype multipart/form-data} \ + ad_form -name $form_id -export { case_id role_id workflow_id {enabled_action_ids $enabled_action_id} bulk_p} -html {enctype multipart/form-data} \ -form [concat {{pretty_name:text(inform) {label "Task"}}} [simulation::ui::forms::document_upload::form_block]] \ -on_request { set pretty_name $action(pretty_name) @@ -118,19 +194,23 @@ } -on_submit { db_transaction { - set entry_id [workflow::case::action::execute \ + foreach one_action $common_enabled_action_ids { + set case_id [lindex $one_action 1] + + set entry_id [workflow::case::action::execute \ -case_id $case_id \ -action_id $action_id \ -comment "Document [lindex $document_file 0] uploaded" \ -comment_mime_type "text/plain"] - simulation::ui::forms::document_upload::insert_document \ - $case_id $role_id $item_id $document_file $title $entry_id + simulation::ui::forms::document_upload::insert_document \ + $case_id $action(assigned_role_id) $item_id $document_file $title $entry_id + } } - ad_returnredirect [export_vars -base tasks { case_id role_id }] + ad_returnredirect $return_url + ad_script_abort } set focus "document.document_file" } - Index: openacs-4/packages/simulation/www/simplay/tasks-bulk.adp =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/simulation/www/simplay/tasks-bulk.adp,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/simulation/www/simplay/tasks-bulk.adp 4 Mar 2004 12:09:44 -0000 1.1 @@ -0,0 +1,10 @@ + + @page_title;noquote@ + @context;noquote@ + + + +

+ If you are using the respond button to respond to multiple tasks + then all checked tasks must share the same task name. +

\ No newline at end of file Index: openacs-4/packages/simulation/www/simplay/tasks-bulk.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/simulation/www/simplay/tasks-bulk.tcl,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/simulation/www/simplay/tasks-bulk.tcl 4 Mar 2004 12:09:44 -0000 1.1 @@ -0,0 +1,16 @@ +ad_page_contract { + This page shows all tasks that an admin has in a certain simulation and + allows the admin to take action on the tasks in bulk. + + @author Peter Marklund +} { + workflow_id:integer + role_id:optional +} + +permission::require_permission -object_id [ad_conn package_id] -privilege sim_adminplayer + +simulation::template::get -workflow_id $workflow_id -array simulation + +set page_title "Your Tasks in Simulation $simulation(pretty_name)" +set context [list [list . "SimPlay"] $page_title]