6 PROCESS logic_header.ttk;
8 pagetype = CGI.param('detail');
9 templates = DBI.tie('reporter.stage2', 'id')
10 reports = DBI.tie('reporter.stage3', 'id')
11 outputs = DBI.tie('reporter.output', 'id')
14 %] <style> table {border-collapse:collapse;}</style> [%
18 INCLUDE header.ttk title="Reporter Dashboard -- Scheduled Reports";
19 INCLUDE navbar.ttk + my_scheduled_reports;
20 CASE 'mycompletereports';
21 INCLUDE header.ttk title="Reporter Dashboard -- Active Reports";
22 INCLUDE navbar.ttk + my_completed_reports;
23 CASE 'report_template_tree';
24 INCLUDE header.ttk title="Reporter Dashboard -- Schedule a report";
25 INCLUDE navbar.ttk + report_template_tree;
27 INCLUDE header.ttk title="Reporter Dashboard";
28 INCLUDE navbar.ttk + summary;
34 WRAPPER html/table border=0 width='100%';
37 content=link(content='Active reports',href='dashboard?detail=mycompletereports')
39 style='border-bottom:1px solid black';
42 WRAPPER html/cell valign='top' style='height:200px';
43 INCLUDE my_completed_reports limit=5;
48 content=link(content='Manage scheduled reports',href='dashboard?detail=myreports')
50 style='border-bottom:1px solid black';
53 WRAPPER html/cell valign='top' style='height:200px';
54 INCLUDE my_scheduled_reports limit=5;
61 content=link(content='Schedule a new report',href='dashboard?detail=report_template_tree')
62 style='border-bottom:1px solid black';
65 WRAPPER html/cell colspan=2 valign='top';
66 INCLUDE report_template_tree;
73 BLOCK my_completed_reports;
74 q = "SELECT o.* FROM reporter.stage3 s JOIN reporter.output o ON (o.stage3 = s.id) WHERE s.owner = " _ user.id() _
75 " ORDER BY COALESCE(o.complete_time, o.error_time, o.run_time, o.queue_time) DESC";
77 q = q _ ' LIMIT ' _ limit;
82 INCLUDE show_complete_reports;
86 BLOCK my_scheduled_reports;
87 q = "SELECT * FROM reporter.stage3 WHERE owner = " _ user.id() _
88 " AND runtime > now() ORDER BY runtime";
90 q = q _ ' LIMIT ' _ limit;
99 BLOCK show_complete_reports;
100 WRAPPER html/table width='100%' class='sortable' id='show_complete_reports';
102 INCLUDE html/cell content='Status' nowrap='nowrap' col='lightgray' style='border:solid gray 1px;';
103 INCLUDE html/cell content='Base Template' nowrap='nowrap' col='lightgray' style='border:solid gray 1px;';
104 INCLUDE html/cell content='Report Defintion' nowrap='nowrap' col='lightgray' style='border:solid gray 1px;';
105 INCLUDE html/cell content='Last Action Time' nowrap='nowrap' col='lightgray' style='border:solid gray 1px;';
107 FOR output = DBI.query(q);
115 report = reports.$rid;
118 template = templates.$tid;
120 p = utils.JSON2perl( report.params );
121 t = utils.JSON2perl( template.params );
123 state = '<span style="font-weight: bold; background-color: lightgray">Waiting in line...</span>';
125 IF output.state == 'complete';
126 state = '<span style="font-weight: bold; background-color: lightgreen">Complete</span>';
127 runtime = output.complete_time;
128 ELSIF output.state == 'error';
129 state = '<span style="font-weight: bold; background-color: lightred">ERROR</span>';
130 runtime = output.error_time;
131 ELSIF output.state == 'running';
132 state = '<span style="font-weight: bold; background-color: lightblue">Running</span>';
133 runtime = output.run_time;
136 name_link = link(content=p.reportname,href="stage3?id=$rid#$output.id");
137 #name_link = t.templatename _ ' :: ' _ name_link;
145 style='padding:5px; border:solid gray 1px;';
147 content=t.templatename
149 style='border:solid gray 1px;';
153 style='border:solid gray 1px;';
156 content=runtime.chunk(16).0
158 style='border:solid gray 1px;';
166 WRAPPER html/table width='100%' class='sortable' id='show_reports';
168 INCLUDE html/cell content='Runs' nowrap='nowrap' col='lightgray' style='border:solid gray 1px;';
169 INCLUDE html/cell content='Public' nowrap='nowrap' col='lightgray' style='border:solid gray 1px;';
170 INCLUDE html/cell content='Base Template' nowrap='nowrap' col='lightgray' style='border:solid gray 1px;';
171 INCLUDE html/cell content='Report Definition' nowrap='nowrap' col='lightgray' style='border:solid gray 1px;';
172 #INCLUDE html/cell content='Create date' nowrap='nowrap' col='lightgray' style='border:solid gray 1px;';
173 INCLUDE html/cell content='Scheduled Run Time' nowrap='nowrap' col='lightgray' style='border:solid gray 1px;';
175 FOR report = DBI.query(q);
181 run_q = 'SELECT * FROM reporter.output WHERE stage3 = ? ORDER BY queue_time LIMIT 1';
182 run_count_q = 'SELECT count(*) as count FROM reporter.output WHERE stage3 = ?';
184 s = DBI.prepare(run_count_q);
185 run_count = s.execute(rid);
187 s = DBI.prepare(run_q);
188 run = s.execute(rid);
193 template = templates.$tid;
195 p = utils.JSON2perl( report.params );
196 t = utils.JSON2perl( template.params );
199 rtime = report.runtime.chunk(16).0;
201 rtime = rtime _ '<br/>(Disabled)';
204 name_link = link(content=p.reportname,href="stage3?id=$rid");
205 #name_link = t.templatename _ ' :: ' _ name_link;
207 INCLUDE html/cell content=run_count.get.count col=bg style='text-align: center; border:solid gray 1px;';
208 INCLUDE html/cell content=(report.pub ? 'Y' : 'N') col=bg style='border:solid gray 1px;' align='center';
209 INCLUDE html/cell content=t.templatename col=bg style='border:solid gray 1px;';
210 INCLUDE html/cell content=name_link col=bg style='border:solid gray 1px;';
211 #INCLUDE html/cell nowrap='nowrap' content=report.create_date.chunk(16).0 col=bg style='border:solid gray 1px;';
216 style='text-align: center; border:solid gray 1px;';
223 q = "SELECT * FROM reporter.stage2 WHERE " _
224 " owner = " _ user.id() _ " ORDER BY create_date DESC";
226 q = q _ ' LIMIT ' _ limit;
231 INCLUDE show_templates;
235 BLOCK public_templates;
236 q = "SELECT * FROM reporter.stage2 WHERE pub is true" _
237 " and owner != " _ user.id() _ " ORDER BY create_date DESC";
239 q = q _ ' LIMIT ' _ limit;
244 INCLUDE show_templates;
248 BLOCK show_templates;
249 WRAPPER html/table width='100%' class='withborder';
251 INCLUDE html/cell content='Public' nowrap='nowrap' col='lightgray' style='border:solid gray 1px;';
252 INCLUDE html/cell content='Template Name' nowrap='nowrap' col='lightgray' style='border:solid gray 1px;';
253 INCLUDE html/cell content='Created at' nowrap='nowrap' col='lightgray' style='border:solid gray 1px;';
255 FOR template = DBI.query(q);
262 p = utils.JSON2perl( template.params );
263 INCLUDE html/cell content=(template.pub ? 'Y' : 'N') col=bg style='border:solid gray 1px;' align='center';
264 INCLUDE html/cell content=link(content=p.templatename,href="stage2?id=$tid") col=bg style='border:solid gray 1px;';
265 INCLUDE html/cell content=template.create_date.chunk(10).0 col=bg style='border:solid gray 1px;';
271 BLOCK report_template_tree;
273 fact_table_xpath = "/reporter/tables/table[@fact-table='true']";
275 FOR tab = config.findnodes(fact_table_xpath);
277 tid = tab.findvalue('@id');
278 tname = tab.findvalue('label');
279 tdesc = tab.findvalue('description');
280 "<div id='fact_tree_$counter'/>";
281 content=link(content=tab.findvalue('label'),href="stage1?id=$tid") style='border:solid gray 1px;';
282 "<script language='javascript'>
283 var tree_$counter = new SlimTree(document.getElementById('fact_tree_$counter'),'tree_$counter');
284 tree_" _ counter _ ".addNode($counter,-1,'$tname','stage1?create_stage2=1&id=$tid','$tdesc');
287 q = "SELECT * FROM reporter.stage2 WHERE (pub is true" _
288 " or owner = " _ user.id() _ ") and stage1 = '$tid' ORDER BY create_date DESC";
290 FOR template = DBI.query(q);
291 p = utils.JSON2perl( template.params );
293 "<script language='javascript'>
294 tree_" _ counter _ ".addNode(
298 'stage2?action=run&id=$s2id',
303 q3 = "SELECT * FROM reporter.stage3 WHERE (pub is true" _
304 " or owner = " _ user.id() _ ") and stage2 = '$s2id' ORDER BY create_date DESC";
305 FOR report = DBI.query(q3);
306 p = utils.JSON2perl( report.params );
308 "<script language='javascript'>
309 tree_" _ counter _ ".addNode(
313 'stage2?action=edit&id=$s2id&report=$s3id',