@universis/ngx-tables 0.8.0 → 0.8.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,8 +1,8 @@
1
1
  (function (global, factory) {
2
- typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('iso-639-1/build'), require('rxjs'), require('jquery'), require('datatables.net'), require('datatables.net-scroller'), require('datatables.net-colreorder'), require('rxjs/add/observable/combineLatest'), require('@angular/common/http'), require('@themost/client'), require('@themost/angular'), require('@angular/common'), require('@ngx-translate/core'), require('@angular/forms'), require('@universis/common'), require('@universis/common/routing'), require('@universis/forms'), require('angular-formio'), require('ngx-bootstrap/modal'), require('ngx-bootstrap/progressbar'), require('ngx-pipes'), require('lodash'), require('@angular/core'), require('@angular/router'), require('@ngrx/store'), require('rxjs/operators')) :
3
- typeof define === 'function' && define.amd ? define('@universis/ngx-tables', ['exports', 'iso-639-1/build', 'rxjs', 'jquery', 'datatables.net', 'datatables.net-scroller', 'datatables.net-colreorder', 'rxjs/add/observable/combineLatest', '@angular/common/http', '@themost/client', '@themost/angular', '@angular/common', '@ngx-translate/core', '@angular/forms', '@universis/common', '@universis/common/routing', '@universis/forms', 'angular-formio', 'ngx-bootstrap/modal', 'ngx-bootstrap/progressbar', 'ngx-pipes', 'lodash', '@angular/core', '@angular/router', '@ngrx/store', 'rxjs/operators'], factory) :
4
- (factory((global.universis = global.universis || {}, global.universis['ngx-tables'] = {}),global.ISO6391,global.rxjs,global.jQuery_,null,null,null,global.rxjs['add/observable/combineLatest'],global.ng.common.http,global.client,global.i1,global.ng.common,global.core,global.ng.forms,global.i2,global.routing,global.forms$1,global.angularFormio,global.modal,global.progressbar,global.ngxPipes,global.lodash,global.ng.core,global.ng.router,global.store,global.rxjs.operators));
5
- }(this, (function (exports,ISO6391,rxjs,jQuery_,datatables_net,datatables_netScroller,datatables_netColreorder,combineLatest,http,client,i1,common,core,forms,i2,routing,forms$1,angularFormio,modal,progressbar,ngxPipes,lodash,i0,i1$1,store,operators) { 'use strict';
2
+ typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('iso-639-1/build'), require('rxjs'), require('jquery'), require('datatables.net'), require('datatables.net-scroller'), require('datatables.net-colreorder'), require('datatables.net-buttons'), require('rxjs/add/observable/combineLatest'), require('@angular/common/http'), require('@themost/client'), require('@themost/angular'), require('@angular/common'), require('@ngx-translate/core'), require('@angular/forms'), require('@universis/common'), require('@universis/common/routing'), require('@universis/forms'), require('angular-formio'), require('ngx-bootstrap/modal'), require('ngx-bootstrap/progressbar'), require('ngx-pipes'), require('lodash'), require('@angular/core'), require('@angular/router'), require('@ngrx/store'), require('rxjs/operators')) :
3
+ typeof define === 'function' && define.amd ? define('@universis/ngx-tables', ['exports', 'iso-639-1/build', 'rxjs', 'jquery', 'datatables.net', 'datatables.net-scroller', 'datatables.net-colreorder', 'datatables.net-buttons', 'rxjs/add/observable/combineLatest', '@angular/common/http', '@themost/client', '@themost/angular', '@angular/common', '@ngx-translate/core', '@angular/forms', '@universis/common', '@universis/common/routing', '@universis/forms', 'angular-formio', 'ngx-bootstrap/modal', 'ngx-bootstrap/progressbar', 'ngx-pipes', 'lodash', '@angular/core', '@angular/router', '@ngrx/store', 'rxjs/operators'], factory) :
4
+ (factory((global.universis = global.universis || {}, global.universis['ngx-tables'] = {}),global.ISO6391,global.rxjs,global.jQuery_,null,null,null,null,global.rxjs['add/observable/combineLatest'],global.ng.common.http,global.client,global.i1,global.ng.common,global.core,global.ng.forms,global.i2,global.routing,global.forms$1,global.angularFormio,global.modal,global.progressbar,global.ngxPipes,global.lodash,global.ng.core,global.ng.router,global.store,global.rxjs.operators));
5
+ }(this, (function (exports,ISO6391,rxjs,jQuery_,datatables_net,datatables_netScroller,datatables_netColreorder,datatables_netButtons,combineLatest,http,client,i1,common,core,forms,i2,routing,forms$1,angularFormio,modal,progressbar,ngxPipes,lodash,i0,i1$1,store,operators) { 'use strict';
6
6
 
7
7
  /*! *****************************************************************************
8
8
  Copyright (c) Microsoft Corporation.
@@ -1029,6 +1029,307 @@
1029
1029
  return ColumnSelectorService;
1030
1030
  }());
1031
1031
 
1032
+ var ActivatedTableService = /** @class */ (function () {
1033
+ function ActivatedTableService(_router, _activatedRoute) {
1034
+ var _this = this;
1035
+ this._router = _router;
1036
+ this._activatedRoute = _activatedRoute;
1037
+ _router.events.forEach(function (event) {
1038
+ if (event instanceof i1$1.NavigationStart) {
1039
+ if (_this._activeTable) {
1040
+ _this._activeTable = null;
1041
+ }
1042
+ }
1043
+ });
1044
+ }
1045
+ Object.defineProperty(ActivatedTableService.prototype, "activeTable", {
1046
+ get: function () {
1047
+ return this._activeTable;
1048
+ },
1049
+ set: function (tableComponent) {
1050
+ this._activeTable = tableComponent;
1051
+ },
1052
+ enumerable: true,
1053
+ configurable: true
1054
+ });
1055
+ ActivatedTableService.decorators = [
1056
+ { type: i0.Injectable, args: [{
1057
+ providedIn: 'root'
1058
+ },] }
1059
+ ];
1060
+ /** @nocollapse */
1061
+ ActivatedTableService.ctorParameters = function () {
1062
+ return [
1063
+ { type: i1$1.Router },
1064
+ { type: i1$1.ActivatedRoute }
1065
+ ];
1066
+ };
1067
+ ActivatedTableService.ngInjectableDef = i0.defineInjectable({ factory: function ActivatedTableService_Factory() { return new ActivatedTableService(i0.inject(i1$1.Router), i0.inject(i1$1.ActivatedRoute)); }, token: ActivatedTableService, providedIn: "root" });
1068
+ return ActivatedTableService;
1069
+ }());
1070
+
1071
+ var MAX_EXPORT_ITEMS = 500;
1072
+ var BtnExpDirective = /** @class */ (function () {
1073
+ function BtnExpDirective(_activatedTable, _context, _config, _translate, _loadingService, _errorService) {
1074
+ this._activatedTable = _activatedTable;
1075
+ this._context = _context;
1076
+ this._config = _config;
1077
+ this._translate = _translate;
1078
+ this._loadingService = _loadingService;
1079
+ this._errorService = _errorService;
1080
+ }
1081
+ BtnExpDirective.prototype.clickEvent = function (event) {
1082
+ return __awaiter(this, void 0, void 0, function () {
1083
+ return __generator(this, function (_a) {
1084
+ event.preventDefault();
1085
+ event.stopPropagation();
1086
+ if (this._activatedTable.activeTable) {
1087
+ return [2 /*return*/, this._activatedTable.activeTable.exportView()];
1088
+ /*
1089
+ const lastQuery = this._activatedTable.activeTable.lastQuery;
1090
+ const tableConfig = this._activatedTable.activeTable.config;
1091
+ const serviceHeaders = this._context.getService().getHeaders();
1092
+ const queryModel = lastQuery.getModel();
1093
+ let query = this._context.model(queryModel).asQueryable();
1094
+ const queryParams = lastQuery.getParams();
1095
+ query = this.constructQuery(query, queryParams, tableConfig, serviceHeaders);
1096
+ // get export settings
1097
+ const exportSettings = this._config.settings as ExportLimitConfiguration;
1098
+ // get export limit
1099
+ const maxExportItems = exportSettings && exportSettings.tables && exportSettings.tables.exportLimit;
1100
+ if (maxExportItems && typeof maxExportItems === 'number' && maxExportItems > 0) {
1101
+ query.skip(0).take(maxExportItems);
1102
+ } else {
1103
+ query.skip(0).take(MAX_EXPORT_ITEMS);
1104
+ }
1105
+ // This constructs the URI based on the way @themost does
1106
+ const url = this.constructURL(query);
1107
+ this.downloadFile(url, query.getService().getHeaders(), query.getModel()); */
1108
+ }
1109
+ return [2 /*return*/];
1110
+ });
1111
+ });
1112
+ };
1113
+ /**
1114
+ * Sets the parameters to the query based on
1115
+ * the active filters of the activated table
1116
+ * @param {ClientDataQueryable} query
1117
+ * @param params: The filters of the last query of the activated table
1118
+ * @return ClientDataQueryable
1119
+ */
1120
+ BtnExpDirective.prototype.setParams = function (query, params) {
1121
+ if (params && typeof params === 'object') {
1122
+ Object.keys(params).forEach(function (key) {
1123
+ query.setParam(key, params[key]);
1124
+ });
1125
+ }
1126
+ return query;
1127
+ };
1128
+ /**
1129
+ * Sets the headers to the query based on
1130
+ * the default headers of the DataContext
1131
+ * and appending the accept header to get
1132
+ * an xlsx file from the API
1133
+ * @param {ClientDataQueryable} query
1134
+ * @param {Headers} headers: The headers to append to the query
1135
+ * @return ClientDataQueryable
1136
+ */
1137
+ BtnExpDirective.prototype.setHeaders = function (query, headers) {
1138
+ Object.keys(headers).forEach(function (key) {
1139
+ if (headers.hasOwnProperty(key)) {
1140
+ query.getService().setHeader(key, headers[key]);
1141
+ }
1142
+ });
1143
+ // sets a header to accept xlsx files
1144
+ query.getService().setHeader('Accept', 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
1145
+ return query;
1146
+ };
1147
+ /**
1148
+ * Constructs the select parameter of the
1149
+ * ClientDataQuery by replacing the target name
1150
+ * of the field based on the localized translation
1151
+ * of that property on the advanced tabled
1152
+ * @param {ClientDataQueryable} query
1153
+ * @param tableConfig: The configuration of the activated table
1154
+ * @return ClientDataQueryable
1155
+ */
1156
+ BtnExpDirective.prototype.constructQueryParam = function (query, tableConfig) {
1157
+ var _this = this;
1158
+ var selectQuery = query.getParams().$select;
1159
+ var selectQueryArray = selectQuery.split(',');
1160
+ selectQueryArray = selectQueryArray.map(function (select) {
1161
+ var e_1, _a, e_2, _b;
1162
+ var words = select.split(' ');
1163
+ if (words.length === 3) {
1164
+ if (tableConfig && tableConfig.columns) {
1165
+ try {
1166
+ for (var _c = __values(tableConfig.columns), _d = _c.next(); !_d.done; _d = _c.next()) {
1167
+ var column = _d.value;
1168
+ if (column.property === words[2] && column.title) {
1169
+ words[2] = "\"" + _this._translate.instant(column.title) + "\"";
1170
+ }
1171
+ else if (column.property === words[2]) {
1172
+ words[2] = "\"" + _this._translate.instant(words[2]) + "\"";
1173
+ }
1174
+ }
1175
+ }
1176
+ catch (e_1_1) {
1177
+ e_1 = { error: e_1_1 };
1178
+ }
1179
+ finally {
1180
+ try {
1181
+ if (_d && !_d.done && (_a = _c.return))
1182
+ _a.call(_c);
1183
+ }
1184
+ finally {
1185
+ if (e_1)
1186
+ throw e_1.error;
1187
+ }
1188
+ }
1189
+ }
1190
+ }
1191
+ if (words.length === 1) {
1192
+ if (tableConfig && tableConfig.columns) {
1193
+ try {
1194
+ for (var _e = __values(tableConfig.columns), _f = _e.next(); !_f.done; _f = _e.next()) {
1195
+ var column = _f.value;
1196
+ if (column.name === words[0] && column.title) {
1197
+ words[0] = words[0] + " as \"" + _this._translate.instant(column.title) + "\"";
1198
+ break;
1199
+ }
1200
+ else if (column.name === words[0] && column.property) {
1201
+ words[0] = words[0] + " as \"" + _this._translate.instant(column.property) + "\"";
1202
+ break;
1203
+ }
1204
+ else if (words[0] === column.name && words[0] === "id" && column.hidden) {
1205
+ break;
1206
+ }
1207
+ else if (words[0] == column.name || words[0] === column.property) {
1208
+ words[0] = words[0] + " as \"" + _this._translate.instant(words[0]) + "\"";
1209
+ }
1210
+ }
1211
+ }
1212
+ catch (e_2_1) {
1213
+ e_2 = { error: e_2_1 };
1214
+ }
1215
+ finally {
1216
+ try {
1217
+ if (_f && !_f.done && (_b = _e.return))
1218
+ _b.call(_e);
1219
+ }
1220
+ finally {
1221
+ if (e_2)
1222
+ throw e_2.error;
1223
+ }
1224
+ }
1225
+ }
1226
+ return words[0];
1227
+ }
1228
+ return words.join(' ');
1229
+ });
1230
+ selectQuery = selectQueryArray.join(',');
1231
+ query.setParam('$select', selectQuery);
1232
+ return query;
1233
+ };
1234
+ /**
1235
+ * Constructs the fetch URL based the query parameters
1236
+ * @param {ClientDataQueryable} query
1237
+ * @return String
1238
+ */
1239
+ BtnExpDirective.prototype.constructURL = function (query) {
1240
+ var baseURL = query.getService().getBase();
1241
+ var url = baseURL.endsWith('/') ? (baseURL + query.getModel() + '?') : (baseURL + '/' + query.getModel() + '?');
1242
+ Object.keys(query.getParams()).forEach(function (key, index) {
1243
+ if (index === 0) {
1244
+ url += key + '=' + query.getParams()[key];
1245
+ }
1246
+ else {
1247
+ url += '&' + key + '=' + query.getParams()[key];
1248
+ }
1249
+ });
1250
+ return url;
1251
+ };
1252
+ /**
1253
+ * Constructs the query by setting the parameters of the
1254
+ * advanced table's active filters, sets the necessary headers
1255
+ * and build the select parameter of the query
1256
+ * @param {ClientDataQueryable} query
1257
+ * @param params: The filters of the last query of the activated table
1258
+ * @param tableConfig: The configuration of the activated table
1259
+ * @param {Headers} headers: The headers to append to the query
1260
+ * @return ClientDataQueryable
1261
+ */
1262
+ BtnExpDirective.prototype.constructQuery = function (query, params, tableConfig, headers) {
1263
+ var _query = this.setParams(query, params);
1264
+ _query = this.setHeaders(_query, headers);
1265
+ _query = this.constructQueryParam(_query, tableConfig);
1266
+ return _query;
1267
+ };
1268
+ /**
1269
+ * Fetches and saves the xlsx file
1270
+ * @param {String} url
1271
+ * @param {Headers} serviceHeaders: The headers to append to the query
1272
+ * @param modelName: The model name of the advanced table
1273
+ */
1274
+ BtnExpDirective.prototype.downloadFile = function (url, serviceHeaders, modelName) {
1275
+ var _this = this;
1276
+ this._loadingService.showLoading();
1277
+ fetch(encodeURI(url), {
1278
+ headers: serviceHeaders,
1279
+ credentials: 'include'
1280
+ }).then(function (response) {
1281
+ if (response && !response.ok) {
1282
+ throw new client.ResponseError(response.statusText, response.status);
1283
+ }
1284
+ return response.blob();
1285
+ }).then(function (blob) {
1286
+ var objectUrl = window.URL.createObjectURL(blob);
1287
+ var a = document.createElement('a');
1288
+ document.body.appendChild(a);
1289
+ a.setAttribute('style', 'display: none');
1290
+ a.href = objectUrl;
1291
+ var downloadName = modelName + ".xlsx";
1292
+ a.download = downloadName;
1293
+ // this adds support for IE and MS Edge (up to version 44.19041)
1294
+ if (window.navigator && window.navigator.msSaveOrOpenBlob) {
1295
+ window.navigator.msSaveOrOpenBlob(blob, downloadName);
1296
+ }
1297
+ else {
1298
+ // for all other browsers
1299
+ a.click();
1300
+ }
1301
+ window.URL.revokeObjectURL(objectUrl);
1302
+ a.remove();
1303
+ _this._loadingService.hideLoading();
1304
+ }).catch(function (err) {
1305
+ _this._loadingService.hideLoading();
1306
+ _this._errorService.showError(err, {
1307
+ continueLink: '.'
1308
+ });
1309
+ });
1310
+ };
1311
+ BtnExpDirective.decorators = [
1312
+ { type: i0.Directive, args: [{
1313
+ selector: '.universis-btn-export'
1314
+ },] }
1315
+ ];
1316
+ /** @nocollapse */
1317
+ BtnExpDirective.ctorParameters = function () {
1318
+ return [
1319
+ { type: ActivatedTableService },
1320
+ { type: i1.AngularDataContext },
1321
+ { type: i2.ConfigurationService },
1322
+ { type: core.TranslateService },
1323
+ { type: i2.LoadingService },
1324
+ { type: i2.ErrorService }
1325
+ ];
1326
+ };
1327
+ BtnExpDirective.propDecorators = {
1328
+ clickEvent: [{ type: i0.HostListener, args: ['click', ['$event'],] }]
1329
+ };
1330
+ return BtnExpDirective;
1331
+ }());
1332
+
1032
1333
  // restore jquery import to avoid Cannot call a namespace ('jquery') error
1033
1334
  var jQuery = jQuery_;
1034
1335
  var DataTablesApi = jQuery.fn.dataTable.Api;
@@ -1061,6 +1362,15 @@
1061
1362
  return TableTranslationChangeDetector;
1062
1363
  }(i0.ChangeDetectorRef));
1063
1364
  var COLUMN_FORMATTERS = new i0.InjectionToken('column.formatters');
1365
+ var ExportLimitExceededError = /** @class */ (function (_super) {
1366
+ __extends(ExportLimitExceededError, _super);
1367
+ function ExportLimitExceededError(message) {
1368
+ var _this = _super.call(this, message) || this;
1369
+ _this.name = 'ExportLimitExceededError';
1370
+ return _this;
1371
+ }
1372
+ return ExportLimitExceededError;
1373
+ }(RangeError));
1064
1374
  var ColumnFormatter = /** @class */ (function (_super) {
1065
1375
  __extends(ColumnFormatter, _super);
1066
1376
  function ColumnFormatter(injector) {
@@ -1091,7 +1401,7 @@
1091
1401
  return (Number(String(Math.random()).slice(2))).toString(36);
1092
1402
  }
1093
1403
  var AdvancedTableComponent = /** @class */ (function () {
1094
- function AdvancedTableComponent(_context, _columnFormatters, _activatedRoute, _translateService, _injector, _advancedFilterValueProvider, _element, _template, _loading, _http, _columnSelector) {
1404
+ function AdvancedTableComponent(_context, _columnFormatters, _activatedRoute, _translateService, _injector, _advancedFilterValueProvider, _element, _template, _loading, _http, _columnSelector, _configuration, _exportSpreadsheet, _modalService, _errorService) {
1095
1405
  var _this = this;
1096
1406
  this._context = _context;
1097
1407
  this._columnFormatters = _columnFormatters;
@@ -1104,6 +1414,10 @@
1104
1414
  this._loading = _loading;
1105
1415
  this._http = _http;
1106
1416
  this._columnSelector = _columnSelector;
1417
+ this._configuration = _configuration;
1418
+ this._exportSpreadsheet = _exportSpreadsheet;
1419
+ this._modalService = _modalService;
1420
+ this._errorService = _errorService;
1107
1421
  this._firstLoad = true;
1108
1422
  this._showFooter = false;
1109
1423
  this._showHeader = true;
@@ -1147,6 +1461,7 @@
1147
1461
  this.customSelect = false;
1148
1462
  this.selected = [];
1149
1463
  this.unselected = [];
1464
+ this._lastQueryTotalItems = 0;
1150
1465
  // initialize translate pipe
1151
1466
  this.translator = new core.TranslatePipe(this._translateService, new TableTranslationChangeDetector());
1152
1467
  jQuery.fn.dataTable.ext.classes.sPageButton = 'btn';
@@ -1170,6 +1485,13 @@
1170
1485
  enumerable: true,
1171
1486
  configurable: true
1172
1487
  });
1488
+ Object.defineProperty(AdvancedTableComponent.prototype, "lastQueryTotalItems", {
1489
+ get: function () {
1490
+ return this._lastQueryTotalItems;
1491
+ },
1492
+ enumerable: true,
1493
+ configurable: true
1494
+ });
1173
1495
  Object.defineProperty(AdvancedTableComponent.prototype, "showFooter", {
1174
1496
  get: function () {
1175
1497
  return this._showFooter;
@@ -1796,6 +2118,7 @@
1796
2118
  recordsFiltered: 0,
1797
2119
  data: [],
1798
2120
  };
2121
+ self._lastQueryTotalItems = 0;
1799
2122
  // emit empty data
1800
2123
  self.load.emit(emptyDataSet);
1801
2124
  // return empty data
@@ -1890,6 +2213,7 @@
1890
2213
  recordsFiltered: items.total,
1891
2214
  data: items.value,
1892
2215
  };
2216
+ self._lastQueryTotalItems = items.total;
1893
2217
  if (items.total === 0) {
1894
2218
  self.resetEmptyTable();
1895
2219
  }
@@ -1903,6 +2227,7 @@
1903
2227
  console.error('TABLES', err);
1904
2228
  // show error
1905
2229
  self.toggleError(err);
2230
+ self._lastQueryTotalItems = 0;
1906
2231
  // by returning empty dataset
1907
2232
  self.load.emit(EMPTY_DATASET);
1908
2233
  return fnCallback(EMPTY_DATASET);
@@ -1915,6 +2240,7 @@
1915
2240
  recordsFiltered: items.total,
1916
2241
  data: items.value,
1917
2242
  };
2243
+ self._lastQueryTotalItems = items.total;
1918
2244
  if (items.total === 0) {
1919
2245
  self.resetEmptyTable();
1920
2246
  }
@@ -2298,6 +2624,126 @@
2298
2624
  }
2299
2625
  });
2300
2626
  };
2627
+ /**
2628
+ *
2629
+ * @param options to pass an errorHandler callback, if desired
2630
+ * @returns void
2631
+ */
2632
+ AdvancedTableComponent.prototype.exportView = function (options) {
2633
+ return __awaiter(this, void 0, void 0, function () {
2634
+ var exportSettings, exportLimit, totalDisplayedItems, _a, body, header, previousDataState, targetDataState, _b, body, header, err_1;
2635
+ return __generator(this, function (_c) {
2636
+ switch (_c.label) {
2637
+ case 0:
2638
+ _c.trys.push([0, 4, 5, 6]);
2639
+ this._loading.showLoading();
2640
+ // validate query items and config
2641
+ if (!(this._lastQueryTotalItems && this.config)) {
2642
+ // do nothing
2643
+ return [2 /*return*/];
2644
+ }
2645
+ exportSettings = this._configuration.settings;
2646
+ exportLimit = (exportSettings && exportSettings.tables && exportSettings.tables.exportLimit > 0)
2647
+ ? exportSettings.tables.exportLimit : MAX_EXPORT_ITEMS;
2648
+ // and validate it
2649
+ if (this._lastQueryTotalItems > exportLimit) {
2650
+ // call error handler
2651
+ // provide a recognizible error type
2652
+ if (options && options.errorHandler) {
2653
+ options.errorHandler(new ExportLimitExceededError('Export limit exceeded'));
2654
+ return [2 /*return*/];
2655
+ }
2656
+ // or show warning modal and exit
2657
+ this._modalService.showWarningDialog(this._translateService.instant('Tables.ExportList'), this._translateService.instant('Tables.ExportLimitExceeded', { dataLength: this._lastQueryTotalItems, exportLimit: exportLimit }), i2.DIALOG_BUTTONS.Ok);
2658
+ return [2 /*return*/];
2659
+ }
2660
+ totalDisplayedItems = Array.from(this.dataTable.context[0].aiDisplay).length;
2661
+ if (!(totalDisplayedItems === this._lastQueryTotalItems))
2662
+ return [3 /*break*/, 1];
2663
+ _a = this.getExportableData(), body = _a.body, header = _a.header;
2664
+ // and export them to excel
2665
+ this._exportSpreadsheet.export(body, this._translateService.instant(this.config.title || 'Tables.ExportResults') + ".xlsx", {
2666
+ header: header,
2667
+ skipHeader: false
2668
+ });
2669
+ return [3 /*break*/, 3];
2670
+ case 1:
2671
+ previousDataState = this.dataTable.rows().data().toArray();
2672
+ return [4 /*yield*/, this.lastQuery.take(exportLimit).getItems()];
2673
+ case 2:
2674
+ targetDataState = _c.sent();
2675
+ // change table data on the fly, but do not redraw
2676
+ this.dataTable.clear().rows.add(targetDataState);
2677
+ _b = this.getExportableData(), body = _b.body, header = _b.header;
2678
+ // reset table data
2679
+ this.dataTable.clear().rows.add(previousDataState);
2680
+ // and export target data to excel
2681
+ this._exportSpreadsheet.export(body, this._translateService.instant(this.config.title || 'Tables.ExportResults') + ".xlsx", {
2682
+ header: header,
2683
+ skipHeader: false
2684
+ });
2685
+ _c.label = 3;
2686
+ case 3:
2687
+ // exit
2688
+ return [2 /*return*/];
2689
+ case 4:
2690
+ err_1 = _c.sent();
2691
+ // log error
2692
+ console.error(err_1);
2693
+ // call error handler, if defined
2694
+ if (options && options.errorHandler) {
2695
+ options.errorHandler(err_1);
2696
+ }
2697
+ else {
2698
+ // use default error service
2699
+ this._errorService.showError(err_1, {
2700
+ continueLink: '.'
2701
+ });
2702
+ }
2703
+ return [3 /*break*/, 6];
2704
+ case 5:
2705
+ this._loading.hideLoading();
2706
+ return [7 /*endfinally*/];
2707
+ case 6: return [2 /*return*/];
2708
+ }
2709
+ });
2710
+ });
2711
+ };
2712
+ AdvancedTableComponent.prototype.getExportableData = function () {
2713
+ var _this = this;
2714
+ if (!(this.dataTable && this.dataTable.buttons
2715
+ && typeof this.dataTable.buttons.exportData === 'function' && this.config)) {
2716
+ return { body: [], header: [] };
2717
+ }
2718
+ // fetch exportable excel data
2719
+ var _a = this.dataTable.buttons.exportData(), body = _a.body, header = _a.header;
2720
+ var cleanupIndexes = [];
2721
+ // clean up headers
2722
+ header = header.filter(function (headerItem, index) {
2723
+ // exclude empty headers
2724
+ if (headerItem.trim().length === 0) {
2725
+ cleanupIndexes.push(index);
2726
+ return false;
2727
+ }
2728
+ // find item by title
2729
+ var findItem = _this.config.columns.find(function (column) {
2730
+ return column.title && column.title.length && _this._translateService.instant(column.title) === headerItem;
2731
+ });
2732
+ // exclude hidden columns
2733
+ if (findItem && findItem.hidden === true) {
2734
+ cleanupIndexes.push(index);
2735
+ return false;
2736
+ }
2737
+ return true;
2738
+ });
2739
+ // clean up body
2740
+ body = body.map(function (row) {
2741
+ return row.filter(function (_, rowIndex) {
2742
+ return cleanupIndexes.indexOf(rowIndex) === -1;
2743
+ });
2744
+ });
2745
+ return { body: body, header: header };
2746
+ };
2301
2747
  AdvancedTableComponent.decorators = [
2302
2748
  { type: i0.Component, args: [{
2303
2749
  // tslint:disable-next-line: component-selector
@@ -2320,7 +2766,11 @@
2320
2766
  { type: i2.TemplatePipe },
2321
2767
  { type: i2.LoadingService },
2322
2768
  { type: http.HttpClient },
2323
- { type: ColumnSelectorService }
2769
+ { type: ColumnSelectorService },
2770
+ { type: i2.ConfigurationService },
2771
+ { type: i2.ExportSpreadsheetService },
2772
+ { type: i2.ModalService },
2773
+ { type: i2.ErrorService }
2324
2774
  ];
2325
2775
  };
2326
2776
  AdvancedTableComponent.propDecorators = {
@@ -3334,49 +3784,10 @@
3334
3784
  /** @nocollapse */
3335
3785
  AdvancedSearchConfigurationResolver.ctorParameters = function () {
3336
3786
  return [
3337
- { type: http.HttpClient }
3338
- ];
3339
- };
3340
- return AdvancedSearchConfigurationResolver;
3341
- }());
3342
-
3343
- var ActivatedTableService = /** @class */ (function () {
3344
- function ActivatedTableService(_router, _activatedRoute) {
3345
- var _this = this;
3346
- this._router = _router;
3347
- this._activatedRoute = _activatedRoute;
3348
- _router.events.forEach(function (event) {
3349
- if (event instanceof i1$1.NavigationStart) {
3350
- if (_this._activeTable) {
3351
- _this._activeTable = null;
3352
- }
3353
- }
3354
- });
3355
- }
3356
- Object.defineProperty(ActivatedTableService.prototype, "activeTable", {
3357
- get: function () {
3358
- return this._activeTable;
3359
- },
3360
- set: function (tableComponent) {
3361
- this._activeTable = tableComponent;
3362
- },
3363
- enumerable: true,
3364
- configurable: true
3365
- });
3366
- ActivatedTableService.decorators = [
3367
- { type: i0.Injectable, args: [{
3368
- providedIn: 'root'
3369
- },] }
3370
- ];
3371
- /** @nocollapse */
3372
- ActivatedTableService.ctorParameters = function () {
3373
- return [
3374
- { type: i1$1.Router },
3375
- { type: i1$1.ActivatedRoute }
3787
+ { type: http.HttpClient }
3376
3788
  ];
3377
3789
  };
3378
- ActivatedTableService.ngInjectableDef = i0.defineInjectable({ factory: function ActivatedTableService_Factory() { return new ActivatedTableService(i0.inject(i1$1.Router), i0.inject(i1$1.ActivatedRoute)); }, token: ActivatedTableService, providedIn: "root" });
3379
- return ActivatedTableService;
3790
+ return AdvancedSearchConfigurationResolver;
3380
3791
  }());
3381
3792
 
3382
3793
  var AdvancedTableSettingsComponent = /** @class */ (function () {
@@ -4314,265 +4725,6 @@
4314
4725
  return AdvancedTableEditorDirective;
4315
4726
  }());
4316
4727
 
4317
- var MAX_EXPORT_ITEMS = 500;
4318
- var BtnExpDirective = /** @class */ (function () {
4319
- function BtnExpDirective(_activatedTable, _context, _config, _translate, _loadingService, _errorService) {
4320
- this._activatedTable = _activatedTable;
4321
- this._context = _context;
4322
- this._config = _config;
4323
- this._translate = _translate;
4324
- this._loadingService = _loadingService;
4325
- this._errorService = _errorService;
4326
- }
4327
- BtnExpDirective.prototype.clickEvent = function (event) {
4328
- return __awaiter(this, void 0, void 0, function () {
4329
- var lastQuery, tableConfig, serviceHeaders, queryModel, query, queryParams, exportSettings, maxExportItems, url;
4330
- return __generator(this, function (_a) {
4331
- event.preventDefault();
4332
- event.stopPropagation();
4333
- if (this._activatedTable.activeTable) {
4334
- lastQuery = this._activatedTable.activeTable.lastQuery;
4335
- tableConfig = this._activatedTable.activeTable.config;
4336
- serviceHeaders = this._context.getService().getHeaders();
4337
- queryModel = lastQuery.getModel();
4338
- query = this._context.model(queryModel).asQueryable();
4339
- queryParams = lastQuery.getParams();
4340
- query = this.constructQuery(query, queryParams, tableConfig, serviceHeaders);
4341
- exportSettings = this._config.settings;
4342
- maxExportItems = exportSettings && exportSettings.tables && exportSettings.tables.exportLimit;
4343
- if (maxExportItems && typeof maxExportItems === 'number' && maxExportItems > 0) {
4344
- query.skip(0).take(maxExportItems);
4345
- }
4346
- else {
4347
- query.skip(0).take(MAX_EXPORT_ITEMS);
4348
- }
4349
- url = this.constructURL(query);
4350
- this.downloadFile(url, query.getService().getHeaders(), query.getModel());
4351
- }
4352
- return [2 /*return*/];
4353
- });
4354
- });
4355
- };
4356
- /**
4357
- * Sets the parameters to the query based on
4358
- * the active filters of the activated table
4359
- * @param {ClientDataQueryable} query
4360
- * @param params: The filters of the last query of the activated table
4361
- * @return ClientDataQueryable
4362
- */
4363
- BtnExpDirective.prototype.setParams = function (query, params) {
4364
- if (params && typeof params === 'object') {
4365
- Object.keys(params).forEach(function (key) {
4366
- query.setParam(key, params[key]);
4367
- });
4368
- }
4369
- return query;
4370
- };
4371
- /**
4372
- * Sets the headers to the query based on
4373
- * the default headers of the DataContext
4374
- * and appending the accept header to get
4375
- * an xlsx file from the API
4376
- * @param {ClientDataQueryable} query
4377
- * @param {Headers} headers: The headers to append to the query
4378
- * @return ClientDataQueryable
4379
- */
4380
- BtnExpDirective.prototype.setHeaders = function (query, headers) {
4381
- Object.keys(headers).forEach(function (key) {
4382
- if (headers.hasOwnProperty(key)) {
4383
- query.getService().setHeader(key, headers[key]);
4384
- }
4385
- });
4386
- // sets a header to accept xlsx files
4387
- query.getService().setHeader('Accept', 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
4388
- return query;
4389
- };
4390
- /**
4391
- * Constructs the select parameter of the
4392
- * ClientDataQuery by replacing the target name
4393
- * of the field based on the localized translation
4394
- * of that property on the advanced tabled
4395
- * @param {ClientDataQueryable} query
4396
- * @param tableConfig: The configuration of the activated table
4397
- * @return ClientDataQueryable
4398
- */
4399
- BtnExpDirective.prototype.constructQueryParam = function (query, tableConfig) {
4400
- var _this = this;
4401
- var selectQuery = query.getParams().$select;
4402
- var selectQueryArray = selectQuery.split(',');
4403
- selectQueryArray = selectQueryArray.map(function (select) {
4404
- var e_1, _a, e_2, _b;
4405
- var words = select.split(' ');
4406
- if (words.length === 3) {
4407
- if (tableConfig && tableConfig.columns) {
4408
- try {
4409
- for (var _c = __values(tableConfig.columns), _d = _c.next(); !_d.done; _d = _c.next()) {
4410
- var column = _d.value;
4411
- if (column.property === words[2] && column.title) {
4412
- words[2] = "\"" + _this._translate.instant(column.title) + "\"";
4413
- }
4414
- else if (column.property === words[2]) {
4415
- words[2] = "\"" + _this._translate.instant(words[2]) + "\"";
4416
- }
4417
- }
4418
- }
4419
- catch (e_1_1) {
4420
- e_1 = { error: e_1_1 };
4421
- }
4422
- finally {
4423
- try {
4424
- if (_d && !_d.done && (_a = _c.return))
4425
- _a.call(_c);
4426
- }
4427
- finally {
4428
- if (e_1)
4429
- throw e_1.error;
4430
- }
4431
- }
4432
- }
4433
- }
4434
- if (words.length === 1) {
4435
- if (tableConfig && tableConfig.columns) {
4436
- try {
4437
- for (var _e = __values(tableConfig.columns), _f = _e.next(); !_f.done; _f = _e.next()) {
4438
- var column = _f.value;
4439
- if (column.name === words[0] && column.title) {
4440
- words[0] = words[0] + " as \"" + _this._translate.instant(column.title) + "\"";
4441
- break;
4442
- }
4443
- else if (column.name === words[0] && column.property) {
4444
- words[0] = words[0] + " as \"" + _this._translate.instant(column.property) + "\"";
4445
- break;
4446
- }
4447
- else if (words[0] === column.name && words[0] === "id" && column.hidden) {
4448
- break;
4449
- }
4450
- else if (words[0] == column.name || words[0] === column.property) {
4451
- words[0] = words[0] + " as \"" + _this._translate.instant(words[0]) + "\"";
4452
- }
4453
- }
4454
- }
4455
- catch (e_2_1) {
4456
- e_2 = { error: e_2_1 };
4457
- }
4458
- finally {
4459
- try {
4460
- if (_f && !_f.done && (_b = _e.return))
4461
- _b.call(_e);
4462
- }
4463
- finally {
4464
- if (e_2)
4465
- throw e_2.error;
4466
- }
4467
- }
4468
- }
4469
- return words[0];
4470
- }
4471
- return words.join(' ');
4472
- });
4473
- selectQuery = selectQueryArray.join(',');
4474
- query.setParam('$select', selectQuery);
4475
- return query;
4476
- };
4477
- /**
4478
- * Constructs the fetch URL based the query parameters
4479
- * @param {ClientDataQueryable} query
4480
- * @return String
4481
- */
4482
- BtnExpDirective.prototype.constructURL = function (query) {
4483
- var baseURL = query.getService().getBase();
4484
- var url = baseURL.endsWith('/') ? (baseURL + query.getModel() + '?') : (baseURL + '/' + query.getModel() + '?');
4485
- Object.keys(query.getParams()).forEach(function (key, index) {
4486
- if (index === 0) {
4487
- url += key + '=' + query.getParams()[key];
4488
- }
4489
- else {
4490
- url += '&' + key + '=' + query.getParams()[key];
4491
- }
4492
- });
4493
- return url;
4494
- };
4495
- /**
4496
- * Constructs the query by setting the parameters of the
4497
- * advanced table's active filters, sets the necessary headers
4498
- * and build the select parameter of the query
4499
- * @param {ClientDataQueryable} query
4500
- * @param params: The filters of the last query of the activated table
4501
- * @param tableConfig: The configuration of the activated table
4502
- * @param {Headers} headers: The headers to append to the query
4503
- * @return ClientDataQueryable
4504
- */
4505
- BtnExpDirective.prototype.constructQuery = function (query, params, tableConfig, headers) {
4506
- var _query = this.setParams(query, params);
4507
- _query = this.setHeaders(_query, headers);
4508
- _query = this.constructQueryParam(_query, tableConfig);
4509
- return _query;
4510
- };
4511
- /**
4512
- * Fetches and saves the xlsx file
4513
- * @param {String} url
4514
- * @param {Headers} serviceHeaders: The headers to append to the query
4515
- * @param modelName: The model name of the advanced table
4516
- */
4517
- BtnExpDirective.prototype.downloadFile = function (url, serviceHeaders, modelName) {
4518
- var _this = this;
4519
- this._loadingService.showLoading();
4520
- fetch(encodeURI(url), {
4521
- headers: serviceHeaders,
4522
- credentials: 'include'
4523
- }).then(function (response) {
4524
- if (response && !response.ok) {
4525
- throw new client.ResponseError(response.statusText, response.status);
4526
- }
4527
- return response.blob();
4528
- }).then(function (blob) {
4529
- var objectUrl = window.URL.createObjectURL(blob);
4530
- var a = document.createElement('a');
4531
- document.body.appendChild(a);
4532
- a.setAttribute('style', 'display: none');
4533
- a.href = objectUrl;
4534
- var downloadName = modelName + ".xlsx";
4535
- a.download = downloadName;
4536
- // this adds support for IE and MS Edge (up to version 44.19041)
4537
- if (window.navigator && window.navigator.msSaveOrOpenBlob) {
4538
- window.navigator.msSaveOrOpenBlob(blob, downloadName);
4539
- }
4540
- else {
4541
- // for all other browsers
4542
- a.click();
4543
- }
4544
- window.URL.revokeObjectURL(objectUrl);
4545
- a.remove();
4546
- _this._loadingService.hideLoading();
4547
- }).catch(function (err) {
4548
- _this._loadingService.hideLoading();
4549
- _this._errorService.showError(err, {
4550
- continueLink: '.'
4551
- });
4552
- });
4553
- };
4554
- BtnExpDirective.decorators = [
4555
- { type: i0.Directive, args: [{
4556
- selector: '.universis-btn-export'
4557
- },] }
4558
- ];
4559
- /** @nocollapse */
4560
- BtnExpDirective.ctorParameters = function () {
4561
- return [
4562
- { type: ActivatedTableService },
4563
- { type: i1.AngularDataContext },
4564
- { type: i2.ConfigurationService },
4565
- { type: core.TranslateService },
4566
- { type: i2.LoadingService },
4567
- { type: i2.ErrorService }
4568
- ];
4569
- };
4570
- BtnExpDirective.propDecorators = {
4571
- clickEvent: [{ type: i0.HostListener, args: ['click', ['$event'],] }]
4572
- };
4573
- return BtnExpDirective;
4574
- }());
4575
-
4576
4728
  var AdvancedAggregatorService = /** @class */ (function () {
4577
4729
  function AdvancedAggregatorService(_context, _template) {
4578
4730
  this._context = _context;
@@ -5157,6 +5309,8 @@
5157
5309
  return ParseTitlePipe;
5158
5310
  }());
5159
5311
 
5312
+ // tslint:disable: quotemark
5313
+ // tslint:disable: max-line-length
5160
5314
  var TABLES_EL = {
5161
5315
  "Tables": {
5162
5316
  "Export": "Εξαγωγή",
@@ -5240,7 +5394,10 @@
5240
5394
  "DataError": {
5241
5395
  "Title": "Σφάλμα κατά την παραλαβή των δεδομένων",
5242
5396
  "Message": "Συνέβη σφάλμα κατά την παραλαβή των δεδομένων. Προσπαθήστε ξανά ή τροποποιήστε τα στοιχεία αναζήτησης."
5243
- }
5397
+ },
5398
+ "ExportList": "Εξαγωγή λίστας",
5399
+ "ExportLimitExceeded": "Το πλήθος των στοιχείων προς εξαγωγή ({{dataLength}}) ξεπερνάει το μέγιστο επιτρεπτό ({{exportLimit}}). Παρακαλούμε προσαρμόστε τα φίλτρα της αναζήτησης και προσπαθήστε ξανά.",
5400
+ "ExportResults": "Δεδομένα λίστας"
5244
5401
  },
5245
5402
  "TrueFalse": {
5246
5403
  "long": {
@@ -5281,6 +5438,8 @@
5281
5438
  }
5282
5439
  };
5283
5440
 
5441
+ // tslint:disable: quotemark
5442
+ // tslint:disable: max-line-length
5284
5443
  var TABLES_EN = {
5285
5444
  "Tables": {
5286
5445
  "Export": "Export",
@@ -5363,7 +5522,10 @@
5363
5522
  "DataError": {
5364
5523
  "Title": "Error while getting data",
5365
5524
  "Message": "An error occurred while getting data. Please try again or change your criteria."
5366
- }
5525
+ },
5526
+ "ExportList": "Export list",
5527
+ "ExportLimitExceeded": "The number of items that are to be exported ({{dataLength}}) exceeds the export limit ({{exportLimit}}). Please apply more specific filters to the search.",
5528
+ "ExportResults": "Exported list"
5367
5529
  },
5368
5530
  "TrueFalse": {
5369
5531
  "long": {
@@ -5829,6 +5991,7 @@
5829
5991
  exports.NgClassFormatter = NgClassFormatter;
5830
5992
  exports.LanguageFormatter = LanguageFormatter;
5831
5993
  exports.COLUMN_FORMATTERS = COLUMN_FORMATTERS;
5994
+ exports.ExportLimitExceededError = ExportLimitExceededError;
5832
5995
  exports.AdvancedTableConfiguration = AdvancedTableConfiguration;
5833
5996
  exports.AdvancedTableComponent = AdvancedTableComponent;
5834
5997
  exports.ɵ0 = ɵ0;
@@ -5843,6 +6006,7 @@
5843
6006
  exports.TableSimpleHeaderComponent = TableSimpleHeaderComponent;
5844
6007
  exports.AdvancedTableNotNullError = AdvancedTableNotNullError;
5845
6008
  exports.AdvancedTableEditorDirective = AdvancedTableEditorDirective;
6009
+ exports.MAX_EXPORT_ITEMS = MAX_EXPORT_ITEMS;
5846
6010
  exports.BtnExpDirective = BtnExpDirective;
5847
6011
  exports.AdvancedAggregatorComponent = AdvancedAggregatorComponent;
5848
6012
  exports.AdvancedAggregatorListComponent = AdvancedAggregatorListComponent;