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