2 var OILS_RPT_TRANSFORMS = {
22 label : 'Count Distinct'
35 /* string transforms ------------------------- */
37 /* XXX not supported yet
39 datatype : OILS_RPT_DTYPE_STRING,
45 datatype : [OILS_RPT_DTYPE_STRING, 'text'],
50 datatype : [OILS_RPT_DTYPE_STRING, 'text'],
54 /* timestamp transforms ----------------------- */
56 datatype : OILS_RPT_DTYPE_TIMESTAMP,
57 label : 'Day of Week',
61 datatype : OILS_RPT_DTYPE_TIMESTAMP,
62 label : 'Day of Month',
63 regex : /^[0-9]{1,2}$/
67 datatype : OILS_RPT_DTYPE_TIMESTAMP,
68 label : 'Day of Year',
69 regex : /^[0-9]{1,3}$/
73 datatype : OILS_RPT_DTYPE_TIMESTAMP,
74 label : 'Week of Year',
75 regex : /^[0-9]{1,2}$/
79 datatype : OILS_RPT_DTYPE_TIMESTAMP,
80 label : 'Month of Year',
85 datatype : OILS_RPT_DTYPE_TIMESTAMP,
86 label : 'Quarter of Year',
91 datatype : OILS_RPT_DTYPE_TIMESTAMP,
92 label : 'Hour of day',
97 datatype : OILS_RPT_DTYPE_TIMESTAMP,
99 regex : /^\d{4}-\d{2}-\d{2}$/,
101 cal_format : '%Y-%m-%d',
106 datatype : OILS_RPT_DTYPE_TIMESTAMP,
107 label : 'Year + Month',
108 regex : /^\d{4}-\d{2}$/,
110 cal_format : '%Y-%m',
115 datatype : OILS_RPT_DTYPE_TIMESTAMP,
124 datatype : OILS_RPT_DTYPE_TIMESTAMP,
133 datatype : OILS_RPT_DTYPE_TIMESTAMP,
138 datatype : OILS_RPT_DTYPE_TIMESTAMP,
142 datatype : OILS_RPT_DTYPE_TIMESTAMP,
147 datatype : OILS_RPT_DTYPE_TIMESTAMP,
152 datatype : OILS_RPT_DTYPE_TIMESTAMP,
153 label : 'Quarters ago'
156 /* int / float transforms ----------------------------------- */
158 datatype : [ OILS_RPT_DTYPE_INT, OILS_RPT_DTYPE_FLOAT ],
164 datatype : [ OILS_RPT_DTYPE_INT, OILS_RPT_DTYPE_FLOAT ],
170 datatype : [ OILS_RPT_DTYPE_INT, OILS_RPT_DTYPE_FLOAT ],
175 datatype : OILS_RPT_DTYPE_FLOAT,
176 label : 'Drop trailing decimals'
181 function oilsRptGetTforms(args) {
182 var dtype = args.datatype;
183 var agg = args.aggregate;
184 var tforms = OILS_RPT_TRANSFORMS;
185 var nonagg = args.non_aggregate;
187 var keys = oilsRptObjectKeys(OILS_RPT_TRANSFORMS);
190 _debug('getting tform '+dtype+' : ' + agg + ' : ' + nonagg);
192 for( var i = 0; i < keys.length; i++ ) {
194 var obj = OILS_RPT_TRANSFORMS[key];
195 if( dtype && !oilsRptTformIsDtype(key,dtype) ) continue;
196 if( agg && !nonagg && !obj.aggregate ) continue;
197 if( !agg && nonagg && obj.aggregate ) continue;
205 function oilsRptTformIsDtype(tform, dtype) {
206 var obj = OILS_RPT_TRANSFORMS[tform];
207 if( typeof obj.datatype == 'string' )
208 return (obj.datatype == dtype);
209 return !obj.datatype || grep(obj.datatype, function(d) { return (d == dtype) });
215 /* builds a new transform picker */
216 function oilsRptTformPicker(args) {
217 this.node = args.node;
218 this.selector = elem('select');
219 this.tforms = oilsRptGetTforms(args);
220 for( var i = 0; i < this.tforms.length; i++ )
221 this.addOpt(this.tforms[i], this.tforms[i] == args.select );
222 appendClear(this.node, this.selector);
225 oilsRptTformPicker.prototype.addOpt = function(key, select) {
226 var tform = OILS_RPT_TRANSFORMS[key];
228 var opt = insertSelectorVal(this.selector, -1, tform.label, key);
229 if( select ) opt.selected = true;
232 oilsRptTformPicker.prototype.getSelected = function(key) {
233 return getSelectorVal(this.selector);