Index: openacs-4/contrib/packages/simulation/lib/sim-template-objects.adp =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/simulation/lib/Attic/sim-template-objects.adp,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/simulation/lib/sim-template-objects.adp 6 Nov 2003 15:35:46 -0000 1.1 @@ -0,0 +1,3 @@ +

+

Add Sim +Objects to this Workflow Index: openacs-4/contrib/packages/simulation/lib/sim-template-objects.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/simulation/lib/Attic/sim-template-objects.tcl,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/simulation/lib/sim-template-objects.tcl 6 Nov 2003 15:35:46 -0000 1.1 @@ -0,0 +1,83 @@ +# an includelet + +############################################################## +# +# sim_objects +# +# A list of all objects associated with the Simulation Template +# +############################################################## + +# maybe replace this chunk of copied text with an includable template +# which passes in a filter for the workflow_id? + + +#------------------------------------------------------------- +# sim_objects list +#------------------------------------------------------------- + +template::list::create \ + -name sim_objects \ + -multirow sim_objects \ + -no_data "No Sim Objects are associated with this Simulation Template" \ + -elements { + edit { + sub_class narrow + link_url_col edit_url + display_template { + Edit + } + } + object_type_pretty { + label "Type" + orderby upper(ot.pretty_name) + } + title { + label "Title" + orderby r.title + link_url_col view_url + } + description { + label "Description" + orderby r.description + } + } + +db_multirow -extend { edit_url view_url delete_url } sim_objects select_sim_objects " + select i.item_id, + i.name, + r.title, + r.description, + i.content_type, + ot.pretty_name as object_type_pretty + from cr_folders f, + cr_items i, + cr_revisions r, + acs_object_types ot, + sim_workflow_object_map swom + where f.package_id = :package_id + and i.parent_id = f.folder_id + and r.revision_id = i.live_revision + and ot.object_type = i.content_type + and swom.workflow_id = :workflow_id + and swom.object_id = i.item_id + + [template::list::orderby_clause -orderby -name "sim_objects"] +" { + set description [string_truncate -len 200 $description] + set edit_url [export_vars -base "object-edit" { item_id }] + set view_url [export_vars -base "object/$name"] + set delete_url [export_vars -base "object-delete" { item_id }] +} + +set sim_types { sim_character sim_prop sim_location } + +db_multirow -extend { create_url label } object_types select_object_types " + select ot.object_type as content_type, + ot.pretty_name + from acs_object_types ot + where ot.object_type in ('[join $sim_types "','"]') +" { + set create_url [export_vars -base object-edit { content_type parent_id }] + set label "Create new $pretty_name" +} Index: openacs-4/contrib/packages/simulation/lib/sim-template-roles.adp =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/simulation/lib/Attic/sim-template-roles.adp,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/simulation/lib/sim-template-roles.adp 6 Nov 2003 15:35:46 -0000 1.1 @@ -0,0 +1,2 @@ +

+

