Index: openacs-4/contrib/packages/simulation/lib/sim-templates.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/simulation/lib/Attic/sim-templates.tcl,v diff -u -r1.9 -r1.10 --- openacs-4/contrib/packages/simulation/lib/sim-templates.tcl 11 Dec 2003 13:21:52 -0000 1.9 +++ openacs-4/contrib/packages/simulation/lib/sim-templates.tcl 11 Dec 2003 15:32:42 -0000 1.10 @@ -16,89 +16,89 @@ } set package_id [ad_conn package_id] -set add_url [export_vars -base "[apm_package_url_from_id $package_id]simbuild/template-edit" ] +set add_url [export_vars -base "[apm_package_url_from_id $package_id]simbuild/template-edit"] set create_p [permission::permission_p -object_id $package_id -privilege sim_template_create] +set actions [list "Add a template" $add_url {} \ + "Load a template" "[apm_package_url_from_id $package_id]simbuild/template-load" {}] + # TODO: make this include honor the display_mode parameter switch $size { short { - template::list::create \ - -name sim_templates \ - -multirow sim_templates \ - -actions " {Add a template} $add_url " \ - -elements { - name { - label "Template" - link_url_col edit_url - orderby upper(ot.pretty_name) - } - role_count { - label "Roles" - } - task_count { - label "Tasks" - } - } + set elements { + name { + label "Template" + link_url_col edit_url + orderby upper(ot.pretty_name) + } + role_count { + label "Roles" + } + task_count { + label "Tasks" + } + } } default { - template::list::create \ - -name sim_templates \ - -multirow sim_templates \ - -actions " {Add a template} $add_url " \ - -elements { - edit { - sub_class narrow - display_template { - - - Edit - - - } - } - name { - label "Name" - orderby upper(ot.pretty_name) - link_url_col view_url - } - description { - label "Description" - orderby r.description - } - created_by { - label "Created by" - orderby r.createdby - } - role_count { - label "Roles" - } - task_count { - label "Tasks" - } - delete { - sub_class narrow - display_template { - - - Delete - - - } - } - clone { - display_template { - Clone this template - } - + set elements { + edit { + sub_class narrow + display_template { + + + Edit + + } - - } + } + name { + label "Name" + orderby upper(ot.pretty_name) + link_url_col view_url + } + description { + label "Description" + orderby r.description + } + created_by { + label "Created by" + orderby r.createdby + } + role_count { + label "Roles" + } + task_count { + label "Tasks" + } + delete { + sub_class narrow + display_template { + + + Delete + + + } + } + clone { + display_template { + Clone this template + } + + } + } } } +template::list::create \ + -name sim_templates \ + -multirow sim_templates \ + -actions $actions \ + -elements $elements + ###################################################################### # # sim_templates 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.9 -r1.10 --- openacs-4/contrib/packages/simulation/tcl/template-procs.tcl 11 Dec 2003 14:24:29 -0000 1.9 +++ openacs-4/contrib/packages/simulation/tcl/template-procs.tcl 11 Dec 2003 15:32:43 -0000 1.10 @@ -9,8 +9,8 @@ namespace eval simulation::template {} ad_proc -public simulation::template::new { - {-short_name:required} {-pretty_name:required} + {-short_name {}} {-sim_type "dev_template"} {-suggested_duration ""} {-package_key:required} @@ -23,8 +23,6 @@ @author Peter Marklund } { db_transaction { - set short_name [util_text_to_url -replacement "_" $short_name] - set workflow_id [workflow::new \ -short_name $short_name \ -pretty_name $pretty_name \ @@ -40,10 +38,42 @@ return $workflow_id } +ad_proc -public simulation::template::new_from_spec { + {-package_key {}} + {-object_id {}} + {-spec:required} + {-array {}} +} { + Create a new simulation template for a spec. + + @return The workflow_id of the created simulation. + + @author Lars Pind +} { + if { ![empty_string_p $array] } { + upvar 1 $array row + set array row + } + + db_transaction { + + set workflow_id [workflow::fsm::new_from_spec \ + -package_key $package_key \ + -object_id $object_id \ + -spec $spec \ + -array $array] + + insert_sim \ + -workflow_id $workflow_id + } + + return $workflow_id +} + ad_proc -private simulation::template::insert_sim { {-workflow_id:required} - {-sim_type:required} - {-suggested_duration:required} + {-sim_type "dev_template"} + {-suggested_duration {}} } { Internal proc for inserting values into the sim_simulations table that are set prior to a template being mapped. @@ -61,7 +91,7 @@ db_dml new_sim " insert into sim_simulations (simulation_id, sim_type, suggested_duration) - values ('$workflow_id', '$sim_type', interval '$suggested_duration')" + values (:workflow_id, :sim_type, interval '[db_quote $suggested_duration]')" } } Index: openacs-4/contrib/packages/simulation/www/simulation-master.adp =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/simulation/www/Attic/simulation-master.adp,v diff -u -r1.8 -r1.9 --- openacs-4/contrib/packages/simulation/www/simulation-master.adp 11 Dec 2003 14:24:29 -0000 1.8 +++ openacs-4/contrib/packages/simulation/www/simulation-master.adp 11 Dec 2003 15:32:43 -0000 1.9 @@ -2,7 +2,7 @@ @title;noquote@ @context;noquote@ @subnavbar_link;noquote@ -@focus;noquote@ + @focus;noquote@ Index: openacs-4/contrib/packages/simulation/www/simbuild/template-clone.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/simulation/www/simbuild/Attic/template-clone.tcl,v diff -u -r1.3 -r1.4 --- openacs-4/contrib/packages/simulation/www/simbuild/template-clone.tcl 11 Dec 2003 14:24:29 -0000 1.3 +++ openacs-4/contrib/packages/simulation/www/simbuild/template-clone.tcl 11 Dec 2003 15:32:43 -0000 1.4 @@ -1,5 +1,5 @@ ad_page_contract { - Create a new simulation + Clone new simulation } { workflow_id:integer } Index: openacs-4/contrib/packages/simulation/www/simbuild/template-load.adp =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/simulation/www/simbuild/Attic/template-load.adp,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/simulation/www/simbuild/template-load.adp 11 Dec 2003 15:32:43 -0000 1.1 @@ -0,0 +1,7 @@ + + @page_title;noquote@ + @context;noquote@ + load.spec + + + Index: openacs-4/contrib/packages/simulation/www/simbuild/template-load.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/simulation/www/simbuild/Attic/template-load.tcl,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/simulation/www/simbuild/template-load.tcl 11 Dec 2003 15:32:43 -0000 1.1 @@ -0,0 +1,43 @@ +ad_page_contract { + Load a simulation from a spec + +} + +permission::require_permission -object_id [ad_conn package_id] -privilege sim_template_create + +set page_title "Load Template" + +set context [list [list "." "SimBuild"] $page_title] + +ad_form -name load -edit_buttons [list [list "Load" ok]] -form { + {pretty_name:text + {label "Name"} + {html {size 50}} + } + {spec:text(textarea) + {label "Spec"} + {help_text {Copy and paste the specification here}} + {html {cols 80 rows 10}} + } +} -on_request { + +} -on_submit { + with_catch errmsg { + set row(pretty_name) $pretty_name + set row(short_name) {} + simulation::template::new_from_spec \ + -package_key "simulation" \ + -object_id [ad_conn package_id] \ + -spec $spec \ + -array row + } { + global errorInfo + ns_log Error "Error loading workflow: $errorInfo" + form set_error load spec $errmsg + break + } + + ad_returnredirect . + ad_script_abort +} + Index: openacs-4/contrib/packages/simulation/www/simbuild/template-spec.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/simulation/www/simbuild/Attic/template-spec.tcl,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/contrib/packages/simulation/www/simbuild/template-spec.tcl 11 Dec 2003 15:32:43 -0000 1.1 @@ -0,0 +1,12 @@ +ad_page_contract { + Generate and download a specification for a workflow. + + @author Lars Pind + @creation-date 2003-12-10 +} { + workflow_id:integer +} + +set spec [workflow::fsm::generate_spec -workflow_id $workflow_id] + +ns_return 200 text/plain [util::array_list_spec_pretty $spec] Index: openacs-4/packages/simulation/lib/sim-templates.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/simulation/lib/sim-templates.tcl,v diff -u -r1.9 -r1.10 --- openacs-4/packages/simulation/lib/sim-templates.tcl 11 Dec 2003 13:21:52 -0000 1.9 +++ openacs-4/packages/simulation/lib/sim-templates.tcl 11 Dec 2003 15:32:42 -0000 1.10 @@ -16,89 +16,89 @@ } set package_id [ad_conn package_id] -set add_url [export_vars -base "[apm_package_url_from_id $package_id]simbuild/template-edit" ] +set add_url [export_vars -base "[apm_package_url_from_id $package_id]simbuild/template-edit"] set create_p [permission::permission_p -object_id $package_id -privilege sim_template_create] +set actions [list "Add a template" $add_url {} \ + "Load a template" "[apm_package_url_from_id $package_id]simbuild/template-load" {}] + # TODO: make this include honor the display_mode parameter switch $size { short { - template::list::create \ - -name sim_templates \ - -multirow sim_templates \ - -actions " {Add a template} $add_url " \ - -elements { - name { - label "Template" - link_url_col edit_url - orderby upper(ot.pretty_name) - } - role_count { - label "Roles" - } - task_count { - label "Tasks" - } - } + set elements { + name { + label "Template" + link_url_col edit_url + orderby upper(ot.pretty_name) + } + role_count { + label "Roles" + } + task_count { + label "Tasks" + } + } } default { - template::list::create \ - -name sim_templates \ - -multirow sim_templates \ - -actions " {Add a template} $add_url " \ - -elements { - edit { - sub_class narrow - display_template { - - - Edit - - - } - } - name { - label "Name" - orderby upper(ot.pretty_name) - link_url_col view_url - } - description { - label "Description" - orderby r.description - } - created_by { - label "Created by" - orderby r.createdby - } - role_count { - label "Roles" - } - task_count { - label "Tasks" - } - delete { - sub_class narrow - display_template { - - - Delete - - - } - } - clone { - display_template { - Clone this template - } - + set elements { + edit { + sub_class narrow + display_template { + + + Edit + + } - - } + } + name { + label "Name" + orderby upper(ot.pretty_name) + link_url_col view_url + } + description { + label "Description" + orderby r.description + } + created_by { + label "Created by" + orderby r.createdby + } + role_count { + label "Roles" + } + task_count { + label "Tasks" + } + delete { + sub_class narrow + display_template { + + + Delete + + + } + } + clone { + display_template { + Clone this template + } + + } + } } } +template::list::create \ + -name sim_templates \ + -multirow sim_templates \ + -actions $actions \ + -elements $elements + ###################################################################### # # sim_templates 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.9 -r1.10 --- openacs-4/packages/simulation/tcl/template-procs.tcl 11 Dec 2003 14:24:29 -0000 1.9 +++ openacs-4/packages/simulation/tcl/template-procs.tcl 11 Dec 2003 15:32:43 -0000 1.10 @@ -9,8 +9,8 @@ namespace eval simulation::template {} ad_proc -public simulation::template::new { - {-short_name:required} {-pretty_name:required} + {-short_name {}} {-sim_type "dev_template"} {-suggested_duration ""} {-package_key:required} @@ -23,8 +23,6 @@ @author Peter Marklund } { db_transaction { - set short_name [util_text_to_url -replacement "_" $short_name] - set workflow_id [workflow::new \ -short_name $short_name \ -pretty_name $pretty_name \ @@ -40,10 +38,42 @@ return $workflow_id } +ad_proc -public simulation::template::new_from_spec { + {-package_key {}} + {-object_id {}} + {-spec:required} + {-array {}} +} { + Create a new simulation template for a spec. + + @return The workflow_id of the created simulation. + + @author Lars Pind +} { + if { ![empty_string_p $array] } { + upvar 1 $array row + set array row + } + + db_transaction { + + set workflow_id [workflow::fsm::new_from_spec \ + -package_key $package_key \ + -object_id $object_id \ + -spec $spec \ + -array $array] + + insert_sim \ + -workflow_id $workflow_id + } + + return $workflow_id +} + ad_proc -private simulation::template::insert_sim { {-workflow_id:required} - {-sim_type:required} - {-suggested_duration:required} + {-sim_type "dev_template"} + {-suggested_duration {}} } { Internal proc for inserting values into the sim_simulations table that are set prior to a template being mapped. @@ -61,7 +91,7 @@ db_dml new_sim " insert into sim_simulations (simulation_id, sim_type, suggested_duration) - values ('$workflow_id', '$sim_type', interval '$suggested_duration')" + values (:workflow_id, :sim_type, interval '[db_quote $suggested_duration]')" } } Index: openacs-4/packages/simulation/www/simulation-master.adp =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/simulation/www/simulation-master.adp,v diff -u -r1.8 -r1.9 --- openacs-4/packages/simulation/www/simulation-master.adp 11 Dec 2003 14:24:29 -0000 1.8 +++ openacs-4/packages/simulation/www/simulation-master.adp 11 Dec 2003 15:32:43 -0000 1.9 @@ -2,7 +2,7 @@ @title;noquote@ @context;noquote@ @subnavbar_link;noquote@ -@focus;noquote@ + @focus;noquote@ Index: openacs-4/packages/simulation/www/simbuild/template-clone.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/simulation/www/simbuild/template-clone.tcl,v diff -u -r1.3 -r1.4 --- openacs-4/packages/simulation/www/simbuild/template-clone.tcl 11 Dec 2003 14:24:29 -0000 1.3 +++ openacs-4/packages/simulation/www/simbuild/template-clone.tcl 11 Dec 2003 15:32:43 -0000 1.4 @@ -1,5 +1,5 @@ ad_page_contract { - Create a new simulation + Clone new simulation } { workflow_id:integer } Index: openacs-4/packages/simulation/www/simbuild/template-load.adp =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/simulation/www/simbuild/template-load.adp,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/simulation/www/simbuild/template-load.adp 11 Dec 2003 15:32:43 -0000 1.1 @@ -0,0 +1,7 @@ + + @page_title;noquote@ + @context;noquote@ + load.spec + + + Index: openacs-4/packages/simulation/www/simbuild/template-load.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/simulation/www/simbuild/template-load.tcl,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/simulation/www/simbuild/template-load.tcl 11 Dec 2003 15:32:43 -0000 1.1 @@ -0,0 +1,43 @@ +ad_page_contract { + Load a simulation from a spec + +} + +permission::require_permission -object_id [ad_conn package_id] -privilege sim_template_create + +set page_title "Load Template" + +set context [list [list "." "SimBuild"] $page_title] + +ad_form -name load -edit_buttons [list [list "Load" ok]] -form { + {pretty_name:text + {label "Name"} + {html {size 50}} + } + {spec:text(textarea) + {label "Spec"} + {help_text {Copy and paste the specification here}} + {html {cols 80 rows 10}} + } +} -on_request { + +} -on_submit { + with_catch errmsg { + set row(pretty_name) $pretty_name + set row(short_name) {} + simulation::template::new_from_spec \ + -package_key "simulation" \ + -object_id [ad_conn package_id] \ + -spec $spec \ + -array row + } { + global errorInfo + ns_log Error "Error loading workflow: $errorInfo" + form set_error load spec $errmsg + break + } + + ad_returnredirect . + ad_script_abort +} + Index: openacs-4/packages/simulation/www/simbuild/template-spec.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/simulation/www/simbuild/template-spec.tcl,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/simulation/www/simbuild/template-spec.tcl 11 Dec 2003 15:32:43 -0000 1.1 @@ -0,0 +1,12 @@ +ad_page_contract { + Generate and download a specification for a workflow. + + @author Lars Pind + @creation-date 2003-12-10 +} { + workflow_id:integer +} + +set spec [workflow::fsm::generate_spec -workflow_id $workflow_id] + +ns_return 200 text/plain [util::array_list_spec_pretty $spec]