| 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
500
501
502
503
504
505
506
507
508
509 | 1×
1×
1×
1×
282×
282×
282×
282×
282×
282×
282×
282×
282×
282×
1×
8176×
1×
131×
1×
87×
87×
178×
1×
956×
956×
1665×
1×
83×
83×
6396×
1×
1529×
1×
420×
420×
420×
420×
420×
420×
420×
420×
420×
420×
420×
123×
123×
123×
123×
13×
13×
13×
8×
5×
13×
407×
1×
406×
406×
15×
15×
406×
406×
406×
406×
406×
406×
23×
23×
23×
92×
35×
35×
35×
35×
406×
406×
804×
806×
804×
406×
804×
803×
406×
406×
406×
406×
1×
406×
405×
2×
4×
405×
1×
404×
404×
404×
404×
404×
34×
404×
404×
404×
404×
404×
404×
404×
404×
404×
404×
404×
404×
404×
404×
404×
404×
404×
404×
3×
3×
3×
3×
3×
3×
3×
3×
3×
3×
3×
3×
3×
3×
1×
18×
18×
16×
18×
18×
18×
18×
1×
198×
179×
36×
179×
38×
21×
21×
179×
179×
179×
19×
19×
8×
19×
19×
19×
19×
9×
10×
179×
18×
8×
8×
18×
161×
12×
161×
161×
133×
80×
161×
29×
161×
161×
11×
161×
19×
19×
19×
19×
3×
3×
16×
16×
16×
16×
16×
16×
16×
16×
16×
16×
1×
124×
248×
457×
124×
27×
97×
582×
582×
57×
80×
14×
40×
40×
40×
40×
40×
6×
6×
6×
7×
1×
462×
462×
28×
28×
28×
4×
28×
28×
434×
434×
434×
434×
53×
434×
433×
434×
434×
52×
1×
719×
719×
719×
674×
18×
674×
45×
18×
45×
45×
45×
1×
369×
369×
369×
2×
2×
2×
2×
2×
2×
2×
2×
2×
2×
2×
2×
2×
2×
2×
2×
2×
2×
367×
2×
2×
2×
2×
365×
360×
360×
360×
360×
360×
360×
360×
360×
360×
360×
360×
365×
365×
365×
365×
365×
365×
365×
365×
365×
91×
91×
2×
2×
34×
34×
13×
13×
42×
42×
91×
2×
1×
16×
16×
16×
2×
16×
16×
16×
16×
16×
16×
16×
16×
16×
16×
1×
534×
265×
269×
269×
269×
269×
269×
269×
269×
269×
269×
269×
269×
269×
269×
269×
269×
269×
269×
269×
269×
269×
269×
269×
269×
269×
269×
269×
1×
1×
| define(["require", "exports", "@syncfusion/ej2-base", "@syncfusion/ej2-data", "../flat/flat-data", "../renderer/render", "../flat/flat-query", "../flat/flat-summary", "../flat/flat-grid", "../flat/flat-fields", "../flat/flat-output", "../../common/base/flat-util", "../../common/base/constant"], function (require, exports, ej2_base_1, ej2_data_1, flat_data_1, render_1, flat_query_1, flat_summary_1, flat_grid_1, flat_fields_1, flat_output_1, flat_util_1, events) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var FlatLayout = (function () {
function FlatLayout(parent) {
this.active = false;
this.columns = [];
this.previousLayout = 'Compact';
this.destroyed = false;
this.generation = 0;
this.committedColumns = [];
this.parent = parent;
this.gridAdapter = new flat_grid_1.FlatGrid(parent);
this.output = new flat_output_1.FlatOutput(parent);
this.fields = new flat_fields_1.FlatFields(parent);
}
Object.defineProperty(FlatLayout.prototype, "renderGeneration", {
get: function () { return this.generation; },
enumerable: true,
configurable: true
});
Object.defineProperty(FlatLayout.prototype, "records", {
get: function () { return this.project(); },
enumerable: true,
configurable: true
});
FlatLayout.prototype.outputSnapshot = function () {
Iif (this.destroyed || !this.committed || !this.committedStore || !this.committedQuery) {
throw new Error('Flat output requires a committed record view.');
}
return { settings: flat_util_1.cloneFlat(this.committed), columns: flat_util_1.cloneFlat(this.committedColumns),
records: this.committedStore.project(this.committedColumns.map(function (column) { return column.field; }), this.committedQuery.ordinals), values: flat_util_1.cloneFlat(this.committedSummaries.values) };
};
FlatLayout.prototype.project = function (skip, take) {
if (skip === void 0) { skip = 0; }
if (take === void 0) { take = this.query ? this.query.ordinals.length : 0; }
return this.store && this.store.length && this.query ? this.store.project(this.columns.map(function (column) { return column.field; }), this.query.ordinals.slice(skip, skip + take)) : [];
};
FlatLayout.prototype.openFields = function () {
Eif (this.parent.showFieldList && this.parent.fieldListModule) {
this.fields.open();
}
};
FlatLayout.prototype.getModuleName = function () { return 'flatLayout'; };
FlatLayout.prototype.snapshot = function () {
return flat_util_1.cloneFlat(this.parent.flatSettings);
};
FlatLayout.prototype.enter = function (initial) {
if (initial === void 0) { initial = false; }
var parent = this.parent;
Iif (this.destroyed || parent.isDestroyed) {
return false;
}
var generation = ++this.generation;
var before = this.committed;
var rendering = false;
try {
before = before || this.snapshot();
var current = this.snapshot();
var info = { previous: flat_util_1.cloneFlat(before, true), current: flat_util_1.cloneFlat(current, true) };
if (!initial && this.action) {
var args = { actionName: this.action || events.layoutChange, cancel: false,
dataSourceSettings: parent.dataSourceSettings, flatInfo: info };
parent.trigger(events.actionBegin, args);
Iif (generation !== this.generation || this.destroyed) {
return false;
}
if (args.cancel) {
var restoreView = this.action === events.flatFiltering ||
this.action === events.flatFieldsChange && this.gridAdapter.columnActionPending;
this.restore(before);
if (this.active && restoreView) {
this.gridAdapter.render(false);
}
else {
this.generation = generation - 1;
}
return false;
}
}
if (parent.dataSourceSettings.providerType === 'SSAS' || parent.dataSourceSettings.mode === 'Server') {
throw new Error('Flat layout requires a complete relational record source.');
}
var source = parent.dataSourceSettings.dataSource;
if (source instanceof ej2_data_1.DataManager) {
Iif (source.dataSource.url) {
throw new Error('Flat layout requires a complete relational record source.');
}
source = source.dataSource.json;
}
Iif (!Array.isArray(source)) {
throw new Error('Flat layout requires a complete relational record source.');
}
var original_1 = source;
var schema = JSON.stringify([parent.dataSourceSettings.type, parent.dataSourceSettings.excludeFields]);
var store_1 = this.sourceReference === source && this.sourceSchema === schema && this.store ? this.store :
new flat_data_1.FlatRecordStore(original_1, parent.dataSourceSettings.excludeFields || [], parent.dataSourceSettings.type === 'CSV');
var columns_1 = parent.flatSettings.columns;
if (columns_1 === undefined) {
var selected_1 = [];
columns_1 = [];
['rows', 'columns', 'values', 'filters'].forEach(function (axis) {
ej2_base_1.getValue(axis, parent.dataSourceSettings).forEach(function (field) {
Eif (store_1.fields.indexOf(field.name) !== -1 && selected_1.indexOf(field.name) === -1) {
selected_1.push(field.name);
var format = parent.dataSourceSettings.formatSettings
.filter(function (entry) { return entry.name === field.name; })[0];
columns_1.push({ field: field.name, headerText: field.caption || field.name,
format: format && format.format });
}
});
});
}
var names_1 = [];
columns_1.forEach(function (column) {
Iif (!column.field || names_1.indexOf(column.field) !== -1 ||
column.field.split('.').some(function (part) { return ['__proto__', 'prototype', 'constructor'].indexOf(part) !== -1; })) {
throw new Error('Flat layout settings contain an invalid value.');
}
names_1.push(column.field);
});
var valid = columns_1.filter(function (column) {
return original_1.length === 0 || store_1.fields.indexOf(column.field) !== -1;
});
var visible = valid.filter(function (column) { return column.visible !== false; });
var querySettings = flat_util_1.cloneFlat(parent.flatSettings);
querySettings.columns = original_1.length > 0 && store_1 !== this.committedStore ? columns_1 : valid;
var pruned = original_1.length > 0 && store_1 !== this.committedStore && flat_util_1.pruneFlatSettings(querySettings, store_1.fields);
if (valid.length !== columns_1.length || pruned) {
parent.actionFailureMethod(new Error('Flat layout ignored an unavailable or unsupported field.'));
}
flat_util_1.validateFlatSettings(querySettings);
var pins = function (settings) {
return JSON.stringify([settings.frozenColumns, (settings.columns || []).map(function (column) {
return [column.field, column.visible, column.width, column.freeze, column.isFrozen];
})]);
};
if (!flat_util_1.flatPinsFit(querySettings, this.gridAdapter.viewportWidth()) && (!this.active || pins(querySettings) !== pins(before))) {
throw new Error(parent.localeObj.getConstant('flatPinningUnavailable'));
}
var query = new flat_query_1.FlatQuery(store_1, querySettings, parent.locale);
var reuseSummaries = this.committedQuery && this.queryConfigurationEqual(current, before) &&
this.sourceReference === source && this.committedLocale === parent.locale;
var summaries = reuseSummaries ? this.committedSummaries :
new flat_summary_1.FlatSummaries(store_1, query, querySettings, parent, parent.element.ownerDocument.defaultView);
Iif (generation !== this.generation || this.destroyed) {
return false;
}
if (this.action === events.flatFieldsChange) {
this.fields.destroy();
}
this.columns = visible;
this.store = store_1;
this.query = query;
this.summaries = summaries;
this.sourceReference = source;
this.sourceSchema = schema;
parent.setProperties({ flatSettings: querySettings }, true);
info.current = flat_util_1.cloneFlat(this.snapshot(), true);
this.active = true;
this.action = initial ? undefined : this.action;
this.info = initial ? undefined : info;
this.candidateSettings = this.snapshot();
this.candidateSource = Object.assign({}, ej2_base_1.getValue('properties', parent.dataSourceSettings));
this.renderError = undefined;
Iif (parent.virtualscrollModule) {
parent.virtualscrollModule.suspend();
}
rendering = true;
this.render();
return true;
}
catch (error) {
Iif (this.generation !== generation) {
return false;
}
Eif (before) {
this.restore(before);
}
else {
parent.setProperties({ gridSettings: { layout: this.previousLayout } }, true);
}
this.store = this.committedStore;
this.sourceReference = this.committedReference;
this.sourceSchema = this.committedSchema;
this.columns = this.committedColumns;
this.query = this.committedQuery;
this.summaries = this.committedSummaries;
Eif (this.active && this.committed) {
Iif (rendering) {
this.gridAdapter.render(false);
}
else {
this.generation = generation - 1;
}
}
parent.actionFailureMethod(error instanceof Error ? error : new Error('Flat layout settings contain an invalid value.'));
return false;
}
};
FlatLayout.prototype.restore = function (settings) {
this.parent.setProperties({ flatSettings: settings, gridSettings: { layout: this.active ? 'Flat' : this.previousLayout } }, true);
if (this.committedSource) {
this.parent.setProperties({ dataSourceSettings: this.committedSource }, true);
}
this.action = undefined;
this.info = undefined;
this.candidateSettings = undefined;
this.candidateSource = undefined;
};
FlatLayout.prototype.update = function (newProp, oldProp) {
if (this.parent.gridSettings.layout === 'Flat') {
if (newProp.dataSourceSettings) {
this.parent.engineModule.pivotValues = undefined;
}
if (newProp.dataSourceSettings && Object.keys(newProp.dataSourceSettings).some(function (key) {
return ['dataSource', 'excludeFields', 'type'].indexOf(key) !== -1;
})) {
this.fields.sourceChanged();
this.sourceReference = undefined;
}
var shared_1 = ['width', 'height', 'locale', 'enableRtl', 'cssClass', 'enableHtmlSanitizer',
'toolbar', 'showToolbar', 'showFieldList'];
var sharedChanged = this.active && Object.keys(newProp).some(function (name) { return shared_1.indexOf(name) !== -1; });
if (sharedChanged) {
this.fields.destroy();
if (this.parent.toolbarModule) {
this.parent.toolbarModule.resetFlatToolbar();
}
this.generation++;
this.parent.localeObj.setLocale(this.parent.locale);
this.parent.globalize = new ej2_base_1.Internationalization(this.parent.locale);
if (this.parent.enableRtl) {
ej2_base_1.addClass([this.parent.element], 'e-rtl');
}
else {
ej2_base_1.removeClass([this.parent.element], 'e-rtl');
}
}
if (this.active && !newProp.flatSettings && !newProp.dataSourceSettings &&
!(newProp.gridSettings && newProp.gridSettings.layout)) {
if (sharedChanged) {
Iif (newProp.locale) {
this.enter(true);
}
else {
this.render();
}
}
return true;
}
if (!this.active) {
this.previousLayout = oldProp.gridSettings && oldProp.gridSettings.layout || 'Compact';
}
var changed = newProp.flatSettings ? Object.keys(newProp.flatSettings) : [];
this.action = newProp.gridSettings && newProp.gridSettings.layout ? events.layoutChange :
changed.indexOf('columns') !== -1 ? events.flatFieldsChange :
changed.some(function (name) { return ['filterSettings', 'advancedFilterSettings', 'searchSettings'].indexOf(name) !== -1; })
? events.flatFiltering : changed.indexOf('sortSettings') !== -1 ? events.flatSorting :
changed.some(function (name) { return ['aggregates', 'totalsPosition'].indexOf(name) !== -1; })
? events.flatTotalsChange : undefined;
if ([events.flatFiltering, events.flatSorting].indexOf(this.action) !== -1) {
this.parent.setProperties({ flatSettings: { pageSettings: { currentPage: 1 } } }, true);
}
this.enter();
if (sharedChanged && this.active && this.parent.gridSettings.layout === 'Flat') {
this.parent.notify(events.initToolbar, {});
}
return true;
}
Eif (this.active) {
var args = { actionName: events.layoutChange, cancel: false,
flatInfo: { previous: flat_util_1.cloneFlat(this.committed, true), current: flat_util_1.cloneFlat(this.snapshot(), true) } };
this.parent.trigger(events.actionBegin, args);
if (args.cancel) {
this.parent.setProperties({ gridSettings: { layout: 'Flat' } }, true);
return true;
}
this.generation++;
this.active = false;
this.previousLayout = this.parent.gridSettings.layout;
this.clearGrid();
this.parent.isTabular = this.previousLayout === 'Tabular';
this.parent.actionObj.actionName = events.layoutChange;
this.parent.actionObj.actionInfo = { flatInfo: args.flatInfo };
this.parent.notify(events.initialLoad, {});
this.parent.notify(events.initToolbar, {});
return true;
}
return false;
};
FlatLayout.prototype.queryConfigurationEqual = function (left, right) {
var fields = function (settings) {
return JSON.stringify((settings.columns || []).map(function (column) {
return [column.field, column.visible !== false, column.allowSearching !== false];
}));
};
if (fields(left) !== fields(right)) {
return false;
}
var keys = ['sortSettings', 'filterSettings', 'searchSettings', 'advancedFilterSettings',
'aggregates', 'totalsPosition'];
if (JSON.stringify(keys.map(function (key) { return ej2_base_1.getValue(key, left); })) !==
JSON.stringify(keys.map(function (key) { return ej2_base_1.getValue(key, right); }))) {
return false;
}
var handlers = function (settings) { return (settings.aggregates || [])
.map(function (row) { return (row.columns || []).map(function (column) { return column.customAggregate; }); }); };
var previousRows = handlers(left);
var currentRows = handlers(right);
Iif (previousRows.length !== currentRows.length) {
return false;
}
var rows = currentRows.values();
return previousRows.every(function (row) {
var current = rows.next().value;
Iif (row.length !== current.length) {
return false;
}
var callbacks = current.values();
return row.every(function (handler) { return handler === callbacks.next().value; });
});
};
FlatLayout.prototype.render = function () {
Iif (!this.active || this.destroyed) {
return;
}
if (this.parent.displayOption.view !== 'Table' && !this.parent.engineModule.pivotValues) {
this.parent.engineModule.pivotValues = [];
var source = this.parent.dataSourceSettings.dataSource;
if (source instanceof ej2_data_1.DataManager) {
this.parent.engineModule.data = source.dataSource.json;
}
this.parent.initEngine();
return;
}
ej2_base_1.addClass([this.parent.element], 'e-pivot-flat');
this.parent.renderModule = this.parent.renderModule || new render_1.Render(this.parent);
this.parent.renderModule.render();
if (this.parent.displayOption.view !== 'Table' && this.parent.pivotChartModule) {
this.parent.pivotChartModule.loadChart(this.parent, this.parent.chartSettings);
}
if (this.parent.grid) {
this.parent.grid.element.style.display = this.parent.displayOption.view === 'Chart' ? 'none' : '';
}
this.updateChartCaption();
if (this.parent.pivotChartModule && this.parent.chart) {
this.parent.pivotChartModule.updateView();
}
};
FlatLayout.prototype.updateChartCaption = function () {
var caption = this.parent.element.querySelector('.e-pivot-flat-chart-caption');
var chart = this.parent.element.querySelector('#' + this.parent.element.id + '_chart');
if (!this.active || this.parent.displayOption.view !== 'Both' || !chart) {
if (caption) {
ej2_base_1.remove(caption);
}
return;
}
if (!caption) {
caption = this.parent.createElement('div', { className: 'e-pivot-flat-chart-caption', attrs: { role: 'note' } });
}
caption.textContent = this.parent.localeObj.getConstant('flatChartCaption');
caption.hidden = this.parent.showToolbar && this.parent.currentView !== 'Chart';
chart.parentNode.insertBefore(caption, chart);
};
FlatLayout.prototype.dataBound = function () {
var _this = this;
Iif (this.destroyed || !this.active) {
return;
}
if (this.renderError) {
var error_1 = this.renderError;
this.renderError = undefined;
this.action = undefined;
this.info = undefined;
this.generation++;
Promise.resolve().then(function () {
Iif (_this.destroyed) {
return;
}
Eif (_this.committed) {
_this.restore(_this.committed);
_this.store = _this.committedStore;
_this.sourceReference = _this.committedReference;
_this.sourceSchema = _this.committedSchema;
_this.columns = _this.committedColumns;
_this.query = _this.committedQuery;
_this.summaries = _this.committedSummaries;
_this.recoveryError = error_1;
_this.render();
}
else {
_this.active = false;
_this.clearGrid();
_this.parent.setProperties({ gridSettings: { layout: _this.previousLayout } }, true);
_this.parent.actionFailureMethod(error_1);
_this.parent.notify(events.initialLoad, {});
}
});
return;
}
if (this.recoveryError) {
var error = this.recoveryError;
this.recoveryError = undefined;
this.parent.actionFailureMethod(error);
return;
}
if (this.candidateSettings) {
this.committed = this.candidateSettings;
this.committedSource = this.candidateSource;
this.committedStore = this.store;
this.committedReference = this.sourceReference;
this.committedSchema = this.sourceSchema;
this.committedLocale = this.parent.locale;
this.committedColumns = this.columns;
this.committedQuery = this.query;
this.committedSummaries = this.summaries;
this.candidateSettings = undefined;
this.candidateSource = undefined;
}
var generation = this.generation;
var action = this.action;
var info = this.info;
this.action = undefined;
this.info = undefined;
this.parent.hideWaitingPopup();
this.parent.notify(events.initToolbar, {});
this.parent.trigger(events.dataBound);
if (action && !this.destroyed && generation === this.generation) {
var complete = void 0;
switch (action) {
case events.layoutChange:
complete = events.layoutChanged;
break;
case events.flatFieldsChange:
complete = events.flatFieldsChanged;
break;
case events.flatFiltering:
complete = events.flatFiltered;
break;
case events.flatSorting:
complete = events.flatSorted;
break;
case events.flatTotalsChange:
complete = events.flatTotalsChanged;
break;
}
this.parent.trigger(events.actionComplete, { actionName: complete, actionInfo: { flatInfo: info } });
}
};
FlatLayout.prototype.failRender = function (error) { this.renderError = this.renderError || error; };
FlatLayout.prototype.clearGrid = function () {
this.fields.destroy();
this.updateChartCaption();
if (this.parent.toolbarModule) {
this.parent.toolbarModule.resetFlatToolbar();
}
this.gridAdapter.destroy();
var empty = this.parent.element.querySelector('.e-pivot-flat-empty');
Iif (empty) {
ej2_base_1.remove(empty);
}
Eif (this.parent.grid && !this.parent.grid.isDestroyed) {
var element = this.parent.grid.element;
this.parent.grid.destroy();
Eif (element.parentElement) {
ej2_base_1.remove(element);
}
this.parent.grid = undefined;
}
ej2_base_1.removeClass([this.parent.element], 'e-pivot-flat');
};
FlatLayout.prototype.destroy = function () {
if (this.destroyed) {
return;
}
this.destroyed = true;
this.output.destroy();
this.generation++;
this.active = false;
this.updateChartCaption();
this.columns = [];
this.committed = undefined;
this.committedSource = undefined;
this.candidateSettings = undefined;
this.candidateSource = undefined;
this.committedStore = undefined;
this.committedReference = undefined;
this.committedColumns = [];
this.store = undefined;
this.query = undefined;
this.summaries = undefined;
this.committedQuery = undefined;
this.committedSummaries = undefined;
this.sourceReference = undefined;
this.sourceSchema = undefined;
this.committedSchema = undefined;
this.committedLocale = undefined;
this.info = undefined;
this.fields.destroy();
this.gridAdapter.destroy();
ej2_base_1.removeClass([this.parent.element], 'e-pivot-flat');
};
return FlatLayout;
}());
exports.FlatLayout = FlatLayout;
});
|