Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
I
intranet-rest
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
project-open
intranet-rest
Commits
3c5d3983
Commit
3c5d3983
authored
Jun 27, 2015
by
Frank Bergmann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
- GanttEditor:
- Working on the CRUD back-end - Fixed assignment saving
parent
11dc614e
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
268 additions
and
3 deletions
+268
-3
intranet-rest-create-procs.tcl
tcl/intranet-rest-create-procs.tcl
+19
-3
intranet-rest-data-source-procs.tcl
tcl/intranet-rest-data-source-procs.tcl
+189
-0
project-task-tree-action.tcl
www/data-source/project-task-tree-action.tcl
+57
-0
project-task-tree.json.tcl
www/data-source/project-task-tree.json.tcl
+3
-0
No files found.
tcl/intranet-rest-create-procs.tcl
View file @
3c5d3983
...
...
@@ -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
{
...
...
tcl/intranet-rest-data-source-procs.tcl
0 → 100644
View file @
3c5d3983
# /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"
}
}
# -------------------------------------------------------
#
# -------------------------------------------------------
www/data-source/project-task-tree-
update
.tcl
→
www/data-source/project-task-tree-
action
.tcl
View file @
3c5d3983
# /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-t
rask-tree-update
: object: json_list=
$json
_list"
im_rest_project_task_tree_
update
-var_hash_list
$json
_list
ns_log Notice
"project-t
ask-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-t
rask-tree-update
: array=
$json
_array"
ns_log Notice
"project-t
ask-tree-action
: array=
$json
_array"
foreach array_elem
$json
_array
{
ns_log Notice
"project-t
rask-tree-update
: array_elem=
$array
_elem"
ns_log Notice
"project-t
ask-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
'
\}
"
www/data-source/project-task-tree.json.tcl
View file @
3c5d3983
...
...
@@ -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
#
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment