Commit c0cd7867 authored by Frank Bergmann's avatar Frank Bergmann

- REST Interface:

  Now allowing to limit the columns returned using "columns" argument
parent 9376cd16
......@@ -794,6 +794,7 @@ ad_proc -private im_rest_get_object_type {
ns_log Notice "im_rest_get_object_type: format=$format, user_id=$current_user_id, rest_otype=$rest_otype, rest_oid=$rest_oid, query_hash=$query_hash_pairs"
array set query_hash $query_hash_pairs
set rest_otype_id [util_memoize [list db_string otype_id "select object_type_id from im_rest_object_types where object_type = '$rest_otype'" -default 0]]
set rest_columns [im_rest_get_rest_columns $query_hash_pairs]
# -------------------------------------------------------
# Get some more information about the current object type
......@@ -968,7 +969,7 @@ ad_proc -private im_rest_get_object_type {
set url "$base_url/$rest_otype/$rest_oid"
switch $format {
xml {
xml {
append result "<object_id id=\"$rest_oid\" href=\"$url\">[ns_quotehtml $object_name]</object_id>\n"
}
json {
......@@ -976,6 +977,12 @@ ad_proc -private im_rest_get_object_type {
if {0 == $obj_ctr} { set komma "" }
set dereferenced_result ""
foreach v $valid_vars {
if {{} != $rest_columns} {
# Skip the column unless it is explicitely mentioned in the rest_columns list
if {![info exists rest_columns($v)]} { continue }
}
eval "set a $$v"
regsub -all {\n} $a {\n} a
regsub -all {\r} $a {} a
......
......@@ -38,6 +38,29 @@ ad_proc -public im_rest_doc_return {args} {
}
ad_proc -public im_rest_get_rest_columns {
query_hash_pairs
} {
Reads the "columns" URL variable and returns the
list of selected REST columns or an empty list
if the variable was not specified.
} {
set rest_columns [list]
set rest_column_arg ""
array set query_hash $query_hash_pairs
if {[info exists query_hash(columns)]} { set rest_column_arg $query_hash(columns) }
if {"" != $rest_column_arg} {
# Accept both space (" ") and komma (",") separated columns
set rest_columns [split $rest_column_arg " "]
if {[llength $rest_columns] <= 1} {
set rest_columns [split $rest_column_arg ","]
}
}
return $rest_columns
}
ad_proc -private im_rest_header_extra_stuff {
{-debug 1}
} {
......
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