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'
97 datatype : OILS_RPT_DTYPE_TIMESTAMP,
98 label : 'Year + Month',
99 regex : /^\d{4}-\d{2}$/,
105 datatype : OILS_RPT_DTYPE_TIMESTAMP,
113 datatype : OILS_RPT_DTYPE_TIMESTAMP,
118 datatype : OILS_RPT_DTYPE_TIMESTAMP,
122 datatype : OILS_RPT_DTYPE_TIMESTAMP,
127 datatype : OILS_RPT_DTYPE_TIMESTAMP,
128 label : 'Relative year'
132 datatype : OILS_RPT_DTYPE_TIMESTAMP,
133 label : 'Relative month'
137 datatype : OILS_RPT_DTYPE_TIMESTAMP,
138 label : 'Relative week'
142 datatype : OILS_RPT_DTYPE_TIMESTAMP,
143 label : 'Relative date'
146 /* int / float transforms ----------------------------------- */
148 datatype : [ OILS_RPT_DTYPE_INT, OILS_RPT_DTYPE_FLOAT ],
154 datatype : [ OILS_RPT_DTYPE_INT, OILS_RPT_DTYPE_FLOAT ],
160 datatype : [ OILS_RPT_DTYPE_INT, OILS_RPT_DTYPE_FLOAT ],
165 datatype : OILS_RPT_DTYPE_FLOAT,
166 label : 'Drop trailing decimals'
171 function oilsRptGetTforms(args) {
172 var dtype = args.datatype;
173 var agg = args.aggregate;
174 var tforms = OILS_RPT_TRANSFORMS;
175 var nonagg = args.non_aggregate;
177 var keys = oilsRptObjectKeys(OILS_RPT_TRANSFORMS);
180 _debug('getting tform '+dtype+' : ' + agg + ' : ' + nonagg);
182 for( var i = 0; i < keys.length; i++ ) {
184 var obj = OILS_RPT_TRANSFORMS[key];
185 if( dtype && !oilsRptTformIsDtype(key,dtype) ) continue;
186 if( agg && !nonagg && !obj.aggregate ) continue;
187 if( !agg && nonagg && obj.aggregate ) continue;
195 function oilsRptTformIsDtype(tform, dtype) {
196 var obj = OILS_RPT_TRANSFORMS[tform];
197 if( typeof obj.datatype == 'string' )
198 return (obj.datatype == dtype);
199 return !obj.datatype || grep(obj.datatype, function(d) { return (d == dtype) });
205 /* builds a new transform picker */
206 function oilsRptTformPicker(args) {
207 this.node = args.node;
208 this.selector = elem('select');
209 this.tforms = oilsRptGetTforms(args);
210 for( var i = 0; i < this.tforms.length; i++ )
211 this.addOpt(this.tforms[i]);
212 appendClear(this.node, this.selector);
215 oilsRptTformPicker.prototype.addOpt = function(key) {
216 var tform = OILS_RPT_TRANSFORMS[key];
218 insertSelectorVal(this.selector, -1, tform.label, key);
221 oilsRptTformPicker.prototype.getSelected = function(key) {
222 return getSelectorVal(this.selector);