-
Notifications
You must be signed in to change notification settings - Fork 1
/
el.html
499 lines (465 loc) · 17.2 KB
/
el.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
<!DOCTYPE html>
<html>
<head>
<script type='text/javascript' src='el.df.js'></script>
<script type='text/javascript' src='bubble.js'></script>
<style type='text/css'>
html {
box-sizing: border-box;
}
*, *:before, *:after {
box-sizing: inherit;
}
body {
font-family: 'Gotham Book', sans-serif;
background-color: rgb(250,250,250);
padding: 0;
margin: 8em 2em 2em 1em;
line-height: 1.5em;
}
img {
padding-right: 4px;
vertical-align: middle;
}
.canvas {
border: 1px solid rgb(229,229,229);
background: rgb(239,239,239);
margin-bottom: 3px;
color: rgb(131,131,131);
font-size: .75em;
}
.canvas.body {
max-height: 30em; overflow-y: auto;
}
.row {width:100%;display:table;table-layout:fixed; border-spacing: 1px;}
.col {display: table-cell; padding: 0.5em 1em 0.5em 1em; background: #fff; text-align: right; }
.col.nospace {
padding: 0;
}
.col.arrow {
width: 1.2em;text-align: center; padding: 0;
}
.row.header .col {
background: rgb(245,245,245);
}
.row.header .col.arrow {
color: #c0c0c0;
}
.row.header .col.arrow[data-scrollable=true] {
background: #000; color: #fff; cursor: pointer;
}
.row.body .col.name {
color: rgb(35,147,224);
}
*[hidden] {
display: none;
}
input, select, textarea, button{font-family:inherit; font-size: inherit;}
input {
width: 100%; outline: none; text-align: right; border: none; border-bottom: 1px solid #fff; color: rgb(66,66,66);
line-height: 1.5em; padding-bottom: 4px;
}
input.adj {
width: calc(100% - 24px);
}
input[readonly] {
color: inherit;
}
input:not([data-index='0']) {
//font-size: .8em;
}
input:hover:not([readonly]), input:focus:not([readonly]) {
border-bottom: 1px dashed rgb(125,190,238);
cursor: url(pencil.png?1), auto;
}
input:not(:focus) {
}
input[data-state=saved] {
color: #31a354;
}
input[data-state=saved]:after {
content="\2713";
color: #31a354;
}
span.sorter {
padding-left: 2px;
color: rgb(35,147,224);
}
.hand {
cursor: pointer;
}
.north {
cursor: n-resize;
}
.south {
cursor: s-resize;
}
.flexy-row {
display: flexbox;
flex-direction: row;
}
.flexy-col {
display: flexbox;
flex-direction: column;
}
.pop {
position: absolute;
background-color: rgba(254,254,254,.9);
border:1px solid rgb(215,215,215);
-moz-box-shadow: 1px 1px 1px rgba(0,0,0,0.2);
-webkit-box-shadow: 1px 1px 1px rgba(0,0,0,0.2);
box-shadow: 1px 1px 3px rgba(0,0,0,0.2);
-webkit-border-radius: 3px;
-moz-border-radius: 3px;
border-radius: 3px;
pointer-events:all;
max-height: 200px;
overflow: auto;
font-size: .75em;
}
.pop .hdr {
background-color: rgb(245,245,245);
padding: 4px 0 4px 10px;
}
</style>
</head>
<body>
<div class='row top'>
<div class='col nospace'>
<div class='row'>
<div class='col more' data-action='more' >More</div>
</div>
<div class='fmgrid row'>
</div>
</div>
<div class='col donuts nospace' style='width: 150px;'></div>
</div>
<script type='text/javascript'>
var width = window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth,
height = window.innerHeight || document.documentElement.clientHeight || document.body.clientHeight,
shortmode = 80, longmode = 125,
visibleCols = Math.floor((width-500)/longmode), scrollFrom = 4, currentScroll = scrollFrom, maxScroll=26,
page = 0, pagesize = 1000, msie = window.navigator.userAgent.match(/msie/i);
var model = {
schema: [
{ key: 'name', label: 'NAME', summary_rw: false, grid_rw: false, fmt: 'str' },
{ key: 'p0', label: 'PLAN', summary_rw: true, grid_rw: true },
{ key: 'fcst', label: 'AVISO FCST', summary_rw: false, grid_rw: false, adj_unadj: true },
{ key: 'larrow', label: '\u276E', fmt: 'str'},
{ key: 'fc0', label: 'CLOSED', summary_rw: false, grid_rw: false},
{ key: 'fc1', label: ' COMMIT', summary_rw: false, grid_rw: true, adj_unadj: true },
{ key: 'fc2', label: 'UPSIDE', summary_rw: true, grid_rw: true, adj_unadj: true },
{ key: 'fc3', label: 'MOST LIKELY', summary_rw: true, grid_rw: true, adj_unadj: true },
{ key: 'fc4', label: 'PIPELINE', summary_rw: false, grid_rw: false },
{ key: 'fc5', label: 'MONTHLY EXIT 1', summary_rw: false, grid_rw: false },
{ key: 'fc6', label: 'MONTHLY EXIT 2', summary_rw: false, grid_rw: false },
{ key: 'fc7', label: 'LICENCE AMT', summary_rw: false, grid_rw: true },
{ key: 'fc8', label: 'RENEWAL AMT', summary_rw: false, grid_rw: true },
{ key: 'fc9', label: 'STAGE AMT', summary_rw: false, grid_rw: true },
{ key: 'fc10', label: 'CUST AMT 1', summary_rw: false, grid_rw: true },
{ key: 'fc11', label: 'CUST AMT 2', summary_rw: false, grid_rw: true },
{ key: 'fc12', label: 'CUST AMT 3', summary_rw: false, grid_rw: true },
{ key: 'fc13', label: 'CUST AMT 4', summary_rw: false, grid_rw: true },
{ key: 'fc14', label: 'CUST AMT 5', summary_rw: false, grid_rw: true },
{ key: 'fc15', label: 'CUST AMT 6', summary_rw: false, grid_rw: true },
{ key: 'fc16', label: 'CUST AMT 7', summary_rw: false, grid_rw: true },
{ key: 'fc17', label: 'CUST AMT 8', summary_rw: false, grid_rw: true },
{ key: 'fc18', label: 'CUST AMT 9', summary_rw: false, grid_rw: true },
{ key: 'fc19', label: 'CUST AMT 10', summary_rw: false, grid_rw: true },
{ key: 'fc20', label: 'CUST AMT 11', summary_rw: false, grid_rw: true },
{ key: 'fc21', label: 'CUST AMT 12', summary_rw: false, grid_rw: true },
{ key: 'fc22', label: 'CUST AMT 13', summary_rw: false, grid_rw: true },
{ key: 'rarrow', label: '\u276F', fmt: 'str'}
],
data: [
]
};
for (var n = 0; n < 10000; n++) {
var r = Math.random();
model.data.push([ ['LongHierarchy Level Name ' + n, [['fc1', '2016-04-26', 'me'],['fc2', '2016-04-25', 'me']['fc3', '2016-04-25', 'me']]] , r*5000000, /*r*10000000,*/ [r*10000000, r*9000000, r*12000000], '',
r*10000000, [r*10000000, r*9000000, r*10200000], [r*1000000, r*900000, r*1200000], [r*1500000, r*1200000, r*1800000],
r*2000000, r*2000000,r*200340000, r*1340000, r*13402389000, r*134450000,r*134450000,r*134450000,
r*134450000,r*134450000,r*134450000,r*134450000,r*134450000,r*134450000,r*134450000,r*134450000,
r*134450000,r*134450000,r*134450000,'']);
}
for (var col = 0, nCol = model.schema.length; col < nCol; col++) {
var t = 0;
for (var r = 1, rLen = model.data.length; r < rLen; r++) {
if (model.schema[col].adj_unadj) {
t += model.data[r][col][0];
} else if (model.schema[col].fmt !== 'str') {
t += model.data[r][col];
}
}
if ( t > 0) {
if (model.schema[col].adj_unadj) {
model.data[0][col][0] = t;
} else if (model.schema[col].fmt !== 'str') {
model.data[0][col] = t;
}
}
}
model.summary = model.data.shift();
var money = function(n) {
return typeof(n) === 'string'? n : n.toFixed(0).replace(/(\d)(?=(\d{3})+(?!\d))/g, "$1,");
}, cellStyle = function(cell) {
return (cell.key.match(/arrow/) ? 'col arrow' : 'col') + ' ' + cell.key;
}, cellAttrs = function(cell, isHeader, cellindex) {
var larrow = cell.key.match(/larrow/), rarrow = cell.key.match(/rarrow/),
a = {'class': (larrow || rarrow ? 'col arrow' : 'col') + ' ' + cell.key, 'data-colindex': cellindex};
if (cellindex >= scrollFrom && !(larrow||rarrow) && (cellindex < currentScroll || cellindex >= currentScroll+visibleCols)) {
// Scrollable cell.
a['hidden'] = '';
}
if (isHeader) {
if (larrow||rarrow) {
a['data-action'] = 'scroll';
a['data-scrollable'] = larrow && currentScroll === scrollFrom || rarrow && currentScroll+visibleCols === maxScroll ? 'false' : 'true';
} else if ('sorted' in cell) {
a['class'] += cell.sorted === -1 ? ' south' : ' north';
a['data-action'] = 'sort';
} else {
a['class'] += ' north';
a['data-action'] = 'sort';
}
}
if (cell.key === 'name') {
a['class'] += ' flexy-row';
}
return a;
}, cleanFloat = function(val) {
if (typeof(val) !== 'string') {
return parseFloat(val.toFixed(0));
}
var cleaned = val.replace(/\<br\>/g, ''), shortened = cleaned.match(/[KMB]$/i),
isNeg = cleaned.match(/^\-|^[^0-9]+\-/),
f = parseFloat(cleaned.replace(/\D/g, ''));
if (shortened) {
var m = {'k': 1000, 'm': 1000*1000, 'b': 1000*1000*1000};
f *= m[shortened[0].toLowerCase()];
}
return isNaN(f) ? 0 : isNeg ? -f : f;
}, money2 = function(n) {
if (typeof(n) === 'string') { return n; }
n = cleanFloat(n);
var s='';
if (n > 1000000000) {
n = n/1000000000; s='B';
} else if (n > 1000000) {
n = n/1000000; s = 'M';
} else if (n > 1000) {
n = n/1000; s = 'K';
}
return n.toFixed(1) + s;
}, toggle = function(sid, isHide) {
var el = document.querySelectorAll('[data-sid="' + sid + '"]'), eLen = el.length;
for (var l = 0; l < eLen; l++) {
if (isHide) {
el[l].setAttribute('hidden', '');
} else {
el[l].removeAttribute('hidden');
}
}
}, sorted = function(colIndex, order) {
var str_sort = function(a,b) {
return a[colIndex].localeCompare(b[colIndex])*order;
}, num_sort = function(a,b) {
return (a[colIndex]-b[colIndex])*order;
}, arr_sort = function(a,b) {
return (a[colIndex][0]-b[colIndex][0]) * order;
}, sorter, cell = model.schema[colIndex];
if (cell.adj_unadj) {
sorter = arr_sort;
} else if (cell.fmt === 'str') {
sorter = str_sort;
} else {
sorter = num_sort;
}
model.data.sort(sorter);
for (var s = 0, sLen = model.schema.length; s < sLen; s++) {
delete model.schema[s].sorted;
}
cell.sorted=order;
}
sorted(2,1);
var inputAttrs = function(val, rw, index, rowindex, colindex) {
var attrs = {'type': 'text', 'value': money(val), 'data-action': 'keyup:save, blur:save',
'data-orig': cleanFloat(val), 'data-state': 'none', 'data-rowindex': rowindex, 'data-colindex': colindex, 'data-index': index,
'tabindex': 0 };
if (!rw) {
attrs['readonly']='';
attrs['tabindex']=-1;
}
if (index === 1) {
attrs['class']='adj';
}
return attrs;
}
var paginate = function() {
var slice = [];
for (var r = page*pagesize, rLen = Math.min((page+1)*pagesize, model.data.length); r < rLen; r++) {
slice.push(model.data[r]);
}
return slice;
}
var cell = function(schema, data, rowindex, cellindex) {
var isSummary = rowindex === 0, rw = isSummary && schema.summary_rw || !isSummary && schema.grid_rw;
if (schema.adj_unadj) {
// The column shows adjusted/unadjusted or Aviso forecast details.
return Elm('div', cellAttrs(schema, false, cellindex))(
data.map(function(datum, idx) {
if (idx === 1 && datum !== data[0] && schema.key !== 'fcst') {
return Elm('span')(
[Elm('img', {'src': 'fm_sync.png', 'class': 'hand', 'data-rowindex': rowindex, 'data-colindex': cellindex,
'data-action': 'acceptAdj'})(),
Elm('input', inputAttrs(datum, rw && !idx, idx, rowindex, cellindex))() ]
)
} else {
return Elm('input', inputAttrs(datum, rw && !idx, idx, rowindex, cellindex))()
}
})
)
} else {
// Normal field; could be text or numeric.
var datum = data instanceof Array ? data[0] : data,
repr = schema.fmt !== 'str' ? Elm('input', inputAttrs(datum, rw, 0, rowindex, cellindex))() :
schema.key === 'name' ? Elm('span')(
[Elm('img', {'src': 'fm_history.png', 'class': 'hand', 'data-rowindex': rowindex, 'data-colindex': cellindex,
'data-action': 'showHistory'})(), Elm('span')(money2(datum))])
: money2(datum);
return Elm('div', cellAttrs(schema, false, cellindex))(repr)
}
};
var paint = function() {
var grid = Elm('div', {'class': 'col nospace parent', 'id': 'parent'})(
Elm('div', {'class': 'canvas'})(
Elm('div', {'class': 'row header'})(
model.schema.map(function(schema, colindex) {
if ('sorted' in schema) {
var ind;
if (schema.sorted === -1) {
ind = '↓';
} else {
ind = '↑';
}
return Elm('div', cellAttrs(schema, true, colindex))([ schema.label,
Elm('span', {'class': 'sorter'})( ind )]);
} else {
return Elm('div', cellAttrs(schema, true, colindex))(schema.label);
}
})
),
Elm('div', {'class': 'row body'})(
model.schema.map(function(col, cid) {
return cell(col, model.summary[cid], 0, cid);
})
)
),
Elm('div', {'class': 'canvas body', 'style': 'margin-right: '+ (msie ? -17 : 0) + 'px;'})(
paginate().map(function(row, rid) {
return Elm('div', {'class': 'row body'})(
model.schema.map(function(schema, cid) {
return cell(schema, row[cid], rid, cid);
})
)
})
)
)
var parent = document.querySelector('.fmgrid.row'), last;
while (last = parent.lastChild)
parent.removeChild(last);
parent.appendChild(grid);
}
paint();
var b = bubble('.row.top');
b.on({
'save': function(e) {
if (e.type==='blur' || (e.type === 'keyup' && (e.keyCode === 13 || e.keyCode === 9))) {
var curr = cleanFloat(e.target.value), orig = cleanFloat(e.target.attributes['data-orig'].value);
if (curr !== orig) {
e.target.attributes['data-orig'].value = curr;
var theInputs = document.querySelectorAll('input[data-key=' + e.target.attributes['data-key'].value + ']'),
iLen = theInputs.length, sum = 0;
for (var inp = 1; inp < iLen; inp++) {
sum += cleanFloat(theInputs[inp].value);
}
theInputs[0].value = money(sum);
theInputs[0].attributes['data-state'].value='saved';
e.target.value = money(curr);
e.target.attributes['data-state'].value='saved';
}
}
},
// Left and right scrollers.
'scroll': function(e) {
if (!'data-scrollable' in e.target.attributes) { return; }
var lScroll = e.target.attributes['class'].value.indexOf('larrow') >= 0;
if (lScroll) {
if (--currentScroll <= scrollFrom) {
currentScroll = scrollFrom;
}
} else {
if (++currentScroll + visibleCols >= maxScroll) {
currentScroll = maxScroll-visibleCols;
}
}
paint();
},
'more': function(e) {
page++;
paint();
},
'sort': function(e) {
var cid = parseInt(e.target.attributes['data-colindex'].value),
order = e.target.attributes['class'].value.indexOf('north') >= 0 ? -1 : 1;
sorted(cid, order);
page=0;
paint();
},
'acceptAdj': function(e) {
var cid = parseInt(e.target.attributes['data-colindex'].value),
rid = parseInt(e.target.attributes['data-rowindex'].value),
diff = model.data[rid][cid][0] - model.data[rid][cid][1];
var mgr = document.querySelector('input[data-rowindex="' +rid + '"][data-colindex="' +cid + '"][data-index="0"]'),
me = document.querySelector('input[data-rowindex="0"][data-colindex="' +cid + '"][data-index="0"]'),
myval = cleanFloat(me.getAttribute('data-orig'));
mgr.setAttribute('value', money(model.data[rid][cid][1]));
mgr.setAttribute('data-orig', model.data[rid][cid][0]);
mgr.setAttribute('data-state', 'saved');
me.setAttribute('value', money(myval+diff));
me.setAttribute('data-orig', myval);
me.setAttribute('data-state', 'saved');
model.data[rid][cid][0] = model.data[rid][cid][1];
},
'showHistory': function(e) {
var cid = parseInt(e.target.attributes['data-colindex'].value),
rid = parseInt(e.target.attributes['data-rowindex'].value),
src = e.target.getAttribute('src'),
history = model.data[rid][cid],
pop = document.querySelector('.pop');
if (src.match(/fm_history/)) {
if (!pop) {
pop = Elm('div', {'class': 'pop flexy-col', 'style': 'width: 400px; height: 150px;'})(
[
Elm('div', {'class': 'hdr'})('LAST UPDATED'),
Elm('div', {'class': 'flexy-row'})(
)
]
)
document.body.appendChild(pop);
pop = document.querySelector('.pop');
}
pop.style.left=(e.clientX+12)+'px';
pop.style.top=(e.clientY)+'px';
e.target.setAttribute('src', 'close.png');
} else {
e.target.setAttribute('src', 'fm_history.png');
if (pop) {
pop.parentNode.removeChild(pop);
}
}
}
});
</script>
</body>
</html>