webmcp

view framework/env/trace/_render_sub_tree.lua @ 65:a54cc7dcabf1

"extos" library calls via "extos." instead of "os."
author jbe
date Tue Apr 17 15:20:42 2012 +0200 (2012-04-17)
parents 3c12e7dd93e0
children 0de41d8e2cf8
line source
1 local function open(class)
2 slot.put('<li class="trace_' .. class .. '">')
3 end
4 local function open_head()
5 slot.put('<div class="trace_head">')
6 end
7 local function close_head()
8 slot.put('</div>')
9 end
10 local function close()
11 slot.put('</li>')
12 end
13 function trace._render_sub_tree(node)
14 local function render_children(tail)
15 if #node > 0 then
16 slot.put('<ul class="trace_list">')
17 for idx, child in ipairs(node) do
18 trace._render_sub_tree(child)
19 end
20 if tail then
21 slot.put(tail)
22 end
23 slot.put("</ul>")
24 end
25 end
26 local function close_with_children()
27 close_head()
28 render_children()
29 close()
30 end
31 local node_type = node.type
32 if node_type == "root" then
33 render_children()
34 elseif node_type == "debug" then
35 open("debug")
36 slot.put(encode.html(node.message))
37 close()
38 elseif node_type == "debug_table" then
39 open("debug")
40 slot.put("<table>")
41 if type(node.message) == "table" then
42 for k, v in pairs(node.message) do
43 slot.put("<tr><td>", encode.html(tostring(k)), "</td><td>", encode.html(tostring(v)), "</td></tr>")
44 end
45 slot.put("</table>")
46 else
47 slot.put("debug_table: not of table type")
48 end
49 close()
50 elseif node_type == "traceback" then
51 open("debug")
52 slot.put('<pre>')
53 slot.put(encode.html(node.message))
54 slot.put('</pre>')
55 close()
56 elseif node_type == "request" then
57 open("request")
58 open_head()
59 slot.put("REQUESTED")
60 if node.view then
61 slot.put(" VIEW")
62 elseif node.action then
63 slot.put(" ACTION")
64 end
65 slot.put(
66 ": ",
67 encode.html(node.module),
68 "/",
69 encode.html(node.view or node.action)
70 )
71 close_with_children()
72 elseif node_type == "config" then
73 open("config")
74 open_head()
75 slot.put('Configuration "', encode.html(node.name), '"')
76 close_with_children()
77 elseif node_type == "filter" then
78 open("filter")
79 open_head()
80 slot.put(encode.html(node.path))
81 close_with_children()
82 elseif node_type == "view" then
83 open("view")
84 open_head()
85 slot.put(
86 "EXECUTE VIEW: ",
87 encode.html(node.module),
88 "/",
89 encode.html(node.view)
90 )
91 close_with_children()
92 elseif node_type == "action" then
93 if
94 node.status and (
95 node.status == "ok" or
96 string.find(node.status, "^ok_")
97 )
98 then
99 open("action_success")
100 elseif
101 node.status and (
102 node.status == "error" or
103 string.find(node.status, "^error_")
104 )
105 then
106 open("action_softfail")
107 else
108 open("action_neutral")
109 end
110 open_head()
111 slot.put(
112 "EXECUTE ACTION: ",
113 encode.html(node.module),
114 "/",
115 encode.html(node.action)
116 )
117 close_head()
118 if node.status == "softfail" then
119 render_children(
120 '<li class="trace_action_status">Status code: "' ..
121 encode.html(node.failure_code) ..
122 '"</li>'
123 )
124 else
125 render_children()
126 end
127 close()
128 elseif node_type == "redirect" then
129 open("redirect")
130 open_head()
131 slot.put("303 REDIRECT TO VIEW: ", encode.html(node.module), "/", encode.html(node.view))
132 close_with_children()
133 elseif node_type == "forward" then
134 open("forward")
135 open_head()
136 slot.put("INTERNAL FORWARD TO VIEW: ", encode.html(node.module), "/", encode.html(node.view))
137 close_with_children()
138 elseif node_type == "exectime" then
139 open("exectime")
140 open_head()
141 slot.put(
142 "Finished after " ..
143 string.format("%.1f", extos.monotonic_hires_time() * 1000) ..
144 ' ms (' ..
145 string.format("%.1f", os.clock() * 1000) ..
146 ' ms CPU)'
147 )
148 close_with_children()
149 elseif node_type == "sql" then
150 open("sql")
151 if node.error_position then
152 -- error position starts counting with 1
153 local part1 = string.sub(node.command, 1, node.error_position - 1)
154 --local part2 = string.sub(node.command, node.error_position - 1, node.error_position + 1)
155 local part2 = string.sub(node.command, node.error_position)
156 slot.put(encode.html(part1))
157 slot.put('<span class="trace_error_position">&rArr;</span>')
158 slot.put(encode.html(part2))
159 --slot.put('</span>')
160 --slot.put(encode.html(part3))
161 else
162 slot.put(encode.html(node.command))
163 end
164 close();
165 elseif node_type == "error" then
166 open("error")
167 open_head()
168 slot.put("UNEXPECTED ERROR")
169 close_head()
170 close()
171 end
172 end

Impressum / About Us