]> git.evergreen-ils.org Git - working/Evergreen.git/blob - Open-ILS/src/reporter/templates/dashboard.ttk
show template name as "parent" of report in "My Completed Reports"
[working/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 -- Completed 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                                 colspan=2
38                                 align='center'
39                                 content=link(content='Schedule a new report',href='bradboard?detail=report_template_tree')
40                                 style='border-bottom:1px solid black';
41                 END;
42                 WRAPPER html/row;
43                         WRAPPER html/cell colspan=2 valign='top';
44                                 INCLUDE report_template_tree;
45                                 '<br/><br/><br/>';
46                         END;
47                 END;
48                 WRAPPER html/row;
49                         INCLUDE html/cell
50                                 content=link(content='Completed reports',href='bradboard?detail=mycompletereports')
51                                 align='center'
52                                 style='border-bottom:1px solid black';
53                 END;
54                 WRAPPER html/row;
55                         WRAPPER html/cell valign='top' style='height:200px';
56                                 INCLUDE my_completed_reports limit=5;
57                         END;
58                 END;
59                 WRAPPER html/row;
60                         INCLUDE html/cell
61                                 content=link(content='Manage scheduled reports',href='bradboard?detail=myreports')
62                                 align='center'
63                                 style='border-bottom:1px solid black';
64                 END;
65                 WRAPPER html/row;
66                         WRAPPER html/cell valign='top' style='height:200px';
67                                 INCLUDE my_scheduled_reports limit=5;
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 DESC";
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%';
101                 WRAPPER html/row;
102                         INCLUDE html/cell content='Run status' nowrap='nowrap' col='lightgray' style='border:solid gray 1px;';
103                         INCLUDE html/cell content='Report name' nowrap='nowrap' col='lightgray' style='border:solid gray 1px;';
104                         INCLUDE html/cell content='Run time' nowrap='nowrap' col='lightgray' style='border:solid gray 1px;';
105                 END;
106                 FOR output = DBI.query(q);
107                         rid = output.stage3;
108
109                         bg='lightblue';
110                         IF loop.count % 2;
111                                 bg='white';
112                         END;
113
114                         report = reports.$rid;
115                         
116                         tid = report.stage2;
117                         template = templates.$tid;
118
119                         p = utils.JSON2perl( report.params );
120                         t = utils.JSON2perl( template.params );
121
122                         state = '<span style="font-weight: bold; background-color: lightgray">Waiting in line...</span>';
123                         
124                         IF output.state == 'complete';
125                                 state = '<span style="font-weight: bold; background-color: lightgreen">Complete</span>';
126                                 runtime = output.complete_time;
127                         ELSIF output.state == 'error';
128                                 state = '<span style="font-weight: bold; background-color: lightred">ERROR</span>';
129                                 runtime = output.error_time;
130                         ELSIF output.state == 'running';
131                                 state = '<span style="font-weight: bold; background-color: lightblue">Running</span>';
132                                 runtime = output.run_time;
133                         END;
134                         
135                         name_link = link(content=p.reportname,href="stage3?id=$rid#$output.id");
136                         name_link = t.templatename _ ' :: ' _ name_link;
137                         
138                         WRAPPER html/row;
139                                 INCLUDE html/cell
140                                         width='5%'
141                                         nowrap='nowrap'
142                                         content=state
143                                         col=bg
144                                         style='padding:5px; border:solid gray 1px;';
145                                 INCLUDE html/cell
146                                         content=name_link
147                                         col=bg
148                                         style='border:solid gray 1px;';
149                                 INCLUDE html/cell
150                                         nowrap='nowrap'
151                                         content=runtime.chunk(19).0
152                                         col=bg
153                                         style='border:solid gray 1px;';
154                         END;
155                 END;
156         END;
157 END;
158
159
160 BLOCK show_reports;
161         WRAPPER html/table width='100%';
162                 WRAPPER html/row;
163                         INCLUDE html/cell content='Public' nowrap='nowrap' col='lightgray' style='border:solid gray 1px;';
164                         INCLUDE html/cell content='Report name' nowrap='nowrap' col='lightgray' style='border:solid gray 1px;';
165                         INCLUDE html/cell content='Create date and time' nowrap='nowrap' col='lightgray' style='border:solid gray 1px;';
166                         INCLUDE html/cell content='Scheduled run time' nowrap='nowrap' col='lightgray' style='border:solid gray 1px;';
167                         INCLUDE html/cell content='Number of runs' nowrap='nowrap' col='lightgray' style='border:solid gray 1px;';
168                 END;
169                 FOR report = DBI.query(q);
170                         rid = report.id;
171                         bg='lightblue';
172                         IF loop.count % 2;
173                                 bg='white';
174                         END;
175                         run_q = 'SELECT * FROM reporter.output WHERE stage3 = ? ORDER BY queue_time LIMIT 1';
176                         run_count_q = 'SELECT count(*) as count FROM reporter.output WHERE stage3 = ?';
177
178                         s = DBI.prepare(run_count_q);
179                         run_count = s.execute(rid);
180                         
181                         s = DBI.prepare(run_q);
182                         run = s.execute(rid);
183                         
184                         WRAPPER html/row;
185                                 p = utils.JSON2perl( report.params );
186                                 INCLUDE html/cell content=(report.pub ? 'Y' : 'N') col=bg style='border:solid gray 1px;' align='center';
187                                 INCLUDE html/cell content=link(content=p.reportname,href="stage3?id=$rid") col=bg style='border:solid gray 1px;';
188                                 INCLUDE html/cell nowrap='nowrap' content=report.create_date.chunk(19).0 col=bg style='border:solid gray 1px;';
189                                 INCLUDE html/cell
190                                         nowrap='nowrap'
191                                         content=report.runtime.chunk(19).0
192                                         col=bg
193                                         style='border:solid gray 1px;';
194                                 INCLUDE html/cell content=run_count.get.count col=bg style='border:solid gray 1px;';
195                         END;
196                 END;
197         END;
198 END;
199
200 BLOCK my_templates;
201         q = "SELECT * FROM reporter.stage2 WHERE " _
202                 " owner = " _ user.id() _ " ORDER BY create_date DESC";
203         IF limit > 0;
204                 q = q _ ' LIMIT ' _ limit;
205         END;
206
207         logme(q);
208
209         INCLUDE show_templates;
210
211 END;
212
213 BLOCK public_templates;
214         q = "SELECT * FROM reporter.stage2 WHERE pub is true" _
215                 " and owner != " _ user.id() _ " ORDER BY create_date DESC";
216         IF limit > 0;
217                 q = q _ ' LIMIT ' _ limit;
218         END;
219
220         logme(q);
221
222         INCLUDE show_templates;
223
224 END;
225
226 BLOCK show_templates;
227         WRAPPER html/table width='100%' class='withborder';
228                 WRAPPER html/row;
229                         INCLUDE html/cell content='Public' nowrap='nowrap' col='lightgray' style='border:solid gray 1px;';
230                         INCLUDE html/cell content='Template Name' nowrap='nowrap' col='lightgray' style='border:solid gray 1px;';
231                         INCLUDE html/cell content='Created at' nowrap='nowrap' col='lightgray' style='border:solid gray 1px;';
232                 END;
233                 FOR template = DBI.query(q);
234                         tid = template.id;
235                         bg='lightblue';
236                         IF loop.count % 2;
237                                 bg='white';
238                         END;
239                         WRAPPER html/row;
240                                 p = utils.JSON2perl( template.params );
241                                 INCLUDE html/cell content=(template.pub ? 'Y' : 'N') col=bg style='border:solid gray 1px;' align='center';
242                                 INCLUDE html/cell content=link(content=p.templatename,href="stage2?id=$tid") col=bg style='border:solid gray 1px;';
243                                 INCLUDE html/cell content=template.create_date.chunk(10).0 col=bg style='border:solid gray 1px;';
244                         END;
245                 END;
246         END;
247 END;
248
249 BLOCK report_template_tree;
250         
251         fact_table_xpath = "/reporter/tables/table[@fact-table='true']";
252         
253         FOR tab = config.findnodes(fact_table_xpath);
254                 counter = loop.count
255                 tid = tab.findvalue('@id');
256                 tname = tab.findvalue('label');
257                 tdesc = tab.findvalue('description');
258                 "<div id='fact_tree_$counter'/>";
259                 content=link(content=tab.findvalue('label'),href="stage1?id=$tid") style='border:solid gray 1px;';
260                 "<script language='javascript'>
261                         var tree_$counter = new SlimTree(document.getElementById('fact_tree_$counter'),'tree_$counter');
262                         tree_" _ counter _ ".addNode($counter,-1,'$tname','stage1?create_stage2=1&id=$tid','$tdesc');
263                 </script>";
264
265                 q = "SELECT * FROM reporter.stage2 WHERE (pub is true" _
266                         " or owner = " _ user.id() _ ") and stage1 = '$tid' ORDER BY create_date DESC";
267
268                 FOR template = DBI.query(q);
269                         p = utils.JSON2perl( template.params );
270                         s2id = template.id;
271                         "<script language='javascript'>
272                                 tree_" _ counter _ ".addNode(
273                                         $template.id,
274                                         $counter,
275                                         '$p.templatename',
276                                         'stage2?action=run&id=$s2id',
277                                         '$p.templatename'
278                                 );
279                         </script>";
280                 END;
281         END;
282 END;
283
284 %]