Add a role Index: openacs-4/contrib/packages/simulation/lib/sim-template-roles.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/simulation/lib/Attic/sim-template-roles.tcl,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/simulation/lib/sim-template-roles.tcl 6 Nov 2003 15:35:46 -0000 1.1 @@ -0,0 +1,68 @@ +# an includelet + +############################################################## +# +# roles +# +# A list of all roles associated with the Simulation Template +# +############################################################## + +# maybe replace this chunk of copied text with an includable template +# which passes in a filter for the workflow_id? + + +#------------------------------------------------------------- +# roles list +#------------------------------------------------------------- + +template::list::create \ + -name roles \ + -multirow roles \ + -no_data "No roles in this Simulation Template" \ + -elements { + edit { + sub_class narrow + link_url_col edit_url + display_template { + Edit + } + } + name { + label "Name" + } + char_name { + label "Character" + link_url_col char_url + } + delete { + sub_class narrow + link_url_col delete_url + display_template { + Edit + } + } + } +#------------------------------------------------------------- +# roles db_multirow +#------------------------------------------------------------- +set return_url "[ad_conn url]?[ad_conn query]" +db_multirow -extend { edit_url char_url delete_url } roles select_roles " + select wr.role_id, + wr.pretty_name as name, + wr.sort_order, + cr.title as char_name + from workflow_roles wr, + sim_roles sr, + cr_items ci, + cr_revisions cr + where wr.workflow_id = :workflow_id + and sr.role_id = wr.role_id + and ci.item_id = sr.character_id + and cr.revision_id = ci.live_revision + [template::list::orderby_clause -orderby -name "roles"] +" { + set edit_url [export_vars -base "role-edit" { role_id }] + set char_url [export_vars -base "object/$char_name"] + set delete_url [export_vars -base "role-delete" { role_id return_url }] +} Index: openacs-4/contrib/packages/simulation/lib/sim-template-tasks.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/simulation/lib/Attic/sim-template-tasks.tcl,v diff -u -N -r1.1 -r1.2 --- openacs-4/contrib/packages/simulation/lib/sim-template-tasks.tcl 30 Oct 2003 11:15:55 -0000 1.1 +++ openacs-4/contrib/packages/simulation/lib/sim-template-tasks.tcl 6 Nov 2003 15:35:46 -0000 1.2 @@ -69,7 +69,7 @@ # tasks db_multirow #------------------------------------------------------------- # TODO: fix this so it returns rows when it should - +set return_url "[ad_conn url]?[ad_conn query]" db_multirow -extend { edit_url view_url delete_url } tasks select_tasks " select wa.action_id, wa.pretty_name as name, @@ -88,5 +88,5 @@ " { set edit_url [export_vars -base "task-edit" { action_id }] set view_url [export_vars -base "task-edit" { action_id }] - set delete_url [export_vars -base "task-delete" { action_id }] + set delete_url [export_vars -base "task-delete" { action_id return_url }] } Index: openacs-4/contrib/packages/simulation/sql/postgresql/simulation-tables-create.sql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/simulation/sql/postgresql/Attic/simulation-tables-create.sql,v diff -u -N -r1.2 -r1.3 --- openacs-4/contrib/packages/simulation/sql/postgresql/simulation-tables-create.sql 27 Oct 2003 12:41:24 -0000 1.2 +++ openacs-4/contrib/packages/simulation/sql/postgresql/simulation-tables-create.sql 6 Nov 2003 15:35:46 -0000 1.3 @@ -3,80 +3,88 @@ -- @cvs-id $Id$ create table sim_workflow_object_map ( - workflow_id integer constraint sim_workflows_object_map_fk - references workflows(workflow_id), - object_id integer constraint sim_workflows_object_map_2_fk - references acs_objects(object_id), + workflow_id integer constraint sim_workflows_object_map_fk + references workflows(workflow_id) + on delete cascade, + object_id integer constraint sim_workflows_object_map_2_fk + references acs_objects(object_id) + on delete cascade, constraint sim_workflow_object_map_pk primary key (workflow_id, object_id) ); comment on table sim_workflow_object_map is 'Each record indicates that one object is used in one simulation template. If a sim_object is a child of another sim_object which is in this table, the child sim_object should not be in the table.'; create table sim_roles ( - role_id integer constraint sim_roles_fk - references workflow_roles - constraint sim_roles_pk - primary key, - character_id integer constraint sim_roles_character_fk - references cr_items + role_id integer constraint sim_roles_ri_fk + references workflow_roles(role_id) + on delete cascade + constraint sim_roles_pk + primary key, + character_id integer constraint sim_roles_character_fk + references cr_items + on delete cascade ); comment on table sim_roles is 'Each record is a role within a simulation template to be played by one or more users or a computer agent when the template is instantiated into cases.'; create table sim_tasks ( - task_id integer constraint sim_tasks_fk - references workflow_actions - constraint sim_tasks_pk - primary key, - recipient integer constraint sim_tasks_recipient_fk - references sim_roles + task_id integer constraint sim_tasks_fk + references workflow_actions + on delete cascade + constraint sim_tasks_pk + primary key, + recipient integer constraint sim_tasks_recipient_fk + references sim_roles + on delete cascade ); comment on table sim_tasks is 'Each record is a task that a role must perform, possibly upon another role.'; create table sim_simulations ( - simulation_id integer constraint sim_simulations_fk - references workflows - constraint sim_simulation_pk - primary key, - enroll_type varchar(20) constraint sim_simulations_enroll_type_ck - check (1=1), - casting_type varchar(20) constraint sim_simulations_casting_type_ck - check (1=1), - enroll_start timestamptz, - enroll_end timestamptz, + simulation_id integer constraint sim_simulations_fk + references workflows + on delete cascade + constraint sim_simulation_pk + primary key, + enroll_type varchar(20) constraint sim_simulations_enroll_type_ck + check (1=1), + casting_type varchar(20) constraint sim_simulations_casting_type_ck + check (1=1), + enroll_start timestamptz, + enroll_end timestamptz, constraint sim_simulations_enroll_end_after_start_end_ck check (enroll_end >= enroll_start), - case_start timestamptz, - case_end timestamptz, + case_start timestamptz, + case_end timestamptz, constraint sim_simulations_case_end_after_start_ck check (case_end >= case_start) ); select acs_object_type__create_type ( - 'simulation', -- object_type - 'Simulation', -- pretty_name - 'Simulations', -- pretty_plural - 'workflow_lite', -- supertype - 'sim_simulations', -- table_name - 'simulation_id', -- id_column - null, -- package_name - 'f', -- abstract_p - null, -- type_extension_table - 'sim_simulation__name' -- name_method - ); - + 'simulation', -- object_type + 'Simulation', -- pretty_name + 'Simulations', -- pretty_plural + 'workflow_lite', -- supertype + 'sim_simulations', -- table_name + 'simulation_id', -- id_column + null, -- package_name + 'f', -- abstract_p + null, -- type_extension_table + 'sim_simulation__name' -- name_method + ); + comment on table sim_simulations is 'Each record is an instantiation of a simulation template, and the parent of zero to many simulation cases.'; create table sim_party_sim_map ( - simulation_id integer constraint sim_party_sim_map_sim_fk - references sim_simulations, - party_id integer constraint sim_party_sim_map_party_fk - references parties, - constraint sim_party_sim_map_pk + simulation_id integer constraint sim_party_sim_map_sim_fk + references sim_simulations + on delete cascade, + party_id integer constraint sim_party_sim_map_party_fk + references parties + on delete cascade, + constraint sim_party_sim_map_pk primary key (simulation_id, party_id) ); comment on table sim_party_sim_map is 'Each record is an invitation to a party to participate in a simulation.'; - Index: openacs-4/contrib/packages/simulation/tcl/simulation-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/simulation/tcl/Attic/simulation-procs.tcl,v diff -u -N -r1.6 -r1.7 --- openacs-4/contrib/packages/simulation/tcl/simulation-procs.tcl 3 Nov 2003 14:13:43 -0000 1.6 +++ openacs-4/contrib/packages/simulation/tcl/simulation-procs.tcl 6 Nov 2003 15:35:47 -0000 1.7 @@ -10,6 +10,8 @@ namespace eval simulation::action {} namespace eval simulation::object_type {} namespace eval simulation::template {} +namespace eval simulation::character {} +namespace eval simulation::role {} ad_proc -public simulation::object_type::get_options { } { @@ -42,6 +44,8 @@ {-always_enabled_p f} {-initial_action_p f} {-recipient_role:required {}} + {-description {}} + {-description_mime_type {}} } { Edit an action. Mostly a wrapper for fsm, plus some simulation-specific stuff. } { @@ -58,21 +62,20 @@ set workflow_id [workflow::action::get_workflow_id -action_id $action_id] - set assigned_role_id [workflow::role::get_id -workflow_id $workflow_id -short_name $assigned_role ] - set recipient_role_id [workflow::role::get_id -workflow_id $workflow_id -short_name $recipient_role ] - db_transaction { db_dml edit_workflow_action { update workflow_actions set short_name = :short_name, pretty_name = :pretty_name, - assigned_role = :assigned_role_id + assigned_role = :assigned_role, + description = :description, + description_mime_type = :description_mime_type where action_id = :action_id } db_dml edit_sim_role { update sim_tasks - set recipient = :recipient_role_id + set recipient = :recipient_role where task_id = :action_id } } @@ -86,28 +89,18 @@ } { Associate an object with a simulation template. Succeeds if the record is added or already exists. } { + set exists_p [db_string row_exists { + select count(*) + from sim_workflow_object_map + where workflow_id = :template_id + and object_id = :object_id + }] - with_catch errmsg { + if { ! $exists_p } { db_dml add_object_to_workflow_insert { insert into sim_workflow_object_map values (:template_id, :object_id) } - } { - # can only be 0 or 1 due to table constraints - set exists_p [db_string row_exists { - select count(*) - from sim_workflow_object_map - where workflow_id = :template_id - and object_id = :object_id - }] - - if { $exists_p } { - # the record already exists. Return normally - } { - # the record didn't exist, so pass on the error - global errorInfo - error $errmsg $errorInfo - } } } @@ -129,3 +122,96 @@ template_tag relation { params } { publish::process_tag relation $params } + +################################ +# +# simulation::character namespace +# +################################ + +ad_proc -public simulation::character::get { + {-character_id:required} + {-array:required} +} { + Get basic information about a character. Gets the following attributes: uri, title. + + @param array The name of an array into which you want the information put. + + @author Peter Marklund +} { + upvar $array row + + db_1row select_character_info {} -column_array row +} + +ad_proc -public simulation::character::get_element { + {-character_id:required} + {-element:required} +} { + Get a particular attribute from a character object. + + @param element Name of the attribute you want to retrieve + + @see simulation::character::get + + @author Peter Marklund +} { + get -character_id $character_id -array character + + return $character($element) +} + +################################ +# +# simulation::role namespace +# +################################ + +ad_proc -public simulation::role::new { + {-template_id:required} + {-character_id:required} + {-role_short_name ""} + {-role_pretty_name ""} +} { + Create a new simulation role for a given simulation template + and character. Will map the character to the template if this + is not already done. + + @author Peter Marklund +} { + # Set default values for names + if { [empty_string_p $role_short_name] || [empty_string_p $role_pretty_name] } { + set character_name [simulation::character::get_element \ + -character_id $character_id \ + -element title] + } + if { [empty_string_p $role_short_name] } { + set role_short_name $character_name + } + if { [empty_string_p $role_pretty_name] } { + set role_pretty_name $character_name + } + + db_transaction { + simulation::template::associate_object \ + -template_id $template_id \ + -object_id $character_id + + # create the role + set role_id [workflow::role::new \ + -workflow_id $template_id \ + -short_name $role_short_name \ + -pretty_name $role_pretty_name] + # and then add extra data for simulation + db_dml set_role_character { + insert into sim_roles + values (:role_id, :character_id) + } + } +} + +ad_proc -public simulation::role::delete { + {-role_id:required} +} { + workflow::role::delete -role_id $role_id +} Index: openacs-4/contrib/packages/simulation/tcl/simulation-procs.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/simulation/tcl/Attic/simulation-procs.xql,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/simulation/tcl/simulation-procs.xql 6 Nov 2003 15:35:47 -0000 1.1 @@ -0,0 +1,16 @@ + + + + + + + select ci.name as uri, + cr.title as title + from cr_items ci, + cr_revisions cr + where ci.live_revision = cr.revision_id + and cr.item_id = :character_id + + + + Index: openacs-4/contrib/packages/simulation/test/demo-data-setup.test =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/simulation/test/Attic/demo-data-setup.test,v diff -u -N -r1.1 -r1.2 --- openacs-4/contrib/packages/simulation/test/demo-data-setup.test 5 Nov 2003 15:00:32 -0000 1.1 +++ openacs-4/contrib/packages/simulation/test/demo-data-setup.test 6 Nov 2003 15:35:47 -0000 1.2 @@ -1,34 +1,178 @@ +namespace eval ::twt::simulation {} + +ad_proc ::twt::simulation::get_object_short_name { name } { + set short_name [string tolower $name] + regsub -all {\s} $short_name {-} short_name + + return $short_name +} + +ad_proc ::twt::simulation::add_image { + {-title:required} + {-description ""} + {-content_file:required} +} { + Create a new simulation image +} { + do_request /simulation/object-list + link follow ~u object-edit?.*parent + + # Choose object type image + set_object_form_type image + + foreach input_name {title description content_file} { + field fill [set $input_name] ~n $input_name + } + form submit +} + +ad_proc ::twt::simulation::set_object_form_type { type } { + form find ~n object + field find ~n content_type + field select2 ~v $type + field find ~n __refreshing_p + field fill 1 + form submit +} + +ad_proc ::twt::simulation::add_object { + {-type:required} + {-title:required} +} { + Create a new simulation object +} { + do_request /simulation/object-list + link follow ~u object-edit?.*parent + + set_object_form_type $type + + field find ~n title + field fill $title + form submit +} + +ad_proc ::twt::simulation::visit_template_page { template_name } { + + do_request /simulation/sim-template-list + link follow ~u sim-template-edit ~c $template_name +} + if { [catch { - source ../../../etc/install/tcl/test-procs.tcl + source [file dirname [info script]]/../../../etc/install/tcl/test-procs.tcl # Test Execution START # TODO: Create users with different roles and for different # actions below be logged in with an appropriate user + # Demo data start + set actors_list { + Teacher + Student + Agent1 + Agent2 + } + array set characters { + Bernadette "Bernadette" + MOTORHOME "MOTORHOME" + "A of Lawfirm X" "Her lawyer" + "A of Lawfirm Y" "Its lawyer" + "B of Lawfirm X" "Partner firm X" + "B of Lawfirm Y" "Partner firm Y" + "C of Lawfirm X" "Secretary firm X" + "C of Lawfirm Y" "Secretary firm Y" + "Portal" "Library" + } + array set tasks { + "Ask information from Bernadette" {assigned_role "Her lawyer" recipient_role "Bernadette"} + "Ask information from MOTORHOME" {assigned_role "Her lawyer" recipient_role "MOTORHOME"} + "Ask information from opponent's lawyer 1" {assigned_role "Its lawyer" recipient_role "Her lawyer"} + "Ask information from opponent's lawyer 2" {assigned_role "Her lawyer" recipient_role "Its lawyer"} + "Ask information from library" {assigned_role "Her lawyer" recipient_role "Library"} + "Ask information from partner" {assigned_role "Her lawyer" recipient_role "Partner firm X"} + "Intervene" {assigned_role "Partner firm X" recipient_role "Her lawyer"} + "Reply to intervention" {assigned_role "Her lawyer" recipient_role "Partner firm X"} + "Give information as Bernadette" {assigned_role "Bernadette" recipient_role "Her lawyer"} + "Give information as Motorhome" {assigned_role "MOTORHOME" recipient_role "Her lawyer"} + "Make/edit draft report" {assigned_role "Her lawyer" recipient_role "Her lawyer"} + "Edit draft report" {assigned_role "Her lawyer" recipient_role "Her lawyer"} + "Give information to opponent's lawyer" {assigned_role "Her lawyer" recipient_role "Its lawyer"} + "Send final report" {assigned_role "Her lawyer" recipient_role "Partner firm X"} + "Send draft report" {assigned_role "Her lawyer" recipient_role "Partner firm X"} + } + # Demo data end + ::twt::log_section "Login the site wide admin" ::twt::user::login_site_wide_admin - # Create sim objects - - # Create a new image object + ::twt::log_section "Create an image object" do_request /simulation/object-list link follow ~u object-edit?.*parent form find ~n object field find ~n content_type field select2 ~v image field find ~n __refreshing_p field fill 1 - form submit - + form submit field find ~n title field fill "New Jersey Lawyers" field find ~n description field fill "New Jersey Lawyers and Consumers" field find ~n content_file - field fill /web/simulation/packages/simulation/test/new-jersey-lawyer-logo.gif + field fill [::twt::config::serverroot]/packages/simulation/test/new-jersey-lawyer-logo.gif form submit + ::twt::log_section "Create characters" + foreach character_name [array names characters] { + ::twt::simulation::add_object -type character -title $character_name + } + + ::twt::log_section "Create simulation template" + do_request /simulation/sim-template-edit + set template_name "Elementary Private Law" + field fill $template_name ~n name + form submit + + ::twt::log_section "Add characters to template" + ::twt::simulation::visit_template_page $template_name + + link follow ~u sim-template-add-objects + foreach character_add_url [::twt::get_url_list [response url] sim-template-add-objects-2] { + do_request $character_add_url + } + + ::twt::log_section "Create roles for template" + ::twt::simulation::visit_template_page $template_name + + link follow ~u role-edit + set add_role_url [response url] + foreach character_name [array names characters] { + do_request $add_role_url + field find ~n character_id + field select [::twt::simulation::get_object_short_name $character_name] + field find ~n name + field fill $characters($character_name) + form submit + } + + ::twt::log_section "Add tasks to template" + ::twt::simulation::visit_template_page $template_name + link follow ~u task-edit + set add_task_url [response url] + foreach task_name [array names tasks] { + array set task $tasks($task_name) + do_request $add_task_url + field find ~n name + field fill $task_name + field find ~n assigned_role + field select $task(assigned_role) + field find ~n recipient_role + field select $task(recipient_role) + field find ~n description + field fill "This is the task description for task $task_name" + form submit + } + } result] } { global errorInfo Index: openacs-4/contrib/packages/simulation/test/new-jersey-lawyer-logo.gif =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/simulation/test/Attic/new-jersey-lawyer-logo.gif,v diff -u -N Binary files differ Index: openacs-4/contrib/packages/simulation/www/role-edit.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/simulation/www/Attic/role-edit.tcl,v diff -u -N -r1.3 -r1.4 --- openacs-4/contrib/packages/simulation/www/role-edit.tcl 29 Oct 2003 12:57:13 -0000 1.3 +++ openacs-4/contrib/packages/simulation/www/role-edit.tcl 6 Nov 2003 15:35:47 -0000 1.4 @@ -104,24 +104,12 @@ set context [list [list "sim-template-list" "Sim Templates"] [list "sim-template-edit?workflow_id=$workflow_id" "$sim_template_array(pretty_name)"] $page_title] } -new_data { - db_transaction { + simulation::role::new \ + -template_id $workflow_id \ + -character_id $character_id \ + -role_short_name $name \ + -role_pretty_name $name - simulation::template::associate_object \ - -template_id $workflow_id \ - -object_id $character_id - - # create the role - set role_id [workflow::role::new \ - -workflow_id $workflow_id \ - -short_name $name \ - -pretty_name $name] - # and then add extra data for simulation - db_dml set_role_character { - insert into sim_roles - values (:role_id, :character_id) - } - -} } -after_submit { ad_returnredirect [export_vars -base "sim-template-edit" { workflow_id }] ad_script_abort Index: openacs-4/contrib/packages/simulation/www/sim-template-edit.adp =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/simulation/www/Attic/sim-template-edit.adp,v diff -u -N -r1.4 -r1.5 --- openacs-4/contrib/packages/simulation/www/sim-template-edit.adp 30 Oct 2003 11:15:55 -0000 1.4 +++ openacs-4/contrib/packages/simulation/www/sim-template-edit.adp 6 Nov 2003 15:35:47 -0000 1.5 @@ -7,9 +7,9 @@

