liquid_feedback_frontend
annotate env/util/autoapi.lua @ 118:93f4e465b50d
add initiator support in delegation
if a delegation is issued from the initiative view, the initiators
from that one are added to the delegation target list. this makes it easier to delegate to the author without the need to add him to the contact list.
if a delegation is issued from the initiative view, the initiators
from that one are added to the delegation target list. this makes it easier to delegate to the author without the need to add him to the contact list.
| author | Daniel Poelzleithner <poelzi@poelzi.org> |
|---|---|
| date | Mon Sep 20 20:32:04 2010 +0200 (2010-09-20) |
| parents | 733f65c0c0a0 |
| children |
| rev | line source |
|---|---|
| bsw@51 | 1 function util.autoapi_xml(args) |
| bsw@75 | 2 local relation_name = assert(args.relation_name) |
| bsw@51 | 3 local selector = assert(args.selector) |
| bsw@51 | 4 local fields = assert(args.fields) |
| bsw@51 | 5 local rows = selector:exec() |
| bsw@75 | 6 slot.set_layout("xml", "application/xml") |
| bsw@75 | 7 slot.put("<", relation_name, "_list>\n") |
| bsw@51 | 8 for i_row, row in ipairs(rows) do |
| bsw@75 | 9 slot.put(" <", relation_name, ">\n") |
| bsw@51 | 10 for i_field, field in ipairs(fields) do |
| bsw@51 | 11 slot.put(" <", field.name, ">") |
| bsw@51 | 12 local value |
| bsw@51 | 13 if field.func then |
| bsw@51 | 14 value = field.func(row) |
| bsw@51 | 15 elseif field.field then |
| bsw@51 | 16 value = row[field.name] |
| bsw@51 | 17 end |
| bsw/jbe@52 | 18 if value ~= nil then |
| bsw@51 | 19 slot.put(encode.html(tostring(value))) |
| bsw/jbe@52 | 20 else |
| bsw/jbe@52 | 21 slot.put("NULL") |
| bsw@51 | 22 end |
| bsw@51 | 23 slot.put("</", field.name, ">\n") |
| bsw@51 | 24 end |
| bsw@75 | 25 slot.put(" </", relation_name, ">\n") |
| bsw@51 | 26 end |
| bsw@75 | 27 slot.put("</", relation_name, "_list>\n") |
| bsw@51 | 28 end |
| bsw@51 | 29 |
| bsw@51 | 30 function util.autoapi_json(args) |
| bsw@75 | 31 slot.set_layout("blank", "application/json") |
| bsw@51 | 32 local selector = assert(args.selector) |
| bsw@51 | 33 local fields = assert(args.fields) |
| bsw@51 | 34 local rows = selector:exec() |
| bsw@75 | 35 slot.put("[\n") |
| bsw@51 | 36 for i_row, row in ipairs(rows) do |
| bsw@51 | 37 slot.put(" {\n") |
| bsw@51 | 38 for i_field, field in ipairs(fields) do |
| bsw@75 | 39 slot.put(" \"", field.name, "\": ") |
| bsw@51 | 40 local value |
| bsw@51 | 41 if field.func then |
| bsw@51 | 42 value = field.func(row) |
| bsw@51 | 43 elseif field.field then |
| bsw@51 | 44 value = row[field.name] |
| bsw@51 | 45 end |
| bsw@75 | 46 slot.put(encode.json(value)) |
| bsw@75 | 47 if i_field < #fields then |
| bsw@75 | 48 slot.put(",") |
| bsw@75 | 49 end |
| bsw@75 | 50 slot.put("\n") |
| bsw@51 | 51 end |
| bsw@75 | 52 slot.put(" }") |
| bsw@75 | 53 if i_row < #rows then |
| bsw@75 | 54 slot.put(",") |
| bsw@75 | 55 end |
| bsw@75 | 56 slot.put("\n") |
| bsw@51 | 57 end |
| bsw@75 | 58 slot.put("]\n") |
| bsw@51 | 59 end |
| bsw@51 | 60 |
| bsw@51 | 61 function util.autoapi(args) |
| bsw@75 | 62 local relation_name = assert(args.relation_name) |
| bsw@51 | 63 local selector = assert(args.selector) |
| bsw@51 | 64 local fields = assert(args.fields) |
| bsw@51 | 65 local api_engine = assert(args.api_engine) |
| bsw@51 | 66 |
| bsw@51 | 67 selector:reset_fields() |
| bsw@51 | 68 |
| bsw@51 | 69 for i_field, field in ipairs(fields) do |
| bsw@51 | 70 if field.field then |
| bsw@51 | 71 selector:add_field(field.field, field.name) |
| bsw@51 | 72 end |
| bsw@51 | 73 end |
| bsw@51 | 74 |
| bsw@51 | 75 if api_engine == "xml" then |
| bsw@51 | 76 util.autoapi_xml{ |
| bsw@75 | 77 relation_name = relation_name, |
| bsw@51 | 78 selector = selector, |
| bsw@51 | 79 fields = fields |
| bsw@51 | 80 } |
| bsw@51 | 81 elseif api_engine == "json" then |
| bsw@51 | 82 util.autoapi_json{ |
| bsw@51 | 83 selector = selector, |
| bsw@51 | 84 fields = fields |
| bsw@51 | 85 } |
| bsw@51 | 86 end |
| bsw@51 | 87 |
| bsw@51 | 88 end |