]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/web/reports/oils_rpt_tforms.js
LP1837059 Angular local admin page
[Evergreen.git] / Open-ILS / web / reports / oils_rpt_tforms.js
1 dojo.requireLocalization("openils.reports", "reports");
2
3 var rpt_strings = dojo.i18n.getLocalization("openils.reports", "reports");
4
5
6 var OILS_RPT_TRANSFORMS = {
7         Bare : {
8                 label : rpt_strings.TFORMS_LABEL_RAW_DATA
9         },
10
11         first : {
12                 label : rpt_strings.TFORMS_LABEL_FIRST
13         },
14
15         last : {
16                 label : rpt_strings.TFORMS_LABEL_LAST
17         },
18
19         count : {
20                 aggregate : true,
21                 label :  rpt_strings.TFORMS_LABEL_COUNT
22         },
23
24         count_distinct : {
25                 aggregate : true,
26                 label : rpt_strings.TFORMS_LABEL_COUNT_DISTINCT
27         },
28
29         min : {
30                 aggregate : true,
31                 label : rpt_strings.TFORMS_LABEL_MIN
32         },
33
34         max : {
35                 aggregate : true,
36                 label : rpt_strings.TFORMS_LABEL_MAX
37         },
38
39         /* string transforms ------------------------- */
40
41    /* XXX not supported yet
42         substring : {
43                 datatype : OILS_RPT_DTYPE_STRING,
44                 label : 'Substring'
45         },
46    */
47
48         lower : {
49                 datatype : [OILS_RPT_DTYPE_STRING, 'text'],
50                 label : rpt_strings.TFORMS_LABEL_LOWER
51         },
52
53         upper : {
54                 datatype : [OILS_RPT_DTYPE_STRING, 'text'],
55                 label : rpt_strings.TFORMS_LABEL_UPPER
56         },
57
58         first5 : {
59                 datatype : [OILS_RPT_DTYPE_STRING, 'text'],
60                 label : rpt_strings.TFORMS_LABEL_FIRST5
61         },
62
63         first_word : {
64                 datatype : [OILS_RPT_DTYPE_STRING, 'text'],
65                 label : rpt_strings.TFORMS_LABEL_FIRST_WORD
66         },
67
68         /* timestamp transforms ----------------------- */
69         dow : {
70                 datatype : OILS_RPT_DTYPE_TIMESTAMP,
71                 label : rpt_strings.TFORMS_LABEL_DOW,
72                 regex : /^[0-6]$/
73         },
74         dom : {
75                 datatype : OILS_RPT_DTYPE_TIMESTAMP,
76                 label : rpt_strings.TFORMS_LABEL_DOM,
77                 regex : /^[0-9]{1,2}$/
78         },
79
80         doy : {
81                 datatype : OILS_RPT_DTYPE_TIMESTAMP,
82                 label : rpt_strings.TFORMS_LABEL_DOY,
83                 regex : /^[0-9]{1,3}$/
84         },
85
86         woy : {
87                 datatype : OILS_RPT_DTYPE_TIMESTAMP,
88                 label : rpt_strings.TFORMS_LABEL_WOY,
89                 regex : /^[0-9]{1,2}$/
90         },
91
92         moy : {
93                 datatype : OILS_RPT_DTYPE_TIMESTAMP,
94                 label : rpt_strings.TFORMS_LABEL_MOY,
95                 regex : /^\d{1,2}$/
96         },
97
98         qoy : {
99                 datatype : OILS_RPT_DTYPE_TIMESTAMP,
100                 label : rpt_strings.TFORMS_LABEL_QOY,
101                 regex : /^[1234]$/
102         }, 
103
104         hod : {
105                 datatype : OILS_RPT_DTYPE_TIMESTAMP,
106                 label : rpt_strings.TFORMS_LABEL_HOD,
107                 regex : /^\d{1,2}$/
108         }, 
109
110         date : {
111                 datatype : OILS_RPT_DTYPE_TIMESTAMP,
112                 label : rpt_strings.TFORMS_LABEL_DATE,
113                 regex : /^\d{4}-\d{2}-\d{2}$/,
114                 hint  : 'YYYY-MM-DD',
115                 cal_format : '%Y-%m-%d',
116                 input_size : 10
117         },
118
119         month_trunc : {
120                 datatype : OILS_RPT_DTYPE_TIMESTAMP,
121                 label : rpt_strings.TFORMS_LABEL_MONTH_TRUNC,
122                 regex : /^\d{4}-\d{2}$/,
123                 hint  : 'YYYY-MM',
124                 cal_format : '%Y-%m',
125                 input_size : 7
126         },
127
128         year_trunc : {
129                 datatype : OILS_RPT_DTYPE_TIMESTAMP,
130                 label : rpt_strings.TFORMS_LABEL_YEAR_TRUNC,
131                 regex : /^\d{4}$/,
132                 hint  : 'YYYY',
133                 cal_format : '%Y',
134                 input_size : 4
135         },
136
137         hour_trunc : {
138                 datatype : OILS_RPT_DTYPE_TIMESTAMP,
139                 label : rpt_strings.TFORMS_LABEL_HOUR_TRUNC,
140                 regex : /^\d{2}$/,
141                 hint  : 'HH',
142                 cal_format : '%H',
143                 input_size : 2
144         },
145
146         day_name : {
147                 datatype : OILS_RPT_DTYPE_TIMESTAMP,
148                 label : rpt_strings.TFORMS_LABEL_DAY_NAME
149         }, 
150
151         month_name : {
152                 datatype : OILS_RPT_DTYPE_TIMESTAMP,
153                 label : rpt_strings.TFORMS_LABEL_MONTH_NAME
154         },
155         age : {
156                 datatype : OILS_RPT_DTYPE_TIMESTAMP,
157                 label : rpt_strings.TFORMS_LABEL_AGE
158         },
159
160         months_ago : {
161                 datatype : OILS_RPT_DTYPE_TIMESTAMP,
162                 label : rpt_strings.TFORMS_LABEL_MONTHS_AGO
163         },
164
165         quarters_ago : {
166                 datatype : OILS_RPT_DTYPE_TIMESTAMP,
167                 label : rpt_strings.TFORMS_LABEL_QUARTERS_AGO
168         },
169
170         /* int  / float transforms ----------------------------------- */
171         sum : {
172                 datatype : [ OILS_RPT_DTYPE_INT, OILS_RPT_DTYPE_FLOAT ],
173                 label : rpt_strings.TFORMS_LABEL_SUM,
174                 aggregate : true
175         }, 
176
177         average : {
178                 datatype : [ OILS_RPT_DTYPE_INT, OILS_RPT_DTYPE_FLOAT ],
179                 label : rpt_strings.TFORMS_LABEL_AVERAGE,
180                 aggregate : true
181         },
182
183         round : {
184                 datatype : [ OILS_RPT_DTYPE_INT, OILS_RPT_DTYPE_FLOAT ],
185                 label : rpt_strings.TFORMS_LABEL_ROUND,
186         },
187
188         'int' : {
189                 datatype : OILS_RPT_DTYPE_FLOAT,
190                 label : rpt_strings.TFORMS_LABEL_INT
191         }
192 }
193
194
195 function oilsRptGetTforms(args) {
196         var dtype = args.datatype;
197         var agg = args.aggregate;
198         var tforms = OILS_RPT_TRANSFORMS;
199         var nonagg = args.non_aggregate;
200
201         var keys = oilsRptObjectKeys(OILS_RPT_TRANSFORMS);
202         var tforms = [];
203
204         _debug('getting tform '+dtype+' : ' + agg + ' : ' + nonagg);
205
206         for( var i = 0; i < keys.length; i++ ) {
207                 var key = keys[i];
208                 var obj = OILS_RPT_TRANSFORMS[key];
209                 if( dtype && !oilsRptTformIsDtype(key,dtype) ) continue;
210                 if( agg && !nonagg && !obj.aggregate ) continue;
211                 if( !agg && nonagg && obj.aggregate ) continue;
212                 tforms.push(key);
213         }
214
215         return tforms;
216 }
217
218
219 function oilsRptTformIsDtype(tform, dtype) {
220         var obj = OILS_RPT_TRANSFORMS[tform];
221         if( typeof obj.datatype == 'string' )
222                 return (obj.datatype == dtype);
223         return !obj.datatype || grep(obj.datatype, function(d) { return (d == dtype) });
224 }
225
226
227
228
229 /* builds a new transform picker */
230 function oilsRptTformPicker(args) {
231         this.node = args.node;
232         this.selector = elem('select');
233         this.tforms = oilsRptGetTforms(args);
234         for( var i = 0; i < this.tforms.length; i++ ) 
235                 this.addOpt(this.tforms[i], this.tforms[i] == args.select );
236         appendClear(this.node, this.selector);
237 }
238
239 oilsRptTformPicker.prototype.addOpt = function(key, select) {
240         var tform = OILS_RPT_TRANSFORMS[key];           
241         var obj = this;
242         var opt = insertSelectorVal(this.selector, -1, tform.label, key);
243         if( select ) opt.selected = true;
244 }
245
246 oilsRptTformPicker.prototype.getSelected = function(key) {
247         return getSelectorVal(this.selector);
248 }
249
250
251