Associated Sim Objects

- +

Roles

- +

Tasks

\ No newline at end of file Index: openacs-4/contrib/packages/simulation/www/sim-template-objects.adp =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/simulation/www/Attic/sim-template-objects.adp,v diff -u -N --- openacs-4/contrib/packages/simulation/www/sim-template-objects.adp 27 Oct 2003 07:42:48 -0000 1.1 +++ /dev/null 1 Jan 1970 00:00:00 -0000 @@ -1,3 +0,0 @@ -

-

Add Sim -Objects to this Workflow Index: openacs-4/contrib/packages/simulation/www/sim-template-objects.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/simulation/www/Attic/sim-template-objects.tcl,v diff -u -N --- openacs-4/contrib/packages/simulation/www/sim-template-objects.tcl 31 Oct 2003 11:08:38 -0000 1.2 +++ /dev/null 1 Jan 1970 00:00:00 -0000 @@ -1,83 +0,0 @@ -# an includelet - -############################################################## -# -# sim_objects -# -# A list of all objects associated with the Simulation Template -# -############################################################## - -# maybe replace this chunk of copied text with an includable template -# which passes in a filter for the workflow_id? - - -#------------------------------------------------------------- -# sim_objects list -#------------------------------------------------------------- - -template::list::create \ - -name sim_objects \ - -multirow sim_objects \ - -no_data "No Sim Objects are associated with this Simulation Template" \ - -elements { - edit { - sub_class narrow - link_url_col edit_url - display_template { - Edit - } - } - object_type_pretty { - label "Type" - orderby upper(ot.pretty_name) - } - title { - label "Title" - orderby r.title - link_url_col view_url - } - description { - label "Description" - orderby r.description - } - } - -db_multirow -extend { edit_url view_url delete_url } sim_objects select_sim_objects " - select i.item_id, - i.name, - r.title, - r.description, - i.content_type, - ot.pretty_name as object_type_pretty - from cr_folders f, - cr_items i, - cr_revisions r, - acs_object_types ot, - sim_workflow_object_map swom - where f.package_id = :package_id - and i.parent_id = f.folder_id - and r.revision_id = i.live_revision - and ot.object_type = i.content_type - and swom.workflow_id = :workflow_id - and swom.object_id = i.item_id - - [template::list::orderby_clause -orderby -name "sim_objects"] -" { - set description [string_truncate -len 200 $description] - set edit_url [export_vars -base "object-edit" { item_id }] - set view_url [export_vars -base "object/$name"] - set delete_url [export_vars -base "object-delete" { item_id }] -} - -set sim_types { sim_character sim_prop sim_location } - -db_multirow -extend { create_url label } object_types select_object_types " - select ot.object_type as content_type, - ot.pretty_name - from acs_object_types ot - where ot.object_type in ('[join $sim_types "','"]') -" { - set create_url [export_vars -base object-edit { content_type parent_id }] - set label "Create new $pretty_name" -} Index: openacs-4/contrib/packages/simulation/www/sim-template-roles.adp =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/simulation/www/Attic/sim-template-roles.adp,v diff -u -N --- openacs-4/contrib/packages/simulation/www/sim-template-roles.adp 27 Oct 2003 07:42:48 -0000 1.1 +++ /dev/null 1 Jan 1970 00:00:00 -0000 @@ -1,2 +0,0 @@ -

