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'],
55 datatype : [OILS_RPT_DTYPE_STRING, 'text'],
56 label : 'First 5 characters (for US ZIP code)'
60 datatype : [OILS_RPT_DTYPE_STRING, 'text'],
61 label : 'First contiguous non-space string'
64 /* timestamp transforms ----------------------- */
66 datatype : OILS_RPT_DTYPE_TIMESTAMP,
67 label : 'Day of Week',
71 datatype : OILS_RPT_DTYPE_TIMESTAMP,
72 label : 'Day of Month',
73 regex : /^[0-9]{1,2}$/
77 datatype : OILS_RPT_DTYPE_TIMESTAMP,
78 label : 'Day of Year',
79 regex : /^[0-9]{1,3}$/
83 datatype : OILS_RPT_DTYPE_TIMESTAMP,
84 label : 'Week of Year',
85 regex : /^[0-9]{1,2}$/
89 datatype : OILS_RPT_DTYPE_TIMESTAMP,
90 label : 'Month of Year',
95 datatype : OILS_RPT_DTYPE_TIMESTAMP,
96 label : 'Quarter of Year',
101 datatype : OILS_RPT_DTYPE_TIMESTAMP,
102 label : 'Hour of day',
107 datatype : OILS_RPT_DTYPE_TIMESTAMP,
109 regex : /^\d{4}-\d{2}-\d{2}$/,
111 cal_format : '%Y-%m-%d',
116 datatype : OILS_RPT_DTYPE_TIMESTAMP,
117 label : 'Year + Month',
118 regex : /^\d{4}-\d{2}$/,
120 cal_format : '%Y-%m',
125 datatype : OILS_RPT_DTYPE_TIMESTAMP,
134 datatype : OILS_RPT_DTYPE_TIMESTAMP,
143 datatype : OILS_RPT_DTYPE_TIMESTAMP,
148 datatype : OILS_RPT_DTYPE_TIMESTAMP,
152 datatype : OILS_RPT_DTYPE_TIMESTAMP,
157 datatype : OILS_RPT_DTYPE_TIMESTAMP,
162 datatype : OILS_RPT_DTYPE_TIMESTAMP,
163 label : 'Quarters ago'
166 /* int / float transforms ----------------------------------- */
168 datatype : [ OILS_RPT_DTYPE_INT, OILS_RPT_DTYPE_FLOAT ],
174 datatype : [ OILS_RPT_DTYPE_INT, OILS_RPT_DTYPE_FLOAT ],
180 datatype : [ OILS_RPT_DTYPE_INT, OILS_RPT_DTYPE_FLOAT ],
185 datatype : OILS_RPT_DTYPE_FLOAT,
186 label : 'Drop trailing decimals'
191 function oilsRptGetTforms(args) {
192 var dtype = args.datatype;
193 var agg = args.aggregate;
194 var tforms = OILS_RPT_TRANSFORMS;
195 var nonagg = args.non_aggregate;
197 var keys = oilsRptObjectKeys(OILS_RPT_TRANSFORMS);
200 _debug('getting tform '+dtype+' : ' + agg + ' : ' + nonagg);
202 for( var i = 0; i < keys.length; i++ ) {
204 var obj = OILS_RPT_TRANSFORMS[key];
205 if( dtype && !oilsRptTformIsDtype(key,dtype) ) continue;
206 if( agg && !nonagg && !obj.aggregate ) continue;
207 if( !agg && nonagg && obj.aggregate ) continue;
215 function oilsRptTformIsDtype(tform, dtype) {
216 var obj = OILS_RPT_TRANSFORMS[tform];
217 if( typeof obj.datatype == 'string' )
218 return (obj.datatype == dtype);
219 return !obj.datatype || grep(obj.datatype, function(d) { return (d == dtype) });
225 /* builds a new transform picker */
226 function oilsRptTformPicker(args) {
227 this.node = args.node;
228 this.selector = elem('select');
229 this.tforms = oilsRptGetTforms(args);
230 for( var i = 0; i < this.tforms.length; i++ )
231 this.addOpt(this.tforms[i], this.tforms[i] == args.select );
232 appendClear(this.node, this.selector);
235 oilsRptTformPicker.prototype.addOpt = function(key, select) {
236 var tform = OILS_RPT_TRANSFORMS[key];
238 var opt = insertSelectorVal(this.selector, -1, tform.label, key);
239 if( select ) opt.selected = true;
242 oilsRptTformPicker.prototype.getSelected = function(key) {
243 return getSelectorVal(this.selector);