]> git.evergreen-ils.org Git - working/Evergreen.git/blob - Open-ILS/src/reporter/templates/class_manip
adding/comitting miker's work
[working/Evergreen.git] / Open-ILS / src / reporter / templates / class_manip
1 [%
2
3 PROCESS inputs;
4
5 dtype_xforms = {
6         'avg'           => {
7                 'name'  => 'Average per group',
8                 'select'        => 'AVG(?COLNAME?)',
9                 'group' => 0 },
10         'stddev'        => {
11                 'label' => 'Standard Deviation per group',
12                 'select'        => 'STDDEV(?COLNAME?)',
13                 'group' => 0 },
14         'sum'           => {
15                 'label' => 'Sum per group',
16                 'select'        => 'SUM(?COLNAME?)',
17                 'group' => 0 },
18         'count'         => {
19                 'label' => 'Count per group',
20                 'select'        => 'COUNT(?COLNAME?)',
21                 'group' => 0 },
22         'count_dist'            => {
23                 'label' => 'Distinct Count per group',
24                 'select'        => 'COUNT(DISTINCT ?COLNAME?)',
25                 'group' => 0 },
26         'lower'         => {
27                 'label' => 'Transform string to lower case',
28                 'select'        => 'LOWER(?COLNAME?)',
29                 'group' => 1 },
30         'upper'         => {
31                 'label' => 'Transform string to upper case',
32                 'select'        => 'UPPER(?COLNAME?)',
33                 'group' => 1 },
34         'substr'                => {
35                 'label' => 'Trim string length',
36                 'select'        => 'substr(?COLNAME?,1,?PARAM?)',
37                 'param' => 1,
38                 'group' => 1 },
39         'age'           => {
40                 'label' => 'Age as of runtime -- day granularity',
41                 'select'        => 'AGE(?COLNAME?::DATE)',
42                 'group' => 1 },
43         'dateformat'            => { # see http://www.postgresql.org/docs/8.0/interactive/functions-formatting.html
44                 'label' => 'Format date and time',
45                 'select'        => 'TO_CHAR(?COLNAME?,?PARAM?)',
46                 'param' => 1,
47                 'group' => 1 },
48         'numformat'             => { # see http://www.postgresql.org/docs/8.0/interactive/functions-formatting.html
49                 'label' => 'Format Numeric data',
50                 'select'        => 'TO_CHAR(?COLNAME?,?PARAM?)',
51                 'param' => 1,
52                 'group' => 1 },
53 };
54
55 dtype_xform_map = {
56         'int'                   => [ 'avg','stddev','sum','count','count_dist','numformat'], 
57         'numeric'       => [ 'avg','stddev','sum','count','count_dist','numformat'], 
58         'float' => [ 'avg','stddev','sum','count','count_dist','numformat'], 
59         'time'  => [ 'count', 'dateformat'], 
60         'date'  => [ 'count', 'age','dateformat'], 
61         'timestamp'     => [ 'count', 'age','dateformat'], 
62         'timestamptz'   => [ 'count', 'age','dateformat'], 
63         'text'  => [ 'count','count_dist','lower','upper','substr'],
64 };
65
66 BLOCK class_table;
67         WRAPPER html/table width='100%' style='border-top: 1px solid black';
68                 WRAPPER html/row;
69                         WRAPPER html/cell align="right" width="30%";
70                                 %]<b>Name:</b>[%
71                         END;
72                         WRAPPER html/cell;
73                                 class.findvalue('label');
74                         END;
75                 END;
76                 WRAPPER html/row;
77                         WRAPPER html/cell align="right";
78                                 %]<b>Description:</b>[%
79                         END;
80                         WRAPPER html/cell;
81                                 class.findvalue('description');
82                         END;
83                 END;
84                 IF class.findvalue('@fact-table') == 'true' AND CGI.param('create_stage2') != 1;
85                         WRAPPER html/row;
86                                 WRAPPER html/cell align="right";
87                                         %]<b>Actions:</b>[%
88                                 END;
89                                 WRAPPER html/cell;
90                                         IF CGI.param('detail');
91                                                 %]<a href="?detail=0&id=[% fact_table %]">No Details</a>[%
92                                         ELSE;
93                                                 %]<a href="?detail=1&id=[% fact_table %]">Details</a>[%
94                                         END;
95                                         %]|<a href="?create_stage2=1&id=[% fact_table %]">New Report Template</a>[%
96                                 END;
97                         END;
98                         WRAPPER html/row;
99                                 INCLUDE html/cell align="right" valign='top' content='<b>Report Templates:</b>';
100                                 WRAPPER html/cell;
101                                         q = 'select * from reporter.stage2 ' _
102                                                 'where pub is true or owner = ' _ DBI.quote(user.id());
103                                         FOR r IN DBI.query(q);
104                                                 INCLUDE anchor
105                                                         href="stage2?id=" _ r.id
106                                                         content=utils.JSON2perl(r.params).templatename;
107                                                         '<br>';
108                                         END;
109                                 END;
110                         END;
111                 END;
112
113                 INCLUDE class_detail IF CGI.param('detail') == 1;
114         END;
115 END; 
116
117
118
119
120
121
122 BLOCK class_fields;
123         FOR f IN class.findnodes('fields/field');
124                 WRAPPER html/row;
125                         WRAPPER html/cell align="right";
126                                 f.findvalue('label');
127                         END;
128                         WRAPPER html/cell;
129                                 %] ([%
130                                 IF f.findvalue('description');
131                                         f.findvalue('description');
132                                         %] -- [%
133                                 END;
134                                 f.findvalue('@name')%]::[%f.findvalue('@datatype') %])[%
135                         END;
136                 END;
137         END;
138 END;
139
140
141
142
143
144
145 BLOCK class_detail;
146
147         INCLUDE class_fields;
148
149         IF class.findvalue('@fact-table') == 'true' AND nosub != 1;
150                 WRAPPER html/row;
151                         WRAPPER html/cell align="right";
152                                 %]<b>Report Dimensions<br>and Attributes:</b>[%
153                         END;
154                         WRAPPER html/cell;
155                                 incs = class.findnodes('links/link/@field');
156
157                                 FOR dim IN incs;
158                                         link_xpath = '/reporter/tables/table[@id="' _ fact_table _'"]'_
159                                                                                 '/links/link[@field="' _ dim.value() _ '"]/@table';
160                                         logme(link_xpath);
161
162                                         dim_table = config.findvalue(link_xpath);
163
164                                         dim_xpath = '/reporter/tables/table[@id="' _ dim_table _ '"]';
165                                         logme(dim_xpath);
166                                                         
167                                         dim_def = config.findnodes(dim_xpath);
168
169                                         INCLUDE class_table class = dim_def;
170                                 END;
171                         END;
172                 END;
173         END;
174 END;
175
176 %]
177