-

Add a role Index: openacs-4/contrib/packages/simulation/www/sim-template-roles.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/simulation/www/Attic/sim-template-roles.tcl,v diff -u -N --- openacs-4/contrib/packages/simulation/www/sim-template-roles.tcl 27 Oct 2003 12:41:24 -0000 1.2 +++ /dev/null 1 Jan 1970 00:00:00 -0000 @@ -1,66 +0,0 @@ -# an includelet - -############################################################## -# -# roles -# -# A list of all roles associated with the Simulation Template -# -############################################################## - -# maybe replace this chunk of copied text with an includable template -# which passes in a filter for the workflow_id? - - -#------------------------------------------------------------- -# roles list -#------------------------------------------------------------- - -template::list::create \ - -name roles \ - -multirow roles \ - -no_data "No roles in this Simulation Template" \ - -elements { - edit { - sub_class narrow - link_url_col edit_url - display_template { - Edit - } - } - name { - label "Name" - } - char_name { - label "Character" - link_url_col char_url - } - delete { - sub_class narrow - link_url_col delete_url - display_template { - Edit - } - } - } -#------------------------------------------------------------- -# roles db_multirow -#------------------------------------------------------------- -# TODO: fix this so it returns rows when it should -db_multirow -extend { edit_url char_url delete_url } roles select_roles " - select wr.role_id, - wr.pretty_name as name, - wr.sort_order, - ci.name as char_name - from workflow_roles wr, - sim_roles sr, - cr_items ci - where wr.workflow_id = :workflow_id - and sr.role_id = wr.role_id - and ci.item_id = sr.character_id - [template::list::orderby_clause -orderby -name "roles"] -" { - set edit_url [export_vars -base "role-edit" { role_id }] - set char_url [export_vars -base "object/$char_name"] - set delete_url [export_vars -base "role-delete" { role_id }] -} Index: openacs-4/contrib/packages/simulation/www/sim-template-tasks.adp =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/simulation/www/Attic/sim-template-tasks.adp,v diff -u -N --- openacs-4/contrib/packages/simulation/www/sim-template-tasks.adp 29 Oct 2003 12:57:13 -0000 1.1 +++ /dev/null 1 Jan 1970 00:00:00 -0000 @@ -1,2 +0,0 @@ -

-

Add a task Index: openacs-4/contrib/packages/simulation/www/sim-template-tasks.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/simulation/www/Attic/sim-template-tasks.tcl,v diff -u -N --- openacs-4/contrib/packages/simulation/www/sim-template-tasks.tcl 29 Oct 2003 12:57:13 -0000 1.1 +++ /dev/null 1 Jan 1970 00:00:00 -0000 @@ -1,78 +0,0 @@ -# an includelet - -# the includelet can be a full -if { ![exists_and_not_null usage_mode] } { - set usage_mode normal -} - -############################################################## -# -# tasks -# -# A list of all tasks associated with the Simulation Template -# -############################################################## - -#------------------------------------------------------------- -# tasks list -#------------------------------------------------------------- -# TODO: missing: discription, type -# how is type going to work? open question pending prototyping - -set hide_edit_p 1 - -template::list::create \ - -name tasks \ - -multirow tasks \ - -no_data "No tasks in this Simulation Template" \ - -elements { - edit { - hide_p $hide_edit_p - sub_class narrow - link_url_col edit_url - display_template { - Edit - } - } - name { - label "Name" - } - assigned_name { - label "Assigned to" - } - recipient_name { - label "Recipient" - } - delete { - sub_class narrow - link_url_col delete_url - display_template { - Edit - } - } - } - -#------------------------------------------------------------- -# tasks db_multirow -#------------------------------------------------------------- -# TODO: fix this so it returns rows when it should - -db_multirow -extend { edit_url delete_url } tasks select_tasks " - select wa.action_id, - wa.pretty_name as name, - (select pretty_name - from workflow_roles - where role_id = wa.assigned_role) as assigned_name, - (select pretty_name - from workflow_roles - where role_id = st.recipient) as recipient_name, - wa.sort_order - from workflow_actions wa, - sim_tasks st - where wa.workflow_id = :workflow_id - and st.task_id = wa.action_id - [template::list::orderby_clause -orderby -name "tasks"] -" { - set edit_url [export_vars -base "task-edit" { action_id }] - set delete_url [export_vars -base "task-delete" { action_id }] -} Index: openacs-4/contrib/packages/simulation/www/task-delete.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/simulation/www/Attic/task-delete.tcl,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/simulation/www/task-delete.tcl 6 Nov 2003 15:35:47 -0000 1.1 @@ -0,0 +1,11 @@ +ad_page_contract { + Delete a task + +} { + action_id:integer + {return_url "sim-template-list"} +} + +workflow::action::fsm::delete -action_id $action_id + +ad_returnredirect $return_url \ No newline at end of file Index: openacs-4/contrib/packages/simulation/www/task-edit.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/simulation/www/Attic/task-edit.tcl,v diff -u -N -r1.2 -r1.3 --- openacs-4/contrib/packages/simulation/www/task-edit.tcl 30 Oct 2003 11:15:55 -0000 1.2 +++ openacs-4/contrib/packages/simulation/www/task-edit.tcl 6 Nov 2003 15:35:47 -0000 1.3 @@ -45,7 +45,7 @@ set role_options [db_list_of_lists role_option_list " select wr.pretty_name, - wr.short_name + wr.role_id from workflow_roles wr where wr.workflow_id = :workflow_id "] @@ -96,6 +96,12 @@ workflow::get -workflow_id $workflow_id -array sim_template_array set page_title "Edit Task $name" set context [list [list "sim-template-list" "Sim Templates"] [list "sim-template-edit?workflow_id=$workflow_id" "$sim_template_array(pretty_name)"] $page_title] + set recipient_role [db_string select_recipient { + select recipient + from sim_tasks + where task_id = :action_id + }] + set assigned_role $task_array(assigned_role) } -new_request { @@ -113,22 +119,24 @@ # create the task + set assigned_role_name [workflow::role::get_element \ + -role_id $assigned_role \ + -element short_name] set action_id [workflow::action::fsm::new \ -workflow_id $workflow_id \ -short_name $name \ -pretty_name $name \ - -assigned_role $assigned_role \ + -assigned_role $assigned_role_name \ -description $description_content \ -description_mime_type $description_mime_type] # TODO - put this stuff into simulation api and change previous call # and then add extra data for simulation # because workflow::action::fsm::new wants role.short_name instead of # role_id, we stay consistent for recipient_role - set recipient_role_id [workflow::role::get_id -workflow_id $workflow_id -short_name $recipient_role] db_dml set_role_recipient { insert into sim_tasks - values (:action_id, :recipient_role_id) + values (:action_id, :recipient_role) } } -edit_data { Index: openacs-4/packages/simulation/lib/sim-template-objects.adp =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/simulation/lib/sim-template-objects.adp,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/simulation/lib/sim-template-objects.adp 6 Nov 2003 15:35:46 -0000 1.1 @@ -0,0 +1,3 @@ +

