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