Commit 9376cd16 authored by Frank Bergmann's avatar Frank Bergmann

- REST Interface:

  Applied now the gzip_p parameter to all list returning
  REST functions
parent 96677bad
......@@ -795,11 +795,6 @@ ad_proc -private im_rest_get_object_type {
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]]
# Should we return the results in gzip format?
set gzip_p 0
if {[info exists query_hash(gzip_p)]} { set gzip_p $query_hash(gzip_p) }
# -------------------------------------------------------
# Get some more information about the current object type
db_1row rest_otype_info "
......@@ -1001,29 +996,21 @@ ad_proc -private im_rest_get_object_type {
switch $format {
html {
set page_title "object_type: $rest_otype"
doc_return 200 "text/html" "
im_rest_doc_return 200 "text/html" "
[im_header $page_title [im_rest_header_extra_stuff]][im_navbar]<table>
<tr class=rowtitle><td class=rowtitle>object_id</td><td class=rowtitle>Link</td></tr>$result
</table>[im_footer]
"
}
xml {
doc_return 200 "text/xml" "<?xml version='1.0'?>\n<object_list>\n$result</object_list>\n"
im_rest_doc_return 200 "text/xml" "<?xml version='1.0'?>\n<object_list>\n$result</object_list>\n"
return
}
json {
# Calculate the total number of objects
set total [db_string total "select count(*) from ($unlimited_sql) t" -default 0]
set result "{\"success\": true,\n\"total\": $total,\n\"message\": \"im_rest_get_object_type: Data loaded\",\n\"data\": \[\n$result\n\]\n}"
# Return the results. Check if compressed
if {$gzip_p} {
db_release_unused_handles
ad_http_cache_control
ns_returnz 200 "text/html" $result
} else {
doc_return 200 "text/html" $result
}
im_rest_doc_return 200 "text/html" $result
return
}
default {
......@@ -1108,7 +1095,7 @@ ad_proc -private im_rest_get_im_invoice_items {
switch $format {
html {
set page_title "object_type: $rest_otype"
doc_return 200 "text/html" "
im_rest_doc_return 200 "text/html" "
[im_header $page_title [im_rest_header_extra_stuff]][im_navbar]<table>
<tr class=rowtitle><td class=rowtitle>object_id</td><td class=rowtitle>Link</td></tr>$result
</table>[im_footer]
......@@ -1116,11 +1103,11 @@ ad_proc -private im_rest_get_im_invoice_items {
return
}
xml {
doc_return 200 "text/xml" "<?xml version='1.0'?>\n<object_list>\n$result</object_list>\n"
im_rest_doc_return 200 "text/xml" "<?xml version='1.0'?>\n<object_list>\n$result</object_list>\n"
return
}
json {
doc_return 200 "text/html" "{object_type: \"$rest_otype\",\n$result\n}"
im_rest_doc_return 200 "text/html" "{object_type: \"$rest_otype\",\n$result\n}"
return
}
}
......@@ -1208,7 +1195,7 @@ ad_proc -private im_rest_get_im_hours {
switch $format {
html {
set page_title "object_type: $rest_otype"
doc_return 200 "text/html" "
im_rest_doc_return 200 "text/html" "
[im_header $page_title [im_rest_header_extra_stuff]][im_navbar]<table>
<tr class=rowtitle><td class=rowtitle>object_id</td><td class=rowtitle>Link</td></tr>$result
</table>[im_footer]
......@@ -1216,11 +1203,11 @@ ad_proc -private im_rest_get_im_hours {
return
}
xml {
doc_return 200 "text/xml" "<?xml version='1.0'?>\n<object_list>\n$result</object_list>\n"
im_rest_doc_return 200 "text/xml" "<?xml version='1.0'?>\n<object_list>\n$result</object_list>\n"
return
}
json {
doc_return 200 "text/html" "\[$result\]\n"
im_rest_doc_return 200 "text/html" "\[$result\]\n"
return
}
}
......@@ -1339,7 +1326,7 @@ ad_proc -private im_rest_get_im_categories {
switch $format {
html {
set page_title "object_type: $rest_otype"
doc_return 200 "text/html" "
im_rest_doc_return 200 "text/html" "
[im_header $page_title [im_rest_header_extra_stuff]][im_navbar]<table>
<tr class=rowtitle><td class=rowtitle>object_id</td><td class=rowtitle>Link</td></tr>$result
</table>[im_footer]
......@@ -1347,13 +1334,13 @@ ad_proc -private im_rest_get_im_categories {
return
}
xml {
doc_return 200 "text/xml" "<?xml version='1.0'?>\n<object_list>\n$result</object_list>\n"
im_rest_doc_return 200 "text/xml" "<?xml version='1.0'?>\n<object_list>\n$result</object_list>\n"
return
}
json {
# Deal with different JSON variants for different AJAX frameworks
set result "{\"success\": true,\n\"message\": \"im_rest_get_im_categories: Data loaded\",\n\"data\": \[\n$result\n\]\n}"
doc_return 200 "text/html" $result
im_rest_doc_return 200 "text/html" $result
return
}
}
......@@ -1436,17 +1423,17 @@ ad_proc -private im_rest_get_im_dynfield_attributes {
switch $format {
html {
set page_title "object_type: $rest_otype"
doc_return 200 "text/html" "
im_rest_doc_return 200 "text/html" "
[im_header $page_title [im_rest_header_extra_stuff]][im_navbar]<table>
<tr class=rowtitle><td class=rowtitle>object_id</td><td class=rowtitle>Link</td></tr>$result
</table>[im_footer]
"
}
xml {
doc_return 200 "text/xml" "<?xml version='1.0'?>\n<object_list>\n$result</object_list>\n"
im_rest_doc_return 200 "text/xml" "<?xml version='1.0'?>\n<object_list>\n$result</object_list>\n"
}
json {
doc_return 200 "text/html" "\[\n$result\n\]\n"
im_rest_doc_return 200 "text/html" "\[\n$result\n\]\n"
}
}
......
......@@ -15,6 +15,29 @@ ad_library {
# Auxillary functions
# --------------------------------------------------------
ad_proc -public im_rest_doc_return {args} {
This is a replacement for doc_return that values if the
gzip_p URL parameters has been set.
} {
# Perform some magic work
db_release_unused_handles
ad_http_cache_control
# find out if we should compress or not
set query_set [ns_conn form]
set gzip_p [ns_set get $query_set gzip_p]
ns_log Notice "im_rest_doc_return: gzip_p=$gzip_p"
# Return the data
if {"1" == $gzip_p} {
return [eval "ns_returnz $args"]
} else {
return [eval "ns_return $args"]
}
}
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