+

Add Sim +Objects to this Workflow Index: openacs-4/packages/simulation/lib/sim-template-objects.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/simulation/lib/sim-template-objects.tcl,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/simulation/lib/sim-template-objects.tcl 6 Nov 2003 15:35:46 -0000 1.1 @@ -0,0 +1,83 @@ +# an includelet + +############################################################## +# +# sim_objects +# +# A list of all objects associated with the Simulation Template +# +############################################################## + +# maybe replace this chunk of copied text with an includable template +# which passes in a filter for the workflow_id? + + +#------------------------------------------------------------- +# sim_objects list +#------------------------------------------------------------- + +template::list::create \ + -name sim_objects \ + -multirow sim_objects \ + -no_data "No Sim Objects are associated with this Simulation Template" \ + -elements { + edit { + sub_class narrow + link_url_col edit_url + display_template { + Edit + } + } + object_type_pretty { + label "Type" + orderby upper(ot.pretty_name) + } + title { + label "Title" + orderby r.title + link_url_col view_url + } + description { + label "Description" + orderby r.description + } + } + +db_multirow -extend { edit_url view_url delete_url } sim_objects select_sim_objects " + select i.item_id, + i.name, + r.title, + r.description, + i.content_type, + ot.pretty_name as object_type_pretty + from cr_folders f, + cr_items i, + cr_revisions r, + acs_object_types ot, + sim_workflow_object_map swom + where f.package_id = :package_id + and i.parent_id = f.folder_id + and r.revision_id = i.live_revision + and ot.object_type = i.content_type + and swom.workflow_id = :workflow_id + and swom.object_id = i.item_id + + [template::list::orderby_clause -orderby -name "sim_objects"] +" { + set description [string_truncate -len 200 $description] + set edit_url [export_vars -base "object-edit" { item_id }] + set view_url [export_vars -base "object/$name"] + set delete_url [export_vars -base "object-delete" { item_id }] +} + +set sim_types { sim_character sim_prop sim_location } + +db_multirow -extend { create_url label } object_types select_object_types " + select ot.object_type as content_type, + ot.pretty_name + from acs_object_types ot + where ot.object_type in ('[join $sim_types "','"]') +" { + set create_url [export_vars -base object-edit { content_type parent_id }] + set label "Create new $pretty_name" +} Index: openacs-4/packages/simulation/lib/sim-template-roles.adp =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/simulation/lib/sim-template-roles.adp,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/simulation/lib/sim-template-roles.adp 6 Nov 2003 15:35:46 -0000 1.1 @@ -0,0 +1,2 @@ +

+

