Commit 11dc614e authored by Frank Bergmann's avatar Frank Bergmann

- Gantt Editor:

  Working on tree panel
parent 74673c00
......@@ -466,7 +466,7 @@ ad_proc -public im_rest_object_type_update_sql {
Updates all the object's tables with the information from the
hash array.
} {
ns_log Notice "im_rest_object_type_update_sql: format=$format, rest_otype=$rest_otype, rest_oid=$rest_oid, hash_array=[array get hash_array]"
ns_log Notice "im_rest_object_type_update_sql: format=$format, rest_otype=$rest_otype, rest_oid=$rest_oid, hash_array=$hash_array"
# Stuff the list of variables into a hash
array set hash $hash_array
......
......@@ -5,13 +5,21 @@
ad_page_contract {
Recieves a POST request from Sencha for an update
of in-line editing a TreeGrid
@param project_id The project
@author frank.bergmann@project-open.com
} {
{debug_p 0}
}
# ---------------------------------------------------------------
# Security
# ---------------------------------------------------------------
# Check that the current_user_id has write permissions to the project
set current_user_id [ad_maybe_redirect_for_registration]
# ---------------------------------------------------------------
# Extract parameters
# Parameters may be send via the URL (project_id=...) or via JSON
......@@ -30,44 +38,72 @@ foreach tuple $tuple_list {
# Parse the JSON POST data
set post_content [ns_conn content]
array set json_hash [util::json::parse $post_content]
# ns_log Notice "project-trask-tree-update: json_content=[array get json_hash]"
set json_list $json_hash(_object_);
# ns_log Notice "project-trask-tree-update: json_list=$json_list"
array set json_var_hash $json_list
foreach var [array names json_var_hash] {
set value $json_var_hash($var)
set var_hash($var) $value
ns_log Notice "project-trask-tree-update: $var=$value"
}
# Check that there was a task_id variable
if {![info exists var_hash(task_id)]} {
doc_return 200 "text/plain" "{success:false, message:'Undefined task_id in URL'}"
ad_script_abort
}
ns_log Notice "project-trask-tree-update: json_hash=[array get json_hash]"
# ---------------------------------------------------------------
# Security
# Procedure to update a task
# ---------------------------------------------------------------
# Check that the current_user_id has write permissions to the project
set current_user_id [ad_maybe_redirect_for_registration]
set task_id $var_hash(task_id)
im_security_alert_check_integer -location "/sencha-task-editor/treegrid-update.tcl: task_id" -value $task_id
im_timesheet_task_permissions $current_user_id $task_id view read write admin
if {!$write} {
doc_return 200 "text/plain" "{success:false, message: 'No permissions to read task_id=$task_id for user=$current_user_id'}"
ad_script_abort
ad_proc im_rest_project_task_tree_update {
-var_hash_list
} {
Update a single task based on the values from var_hash
} {
ns_log Notice "project-trask-tree-update: im_rest_project_task_tree_update: var_hash_list=$var_hash_list"
set current_user_id [ad_get_user_id]
array set var_hash $var_hash_list
# Get the project/task_id
set project_id ""
if {[info exists var_hash(project_id)] && "" != $var_hash(project_id)} { set project_id $var_hash(project_id) }
if {[info exists var_hash(task_id)] && "" != $var_hash(task_id)} { set project_id $var_hash(task_id) }
if {[info exists var_hash(id)] && "" != $var_hash(id)} { set project_id $var_hash(id) }
if {"" == $project_id} {
doc_return 200 "text/plain" "{success:false, message:'Undefined task_id or roject_id in POST data: [array get var_hash]'}"
ad_script_abort
}
set object_type [util_memoize [list db_string otype "select object_type from acs_objects where object_id = $project_id"]]
${object_type}_permissions $current_user_id $project_id view read write admin
if {!$write} {
doc_return 200 "text/plain" "{success:false, message: 'No permissions to write project_id=$project_id for user=$current_user_id'}"
ad_script_abort
}
im_rest_object_type_update_sql \
-format "json" \
-rest_otype "im_timesheet_task" \
-rest_oid $project_id \
-hash_array $var_hash_list
}
# ---------------------------------------------------------------
# Perform the update
# Check for single or multiple updates
# ---------------------------------------------------------------
if {[info exists json_hash(_object_)]} {
set json_list $json_hash(_object_)
ns_log Notice "project-trask-tree-update: object: json_list=$json_list"
im_rest_project_task_tree_update -var_hash_list $json_list
}
if {[info exists json_hash(_array_)]} {
set json_array $json_hash(_array_)
ns_log Notice "project-trask-tree-update: array=$json_array"
foreach array_elem $json_array {
ns_log Notice "project-trask-tree-update: array_elem=$array_elem"
set obj [lindex $array_elem 0]
set json_list [lindex $array_elem 1]
ns_log Notice "project-trask-tree-update: decomposing array_elem: $obj=$json_list"
im_rest_project_task_tree_update -var_hash_list $json_list
}
}
# ---------------------------------------------------------------
# Return a success JSON
# ---------------------------------------------------------------
doc_return 200 "text/plain" "\{success:true, message: 'Successfully updated task'\}"
doc_return 200 "text/plain" "\{success:true, message: 'Successfully updated task(s)'\}"
......@@ -75,7 +75,34 @@ db_foreach assignee $assignee_sql {
set assignee_hash($object_id_one) $assignees
}
# ad_return_complaint 1 [join [array get assignee_hash] "<br>"]
# --------------------------------------------
# Get the list of projects that should not be displayed
#
set non_display_projects_sql "
select distinct sub_p.project_id -- Select all sup-projects of somehow non-displays
from im_projects super_p,
im_projects sub_p
where sub_p.tree_sortkey between super_p.tree_sortkey and tree_right(super_p.tree_sortkey) and
sub_p.project_id != :project_id and
super_p.project_id in (
-- The list of projects that should not be displayed
select p.project_id
from im_projects p,
acs_objects o,
im_projects main_p
where main_p.project_id = :project_id and
main_p.project_id != p.project_id and
p.project_id = o.object_id and
p.tree_sortkey between main_p.tree_sortkey and tree_right(main_p.tree_sortkey) and
o.object_type = 'im_project'
)
"
# set non_display_projects [db_list non_display_projects $non_display_projects_sql]
set non_display_projects [list]
lappend non_display_projects 0
# ad_return_complaint 1 $non_display_projects
# --------------------------------------------
# Get all the variables valid for timesheet task
......@@ -106,7 +133,8 @@ set projects_sql "
bts.user_id = :current_user_id
)
where main_p.project_id = :project_id and
p.tree_sortkey between main_p.tree_sortkey and tree_right(main_p.tree_sortkey)
p.tree_sortkey between main_p.tree_sortkey and tree_right(main_p.tree_sortkey) and
p.project_id not in ([join $non_display_projects ","])
order by
coalesce(p.sort_order, 0)
"
......@@ -114,22 +142,16 @@ set projects_sql "
# Read the query into a Multirow, so that we can order
# it according to sort_order within the individual sub-levels.
db_multirow task_multirow task_list $projects_sql {
# By default keep the main project "open".
if {"" == $parent_id} { set expanded "true" }
}
# Sort the tree according to the specified sort order
# "sort_order" is an integer, so we have to tell the sort algorithm to use integer sorting
ns_log Notice "project-tree.json.tcl: starting to sort multirow"
multirow_sort_tree -integer task_multirow project_id parent_id sort_order
set title ""
set task_json ""
set ctr 0
set old_level 1
......@@ -203,10 +225,8 @@ ${indent}\texpanded:$expanded,
set mapped_value [string map {"\n" "<br>" "\r" ""} $value]
append task_json "${indent}\t$var:'$mapped_value',\n"
}
append task_json "${indent}\tleaf:$leaf_json"
incr ctr
set old_level $level
}
......@@ -221,8 +241,6 @@ while {$level < $old_level} {
for {set i 0} {$i < $old_level} {incr i} { append indent "\t" }
}
doc_return 200 "text/plain" "{'text':'.','children': \[
$task_json
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment