]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/web/reports/oils_rpt_tforms.js
added bucket id entry field for exporting buckets by id. put some borders in to...
[Evergreen.git] / Open-ILS / web / reports / oils_rpt_tforms.js
1
2 var OILS_RPT_TRANSFORMS = {
3         Bare : {
4                 label : 'Raw Data'
5         },
6
7         first : {
8                 label : 'First Value'
9         },
10
11         last : {
12                 label : 'Last Value'
13         },
14
15         count : {
16                 aggregate : true,
17                 label :  'Count'
18         },
19
20         count_distinct : {
21                 aggregate : true,
22                 label : 'Count Distinct'
23         },
24
25         min : {
26                 aggregate : true,
27                 label : 'Min'
28         },
29
30         max : {
31                 aggregate : true,
32                 label : 'Max'
33         },
34
35         /* string transforms ------------------------- */
36
37    /* XXX not supported yet
38         substring : {
39                 datatype : OILS_RPT_DTYPE_STRING,
40                 label : 'Substring'
41         },
42    */
43
44         lower : {
45                 datatype : [OILS_RPT_DTYPE_STRING, 'text'],
46                 label : 'Lower case'
47         },
48
49         upper : {
50                 datatype : [OILS_RPT_DTYPE_STRING, 'text'],
51                 label : 'Upper case'
52         },
53
54         first5 : {
55                 datatype : [OILS_RPT_DTYPE_STRING, 'text'],
56                 label : 'First 5 characters (for US ZIP code)'
57         },
58
59         first_word : {
60                 datatype : [OILS_RPT_DTYPE_STRING, 'text'],
61                 label : 'First contiguous non-space string'
62         },
63
64         /* timestamp transforms ----------------------- */
65         dow : {
66                 datatype : OILS_RPT_DTYPE_TIMESTAMP,
67                 label : 'Day of Week',
68                 regex : /^[0-6]$/
69         },
70         dom : {
71                 datatype : OILS_RPT_DTYPE_TIMESTAMP,
72                 label : 'Day of Month',
73                 regex : /^[0-9]{1,2}$/
74         },
75
76         doy : {
77                 datatype : OILS_RPT_DTYPE_TIMESTAMP,
78                 label : 'Day of Year',
79                 regex : /^[0-9]{1,3}$/
80         },
81
82         woy : {
83                 datatype : OILS_RPT_DTYPE_TIMESTAMP,
84                 label : 'Week of Year',
85                 regex : /^[0-9]{1,2}$/
86         },
87
88         moy : {
89                 datatype : OILS_RPT_DTYPE_TIMESTAMP,
90                 label : 'Month of Year',
91                 regex : /^\d{1,2}$/
92         },
93
94         qoy : {
95                 datatype : OILS_RPT_DTYPE_TIMESTAMP,
96                 label : 'Quarter of Year',
97                 regex : /^[1234]$/
98         }, 
99
100         hod : {
101                 datatype : OILS_RPT_DTYPE_TIMESTAMP,
102                 label : 'Hour of day',
103                 regex : /^\d{1,2}$/
104         }, 
105
106         date : {
107                 datatype : OILS_RPT_DTYPE_TIMESTAMP,
108                 label : 'Date',
109                 regex : /^\d{4}-\d{2}-\d{2}$/,
110                 hint  : 'YYYY-MM-DD',
111                 cal_format : '%Y-%m-%d',
112                 input_size : 10
113         },
114
115         month_trunc : {
116                 datatype : OILS_RPT_DTYPE_TIMESTAMP,
117                 label : 'Year + Month',
118                 regex : /^\d{4}-\d{2}$/,
119                 hint  : 'YYYY-MM',
120                 cal_format : '%Y-%m',
121                 input_size : 7
122         },
123
124         year_trunc : {
125                 datatype : OILS_RPT_DTYPE_TIMESTAMP,
126                 label : 'Year',
127                 regex : /^\d{4}$/,
128                 hint  : 'YYYY',
129                 cal_format : '%Y',
130                 input_size : 4
131         },
132
133         hour_trunc : {
134                 datatype : OILS_RPT_DTYPE_TIMESTAMP,
135                 label : 'Hour',
136                 regex : /^\d{2}$/,
137                 hint  : 'HH',
138                 cal_format : '%H',
139                 input_size : 2
140         },
141
142         day_name : {
143                 datatype : OILS_RPT_DTYPE_TIMESTAMP,
144                 label : 'Day Name'
145         }, 
146
147         month_name : {
148                 datatype : OILS_RPT_DTYPE_TIMESTAMP,
149                 label : 'Month Name'
150         },
151         age : {
152                 datatype : OILS_RPT_DTYPE_TIMESTAMP,
153                 label : 'Age'
154         },
155
156         months_ago : {
157                 datatype : OILS_RPT_DTYPE_TIMESTAMP,
158                 label : 'Months ago'
159         },
160
161         quarters_ago : {
162                 datatype : OILS_RPT_DTYPE_TIMESTAMP,
163                 label : 'Quarters ago'
164         },
165
166         /* int  / float transforms ----------------------------------- */
167         sum : {
168                 datatype : [ OILS_RPT_DTYPE_INT, OILS_RPT_DTYPE_FLOAT ],
169                 label : 'Sum',
170                 aggregate : true
171         }, 
172
173         average : {
174                 datatype : [ OILS_RPT_DTYPE_INT, OILS_RPT_DTYPE_FLOAT ],
175                 label : 'Average',
176                 aggregate : true
177         },
178
179         round : {
180                 datatype : [ OILS_RPT_DTYPE_INT, OILS_RPT_DTYPE_FLOAT ],
181                 label : 'Round',
182         },
183
184         'int' : {
185                 datatype : OILS_RPT_DTYPE_FLOAT,
186                 label : 'Drop trailing decimals'
187         }
188 }
189
190
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;
196
197         var keys = oilsRptObjectKeys(OILS_RPT_TRANSFORMS);
198         var tforms = [];
199
200         _debug('getting tform '+dtype+' : ' + agg + ' : ' + nonagg);
201
202         for( var i = 0; i < keys.length; i++ ) {
203                 var key = keys[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;
208                 tforms.push(key);
209         }
210
211         return tforms;
212 }
213
214
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) });
220 }
221
222
223
224
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);
233 }
234
235 oilsRptTformPicker.prototype.addOpt = function(key, select) {
236         var tform = OILS_RPT_TRANSFORMS[key];           
237         var obj = this;
238         var opt = insertSelectorVal(this.selector, -1, tform.label, key);
239         if( select ) opt.selected = true;
240 }
241
242 oilsRptTformPicker.prototype.getSelected = function(key) {
243         return getSelectorVal(this.selector);
244 }
245
246
247