Add a role Index: openacs-4/packages/simulation/lib/sim-template-roles.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/simulation/lib/sim-template-roles.tcl,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/simulation/lib/sim-template-roles.tcl 6 Nov 2003 15:35:46 -0000 1.1 @@ -0,0 +1,68 @@ +# an includelet + +############################################################## +# +# roles +# +# A list of all roles associated with the Simulation Template +# +############################################################## + +# maybe replace this chunk of copied text with an includable template +# which passes in a filter for the workflow_id? + + +#------------------------------------------------------------- +# roles list +#------------------------------------------------------------- + +template::list::create \ + -name roles \ + -multirow roles \ + -no_data "No roles in this Simulation Template" \ + -elements { + edit { + sub_class narrow + link_url_col edit_url + display_template { + Edit + } + } + name { + label "Name" + } + char_name { + label "Character" + link_url_col char_url + } + delete { + sub_class narrow + link_url_col delete_url + display_template { + Edit + } + } + } +#------------------------------------------------------------- +# roles db_multirow +#------------------------------------------------------------- +set return_url "[ad_conn url]?[ad_conn query]" +db_multirow -extend { edit_url char_url delete_url } roles select_roles " + select wr.role_id, + wr.pretty_name as name, + wr.sort_order, + cr.title as char_name + from workflow_roles wr, + sim_roles sr, + cr_items ci, + cr_revisions cr + where wr.workflow_id = :workflow_id + and sr.role_id = wr.role_id + and ci.item_id = sr.character_id + and cr.revision_id = ci.live_revision + [template::list::orderby_clause -orderby -name "roles"] +" { + set edit_url [export_vars -base "role-edit" { role_id }] + set char_url [export_vars -base "object/$char_name"] + set delete_url [export_vars -base "role-delete" { role_id return_url }] +} Index: openacs-4/packages/simulation/lib/sim-template-tasks.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/simulation/lib/sim-template-tasks.tcl,v diff -u -N -r1.1 -r1.2 --- openacs-4/packages/simulation/lib/sim-template-tasks.tcl 30 Oct 2003 11:15:55 -0000 1.1 +++ openacs-4/packages/simulation/lib/sim-template-tasks.tcl 6 Nov 2003 15:35:46 -0000 1.2 @@ -69,7 +69,7 @@ # tasks db_multirow #------------------------------------------------------------- # TODO: fix this so it returns rows when it should - +set return_url "[ad_conn url]?[ad_conn query]" db_multirow -extend { edit_url view_url delete_url } tasks select_tasks " select wa.action_id, wa.pretty_name as name, @@ -88,5 +88,5 @@ " { set edit_url [export_vars -base "task-edit" { action_id }] set view_url [export_vars -base "task-edit" { action_id }] - set delete_url [export_vars -base "task-delete" { action_id }] + set delete_url [export_vars -base "task-delete" { action_id return_url }] } Index: openacs-4/packages/simulation/sql/postgresql/simulation-tables-create.sql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/simulation/sql/postgresql/simulation-tables-create.sql,v diff -u -N -r1.2 -r1.3 --- openacs-4/packages/simulation/sql/postgresql/simulation-tables-create.sql 27 Oct 2003 12:41:24 -0000 1.2 +++ openacs-4/packages/simulation/sql/postgresql/simulation-tables-create.sql 6 Nov 2003 15:35:46 -0000 1.3 @@ -3,80 +3,88 @@ -- @cvs-id $Id$ create table sim_workflow_object_map ( - workflow_id integer constraint sim_workflows_object_map_fk - references workflows(workflow_id), - object_id integer constraint sim_workflows_object_map_2_fk - references acs_objects(object_id), + workflow_id integer constraint sim_workflows_object_map_fk + references workflows(workflow_id) + on delete cascade, + object_id integer constraint sim_workflows_object_map_2_fk + references acs_objects(object_id) + on delete cascade, constraint sim_workflow_object_map_pk primary key (workflow_id, object_id) ); comment on table sim_workflow_object_map is 'Each record indicates that one object is used in one simulation template. If a sim_object is a child of another sim_object which is in this table, the child sim_object should not be in the table.'; create table sim_roles ( - role_id integer constraint sim_roles_fk - references workflow_roles - constraint sim_roles_pk - primary key, - character_id integer constraint sim_roles_character_fk - references cr_items + role_id integer constraint sim_roles_ri_fk + references workflow_roles(role_id) + on delete cascade + constraint sim_roles_pk + primary key, + character_id integer constraint sim_roles_character_fk + references cr_items + on delete cascade ); comment on table sim_roles is 'Each record is a role within a simulation template to be played by one or more users or a computer agent when the template is instantiated into cases.'; create table sim_tasks ( - task_id integer constraint sim_tasks_fk - references workflow_actions - constraint sim_tasks_pk - primary key, - recipient integer constraint sim_tasks_recipient_fk - references sim_roles + task_id integer constraint sim_tasks_fk + references workflow_actions + on delete cascade + constraint sim_tasks_pk + primary key, + recipient integer constraint sim_tasks_recipient_fk + references sim_roles + on delete cascade ); comment on table sim_tasks is 'Each record is a task that a role must perform, possibly upon another role.'; create table sim_simulations ( - simulation_id integer constraint sim_simulations_fk - references workflows - constraint sim_simulation_pk - primary key, - enroll_type varchar(20) constraint sim_simulations_enroll_type_ck - check (1=1), - casting_type varchar(20) constraint sim_simulations_casting_type_ck - check (1=1), - enroll_start timestamptz, - enroll_end timestamptz, + simulation_id integer constraint sim_simulations_fk + references workflows + on delete cascade + constraint sim_simulation_pk + primary key, + enroll_type varchar(20) constraint sim_simulations_enroll_type_ck + check (1=1), + casting_type varchar(20) constraint sim_simulations_casting_type_ck + check (1=1), + enroll_start timestamptz, + enroll_end timestamptz, constraint sim_simulations_enroll_end_after_start_end_ck check (enroll_end >= enroll_start), - case_start timestamptz, - case_end timestamptz, + case_start timestamptz, + case_end timestamptz, constraint sim_simulations_case_end_after_start_ck check (case_end >= case_start) ); select acs_object_type__create_type ( - 'simulation', -- object_type - 'Simulation', -- pretty_name - 'Simulations', -- pretty_plural - 'workflow_lite', -- supertype - 'sim_simulations', -- table_name - 'simulation_id', -- id_column - null, -- package_name - 'f', -- abstract_p - null, -- type_extension_table - 'sim_simulation__name' -- name_method - ); - + 'simulation', -- object_type + 'Simulation', -- pretty_name + 'Simulations', -- pretty_plural + 'workflow_lite', -- supertype + 'sim_simulations', -- table_name + 'simulation_id', -- id_column + null, -- package_name + 'f', -- abstract_p + null, -- type_extension_table + 'sim_simulation__name' -- name_method + ); + comment on table sim_simulations is 'Each record is an instantiation of a simulation template, and the parent of zero to many simulation cases.'; create table sim_party_sim_map ( - simulation_id integer constraint sim_party_sim_map_sim_fk - references sim_simulations, - party_id integer constraint sim_party_sim_map_party_fk - references parties, - constraint sim_party_sim_map_pk + simulation_id integer constraint sim_party_sim_map_sim_fk + references sim_simulations + on delete cascade, + party_id integer constraint sim_party_sim_map_party_fk + references parties + on delete cascade, + constraint sim_party_sim_map_pk primary key (simulation_id, party_id) ); comment on table sim_party_sim_map is 'Each record is an invitation to a party to participate in a simulation.'; - Index: openacs-4/packages/simulation/tcl/simulation-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/simulation/tcl/simulation-procs.tcl,v diff -u -N -r1.6 -r1.7 --- openacs-4/packages/simulation/tcl/simulation-procs.tcl 3 Nov 2003 14:13:43 -0000 1.6 +++ openacs-4/packages/simulation/tcl/simulation-procs.tcl 6 Nov 2003 15:35:47 -0000 1.7 @@ -10,6 +10,8 @@ namespace eval simulation::action {} namespace eval simulation::object_type {} namespace eval simulation::template {} +namespace eval simulation::character {} +namespace eval simulation::role {} ad_proc -public simulation::object_type::get_options { } { @@ -42,6 +44,8 @@ {-always_enabled_p f} {-initial_action_p f} {-recipient_role:required {}} + {-description {}} + {-description_mime_type {}} } { Edit an action. Mostly a wrapper for fsm, plus some simulation-specific stuff. } { @@ -58,21 +62,20 @@ set workflow_id [workflow::action::get_workflow_id -action_id $action_id] - set assigned_role_id [workflow::role::get_id -workflow_id $workflow_id -short_name $assigned_role ] - set recipient_role_id [workflow::role::get_id -workflow_id $workflow_id -short_name $recipient_role ] - db_transaction { db_dml edit_workflow_action { update workflow_actions set short_name = :short_name, pretty_name = :pretty_name, - assigned_role = :assigned_role_id + assigned_role = :assigned_role, + description = :description, + description_mime_type = :description_mime_type where action_id = :action_id } db_dml edit_sim_role { update sim_tasks - set recipient = :recipient_role_id + set recipient = :recipient_role where task_id = :action_id } } @@ -86,28 +89,18 @@ } { Associate an object with a simulation template. Succeeds if the record is added or already exists. } { + set exists_p [db_string row_exists { + select count(*) + from sim_workflow_object_map + where workflow_id = :template_id + and object_id = :object_id + }] - with_catch errmsg { + if { ! $exists_p } { db_dml add_object_to_workflow_insert { insert into sim_workflow_object_map values (:template_id, :object_id) } - } { - # can only be 0 or 1 due to table constraints - set exists_p [db_string row_exists { - select count(*) - from sim_workflow_object_map - where workflow_id = :template_id - and object_id = :object_id - }] - - if { $exists_p } { - # the record already exists. Return normally - } { - # the record didn't exist, so pass on the error - global errorInfo - error $errmsg $errorInfo - } } } @@ -129,3 +122,96 @@ template_tag relation { params } { publish::process_tag relation $params } + +################################ +# +# simulation::character namespace +# +################################ + +ad_proc -public simulation::character::get { + {-character_id:required} + {-array:required} +} { + Get basic information about a character. Gets the following attributes: uri, title. + + @param array The name of an array into which you want the information put. + + @author Peter Marklund +} { + upvar $array row + + db_1row select_character_info {} -column_array row +} + +ad_proc -public simulation::character::get_element { + {-character_id:required} + {-element:required} +} { + Get a particular attribute from a character object. + + @param element Name of the attribute you want to retrieve + + @see simulation::character::get + + @author Peter Marklund +} { + get -character_id $character_id -array character + + return $character($element) +} + +################################ +# +# simulation::role namespace +# +################################ + +ad_proc -public simulation::role::new { + {-template_id:required} + {-character_id:required} + {-role_short_name ""} + {-role_pretty_name ""} +} { + Create a new simulation role for a given simulation template + and character. Will map the character to the template if this + is not already done. + + @author Peter Marklund +} { + # Set default values for names + if { [empty_string_p $role_short_name] || [empty_string_p $role_pretty_name] } { + set character_name [simulation::character::get_element \ + -character_id $character_id \ + -element title] + } + if { [empty_string_p $role_short_name] } { + set role_short_name $character_name + } + if { [empty_string_p $role_pretty_name] } { + set role_pretty_name $character_name + } + + db_transaction { + simulation::template::associate_object \ + -template_id $template_id \ + -object_id $character_id + + # create the role + set role_id [workflow::role::new \ + -workflow_id $template_id \ + -short_name $role_short_name \ + -pretty_name $role_pretty_name] + # and then add extra data for simulation + db_dml set_role_character { + insert into sim_roles + values (:role_id, :character_id) + } + } +} + +ad_proc -public simulation::role::delete { + {-role_id:required} +} { + workflow::role::delete -role_id $role_id +} Index: openacs-4/packages/simulation/tcl/simulation-procs.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/simulation/tcl/simulation-procs.xql,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/simulation/tcl/simulation-procs.xql 6 Nov 2003 15:35:47 -0000 1.1 @@ -0,0 +1,16 @@ + + + + + + + select ci.name as uri, + cr.title as title + from cr_items ci, + cr_revisions cr + where ci.live_revision = cr.revision_id + and cr.item_id = :character_id + + + + Index: openacs-4/packages/simulation/test/demo-data-setup.test =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/simulation/test/demo-data-setup.test,v diff -u -N -r1.1 -r1.2 --- openacs-4/packages/simulation/test/demo-data-setup.test 5 Nov 2003 15:00:32 -0000 1.1 +++ openacs-4/packages/simulation/test/demo-data-setup.test 6 Nov 2003 15:35:47 -0000 1.2 @@ -1,34 +1,178 @@ +namespace eval ::twt::simulation {} + +ad_proc ::twt::simulation::get_object_short_name { name } { + set short_name [string tolower $name] + regsub -all {\s} $short_name {-} short_name + + return $short_name +} + +ad_proc ::twt::simulation::add_image { + {-title:required} + {-description ""} + {-content_file:required} +} { + Create a new simulation image +} { + do_request /simulation/object-list + link follow ~u object-edit?.*parent + + # Choose object type image + set_object_form_type image + + foreach input_name {title description content_file} { + field fill [set $input_name] ~n $input_name + } + form submit +} + +ad_proc ::twt::simulation::set_object_form_type { type } { + form find ~n object + field find ~n content_type + field select2 ~v $type + field find ~n __refreshing_p + field fill 1 + form submit +} + +ad_proc ::twt::simulation::add_object { + {-type:required} + {-title:required} +} { + Create a new simulation object +} { + do_request /simulation/object-list + link follow ~u object-edit?.*parent + + set_object_form_type $type + + field find ~n title + field fill $title + form submit +} + +ad_proc ::twt::simulation::visit_template_page { template_name } { + + do_request /simulation/sim-template-list + link follow ~u sim-template-edit ~c $template_name +} + if { [catch { - source ../../../etc/install/tcl/test-procs.tcl + source [file dirname [info script]]/../../../etc/install/tcl/test-procs.tcl # Test Execution START # TODO: Create users with different roles and for different # actions below be logged in with an appropriate user + # Demo data start + set actors_list { + Teacher + Student + Agent1 + Agent2 + } + array set characters { + Bernadette "Bernadette" + MOTORHOME "MOTORHOME" + "A of Lawfirm X" "Her lawyer" + "A of Lawfirm Y" "Its lawyer" + "B of Lawfirm X" "Partner firm X" + "B of Lawfirm Y" "Partner firm Y" + "C of Lawfirm X" "Secretary firm X" + "C of Lawfirm Y" "Secretary firm Y" + "Portal" "Library" + } + array set tasks { + "Ask information from Bernadette" {assigned_role "Her lawyer" recipient_role "Bernadette"} + "Ask information from MOTORHOME" {assigned_role "Her lawyer" recipient_role "MOTORHOME"} + "Ask information from opponent's lawyer 1" {assigned_role "Its lawyer" recipient_role "Her lawyer"} + "Ask information from opponent's lawyer 2" {assigned_role "Her lawyer" recipient_role "Its lawyer"} + "Ask information from library" {assigned_role "Her lawyer" recipient_role "Library"} + "Ask information from partner" {assigned_role "Her lawyer" recipient_role "Partner firm X"} + "Intervene" {assigned_role "Partner firm X" recipient_role "Her lawyer"} + "Reply to intervention" {assigned_role "Her lawyer" recipient_role "Partner firm X"} + "Give information as Bernadette" {assigned_role "Bernadette" recipient_role "Her lawyer"} + "Give information as Motorhome" {assigned_role "MOTORHOME" recipient_role "Her lawyer"} + "Make/edit draft report" {assigned_role "Her lawyer" recipient_role "Her lawyer"} + "Edit draft report" {assigned_role "Her lawyer" recipient_role "Her lawyer"} + "Give information to opponent's lawyer" {assigned_role "Her lawyer" recipient_role "Its lawyer"} + "Send final report" {assigned_role "Her lawyer" recipient_role "Partner firm X"} + "Send draft report" {assigned_role "Her lawyer" recipient_role "Partner firm X"} + } + # Demo data end + ::twt::log_section "Login the site wide admin" ::twt::user::login_site_wide_admin - # Create sim objects - - # Create a new image object + ::twt::log_section "Create an image object" do_request /simulation/object-list link follow ~u object-edit?.*parent form find ~n object field find ~n content_type field select2 ~v image field find ~n __refreshing_p field fill 1 - form submit - + form submit field find ~n title field fill "New Jersey Lawyers" field find ~n description field fill "New Jersey Lawyers and Consumers" field find ~n content_file - field fill /web/simulation/packages/simulation/test/new-jersey-lawyer-logo.gif + field fill [::twt::config::serverroot]/packages/simulation/test/new-jersey-lawyer-logo.gif form submit + ::twt::log_section "Create characters" + foreach character_name [array names characters] { + ::twt::simulation::add_object -type character -title $character_name + } + + ::twt::log_section "Create simulation template" + do_request /simulation/sim-template-edit + set template_name "Elementary Private Law" + field fill $template_name ~n name + form submit + + ::twt::log_section "Add characters to template" + ::twt::simulation::visit_template_page $template_name + + link follow ~u sim-template-add-objects + foreach character_add_url [::twt::get_url_list [response url] sim-template-add-objects-2] { + do_request $character_add_url + } + + ::twt::log_section "Create roles for template" + ::twt::simulation::visit_template_page $template_name + + link follow ~u role-edit + set add_role_url [response url] + foreach character_name [array names characters] { + do_request $add_role_url + field find ~n character_id + field select [::twt::simulation::get_object_short_name $character_name] + field find ~n name + field fill $characters($character_name) + form submit + } + + ::twt::log_section "Add tasks to template" + ::twt::simulation::visit_template_page $template_name + link follow ~u task-edit + set add_task_url [response url] + foreach task_name [array names tasks] { + array set task $tasks($task_name) + do_request $add_task_url + field find ~n name + field fill $task_name + field find ~n assigned_role + field select $task(assigned_role) + field find ~n recipient_role + field select $task(recipient_role) + field find ~n description + field fill "This is the task description for task $task_name" + form submit + } + } result] } { global errorInfo Index: openacs-4/packages/simulation/test/new-jersey-lawyer-logo.gif =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/simulation/test/new-jersey-lawyer-logo.gif,v diff -u -N Binary files differ Index: openacs-4/packages/simulation/www/role-edit.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/simulation/www/Attic/role-edit.tcl,v diff -u -N -r1.3 -r1.4 --- openacs-4/packages/simulation/www/role-edit.tcl 29 Oct 2003 12:57:13 -0000 1.3 +++ openacs-4/packages/simulation/www/role-edit.tcl 6 Nov 2003 15:35:47 -0000 1.4 @@ -104,24 +104,12 @@ set context [list [list "sim-template-list" "Sim Templates"] [list "sim-template-edit?workflow_id=$workflow_id" "$sim_template_array(pretty_name)"] $page_title] } -new_data { - db_transaction { + simulation::role::new \ + -template_id $workflow_id \ + -character_id $character_id \ + -role_short_name $name \ + -role_pretty_name $name - simulation::template::associate_object \ - -template_id $workflow_id \ - -object_id $character_id - - # create the role - set role_id [workflow::role::new \ - -workflow_id $workflow_id \ - -short_name $name \ - -pretty_name $name] - # and then add extra data for simulation - db_dml set_role_character { - insert into sim_roles - values (:role_id, :character_id) - } - -} } -after_submit { ad_returnredirect [export_vars -base "sim-template-edit" { workflow_id }] ad_script_abort Index: openacs-4/packages/simulation/www/sim-template-edit.adp =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/simulation/www/Attic/sim-template-edit.adp,v diff -u -N -r1.4 -r1.5 --- openacs-4/packages/simulation/www/sim-template-edit.adp 30 Oct 2003 11:15:55 -0000 1.4 +++ openacs-4/packages/simulation/www/sim-template-edit.adp 6 Nov 2003 15:35:47 -0000 1.5 @@ -7,9 +7,9 @@

