Commit 3c5d3983 authored by Frank Bergmann's avatar Frank Bergmann

- GanttEditor:

  - Working on the CRUD back-end
  - Fixed assignment saving
parent 11dc614e
......@@ -276,6 +276,7 @@ ad_proc -private im_rest_post_object_type_im_timesheet_task {
{ -format "json" }
{ -rest_user_id 0 }
{ -content "" }
{ -hash_array_list ""}
{ -rest_otype "im_timesheet_task" }
{ -rest_otype_pretty "Timesheet Task" }
} {
......@@ -293,15 +294,20 @@ ad_proc -private im_rest_post_object_type_im_timesheet_task {
set planned_units ""
set billable_units ""
set cost_center_id ""
set material_id ""
set invoice_id ""
set priority ""
set sort_order ""
set gantt_project_id ""
set note ""
# Extract a key-value list of variables from JSON POST request
array set hash_array [im_rest_parse_json_content -rest_otype $rest_otype -format $format -content $content]
if {"" != $hash_array_list} {
array set hash_array $hash_array_list
} else {
array set hash_array [im_rest_parse_json_content -rest_otype $rest_otype -format $format -content $content]
}
# write hash values as local variables
foreach key [array names hash_array] {
set value $hash_array($key)
......@@ -309,6 +315,16 @@ ad_proc -private im_rest_post_object_type_im_timesheet_task {
set $key $value
}
# Create default values if not yet set
if {"" == $material_id} {
set material_id [im_material_default_material_id]
set hash_array(material_id) $material_id
}
if {"" == $uom_id} {
set uom_id 320
set hash_array(uom_id) $uom_id
}
# Check that all required variables are there
set required_vars {project_name project_nr parent_id project_status_id project_type_id uom_id material_id}
foreach var $required_vars {
......
# /packages/intranet-rest/tcl/intranet-rest-procs.tcl
#
# Copyright (C) 2009 ]project-open[
#
# All rights reserved. Please check
# http://www.project-open.com/license/ for details.
ad_library {
REST Web Service Component Library
@author frank.bergmann@project-open.com
}
# ---------------------------------------------------------------
# Task-Tree: Create and update tasks based on Procedure to update a task
# ---------------------------------------------------------------
ad_proc im_rest_project_task_tree_action {
{ -action "" }
-var_hash_list:required
} {
Create, Update or Delete a task coming from TreeStore
} {
ns_log Notice "im_rest_project_task_tree_action: 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) }
switch $action {
update { im_rest_project_task_tree_update -project_id $project_id -var_hash_list $var_hash_list }
create { im_rest_project_task_tree_create -project_id $project_id -var_hash_list $var_hash_list }
delete { im_rest_project_task_tree_delete -project_id $project_id -var_hash_list $var_hash_list }
default {
doc_return 200 "text/plain" "{success:false, message: 'tree_action: found invalid action=$action'}"
}
}
# The calling procedure will return a suitable JSON success message
}
ad_proc im_rest_project_task_tree_update {
-project_id:required
-var_hash_list:required
} {
Update a task coming from TreeStore
} {
ns_log Notice "im_rest_project_task_tree_update: project_id=$project_id, var_hash_list=$var_hash_list"
set current_user_id [ad_get_user_id]
array set var_hash $var_hash_list
if {"" == $project_id} {
doc_return 200 "text/plain" "{success:false, message: 'Update failed because we did not find project_id in JSON data: $var_hash_list'}"
return
}
# project_id exists - update the existing task
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
}
# Update the main project fields via a generic REST routine
im_rest_object_type_update_sql \
-format "json" \
-rest_otype "im_timesheet_task" \
-rest_oid $project_id \
-hash_array $var_hash_list
# Update assignments
im_rest_project_task_tree_assignments -project_id $project_id -var_hash_list $var_hash_list
}
ad_proc im_rest_project_task_tree_delete {
-project_id:required
-var_hash_list:required
} {
Delete a task coming from TreeStore
} {
ns_log Notice "im_rest_project_task_tree_delete: project_id=$project_id, var_hash_list=$var_hash_list"
set current_user_id [ad_get_user_id]
array set var_hash $var_hash_list
if {"" == $project_id} {
doc_return 200 "text/plain" "{success:false, message: 'Delete failed because we did not find project_id in JSON data: $var_hash_list'}"
return
}
# project_id exists - update the existing task
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 {!$admin} {
doc_return 200 "text/plain" "{success:false, message: 'No permissions to admin project_id=$project_id for user=$current_user_id'}"
ad_script_abort
}
im_rest_delete_object \
-format "json" \
-rest_user_id $current_user_id \
-rest_otype $object_type \
-rest_oid $project_id \
-query_hash_pairs $var_hash_list
}
ad_proc im_rest_project_task_tree_create {
-project_id:required
-var_hash_list:required
} {
Create a new task coming from TreeStore
} {
ns_log Notice "im_rest_project_task_tree_create: project_id=$project_id, var_hash_list=$var_hash_list"
set current_user_id [ad_get_user_id]
array set var_hash $var_hash_list
# No project_id!
if {"" != $project_id} {
doc_return 200 "text/plain" "{success:false, message: 'Create failed, object already contains project_id=$project_id in JSON data: $var_hash_list'}"
return
}
set parent_id ""
if {[info exists var_hash(parent_id)]} { set parent_id $var_hash(parent_id) }
if {"" == $parent_id} {
doc_return 200 "text/plain" "{success:false, message: 'Create failed, no parent_id specified for new task in post data: $var_hash_list'}"
ad_script_abort
}
set parent_object_type [util_memoize [list db_string otype "select object_type from acs_objects where object_id = $parent_id"]]
${parent_object_type}_permissions $current_user_id $parent_id view read write admin
if {!$write} {
doc_return 200 "text/plain" "{success:false, message: 'No permissions to write to parent_id=$parent_id for user=$current_user_id'}"
ad_script_abort
}
set project_id [im_rest_post_object_type_im_timesheet_task \
-format "json" \
-rest_user_id $current_user_id \
-rest_otype "im_timesheet_task" \
-rest_otype_pretty "Timesheet Task" \
-hash_array_list $var_hash_list]
# Update assignments
im_rest_project_task_tree_assignments -project_id $project_id -var_hash_list $var_hash_list
}
ad_proc im_rest_project_task_tree_assignments {
-project_id:required
-var_hash_list:required
} {
Update the resource assignments to the task
} {
ns_log Notice "im_rest_project_task_tree_assignments: project_id=$project_id, var_hash_list=$var_hash_list"
array set var_hash $var_hash_list
# Update task assignments
set assignees $var_hash(assignees)
ns_log Notice "im_rest_project_task_tree_assignments: assignees=$assignees"
set assignee_list [lindex $assignees 1]
foreach assignee_object $assignee_list {
set object_hash_list [lindex $assignee_object 1]
ns_log Notice "im_rest_project_task_tree_assignments: object_hash=$object_hash_list"
array unset object_hash
array set object_hash $object_hash_list
set user_id $object_hash(user_id)
set percent $object_hash(percent)
# Add the dude to the project and update percentage
set rel_id [im_biz_object_add_role $user_id $project_id [im_biz_object_role_full_member]]
db_dml update_assignation "update im_biz_object_members set percentage = :percent where rel_id = :rel_id"
ns_log Notice "im_rest_project_task_tree_assignments: rel_id=$rel_id"
}
}
# -------------------------------------------------------
#
# -------------------------------------------------------
# /packages/intranet-rest/www/data-source/project-trask-tree-update.tcl
# /packages/intranet-rest/www/data-source/project-trask-tree-action.tcl
#
# Copyright (C) 2013 ]project-open[
......@@ -11,71 +11,21 @@ ad_page_contract {
}
# ---------------------------------------------------------------
# Security
# ---------------------------------------------------------------
# Check that the current_user_id has write permissions to the project
# Check that the user is logged in
set current_user_id [ad_maybe_redirect_for_registration]
ns_log Notice "project-task-tree-action: query_hash_pairs=$query_hash_pairs"
array set var_hash $query_hash_pairs
set action $var_hash(action)
# ---------------------------------------------------------------
# Extract parameters
# Parameters may be send via the URL (project_id=...) or via JSON
# ---------------------------------------------------------------
# Parse the URL line for variables
set query_string [ns_conn query]
set tuple_list [split $query_string "&"]
foreach tuple $tuple_list {
if {[regexp {^([^=]+)\=(.*)} $tuple match var value]} {
set var_hash($var) $value
ns_log Notice "project-trask-tree-update: $var=$value"
}
}
# 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_hash=[array get json_hash]"
# ---------------------------------------------------------------
# Procedure to update a task
# ---------------------------------------------------------------
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
}
ns_log Notice "project-task-tree-action: json_hash=[array get json_hash]"
# ---------------------------------------------------------------
......@@ -84,26 +34,24 @@ ad_proc im_rest_project_task_tree_update {
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
ns_log Notice "project-task-tree-action: object: json_list=$json_list"
im_rest_project_task_tree_action -action $action -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"
ns_log Notice "project-task-tree-action: array=$json_array"
foreach array_elem $json_array {
ns_log Notice "project-trask-tree-update: array_elem=$array_elem"
ns_log Notice "project-task-tree-action: 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
ns_log Notice "project-task-tree-action: decomposing array_elem: $obj=$json_list"
im_rest_project_task_tree_action -action $action -var_hash_list $json_list
}
}
# ---------------------------------------------------------------
# Return a success JSON
# ---------------------------------------------------------------
doc_return 200 "text/plain" "\{success:true, message: 'Successfully updated task(s)'\}"
doc_return 200 "text/plain" "\{success:true, message: 'Successfully performed action=$action'\}"
......@@ -11,6 +11,9 @@ ad_page_contract {
{debug_p 0}
}
ns_log Notice "project-task-tree.json: query_hash_pairs=$query_hash_pairs"
# --------------------------------------------
# Security & Permissions
#
......
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