]> git.evergreen-ils.org Git - working/Evergreen.git/blob - Open-ILS/src/reporter/templates/stage1.ttk
removing stage1 reporter xml config
[working/Evergreen.git] / Open-ILS / src / reporter / templates / stage1.ttk
1 [%
2
3 BLOCK logme_block;
4         "\n\t<!-- " _ x _ " -->\n";
5 END;
6
7 MACRO logme(a) PROCESS logme_block x = a.list.join(', ');
8
9 USE CGI;
10 USE DBI;
11 USE WebSession;
12 USE utils = WebUtils;
13 USE config = XML.LibXML(config_xml, expand_xinclude => 1);
14
15 dir = '/reporter/setup/files/' _ stage_dir;
16 dir = config.findvalue(dir);
17
18 dbname = config.findvalue('/reporter/setup/database/name');
19 dbhost = config.findvalue('/reporter/setup/database/host');
20 d_u = config.findvalue('/reporter/setup/database/user');
21 d_p = config.findvalue('/reporter/setup/database/password');
22
23 dsn = "dbi:Pg:dbname=" _ dbname _';host=' _ dbhost;
24
25 logme([dsn,d_u,d_p]);
26         
27 DBI.connect(dsn,d_u,d_p);
28
29
30 WRAPPER html/html;
31         INCLUDE header.ttk title="Basic Report Types";
32         WRAPPER html/body;
33                 INCLUDE logout.ttk;
34                 IF !CGI.param('id');
35                         IF CGI.param('detail');
36                                 %]|<a href="?detail=0">No Details (All)</a>[%
37                         ELSE;
38                                 %]|<a href="?detail=1">Details (All)</a>[%
39                         END;
40                         PROCESS all_stage1;
41                 ELSE;
42                         PROCESS one_stage1;
43                 END;
44         END;
45         INCLUDE footer.ttk;
46 END;
47
48
49
50
51 #=============================================================================
52
53
54 BLOCK one_stage1;
55         %]|<a href="[%
56         CGI.url('-absolute',1,'-path_info',1,'-query',1).replace('[&\?;]?id=[\w\.]+','');
57         %]">Show all</a>[%
58
59         table_xpath =
60                 '/reporter/tables/table[@id="' _
61                 CGI.param('id') _ '"]';
62         table = config.findnodes(table_xpath);
63
64         fact_table = table.findvalue('@id');
65         logme(fact_table);
66
67         INCLUDE stage1_summary;
68         INCLUDE stage2_new IF CGI.param('create_stage2') == 1;
69
70 END;
71
72
73
74
75 BLOCK all_stage1;
76         '<ul>';
77
78         FOR tab IN config.findnodes("//tables/table[@fact-table='true']");
79
80                 fact_table = tab.findvalue("@id");
81                 logme("Fact Table is $fact_table");
82
83                 '<li>';
84
85                 INCLUDE stage1_summary links = 1 table = tab;
86
87                 IF loop.count != loop.size;
88                 '<hr>';
89                 END;
90         END;
91         '</ul>';
92 END;
93
94
95
96
97 BLOCK stage1_summary links=0;
98         fact_table = table.findvalue('@id');
99         WRAPPER html/table width="100%";
100                 WRAPPER html/row;
101                         WRAPPER html/cell align="right";
102                                 %]<b>Name:</b>[%
103                         END;
104                         WRAPPER html/cell;
105                                 table.findvalue('label');
106                         END;
107                 END;
108                 WRAPPER html/row;
109                         WRAPPER html/cell align="right";
110                                 %]<b>Description:</b>[%
111                         END;
112                         WRAPPER html/cell;
113                                 table.findvalue('description');
114                         END;
115                 END;
116                 WRAPPER html/row;
117                         WRAPPER html/cell align="right";
118                                 %]<b>Actions:</b>[%
119                         END;
120                         WRAPPER html/cell;
121                                 IF CGI.param('detail');
122                                         %]<a href="?detail=0&id=[% fact_table %]">No Details</a>[%
123                                 ELSE;
124                                         %]<a href="?detail=1&id=[% fact_table %]">Details</a>[%
125                                 END;
126                                 %]|<a href="?create_stage2=1&id=[% fact_table %]">New Report Template</a>[%
127                         END;
128                 END;
129                 PROCESS stage1_detail IF CGI.param('detail') == 1;
130         END;
131 END;
132
133
134 %][%
135
136 BLOCK stage2_new;
137         col_xpath = "/reporter/tables/table[@id='" _ fact_table _ "']/fields/field[@core='true']";
138         logme(col_xpath);
139
140         WRAPPER html/table width="100%" border=1;
141                 WRAPPER html/row;
142                         WRAPPER html/cell colspan=2;
143                                 # hidden input here ...
144                                 table = config.findnodes("/reporter/tables/table[@id='$fact_table']");
145                                 INCLUDE hidden name="filtertable" value=fact_table;
146                                 table.findvalue('label');
147                                 ' Core Columns';
148                         END;
149                 END;
150                 INCLUDE widget_selector tableid=fact_table columns=config.findnodes(col_xpath) force=1;
151         END;
152
153         dim_xpath = "/reporter/tables/table[@id='$fact_table']/links/link/@table";
154         FOR dim_table IN config.findnodes(dim_xpath);
155                 dim_table = dim_table.value();
156                 dimension = config.findnodes("/reporter/tables/table[@id='$dim_table']");
157
158                 WRAPPER html/table width="100%" border=1;
159                         WRAPPER html/row;
160                                 WRAPPER html/cell colspan=2;
161                                         # checkbox input here ...
162                                         INCLUDE checkbox name="filtertable" value=dim_table checked=1;
163                                         dimension.findvalue('label');
164                                         ' Dimension';
165                                 END;
166                         END;
167                         INCLUDE widget_selector tableid=dim_table;
168                 END;
169         END;
170
171 END;
172
173
174 BLOCK widget_selector;
175
176         logme("widget_selector called for table $tableid");
177
178         #   if we got some columns, use them. if not, get all non-primary columns
179         IF ! columns;
180                 columns_xpath =
181                         '/reporter/tables/table[@id="' _ tableid _
182                         '"]/fields/field[not(@primary) or @primary!="true"]'
183                 columns = config.findnodes(columns_xpath);
184                 logme("widget_selector had to grab columns for table $tableid!");
185         END;
186
187         column_input_type="checkbox";
188         IF force;
189                 column_input_type="hidden";
190         END;
191
192         FOR column IN columns;
193                 column_name=column.findvalue('@name');
194
195                 WRAPPER html/row;
196                         WRAPPER html/cell valign='top';
197                                 # checkbox for column filter here ...
198                                 INCLUDE $column_input_type
199                                         name="filtercolumn:$tableid"
200                                         value=column_name
201                                         checked=1; 
202                                 column.findvalue('label');
203                         END;
204                         WRAPPER html/cell;
205
206                                 col_widget_fams_xpath =
207                                         '/reporter/widgets/widget-family[@datatype="' _
208                                         column.findvalue('@datatype') _ '"]';
209
210                                 IF column.findnodes('@widget-family');
211                                         col_widget_fams_xpath =
212                                                 '/reporter/widgets/widget-family[@name="' _
213                                                 column.findvalue('@widget-family') _ '"]';
214                                 END;
215
216                                 logme("finding widget families using $col_widget_fams_xpath");
217
218                                 widget_fams = config.findnodes(col_widget_fams_xpath);
219
220                                 '<UL>';
221                                 FOR fam IN widget_fams;
222
223                                         fam_input = 'radio';
224                                         IF loop.size == 1;
225                                                 fam_input = 'hidden';
226                                         END;
227
228                                         checked = 0;
229                                         IF loop.count == 1;
230                                                 checked = 1;
231                                         END;
232
233                                         fam_name = fam.findvalue('@name');
234                                         # radio for widget family here ...
235                                         '<LI>';
236                                         INCLUDE $fam_input
237                                                 name="filterfamily:$tableid:$column_name"
238                                                 value= fam_name;
239                                         fam.findvalue('label');
240                                         '<UL>';
241                                         
242                                         FOR widget IN fam.findnodes('widget');
243
244                                                 fam_input = 'radio';
245                                                 IF loop.size == 1;
246                                                         fam_input = 'hidden';
247                                                 END;
248
249                                                 checked = 0;
250                                                 IF loop.count == 1;
251                                                         checked = 1;
252                                                 END;
253
254                                                 widget_name = widget.findvalue('@name');
255                                                 # radio for widget here ...
256                                                 '<LI>';
257                                                 INCLUDE $fam_input
258                                                         name="filter:$tableid:$column_name:$fam_name"
259                                                         value= widget_name;
260                                                 widget.findvalue('label');
261                                                 '</LI>';
262                                         END;
263                                         '</UL>';
264                                         '</LI>';
265                                 END;
266                                 '</UL>';
267                         END;
268                 END;
269         END;
270 END;
271
272
273
274
275
276 %][%
277
278
279
280
281 BLOCK text;
282         %]<INPUT TYPE="text" NAME="[%
283                 name;
284                 %]" VALUE="[%
285                 value;
286                 %]" [%
287                 IF sz;
288                         %]SIZE="[% sz %]" [%
289                 END;
290                 IF mx;
291                         %]MAXLENGTH="[% mx %]" [%
292                 END;
293                 %]>[%
294 END;
295
296 BLOCK textarea;
297         %]<TEXTAREA NAME="[% name %]">[% value %]</TEXTAREA>[%
298 END;
299
300 BLOCK hidden;
301         %]<INPUT TYPE="hidden" NAME="[% name %]" VALUE="[% value %]">[%
302 END;
303
304 BLOCK radio;
305         %]<INPUT TYPE="radio" NAME="[% name %]" VALUE="[% value %]" [% IF checked %]CHECKED[% END %]>[%
306 END;
307
308 BLOCK checkbox;
309         %]<INPUT TYPE="checkbox" NAME="[% name %]" VALUE="[% value %]" [% IF checked %]CHECKED[% END %]>[%
310 END;
311
312
313
314
315 BLOCK render_dimension;
316         INCLUDE checkbox checked = 1 name = 's2_dim_table' value = dim_object.findvalue('@id');
317         %]<b>[% dim_object.findvalue('name') %]</b><br>[%
318         
319         WRAPPER html/table width="100%" ;
320                 WRAPPER html/row;
321                         WRAPPER html/cell align="right";
322                         END;
323                 END;
324         END;
325 END;
326
327
328
329
330
331 BLOCK dim_description;
332         WRAPPER html/row;
333                 WRAPPER html/cell align="right";
334                         %]Name:[%
335                 END;
336                 WRAPPER html/cell;
337                         dim.findvalue('label');
338                 END;
339         END;
340         PROCESS table_fields table = dim;
341 END; 
342
343
344
345
346
347
348 BLOCK table_fields;
349         FOR f IN table.findnodes('fields/field');
350                 WRAPPER html/row;
351                         WRAPPER html/cell align="right";
352                                 %]Field:[%
353                         END;
354                         WRAPPER html/cell;
355                                 f.findvalue('@name');
356                                 %] ([% f.findvalue('@datatype') %])[%
357                         END;
358                 END;
359         END;
360 END;
361
362
363
364
365
366
367 BLOCK stage1_detail;
368         WRAPPER html/row;
369                 WRAPPER html/cell align="right";
370                         %]Visible Stage2 reports:[%
371                 END;
372                 WRAPPER html/cell;
373                         q = 'select count(*) as x from reporter.stage2 ' _
374                                 'where pub is true or owner = ' _ DBI.quote(user.id());
375                         FOR r IN DBI.query(q);
376                                 r.x;
377                         END;
378                 END;
379         END;
380
381         PROCESS table_fields table = config.findnodes("/reporter/tables/table[@id='$fact_table']");
382
383         WRAPPER html/row;
384                 WRAPPER html/cell align="right";
385                         %]Report Attributes<br/>(dimensions):[%
386                 END;
387                 WRAPPER html/cell;
388                         incs_xpath =
389                                 '/reporter/tables/table[@id="' _ fact_table _'"]'_
390                                 '/links/link/@field';
391                         logme(incs_xpath);
392
393                         incs = config.findnodes(incs_xpath);
394
395                         FOR dim IN incs;
396                                 %]<table border=1 width="100%">[%
397
398                                 link_xpath = '/reporter/tables/table[@id="' _ fact_table _'"]'_
399                                                                         '/links/link[@field="' _ dim.value() _ '"]/@table';
400                                 logme(link_xpath);
401
402                                 dim_table = config.findvalue(link_xpath);
403
404                                 dim_xpath = '/reporter/tables/table[@id="' _ dim_table _'"]';
405                                 logme(dim_xpath);
406                                                         
407                                 dim_def = config.findnodes(dim_xpath);
408
409                                 PROCESS dim_description dim = dim_def;
410                                 %]</table>[%
411                         END;
412                 END;
413         END;
414 END;
415
416 %]
417