Associated Sim Objects

- +

Roles

- +

Tasks

\ No newline at end of file Index: openacs-4/packages/simulation/www/sim-template-objects.adp =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/simulation/www/Attic/sim-template-objects.adp,v diff -u -N --- openacs-4/packages/simulation/www/sim-template-objects.adp 27 Oct 2003 07:42:48 -0000 1.1 +++ /dev/null 1 Jan 1970 00:00:00 -0000 @@ -1,3 +0,0 @@ -

-

Add Sim -Objects to this Workflow Index: openacs-4/packages/simulation/www/sim-template-objects.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/simulation/www/Attic/sim-template-objects.tcl,v diff -u -N --- openacs-4/packages/simulation/www/sim-template-objects.tcl 31 Oct 2003 11:08:38 -0000 1.2 +++ /dev/null 1 Jan 1970 00:00:00 -0000 @@ -1,83 +0,0 @@ -# an includelet - -############################################################## -# -# sim_objects -# -# A list of all objects associated with the Simulation Template -# -############################################################## - -# maybe replace this chunk of copied text with an includable template -# which passes in a filter for the workflow_id? - - -#------------------------------------------------------------- -# sim_objects list -#------------------------------------------------------------- - -template::list::create \ - -name sim_objects \ - -multirow sim_objects \ - -no_data "No Sim Objects are associated with this Simulation Template" \ - -elements { - edit { - sub_class narrow - link_url_col edit_url - display_template { - Edit - } - } - object_type_pretty { - label "Type" - orderby upper(ot.pretty_name) - } - title { - label "Title" - orderby r.title - link_url_col view_url - } - description { - label "Description" - orderby r.description - } - } - -db_multirow -extend { edit_url view_url delete_url } sim_objects select_sim_objects " - select i.item_id, - i.name, - r.title, - r.description, - i.content_type, - ot.pretty_name as object_type_pretty - from cr_folders f, - cr_items i, - cr_revisions r, - acs_object_types ot, - sim_workflow_object_map swom - where f.package_id = :package_id - and i.parent_id = f.folder_id - and r.revision_id = i.live_revision - and ot.object_type = i.content_type - and swom.workflow_id = :workflow_id - and swom.object_id = i.item_id - - [template::list::orderby_clause -orderby -name "sim_objects"] -" { - set description [string_truncate -len 200 $description] - set edit_url [export_vars -base "object-edit" { item_id }] - set view_url [export_vars -base "object/$name"] - set delete_url [export_vars -base "object-delete" { item_id }] -} - -set sim_types { sim_character sim_prop sim_location } - -db_multirow -extend { create_url label } object_types select_object_types " - select ot.object_type as content_type, - ot.pretty_name - from acs_object_types ot - where ot.object_type in ('[join $sim_types "','"]') -" { - set create_url [export_vars -base object-edit { content_type parent_id }] - set label "Create new $pretty_name" -} Index: openacs-4/packages/simulation/www/sim-template-roles.adp =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/simulation/www/Attic/sim-template-roles.adp,v diff -u -N --- openacs-4/packages/simulation/www/sim-template-roles.adp 27 Oct 2003 07:42:48 -0000 1.1 +++ /dev/null 1 Jan 1970 00:00:00 -0000 @@ -1,2 +0,0 @@ -

