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',
79 regex : /^[0-9]{1,2}$/
83 datatype : OILS_RPT_DTYPE_TIMESTAMP,
84 label : 'Quarter of Year',
89 datatype : OILS_RPT_DTYPE_TIMESTAMP,
91 regex : /^\d{4}-\d{2}-\d{2}$/,
93 cal_format : '%Y-%m-%d',
98 datatype : OILS_RPT_DTYPE_TIMESTAMP,
99 label : 'Year + Month',
100 regex : /^\d{4}-\d{2}$/,
102 cal_format : '%Y-%m',
107 datatype : OILS_RPT_DTYPE_TIMESTAMP,
116 datatype : OILS_RPT_DTYPE_TIMESTAMP,
121 datatype : OILS_RPT_DTYPE_TIMESTAMP,
125 datatype : OILS_RPT_DTYPE_TIMESTAMP,
130 datatype : OILS_RPT_DTYPE_TIMESTAMP,
131 label : 'Relative year'
135 datatype : OILS_RPT_DTYPE_TIMESTAMP,
136 label : 'Relative month'
140 datatype : OILS_RPT_DTYPE_TIMESTAMP,
141 label : 'Relative week'
145 datatype : OILS_RPT_DTYPE_TIMESTAMP,
146 label : 'Relative date'
149 /* int / float transforms ----------------------------------- */
151 datatype : [ OILS_RPT_DTYPE_INT, OILS_RPT_DTYPE_FLOAT ],
157 datatype : [ OILS_RPT_DTYPE_INT, OILS_RPT_DTYPE_FLOAT ],
163 datatype : [ OILS_RPT_DTYPE_INT, OILS_RPT_DTYPE_FLOAT ],
168 datatype : OILS_RPT_DTYPE_FLOAT,
169 label : 'Drop trailing decimals'
174 function oilsRptGetTforms(args) {
175 var dtype = args.datatype;
176 var agg = args.aggregate;
177 var tforms = OILS_RPT_TRANSFORMS;
178 var nonagg = args.non_aggregate;
180 var keys = oilsRptObjectKeys(OILS_RPT_TRANSFORMS);
183 _debug('getting tform '+dtype+' : ' + agg + ' : ' + nonagg);
185 for( var i = 0; i < keys.length; i++ ) {
187 var obj = OILS_RPT_TRANSFORMS[key];
188 if( dtype && !oilsRptTformIsDtype(key,dtype) ) continue;
189 if( agg && !nonagg && !obj.aggregate ) continue;
190 if( !agg && nonagg && obj.aggregate ) continue;
198 function oilsRptTformIsDtype(tform, dtype) {
199 var obj = OILS_RPT_TRANSFORMS[tform];
200 if( typeof obj.datatype == 'string' )
201 return (obj.datatype == dtype);
202 return !obj.datatype || grep(obj.datatype, function(d) { return (d == dtype) });
208 /* builds a new transform picker */
209 function oilsRptTformPicker(args) {
210 this.node = args.node;
211 this.selector = elem('select');
212 this.tforms = oilsRptGetTforms(args);
213 for( var i = 0; i < this.tforms.length; i++ )
214 this.addOpt(this.tforms[i]);
215 appendClear(this.node, this.selector);
218 oilsRptTformPicker.prototype.addOpt = function(key) {
219 var tform = OILS_RPT_TRANSFORMS[key];
221 insertSelectorVal(this.selector, -1, tform.label, key);
224 oilsRptTformPicker.prototype.getSelected = function(key) {
225 return getSelectorVal(this.selector);