2 var OILS_RPT_TRANSFORMS = {
22 label : 'Count Distinct'
35 /* string transforms ------------------------- */
38 datatype : OILS_RPT_DTYPE_STRING,
43 datatype : OILS_RPT_DTYPE_STRING,
48 datatype : OILS_RPT_DTYPE_STRING,
52 /* timestamp transforms ----------------------- */
54 datatype : OILS_RPT_DTYPE_TIMESTAMP,
55 label : 'Day of Week',
59 datatype : OILS_RPT_DTYPE_TIMESTAMP,
60 label : 'Day of Month',
61 regex : /^[0-9]{1,2}$/
65 datatype : OILS_RPT_DTYPE_TIMESTAMP,
66 label : 'Day of Year',
67 regex : /^[0-9]{1,3}$/
71 datatype : OILS_RPT_DTYPE_TIMESTAMP,
72 label : 'Week of Year',
73 regex : /^[0-9]{1,2}$/
77 datatype : OILS_RPT_DTYPE_TIMESTAMP,
78 label : 'Month of Year',
83 datatype : OILS_RPT_DTYPE_TIMESTAMP,
84 label : 'Quarter of Year',
89 datatype : OILS_RPT_DTYPE_TIMESTAMP,
90 label : 'Hour of day',
95 datatype : OILS_RPT_DTYPE_TIMESTAMP,
97 regex : /^\d{4}-\d{2}-\d{2}$/,
99 cal_format : '%Y-%m-%d',
104 datatype : OILS_RPT_DTYPE_TIMESTAMP,
105 label : 'Year + Month',
106 regex : /^\d{4}-\d{2}$/,
108 cal_format : '%Y-%m',
113 datatype : OILS_RPT_DTYPE_TIMESTAMP,
122 datatype : OILS_RPT_DTYPE_TIMESTAMP,
131 datatype : OILS_RPT_DTYPE_TIMESTAMP,
136 datatype : OILS_RPT_DTYPE_TIMESTAMP,
140 datatype : OILS_RPT_DTYPE_TIMESTAMP,
146 datatype : OILS_RPT_DTYPE_TIMESTAMP,
147 label : 'Relative year'
151 datatype : OILS_RPT_DTYPE_TIMESTAMP,
152 label : 'Relative month'
156 datatype : OILS_RPT_DTYPE_TIMESTAMP,
157 label : 'Relative week'
161 datatype : OILS_RPT_DTYPE_TIMESTAMP,
162 label : 'Relative date'
168 datatype : OILS_RPT_DTYPE_TIMESTAMP,
174 datatype : OILS_RPT_DTYPE_TIMESTAMP,
179 datatype : OILS_RPT_DTYPE_TIMESTAMP,
180 label : 'Quarters ago'
186 datatype : OILS_RPT_DTYPE_TIMESTAMP,
192 /* int / float transforms ----------------------------------- */
194 datatype : [ OILS_RPT_DTYPE_INT, OILS_RPT_DTYPE_FLOAT ],
200 datatype : [ OILS_RPT_DTYPE_INT, OILS_RPT_DTYPE_FLOAT ],
206 datatype : [ OILS_RPT_DTYPE_INT, OILS_RPT_DTYPE_FLOAT ],
211 datatype : OILS_RPT_DTYPE_FLOAT,
212 label : 'Drop trailing decimals'
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;
223 var keys = oilsRptObjectKeys(OILS_RPT_TRANSFORMS);
226 _debug('getting tform '+dtype+' : ' + agg + ' : ' + nonagg);
228 for( var i = 0; i < keys.length; 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;
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) });
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);
261 oilsRptTformPicker.prototype.addOpt = function(key) {
262 var tform = OILS_RPT_TRANSFORMS[key];
264 insertSelectorVal(this.selector, -1, tform.label, key);
267 oilsRptTformPicker.prototype.getSelected = function(key) {
268 return getSelectorVal(this.selector);