-

Add a role Index: openacs-4/packages/simulation/www/sim-template-roles.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/simulation/www/Attic/sim-template-roles.tcl,v diff -u -N --- openacs-4/packages/simulation/www/sim-template-roles.tcl 27 Oct 2003 12:41:24 -0000 1.2 +++ /dev/null 1 Jan 1970 00:00:00 -0000 @@ -1,66 +0,0 @@ -# an includelet - -############################################################## -# -# roles -# -# A list of all roles associated with the Simulation Template -# -############################################################## - -# maybe replace this chunk of copied text with an includable template -# which passes in a filter for the workflow_id? - - -#------------------------------------------------------------- -# roles list -#------------------------------------------------------------- - -template::list::create \ - -name roles \ - -multirow roles \ - -no_data "No roles in this Simulation Template" \ - -elements { - edit { - sub_class narrow - link_url_col edit_url - display_template { - Edit - } - } - name { - label "Name" - } - char_name { - label "Character" - link_url_col char_url - } - delete { - sub_class narrow - link_url_col delete_url - display_template { - Edit - } - } - } -#------------------------------------------------------------- -# roles db_multirow -#------------------------------------------------------------- -# TODO: fix this so it returns rows when it should -db_multirow -extend { edit_url char_url delete_url } roles select_roles " - select wr.role_id, - wr.pretty_name as name, - wr.sort_order, - ci.name as char_name - from workflow_roles wr, - sim_roles sr, - cr_items ci - where wr.workflow_id = :workflow_id - and sr.role_id = wr.role_id - and ci.item_id = sr.character_id - [template::list::orderby_clause -orderby -name "roles"] -" { - set edit_url [export_vars -base "role-edit" { role_id }] - set char_url [export_vars -base "object/$char_name"] - set delete_url [export_vars -base "role-delete" { role_id }] -} Index: openacs-4/packages/simulation/www/sim-template-tasks.adp =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/simulation/www/Attic/sim-template-tasks.adp,v diff -u -N --- openacs-4/packages/simulation/www/sim-template-tasks.adp 29 Oct 2003 12:57:13 -0000 1.1 +++ /dev/null 1 Jan 1970 00:00:00 -0000 @@ -1,2 +0,0 @@ -

-

Add a task Index: openacs-4/packages/simulation/www/sim-template-tasks.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/simulation/www/Attic/sim-template-tasks.tcl,v diff -u -N --- openacs-4/packages/simulation/www/sim-template-tasks.tcl 29 Oct 2003 12:57:13 -0000 1.1 +++ /dev/null 1 Jan 1970 00:00:00 -0000 @@ -1,78 +0,0 @@ -# an includelet - -# the includelet can be a full -if { ![exists_and_not_null usage_mode] } { - set usage_mode normal -} - -############################################################## -# -# tasks -# -# A list of all tasks associated with the Simulation Template -# -############################################################## - -#------------------------------------------------------------- -# tasks list -#------------------------------------------------------------- -# TODO: missing: discription, type -# how is type going to work? open question pending prototyping - -set hide_edit_p 1 - -template::list::create \ - -name tasks \ - -multirow tasks \ - -no_data "No tasks in this Simulation Template" \ - -elements { - edit { - hide_p $hide_edit_p - sub_class narrow - link_url_col edit_url - display_template { - Edit - } - } - name { - label "Name" - } - assigned_name { - label "Assigned to" - } - recipient_name { - label "Recipient" - } - delete { - sub_class narrow - link_url_col delete_url - display_template { - Edit - } - } - } - -#------------------------------------------------------------- -# tasks db_multirow -#------------------------------------------------------------- -# TODO: fix this so it returns rows when it should - -db_multirow -extend { edit_url delete_url } tasks select_tasks " - select wa.action_id, - wa.pretty_name as name, - (select pretty_name - from workflow_roles - where role_id = wa.assigned_role) as assigned_name, - (select pretty_name - from workflow_roles - where role_id = st.recipient) as recipient_name, - wa.sort_order - from workflow_actions wa, - sim_tasks st - where wa.workflow_id = :workflow_id - and st.task_id = wa.action_id - [template::list::orderby_clause -orderby -name "tasks"] -" { - set edit_url [export_vars -base "task-edit" { action_id }] - set delete_url [export_vars -base "task-delete" { action_id }] -} Index: openacs-4/packages/simulation/www/task-delete.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/simulation/www/Attic/task-delete.tcl,v diff -u -N --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/simulation/www/task-delete.tcl 6 Nov 2003 15:35:47 -0000 1.1 @@ -0,0 +1,11 @@ +ad_page_contract { + Delete a task + +} { + action_id:integer + {return_url "sim-template-list"} +} + +workflow::action::fsm::delete -action_id $action_id + +ad_returnredirect $return_url \ No newline at end of file Index: openacs-4/packages/simulation/www/task-edit.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/simulation/www/Attic/task-edit.tcl,v diff -u -N -r1.2 -r1.3 --- openacs-4/packages/simulation/www/task-edit.tcl 30 Oct 2003 11:15:55 -0000 1.2 +++ openacs-4/packages/simulation/www/task-edit.tcl 6 Nov 2003 15:35:47 -0000 1.3 @@ -45,7 +45,7 @@ set role_options [db_list_of_lists role_option_list " select wr.pretty_name, - wr.short_name + wr.role_id from workflow_roles wr where wr.workflow_id = :workflow_id "] @@ -96,6 +96,12 @@ workflow::get -workflow_id $workflow_id -array sim_template_array set page_title "Edit Task $name" set context [list [list "sim-template-list" "Sim Templates"] [list "sim-template-edit?workflow_id=$workflow_id" "$sim_template_array(pretty_name)"] $page_title] + set recipient_role [db_string select_recipient { + select recipient + from sim_tasks + where task_id = :action_id + }] + set assigned_role $task_array(assigned_role) } -new_request { @@ -113,22 +119,24 @@ # create the task + set assigned_role_name [workflow::role::get_element \ + -role_id $assigned_role \ + -element short_name] set action_id [workflow::action::fsm::new \ -workflow_id $workflow_id \ -short_name $name \ -pretty_name $name \ - -assigned_role $assigned_role \ + -assigned_role $assigned_role_name \ -description $description_content \ -description_mime_type $description_mime_type] # TODO - put this stuff into simulation api and change previous call # and then add extra data for simulation # because workflow::action::fsm::new wants role.short_name instead of # role_id, we stay consistent for recipient_role - set recipient_role_id [workflow::role::get_id -workflow_id $workflow_id -short_name $recipient_role] db_dml set_role_recipient { insert into sim_tasks - values (:action_id, :recipient_role_id) + values (:action_id, :recipient_role) } } -edit_data {