]> git.evergreen-ils.org Git - working/Evergreen.git/blob - Open-ILS/web/reports/oils_rpt_tforms.js
added relative tforms to tform set, some small tweaks, beginnings of potential altern...
[working/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         substring : {
38                 datatype : OILS_RPT_DTYPE_STRING,
39                 label : 'Substring'
40         },
41
42         lower : {
43                 datatype : OILS_RPT_DTYPE_STRING,
44                 label : 'Lower case'
45         },
46
47         upper : {
48                 datatype : OILS_RPT_DTYPE_STRING,
49                 label : 'Upper case'
50         },
51
52         /* timestamp transforms ----------------------- */
53         dow : {
54                 datatype : OILS_RPT_DTYPE_TIMESTAMP,
55                 label : 'Day of Week',
56                 regex : /^[0-6]$/
57         },
58         dom : {
59                 datatype : OILS_RPT_DTYPE_TIMESTAMP,
60                 label : 'Day of Month',
61                 regex : /^[0-9]{1,2}$/
62         },
63
64         doy : {
65                 datatype : OILS_RPT_DTYPE_TIMESTAMP,
66                 label : 'Day of Year',
67                 regex : /^[0-9]{1,3}$/
68         },
69
70         woy : {
71                 datatype : OILS_RPT_DTYPE_TIMESTAMP,
72                 label : 'Week of Year',
73                 regex : /^[0-9]{1,2}$/
74         },
75
76         moy : {
77                 datatype : OILS_RPT_DTYPE_TIMESTAMP,
78                 label : 'Month of Year',
79                 regex : /^[0-9]{1,2}$/
80         },
81
82         qoy : {
83                 datatype : OILS_RPT_DTYPE_TIMESTAMP,
84                 label : 'Quarter of Year',
85                 regex : /^[1234]$/
86         }, 
87
88         date : {
89                 datatype : OILS_RPT_DTYPE_TIMESTAMP,
90                 label : 'Date',
91                 regex : /^\d{4}-\d{2}-\d{2}$/,
92                 hint  : 'YYYY-MM-DD',
93                 cal_format : '%Y-%m-%d'
94         },
95
96         month_trunc : {
97                 datatype : OILS_RPT_DTYPE_TIMESTAMP,
98                 label : 'Year + Month',
99                 regex : /^\d{4}-\d{2}$/,
100                 hint  : 'YYYY-MM',
101                 cal_format : '%Y-%m'
102         },
103
104         year_trunc : {
105                 datatype : OILS_RPT_DTYPE_TIMESTAMP,
106                 label : 'Year',
107                 regex : /^\d{4}$/,
108                 hint  : 'YYYY',
109                 cal_format : '%Y'
110         },
111
112         day_name : {
113                 datatype : OILS_RPT_DTYPE_TIMESTAMP,
114                 label : 'Day Name'
115         }, 
116
117         month_name : {
118                 datatype : OILS_RPT_DTYPE_TIMESTAMP,
119                 label : 'Month Name'
120         },
121         age : {
122                 datatype : OILS_RPT_DTYPE_TIMESTAMP,
123                 label : 'Age'
124         },
125
126         relative_year : {
127                 datatype : OILS_RPT_DTYPE_TIMESTAMP,
128                 label : 'Relative year'
129         },
130
131         relative_month : {
132                 datatype : OILS_RPT_DTYPE_TIMESTAMP,
133                 label : 'Relative month'
134         },
135
136         relative_week : {
137                 datatype : OILS_RPT_DTYPE_TIMESTAMP,
138                 label : 'Relative week'
139         },
140
141         relative_date : {
142                 datatype : OILS_RPT_DTYPE_TIMESTAMP,
143                 label : 'Relative date'
144         },
145
146         /* int  / float transforms ----------------------------------- */
147         sum : {
148                 datatype : [ OILS_RPT_DTYPE_INT, OILS_RPT_DTYPE_FLOAT ],
149                 label : 'Sum',
150                 aggregate : true
151         }, 
152
153         average : {
154                 datatype : [ OILS_RPT_DTYPE_INT, OILS_RPT_DTYPE_FLOAT ],
155                 label : 'Average',
156                 aggregate : true
157         },
158
159         round : {
160                 datatype : [ OILS_RPT_DTYPE_INT, OILS_RPT_DTYPE_FLOAT ],
161                 label : 'Round',
162         },
163
164         'int' : {
165                 datatype : OILS_RPT_DTYPE_FLOAT,
166                 label : 'Drop trailing decimals'
167         }
168 }
169
170
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;
176
177         var keys = oilsRptObjectKeys(OILS_RPT_TRANSFORMS);
178         var tforms = [];
179
180         _debug('getting tform '+dtype+' : ' + agg + ' : ' + nonagg);
181
182         for( var i = 0; i < keys.length; i++ ) {
183                 var key = keys[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;
188                 tforms.push(key);
189         }
190
191         return tforms;
192 }
193
194
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) });
200 }
201
202
203
204
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);
213 }
214
215 oilsRptTformPicker.prototype.addOpt = function(key) {
216         var tform = OILS_RPT_TRANSFORMS[key];           
217         var obj = this;
218         insertSelectorVal(this.selector, -1, tform.label, key);
219 }
220
221 oilsRptTformPicker.prototype.getSelected = function(key) {
222         return getSelectorVal(this.selector);
223 }
224
225
226