]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/src/reporter/templates/dashboard.ttk
6cc22336535db56366a145937217083209e76aad
[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
187                                 rtime = report.runtime.chunk(19).0;
188                                 IF report.disable;
189                                         rtime = rtime _ '<br/>(Disabled)';
190                                 END;
191
192                                 INCLUDE html/cell content=(report.pub ? 'Y' : 'N') col=bg style='border:solid gray 1px;' align='center';
193                                 INCLUDE html/cell content=link(content=p.reportname,href="stage3?id=$rid") col=bg style='border:solid gray 1px;';
194                                 INCLUDE html/cell nowrap='nowrap' content=report.create_date.chunk(19).0 col=bg style='border:solid gray 1px;';
195                                 INCLUDE html/cell
196                                         nowrap='nowrap'
197                                         content=rtime
198                                         col=bg
199                                         style='border:solid gray 1px;';
200                                 INCLUDE html/cell content=run_count.get.count col=bg style='border:solid gray 1px;';
201                         END;
202                 END;
203         END;
204 END;
205
206 BLOCK my_templates;
207         q = "SELECT * FROM reporter.stage2 WHERE " _
208                 " owner = " _ user.id() _ " ORDER BY create_date DESC";
209         IF limit > 0;
210                 q = q _ ' LIMIT ' _ limit;
211         END;
212
213         logme(q);
214
215         INCLUDE show_templates;
216
217 END;
218
219 BLOCK public_templates;
220         q = "SELECT * FROM reporter.stage2 WHERE pub is true" _
221                 " and owner != " _ user.id() _ " ORDER BY create_date DESC";
222         IF limit > 0;
223                 q = q _ ' LIMIT ' _ limit;
224         END;
225
226         logme(q);
227
228         INCLUDE show_templates;
229
230 END;
231
232 BLOCK show_templates;
233         WRAPPER html/table width='100%' class='withborder';
234                 WRAPPER html/row;
235                         INCLUDE html/cell content='Public' nowrap='nowrap' col='lightgray' style='border:solid gray 1px;';
236                         INCLUDE html/cell content='Template Name' nowrap='nowrap' col='lightgray' style='border:solid gray 1px;';
237                         INCLUDE html/cell content='Created at' nowrap='nowrap' col='lightgray' style='border:solid gray 1px;';
238                 END;
239                 FOR template = DBI.query(q);
240                         tid = template.id;
241                         bg='lightblue';
242                         IF loop.count % 2;
243                                 bg='white';
244                         END;
245                         WRAPPER html/row;
246                                 p = utils.JSON2perl( template.params );
247                                 INCLUDE html/cell content=(template.pub ? 'Y' : 'N') col=bg style='border:solid gray 1px;' align='center';
248                                 INCLUDE html/cell content=link(content=p.templatename,href="stage2?id=$tid") col=bg style='border:solid gray 1px;';
249                                 INCLUDE html/cell content=template.create_date.chunk(10).0 col=bg style='border:solid gray 1px;';
250                         END;
251                 END;
252         END;
253 END;
254
255 BLOCK report_template_tree;
256         
257         fact_table_xpath = "/reporter/tables/table[@fact-table='true']";
258         
259         FOR tab = config.findnodes(fact_table_xpath);
260                 counter = loop.count
261                 tid = tab.findvalue('@id');
262                 tname = tab.findvalue('label');
263                 tdesc = tab.findvalue('description');
264                 "<div id='fact_tree_$counter'/>";
265                 content=link(content=tab.findvalue('label'),href="stage1?id=$tid") style='border:solid gray 1px;';
266                 "<script language='javascript'>
267                         var tree_$counter = new SlimTree(document.getElementById('fact_tree_$counter'),'tree_$counter');
268                         tree_" _ counter _ ".addNode($counter,-1,'$tname','stage1?create_stage2=1&id=$tid','$tdesc');
269                 </script>";
270
271                 q = "SELECT * FROM reporter.stage2 WHERE (pub is true" _
272                         " or owner = " _ user.id() _ ") and stage1 = '$tid' ORDER BY create_date DESC";
273
274                 FOR template = DBI.query(q);
275                         p = utils.JSON2perl( template.params );
276                         s2id = template.id;
277                         "<script language='javascript'>
278                                 tree_" _ counter _ ".addNode(
279                                         $template.id,
280                                         $counter,
281                                         '$p.templatename',
282                                         'stage2?action=run&id=$s2id',
283                                         '$p.templatename'
284                                 );
285                         </script>";
286                 END;
287         END;
288 END;
289
290 %]