]> git.evergreen-ils.org Git - working/Evergreen.git/blob - Open-ILS/web/reports/oils_rpt_tforms.js
more widget work
[working/Evergreen.git] / Open-ILS / web / reports / oils_rpt_tforms.js
1
2 var OILS_RPT_TRANSFORMS = {
3         Bare : {
4                 label : 'Raw Data'
5         },
6
7         first : {
8                 label : 'First Value'
9         },
10
11         last : {
12                 label : 'Last Value'
13         },
14
15         count : {
16                 aggregate : true,
17                 label :  'Count'
18         },
19
20         count_distinct : {
21                 aggregate : true,
22                 label : 'Count Distinct'
23         },
24
25         min : {
26                 aggregate : true,
27                 label : 'Min'
28         },
29
30         max : {
31                 aggregate : true,
32                 label : 'Max'
33         },
34
35         /* string transforms ------------------------- */
36
37         substring : {
38                 datatype : OILS_RPT_DTYPE_STRING,
39                 label : 'Substring'
40         },
41
42         lower : {
43                 datatype : OILS_RPT_DTYPE_STRING,
44                 label : 'Lower case'
45         },
46
47         upper : {
48                 datatype : OILS_RPT_DTYPE_STRING,
49                 label : 'Upper case'
50         },
51
52         /* timestamp transforms ----------------------- */
53         dow : {
54                 datatype : OILS_RPT_DTYPE_TIMESTAMP,
55                 label : 'Day of Week',
56                 regex : /^[0-6]$/
57         },
58         dom : {
59                 datatype : OILS_RPT_DTYPE_TIMESTAMP,
60                 label : 'Day of Month',
61                 regex : /^[0-9]{1,2}$/
62         },
63
64         doy : {
65                 datatype : OILS_RPT_DTYPE_TIMESTAMP,
66                 label : 'Day of Year',
67                 regex : /^[0-9]{1,3}$/
68         },
69
70         woy : {
71                 datatype : OILS_RPT_DTYPE_TIMESTAMP,
72                 label : 'Week of Year',
73                 regex : /^[0-9]{1,2}$/
74         },
75
76         moy : {
77                 datatype : OILS_RPT_DTYPE_TIMESTAMP,
78                 label : 'Month of Year',
79                 regex : /^\d{1,2}$/
80         },
81
82         qoy : {
83                 datatype : OILS_RPT_DTYPE_TIMESTAMP,
84                 label : 'Quarter of Year',
85                 regex : /^[1234]$/
86         }, 
87
88         hod : {
89                 datatype : OILS_RPT_DTYPE_TIMESTAMP,
90                 label : 'Hour of day',
91                 regex : /^\d{1,2}$/
92         }, 
93
94         date : {
95                 datatype : OILS_RPT_DTYPE_TIMESTAMP,
96                 label : 'Date',
97                 regex : /^\d{4}-\d{2}-\d{2}$/,
98                 hint  : 'YYYY-MM-DD',
99                 cal_format : '%Y-%m-%d',
100                 input_size : 10
101         },
102
103         month_trunc : {
104                 datatype : OILS_RPT_DTYPE_TIMESTAMP,
105                 label : 'Year + Month',
106                 regex : /^\d{4}-\d{2}$/,
107                 hint  : 'YYYY-MM',
108                 cal_format : '%Y-%m',
109                 input_size : 7
110         },
111
112         year_trunc : {
113                 datatype : OILS_RPT_DTYPE_TIMESTAMP,
114                 label : 'Year',
115                 regex : /^\d{4}$/,
116                 hint  : 'YYYY',
117                 cal_format : '%Y',
118                 input_size : 4
119         },
120
121         hour_trunc : {
122                 datatype : OILS_RPT_DTYPE_TIMESTAMP,
123                 label : 'Hour',
124                 regex : /^\d{2}$/,
125                 hint  : 'HH',
126                 cal_format : '%H',
127                 input_size : 2
128         },
129
130         day_name : {
131                 datatype : OILS_RPT_DTYPE_TIMESTAMP,
132                 label : 'Day Name'
133         }, 
134
135         month_name : {
136                 datatype : OILS_RPT_DTYPE_TIMESTAMP,
137                 label : 'Month Name'
138         },
139         age : {
140                 datatype : OILS_RPT_DTYPE_TIMESTAMP,
141                 label : 'Age'
142         },
143
144         /*
145         relative_year : {
146                 datatype : OILS_RPT_DTYPE_TIMESTAMP,
147                 label : 'Relative year'
148         },
149
150         relative_month : {
151                 datatype : OILS_RPT_DTYPE_TIMESTAMP,
152                 label : 'Relative month'
153         },
154
155         relative_week : {
156                 datatype : OILS_RPT_DTYPE_TIMESTAMP,
157                 label : 'Relative week'
158         },
159
160         relative_date : {
161                 datatype : OILS_RPT_DTYPE_TIMESTAMP,
162                 label : 'Relative date'
163         },
164         */
165
166         /* exists?
167         days_ago : {
168                 datatype : OILS_RPT_DTYPE_TIMESTAMP,
169                 label : 'Days ago'
170         }
171         */
172
173         months_ago : {
174                 datatype : OILS_RPT_DTYPE_TIMESTAMP,
175                 label : 'Months ago'
176         },
177
178         quarters_ago : {
179                 datatype : OILS_RPT_DTYPE_TIMESTAMP,
180                 label : 'Quarters ago'
181         },
182
183
184         /* exists?
185         years_ago : {
186                 datatype : OILS_RPT_DTYPE_TIMESTAMP,
187                 label : 'Years ago'
188         },
189         */
190
191
192         /* int  / float transforms ----------------------------------- */
193         sum : {
194                 datatype : [ OILS_RPT_DTYPE_INT, OILS_RPT_DTYPE_FLOAT ],
195                 label : 'Sum',
196                 aggregate : true
197         }, 
198
199         average : {
200                 datatype : [ OILS_RPT_DTYPE_INT, OILS_RPT_DTYPE_FLOAT ],
201                 label : 'Average',
202                 aggregate : true
203         },
204
205         round : {
206                 datatype : [ OILS_RPT_DTYPE_INT, OILS_RPT_DTYPE_FLOAT ],
207                 label : 'Round',
208         },
209
210         'int' : {
211                 datatype : OILS_RPT_DTYPE_FLOAT,
212                 label : 'Drop trailing decimals'
213         }
214 }
215
216
217 function oilsRptGetTforms(args) {
218         var dtype = args.datatype;
219         var agg = args.aggregate;
220         var tforms = OILS_RPT_TRANSFORMS;
221         var nonagg = args.non_aggregate;
222
223         var keys = oilsRptObjectKeys(OILS_RPT_TRANSFORMS);
224         var tforms = [];
225
226         _debug('getting tform '+dtype+' : ' + agg + ' : ' + nonagg);
227
228         for( var i = 0; i < keys.length; i++ ) {
229                 var key = keys[i];
230                 var obj = OILS_RPT_TRANSFORMS[key];
231                 if( dtype && !oilsRptTformIsDtype(key,dtype) ) continue;
232                 if( agg && !nonagg && !obj.aggregate ) continue;
233                 if( !agg && nonagg && obj.aggregate ) continue;
234                 tforms.push(key);
235         }
236
237         return tforms;
238 }
239
240
241 function oilsRptTformIsDtype(tform, dtype) {
242         var obj = OILS_RPT_TRANSFORMS[tform];
243         if( typeof obj.datatype == 'string' )
244                 return (obj.datatype == dtype);
245         return !obj.datatype || grep(obj.datatype, function(d) { return (d == dtype) });
246 }
247
248
249
250
251 /* builds a new transform picker */
252 function oilsRptTformPicker(args) {
253         this.node = args.node;
254         this.selector = elem('select');
255         this.tforms = oilsRptGetTforms(args);
256         for( var i = 0; i < this.tforms.length; i++ ) 
257                 this.addOpt(this.tforms[i]);
258         appendClear(this.node, this.selector);
259 }
260
261 oilsRptTformPicker.prototype.addOpt = function(key) {
262         var tform = OILS_RPT_TRANSFORMS[key];           
263         var obj = this;
264         insertSelectorVal(this.selector, -1, tform.label, key);
265 }
266
267 oilsRptTformPicker.prototype.getSelected = function(key) {
268         return getSelectorVal(this.selector);
269 }
270
271
272