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.11 -r1.12
--- openacs-4/contrib/packages/simulation/tcl/template-procs.tcl 11 Dec 2003 15:49:40 -0000 1.11
+++ openacs-4/contrib/packages/simulation/tcl/template-procs.tcl 15 Dec 2003 13:40:22 -0000 1.12
@@ -97,43 +97,65 @@
ad_proc -public simulation::template::edit {
{-workflow_id:required}
- {-short_name:required}
- {-pretty_name:required}
- {-sim_type:required}
- {-suggested_duration ""}
- {-package_key:required}
- {-object_id:required}
+ {-array:required}
} {
Edit a new simulation template. TODO: need better tests for duration before passing it into the database.
+
+ @param workflow_id The id of the template to edit.
+ @param array The name of an array in the callers scope that contains properties to edit.
@return nothing
@author Joel Aufrecht
} {
+ upvar $array edit_array
+
db_transaction {
+ # Update workflows table
+
# TODO: this should be in a new API call, workflow::edit
+ set set_clauses [list]
+ foreach col {short_name pretty_name package_key object_id description} {
+ if { [info exists edit_array($col)] } {
+ lappend set_clauses "$col = :$col"
+ set $col $edit_array($col)
+ }
+ }
- db_dml edit_workflow "
+ if { [llength $set_clauses] > 0 } {
+ db_dml edit_workflow "
update workflows
- set short_name=:short_name,
- pretty_name=:pretty_name
+ set [join $set_clauses ", "]
where workflow_id=:workflow_id"
+ }
- if { [empty_string_p $suggested_duration] } {
- db_dml edit_sim {
- update sim_simulations
- set sim_type=:sim_type,
- suggested_duration = null
- where simulation_id=:workflow_id
+ # Update sim_simulations table
+
+ set set_clauses [list]
+ foreach col {sim_type suggested_duration} {
+ if { [info exists edit_array($col)] } {
+ if { [string equal $col suggested_duration] } {
+ # Suggested duration needs special interval update syntax
+ if { [empty_string_p $edit_array($col)] } {
+ lappend set_clauses "$col = null"
+ } else {
+ lappend set_clauses "$col = (interval '$edit_array($col)')"
+ }
+ } else {
+ lappend set_clauses "$col = :$col"
+ }
+
+ set $col $edit_array($col)
}
- } else {
+ }
+
+ if { [llength $set_clauses] > 0 } {
db_dml edit_sim "
- update sim_simulations
- set sim_type=:sim_type,
- suggested_duration=(interval '$suggested_duration')
- where simulation_id=:workflow_id
- "
+ update sim_simulations
+ set [join $set_clauses ", "]
+ where simulation_id=:workflow_id
+ "
}
}
}
@@ -181,6 +203,7 @@
}
}
}
+
ad_proc -public simulation::template::clone {
{-workflow_id:required}
{-package_key {}}
@@ -255,6 +278,56 @@
db_1row select_template {} -column_array row
}
+ad_proc -public simulation::template::ready_for_casting_p {
+ {-workflow_id ""}
+ {-role_empty_count ""}
+ {-prop_empty_count ""}
+} {
+ Return 1 if the simulation is ready for casting and 0 otherwise.
+ Goes to the database if workflow_id is provided and uses the other
+ proc parameters otherwise to do the test.
+
+ @param workflow_id The id of the simulation to check. The proc
+ will go to the database to get info about the simulation
+ if id is provided.
+ @param role_empty_count The number of empty roles for the simulation. Must be
+ provided if workflow_id is not.
+ @param prop_empty_count The number of empty properties for the simulation. Must be
+ provided if workflow_id is not.
+
+ @author Peter Marklund
+} {
+ if { ![empty_string_p $workflow_id] } {
+ # workflow_id provided
+
+ set role_empty_count [db_string role_empty_count {
+ select count(*)
+ from sim_roles sr,
+ workflow_roles wr
+ where sr.role_id = wr.role_id
+ and wr.workflow_id = :workflow_id
+ and character_id is null
+ }]
+
+ set prop_empty_count [db_string prop_empty_count {
+ select count(*)
+ from sim_task_object_map stom,
+ workflow_actions wa
+ where stom.task_id = wa.action_id
+ and wa.workflow_id = :workflow_id
+ and stom.object_id is null
+ }]
+
+ } else {
+ # No workflow_id required
+ if { [empty_string_p $role_empty_count] || [empty_string_p $prop_empty_count] } {
+ error "When no workflow_id is provided you must provide role_empty_count and prop_empty_count"
+ }
+ }
+
+ return [expr [string equal $role_empty_count 0] && [string equal $prop_empty_count 0]]
+}
+
ad_proc -public simulation::template::get_workflow_id_from_action {
{-action_id:required}
} {
Index: openacs-4/contrib/packages/simulation/tcl/template-procs.xql
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/simulation/tcl/Attic/template-procs.xql,v
diff -u -r1.2 -r1.3
--- openacs-4/contrib/packages/simulation/tcl/template-procs.xql 10 Dec 2003 10:05:19 -0000 1.2
+++ openacs-4/contrib/packages/simulation/tcl/template-procs.xql 15 Dec 2003 13:40:22 -0000 1.3
@@ -9,6 +9,7 @@
w.object_id,
w.package_key,
w.object_type,
+ w.description,
s.suggested_duration,
s.sim_type,
s.enroll_type,
Index: openacs-4/contrib/packages/simulation/www/simbuild/template-edit.tcl
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/simulation/www/simbuild/Attic/template-edit.tcl,v
diff -u -r1.9 -r1.10
--- openacs-4/contrib/packages/simulation/www/simbuild/template-edit.tcl 11 Dec 2003 14:24:29 -0000 1.9
+++ openacs-4/contrib/packages/simulation/www/simbuild/template-edit.tcl 15 Dec 2003 13:40:22 -0000 1.10
@@ -69,6 +69,7 @@
permission::require_write_permission -object_id $workflow_id
simulation::template::get -workflow_id $workflow_id -array sim_template_array
set name $sim_template_array(pretty_name)
+ set description $sim_template_array(description)
# translate sim_type to ready/not-ready
# TODO: we should only see ready_template and dev_template here, so maybe assert that?
@@ -103,14 +104,17 @@
}
permission::require_write_permission -object_id $workflow_id
+
+ set simulation(short_name) $name
+ set simulation(pretty_name $name
+ set simulation(sim_type) $sim_type
+ set simulation(suggested_duration) $suggested_duration
+ set simulation(package_key) $package_key
+ set simulation(object_id) $package_id
+ set simulation(description) $description
simulation::template::edit \
-workflow_id $workflow_id \
- -short_name $name \
- -pretty_name $name \
- -sim_type $sim_type \
- -suggested_duration $suggested_duration \
- -package_key $package_key \
- -object_id $package_id
+ -array simulation
} -after_submit {
Index: openacs-4/contrib/packages/simulation/www/siminst/index.tcl
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/simulation/www/siminst/Attic/index.tcl,v
diff -u -r1.14 -r1.15
--- openacs-4/contrib/packages/simulation/www/siminst/index.tcl 15 Dec 2003 10:54:31 -0000 1.14
+++ openacs-4/contrib/packages/simulation/www/siminst/index.tcl 15 Dec 2003 13:40:22 -0000 1.15
@@ -108,7 +108,7 @@
and ss.sim_type = 'dev_sim'
$sim_in_dev_filter_sql
" {
- if { [string equal $role_empty_count 0] && [string equal $prop_empty_count 0]} {
+ if { [simulation::template::ready_for_casting_p -role_empty_count $role_empty_count -prop_empty_count $prop_empty_count] } {
set cast_url [export_vars -base "${base_url}siminst/simulation-casting" { workflow_id }]
} else {
set cast_url ""
Index: openacs-4/contrib/packages/simulation/www/siminst/simulation-casting.adp
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/simulation/www/siminst/Attic/simulation-casting.adp,v
diff -u -r1.6 -r1.7
--- openacs-4/contrib/packages/simulation/www/siminst/simulation-casting.adp 12 Dec 2003 15:40:32 -0000 1.6
+++ openacs-4/contrib/packages/simulation/www/siminst/simulation-casting.adp 15 Dec 2003 13:40:22 -0000 1.7
@@ -2,7 +2,4 @@
@page_title;noquote@
@context;noquote@
-TODO:
-see tcl file. No UI here unless there's a problem.
-
-
+The template \"@simulation.pretty_name@\" is not ready for casting as it has unmapped roles or properties.
Index: openacs-4/contrib/packages/simulation/www/siminst/simulation-casting.tcl
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/simulation/www/siminst/Attic/simulation-casting.tcl,v
diff -u -r1.6 -r1.7
--- openacs-4/contrib/packages/simulation/www/siminst/simulation-casting.tcl 15 Dec 2003 10:33:07 -0000 1.6
+++ openacs-4/contrib/packages/simulation/www/siminst/simulation-casting.tcl 15 Dec 2003 13:40:22 -0000 1.7
@@ -4,16 +4,17 @@
workflow_id:integer
}
-set page_title "Edit a simulation"
-set context [list [list "." "SimInst"] $page_title]
-set package_id [ad_conn package_id]
+# Redirect to next casting page if the template is ready for casting
+if { [simulation::template::ready_for_casting_p -workflow_id $workflow_id] } {
-# Perform the same test as in siminst/index.tcl:
-# if { [string equal $role_empty_count 0] && [string equal $prop_empty_count 0]} {
-# change sim_type to casting_sim
-# ad_returnredirect [export_vars -base "simulation-casting-2" { workflow_id }]
-# } else {
-# show an error page with links to the incomplete roles and props
-# }
+ set simulation(sim_type) casting_sim
+ simulation::template::edit -workflow_id $workflow_id -array simulation
+ ad_returnredirect [export_vars -base "simulation-casting-2" { workflow_id }]
+}
+simulation::template::get -workflow_id $workflow_id -array simulation
+
+set page_title "Template \"$simulation(pretty_name)\" not ready for casting"
+set context [list [list "." "SimInst"] $page_title]
+set package_id [ad_conn package_id]
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.11 -r1.12
--- openacs-4/packages/simulation/tcl/template-procs.tcl 11 Dec 2003 15:49:40 -0000 1.11
+++ openacs-4/packages/simulation/tcl/template-procs.tcl 15 Dec 2003 13:40:22 -0000 1.12
@@ -97,43 +97,65 @@
ad_proc -public simulation::template::edit {
{-workflow_id:required}
- {-short_name:required}
- {-pretty_name:required}
- {-sim_type:required}
- {-suggested_duration ""}
- {-package_key:required}
- {-object_id:required}
+ {-array:required}
} {
Edit a new simulation template. TODO: need better tests for duration before passing it into the database.
+
+ @param workflow_id The id of the template to edit.
+ @param array The name of an array in the callers scope that contains properties to edit.
@return nothing
@author Joel Aufrecht
} {
+ upvar $array edit_array
+
db_transaction {
+ # Update workflows table
+
# TODO: this should be in a new API call, workflow::edit
+ set set_clauses [list]
+ foreach col {short_name pretty_name package_key object_id description} {
+ if { [info exists edit_array($col)] } {
+ lappend set_clauses "$col = :$col"
+ set $col $edit_array($col)
+ }
+ }
- db_dml edit_workflow "
+ if { [llength $set_clauses] > 0 } {
+ db_dml edit_workflow "
update workflows
- set short_name=:short_name,
- pretty_name=:pretty_name
+ set [join $set_clauses ", "]
where workflow_id=:workflow_id"
+ }
- if { [empty_string_p $suggested_duration] } {
- db_dml edit_sim {
- update sim_simulations
- set sim_type=:sim_type,
- suggested_duration = null
- where simulation_id=:workflow_id
+ # Update sim_simulations table
+
+ set set_clauses [list]
+ foreach col {sim_type suggested_duration} {
+ if { [info exists edit_array($col)] } {
+ if { [string equal $col suggested_duration] } {
+ # Suggested duration needs special interval update syntax
+ if { [empty_string_p $edit_array($col)] } {
+ lappend set_clauses "$col = null"
+ } else {
+ lappend set_clauses "$col = (interval '$edit_array($col)')"
+ }
+ } else {
+ lappend set_clauses "$col = :$col"
+ }
+
+ set $col $edit_array($col)
}
- } else {
+ }
+
+ if { [llength $set_clauses] > 0 } {
db_dml edit_sim "
- update sim_simulations
- set sim_type=:sim_type,
- suggested_duration=(interval '$suggested_duration')
- where simulation_id=:workflow_id
- "
+ update sim_simulations
+ set [join $set_clauses ", "]
+ where simulation_id=:workflow_id
+ "
}
}
}
@@ -181,6 +203,7 @@
}
}
}
+
ad_proc -public simulation::template::clone {
{-workflow_id:required}
{-package_key {}}
@@ -255,6 +278,56 @@
db_1row select_template {} -column_array row
}
+ad_proc -public simulation::template::ready_for_casting_p {
+ {-workflow_id ""}
+ {-role_empty_count ""}
+ {-prop_empty_count ""}
+} {
+ Return 1 if the simulation is ready for casting and 0 otherwise.
+ Goes to the database if workflow_id is provided and uses the other
+ proc parameters otherwise to do the test.
+
+ @param workflow_id The id of the simulation to check. The proc
+ will go to the database to get info about the simulation
+ if id is provided.
+ @param role_empty_count The number of empty roles for the simulation. Must be
+ provided if workflow_id is not.
+ @param prop_empty_count The number of empty properties for the simulation. Must be
+ provided if workflow_id is not.
+
+ @author Peter Marklund
+} {
+ if { ![empty_string_p $workflow_id] } {
+ # workflow_id provided
+
+ set role_empty_count [db_string role_empty_count {
+ select count(*)
+ from sim_roles sr,
+ workflow_roles wr
+ where sr.role_id = wr.role_id
+ and wr.workflow_id = :workflow_id
+ and character_id is null
+ }]
+
+ set prop_empty_count [db_string prop_empty_count {
+ select count(*)
+ from sim_task_object_map stom,
+ workflow_actions wa
+ where stom.task_id = wa.action_id
+ and wa.workflow_id = :workflow_id
+ and stom.object_id is null
+ }]
+
+ } else {
+ # No workflow_id required
+ if { [empty_string_p $role_empty_count] || [empty_string_p $prop_empty_count] } {
+ error "When no workflow_id is provided you must provide role_empty_count and prop_empty_count"
+ }
+ }
+
+ return [expr [string equal $role_empty_count 0] && [string equal $prop_empty_count 0]]
+}
+
ad_proc -public simulation::template::get_workflow_id_from_action {
{-action_id:required}
} {
Index: openacs-4/packages/simulation/tcl/template-procs.xql
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/simulation/tcl/template-procs.xql,v
diff -u -r1.2 -r1.3
--- openacs-4/packages/simulation/tcl/template-procs.xql 10 Dec 2003 10:05:19 -0000 1.2
+++ openacs-4/packages/simulation/tcl/template-procs.xql 15 Dec 2003 13:40:22 -0000 1.3
@@ -9,6 +9,7 @@
w.object_id,
w.package_key,
w.object_type,
+ w.description,
s.suggested_duration,
s.sim_type,
s.enroll_type,
Index: openacs-4/packages/simulation/www/simbuild/template-edit.tcl
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/simulation/www/simbuild/template-edit.tcl,v
diff -u -r1.9 -r1.10
--- openacs-4/packages/simulation/www/simbuild/template-edit.tcl 11 Dec 2003 14:24:29 -0000 1.9
+++ openacs-4/packages/simulation/www/simbuild/template-edit.tcl 15 Dec 2003 13:40:22 -0000 1.10
@@ -69,6 +69,7 @@
permission::require_write_permission -object_id $workflow_id
simulation::template::get -workflow_id $workflow_id -array sim_template_array
set name $sim_template_array(pretty_name)
+ set description $sim_template_array(description)
# translate sim_type to ready/not-ready
# TODO: we should only see ready_template and dev_template here, so maybe assert that?
@@ -103,14 +104,17 @@
}
permission::require_write_permission -object_id $workflow_id
+
+ set simulation(short_name) $name
+ set simulation(pretty_name $name
+ set simulation(sim_type) $sim_type
+ set simulation(suggested_duration) $suggested_duration
+ set simulation(package_key) $package_key
+ set simulation(object_id) $package_id
+ set simulation(description) $description
simulation::template::edit \
-workflow_id $workflow_id \
- -short_name $name \
- -pretty_name $name \
- -sim_type $sim_type \
- -suggested_duration $suggested_duration \
- -package_key $package_key \
- -object_id $package_id
+ -array simulation
} -after_submit {
Index: openacs-4/packages/simulation/www/siminst/index.tcl
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/simulation/www/siminst/index.tcl,v
diff -u -r1.14 -r1.15
--- openacs-4/packages/simulation/www/siminst/index.tcl 15 Dec 2003 10:54:31 -0000 1.14
+++ openacs-4/packages/simulation/www/siminst/index.tcl 15 Dec 2003 13:40:22 -0000 1.15
@@ -108,7 +108,7 @@
and ss.sim_type = 'dev_sim'
$sim_in_dev_filter_sql
" {
- if { [string equal $role_empty_count 0] && [string equal $prop_empty_count 0]} {
+ if { [simulation::template::ready_for_casting_p -role_empty_count $role_empty_count -prop_empty_count $prop_empty_count] } {
set cast_url [export_vars -base "${base_url}siminst/simulation-casting" { workflow_id }]
} else {
set cast_url ""
Index: openacs-4/packages/simulation/www/siminst/simulation-casting.adp
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/simulation/www/siminst/simulation-casting.adp,v
diff -u -r1.6 -r1.7
--- openacs-4/packages/simulation/www/siminst/simulation-casting.adp 12 Dec 2003 15:40:32 -0000 1.6
+++ openacs-4/packages/simulation/www/siminst/simulation-casting.adp 15 Dec 2003 13:40:22 -0000 1.7
@@ -2,7 +2,4 @@
@page_title;noquote@
@context;noquote@
-TODO:
-see tcl file. No UI here unless there's a problem.
-
-
+The template \"@simulation.pretty_name@\" is not ready for casting as it has unmapped roles or properties.
Index: openacs-4/packages/simulation/www/siminst/simulation-casting.tcl
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/simulation/www/siminst/simulation-casting.tcl,v
diff -u -r1.6 -r1.7
--- openacs-4/packages/simulation/www/siminst/simulation-casting.tcl 15 Dec 2003 10:33:07 -0000 1.6
+++ openacs-4/packages/simulation/www/siminst/simulation-casting.tcl 15 Dec 2003 13:40:22 -0000 1.7
@@ -4,16 +4,17 @@
workflow_id:integer
}
-set page_title "Edit a simulation"
-set context [list [list "." "SimInst"] $page_title]
-set package_id [ad_conn package_id]
+# Redirect to next casting page if the template is ready for casting
+if { [simulation::template::ready_for_casting_p -workflow_id $workflow_id] } {
-# Perform the same test as in siminst/index.tcl:
-# if { [string equal $role_empty_count 0] && [string equal $prop_empty_count 0]} {
-# change sim_type to casting_sim
-# ad_returnredirect [export_vars -base "simulation-casting-2" { workflow_id }]
-# } else {
-# show an error page with links to the incomplete roles and props
-# }
+ set simulation(sim_type) casting_sim
+ simulation::template::edit -workflow_id $workflow_id -array simulation
+ ad_returnredirect [export_vars -base "simulation-casting-2" { workflow_id }]
+}
+simulation::template::get -workflow_id $workflow_id -array simulation
+
+set page_title "Template \"$simulation(pretty_name)\" not ready for casting"
+set context [list [list "." "SimInst"] $page_title]
+set package_id [ad_conn package_id]