]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/src/reporter/templates/dashboard.ttk
big ol reporter cleanup for the meeting
[Evergreen.git] / Open-ILS / src / reporter / templates / dashboard.ttk
1 [%
2
3 PROCESS inputs;
4 PROCESS class_manip;
5 PROCESS widget_manip;
6 PROCESS logic_header.ttk;
7
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')
12
13
14 %] <style> table {border-collapse:collapse;}</style> [%
15
16 SWITCH pagetype;
17         CASE 'myreports';
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;
26         CASE;
27                 INCLUDE header.ttk title="Reporter Dashboard";
28                 INCLUDE navbar.ttk + summary;
29 END;
30
31 PROCESS logout.ttk;
32
33 BLOCK summary; 
34         WRAPPER html/table border=0 width='100%';
35                 WRAPPER html/row;
36                         INCLUDE html/cell
37                                 content=link(content='Active reports',href='dashboard?detail=mycompletereports')
38                                 align='center'
39                                 style='border-bottom:1px solid black';
40                 END;
41                 WRAPPER html/row;
42                         WRAPPER html/cell valign='top' style='height:200px';
43                                 INCLUDE my_completed_reports limit=5;
44                         END;
45                 END;
46                 WRAPPER html/row;
47                         INCLUDE html/cell
48                                 content=link(content='Manage scheduled reports',href='dashboard?detail=myreports')
49                                 align='center'
50                                 style='border-bottom:1px solid black';
51                 END;
52                 WRAPPER html/row;
53                         WRAPPER html/cell valign='top' style='height:200px';
54                                 INCLUDE my_scheduled_reports limit=5;
55                         END;
56                 END;
57                 WRAPPER html/row;
58                         INCLUDE html/cell
59                                 colspan=2
60                                 align='center'
61                                 content=link(content='Schedule a new report',href='dashboard?detail=report_template_tree')
62                                 style='border-bottom:1px solid black';
63                 END;
64                 WRAPPER html/row;
65                         WRAPPER html/cell colspan=2 valign='top';
66                                 INCLUDE report_template_tree;
67                                 '<br/><br/><br/>';
68                         END;
69                 END;
70         END;
71 END;
72
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";
76         IF limit > 0;
77                 q = q _ ' LIMIT ' _ limit;
78         END;
79
80         logme(q);
81
82         INCLUDE show_complete_reports;
83
84 END;
85
86 BLOCK my_scheduled_reports;
87         q = "SELECT * FROM reporter.stage3 WHERE owner = " _ user.id() _
88                 " AND runtime > now() ORDER BY runtime";
89         IF limit > 0;
90                 q = q _ ' LIMIT ' _ limit;
91         END;
92
93         logme(q);
94
95         INCLUDE show_reports;
96
97 END;
98
99 BLOCK show_complete_reports;
100         WRAPPER html/table width='100%' class='sortable' id='show_complete_reports';
101                 WRAPPER html/row;
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;';
106                 END;
107                 FOR output = DBI.query(q);
108                         rid = output.stage3;
109
110                         bg='lightblue';
111                         IF loop.count % 2;
112                                 bg='white';
113                         END;
114
115                         report = reports.$rid;
116                         
117                         tid = report.stage2;
118                         template = templates.$tid;
119
120                         p = utils.JSON2perl( report.params );
121                         t = utils.JSON2perl( template.params );
122
123                         state = '<span style="font-weight: bold; background-color: lightgray">Waiting in line...</span>';
124                         
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;
134                         END;
135                         
136                         name_link = link(content=p.reportname,href="stage3?id=$rid#$output.id");
137                         #name_link = t.templatename _ ' :: ' _ name_link;
138                         
139                         WRAPPER html/row;
140                                 INCLUDE html/cell
141                                         width='5%'
142                                         nowrap='nowrap'
143                                         content=state
144                                         col=bg
145                                         style='padding:5px; border:solid gray 1px;';
146                                 INCLUDE html/cell
147                                         content=t.templatename
148                                         col=bg
149                                         style='border:solid gray 1px;';
150                                 INCLUDE html/cell
151                                         content=name_link
152                                         col=bg
153                                         style='border:solid gray 1px;';
154                                 INCLUDE html/cell
155                                         nowrap='nowrap'
156                                         content=runtime.chunk(16).0
157                                         col=bg
158                                         style='border:solid gray 1px;';
159                         END;
160                 END;
161         END;
162 END;
163
164
165 BLOCK show_reports;
166         WRAPPER html/table width='100%' class='sortable' id='show_reports';
167                 WRAPPER html/row;
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;';
174                 END;
175                 FOR report = DBI.query(q);
176                         rid = report.id;
177                         bg='lightblue';
178                         IF loop.count % 2;
179                                 bg='white';
180                         END;
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 = ?';
183
184                         s = DBI.prepare(run_count_q);
185                         run_count = s.execute(rid);
186                         
187                         s = DBI.prepare(run_q);
188                         run = s.execute(rid);
189                         
190                         WRAPPER html/row;
191
192                                 tid = report.stage2;
193                                 template = templates.$tid;
194
195                                 p = utils.JSON2perl( report.params );
196                                 t = utils.JSON2perl( template.params );
197
198
199                                 rtime = report.runtime.chunk(16).0;
200                                 IF report.disable;
201                                         rtime = rtime _ '<br/>(Disabled)';
202                                 END;
203
204                                 name_link = link(content=p.reportname,href="stage3?id=$rid");
205                                 #name_link = t.templatename _ ' :: ' _ name_link;
206
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;';
212                                 INCLUDE html/cell
213                                         nowrap='nowrap'
214                                         content=rtime
215                                         col=bg
216                                         style='text-align: center; border:solid gray 1px;';
217                         END;
218                 END;
219         END;
220 END;
221
222 BLOCK my_templates;
223         q = "SELECT * FROM reporter.stage2 WHERE " _
224                 " owner = " _ user.id() _ " ORDER BY create_date DESC";
225         IF limit > 0;
226                 q = q _ ' LIMIT ' _ limit;
227         END;
228
229         logme(q);
230
231         INCLUDE show_templates;
232
233 END;
234
235 BLOCK public_templates;
236         q = "SELECT * FROM reporter.stage2 WHERE pub is true" _
237                 " and owner != " _ user.id() _ " ORDER BY create_date DESC";
238         IF limit > 0;
239                 q = q _ ' LIMIT ' _ limit;
240         END;
241
242         logme(q);
243
244         INCLUDE show_templates;
245
246 END;
247
248 BLOCK show_templates;
249         WRAPPER html/table width='100%' class='withborder';
250                 WRAPPER html/row;
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;';
254                 END;
255                 FOR template = DBI.query(q);
256                         tid = template.id;
257                         bg='lightblue';
258                         IF loop.count % 2;
259                                 bg='white';
260                         END;
261                         WRAPPER html/row;
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;';
266                         END;
267                 END;
268         END;
269 END;
270
271 BLOCK report_template_tree;
272         
273         fact_table_xpath = "/reporter/tables/table[@fact-table='true']";
274         
275         FOR tab = config.findnodes(fact_table_xpath);
276                 counter = loop.count
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');
285                 </script>";
286
287                 q = "SELECT * FROM reporter.stage2 WHERE (pub is true" _
288                         " or owner = " _ user.id() _ ") and stage1 = '$tid' ORDER BY create_date DESC";
289
290                 FOR template = DBI.query(q);
291                         p = utils.JSON2perl( template.params );
292                         s2id = template.id;
293                         "<script language='javascript'>
294                                 tree_" _ counter _ ".addNode(
295                                         $template.id,
296                                         $counter,
297                                         '$p.templatename',
298                                         'stage2?action=run&id=$s2id',
299                                         '$p.templatename'
300                                 );
301                         </script>";
302
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 );
307                                 s3id = report.id;
308                                 "<script language='javascript'>
309                                         tree_" _ counter _ ".addNode(
310                                                 'r_$report.id',
311                                                 $template.id,
312                                                 '$p.reportname',
313                                                 'stage2?action=edit&id=$s2id&report=$s3id',
314                                                 '$p.reportname'
315                                         );
316                                 </script>";
317                         END;
318
319                 END;
320         END;
321 END;
322
323 %]