@universis/ngx-tables 0.6.0

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.
Files changed (103) hide show
  1. package/LICENSE +163 -0
  2. package/README.md +121 -0
  3. package/bundles/universis-ngx-tables.umd.js +4591 -0
  4. package/bundles/universis-ngx-tables.umd.js.map +1 -0
  5. package/bundles/universis-ngx-tables.umd.min.js +2 -0
  6. package/bundles/universis-ngx-tables.umd.min.js.map +1 -0
  7. package/esm2015/lib/components/add-items/add-items.component.js +142 -0
  8. package/esm2015/lib/components/advanced-aggregator/advanced-aggregator.component.js +120 -0
  9. package/esm2015/lib/components/advanced-aggregator-list/advanced-aggregator-list.component.js +53 -0
  10. package/esm2015/lib/components/advanced-list/advanced-list.component.js +173 -0
  11. package/esm2015/lib/components/advanced-row-action/advanced-row-action.component.js +175 -0
  12. package/esm2015/lib/components/advanced-search-form/advanced-search-form.component.js +134 -0
  13. package/esm2015/lib/components/advanced-select/advanced-select.component.js +51 -0
  14. package/esm2015/lib/components/advanced-select/advanced-select.service.js +40 -0
  15. package/esm2015/lib/components/advanced-table/advanced-filter-value-provider.service.js +37 -0
  16. package/esm2015/lib/components/advanced-table/advanced-table-resolvers.js +44 -0
  17. package/esm2015/lib/components/advanced-table/advanced-table-search-base.js +23 -0
  18. package/esm2015/lib/components/advanced-table/advanced-table-search.component.js +519 -0
  19. package/esm2015/lib/components/advanced-table/advanced-table-settings.component.js +109 -0
  20. package/esm2015/lib/components/advanced-table/advanced-table.component.js +1007 -0
  21. package/esm2015/lib/components/advanced-table/advanced-table.formatters.interface.js +16 -0
  22. package/esm2015/lib/components/advanced-table/advanced-table.formatters.js +271 -0
  23. package/esm2015/lib/components/advanced-table/advanced-table.interfaces.js +2 -0
  24. package/esm2015/lib/components/advanced-table-modal/advanced-table-modal-base.component.js +379 -0
  25. package/esm2015/lib/components/table-simple-header/table-simple-header.component.js +52 -0
  26. package/esm2015/lib/directives/advanced-table-editor.directive.js +157 -0
  27. package/esm2015/lib/directives/btnexp.directive.js +225 -0
  28. package/esm2015/lib/i18n/tables.el.js +104 -0
  29. package/esm2015/lib/i18n/tables.en.js +103 -0
  30. package/esm2015/lib/pipes/advanced-aggregator.pipe.js +35 -0
  31. package/esm2015/lib/pipes/advansed-aggregator-list-title-parse.pipe.js +46 -0
  32. package/esm2015/lib/services/advanced-aggregator/advanced-aggregator.service.js +117 -0
  33. package/esm2015/lib/tables.activated-table.service.js +36 -0
  34. package/esm2015/lib/tables.module.js +134 -0
  35. package/esm2015/public_api.js +22 -0
  36. package/esm2015/universis-ngx-tables.js +14 -0
  37. package/esm5/lib/components/add-items/add-items.component.js +153 -0
  38. package/esm5/lib/components/advanced-aggregator/advanced-aggregator.component.js +169 -0
  39. package/esm5/lib/components/advanced-aggregator-list/advanced-aggregator-list.component.js +56 -0
  40. package/esm5/lib/components/advanced-list/advanced-list.component.js +185 -0
  41. package/esm5/lib/components/advanced-row-action/advanced-row-action.component.js +179 -0
  42. package/esm5/lib/components/advanced-search-form/advanced-search-form.component.js +137 -0
  43. package/esm5/lib/components/advanced-select/advanced-select.component.js +56 -0
  44. package/esm5/lib/components/advanced-select/advanced-select.service.js +43 -0
  45. package/esm5/lib/components/advanced-table/advanced-filter-value-provider.service.js +50 -0
  46. package/esm5/lib/components/advanced-table/advanced-table-resolvers.js +48 -0
  47. package/esm5/lib/components/advanced-table/advanced-table-search-base.js +29 -0
  48. package/esm5/lib/components/advanced-table/advanced-table-search.component.js +556 -0
  49. package/esm5/lib/components/advanced-table/advanced-table-settings.component.js +115 -0
  50. package/esm5/lib/components/advanced-table/advanced-table.component.js +1035 -0
  51. package/esm5/lib/components/advanced-table/advanced-table.formatters.interface.js +16 -0
  52. package/esm5/lib/components/advanced-table/advanced-table.formatters.js +313 -0
  53. package/esm5/lib/components/advanced-table/advanced-table.interfaces.js +2 -0
  54. package/esm5/lib/components/advanced-table-modal/advanced-table-modal-base.component.js +295 -0
  55. package/esm5/lib/components/table-simple-header/table-simple-header.component.js +58 -0
  56. package/esm5/lib/directives/advanced-table-editor.directive.js +175 -0
  57. package/esm5/lib/directives/btnexp.directive.js +253 -0
  58. package/esm5/lib/i18n/tables.el.js +104 -0
  59. package/esm5/lib/i18n/tables.en.js +103 -0
  60. package/esm5/lib/pipes/advanced-aggregator.pipe.js +39 -0
  61. package/esm5/lib/pipes/advansed-aggregator-list-title-parse.pipe.js +49 -0
  62. package/esm5/lib/services/advanced-aggregator/advanced-aggregator.service.js +130 -0
  63. package/esm5/lib/tables.activated-table.service.js +43 -0
  64. package/esm5/lib/tables.module.js +139 -0
  65. package/esm5/public_api.js +22 -0
  66. package/esm5/universis-ngx-tables.js +14 -0
  67. package/fesm2015/universis-ngx-tables.js +4127 -0
  68. package/fesm2015/universis-ngx-tables.js.map +1 -0
  69. package/fesm5/universis-ngx-tables.js +4313 -0
  70. package/fesm5/universis-ngx-tables.js.map +1 -0
  71. package/lib/advanced-aggregator.d.ts +124 -0
  72. package/lib/components/add-items/add-items.component.d.ts +44 -0
  73. package/lib/components/advanced-aggregator/advanced-aggregator.component.d.ts +45 -0
  74. package/lib/components/advanced-aggregator-list/advanced-aggregator-list.component.d.ts +25 -0
  75. package/lib/components/advanced-list/advanced-list.component.d.ts +42 -0
  76. package/lib/components/advanced-row-action/advanced-row-action.component.d.ts +42 -0
  77. package/lib/components/advanced-search-form/advanced-search-form.component.d.ts +27 -0
  78. package/lib/components/advanced-select/advanced-select.component.d.ts +14 -0
  79. package/lib/components/advanced-select/advanced-select.service.d.ts +9 -0
  80. package/lib/components/advanced-table/advanced-filter-value-provider.service.d.ts +8 -0
  81. package/lib/components/advanced-table/advanced-table-resolvers.d.ts +12 -0
  82. package/lib/components/advanced-table/advanced-table-search-base.d.ts +7 -0
  83. package/lib/components/advanced-table/advanced-table-search.component.d.ts +80 -0
  84. package/lib/components/advanced-table/advanced-table-settings.component.d.ts +35 -0
  85. package/lib/components/advanced-table/advanced-table.component.d.ts +142 -0
  86. package/lib/components/advanced-table/advanced-table.formatters.d.ts +62 -0
  87. package/lib/components/advanced-table/advanced-table.formatters.interface.d.ts +15 -0
  88. package/lib/components/advanced-table/advanced-table.interfaces.d.ts +27 -0
  89. package/lib/components/advanced-table-modal/advanced-table-modal-base.component.d.ts +82 -0
  90. package/lib/components/table-simple-header/table-simple-header.component.d.ts +14 -0
  91. package/lib/directives/advanced-table-editor.directive.d.ts +25 -0
  92. package/lib/directives/btnexp.directive.d.ts +68 -0
  93. package/lib/i18n/tables.el.d.ts +102 -0
  94. package/lib/i18n/tables.en.d.ts +101 -0
  95. package/lib/pipes/advanced-aggregator.pipe.d.ts +21 -0
  96. package/lib/pipes/advansed-aggregator-list-title-parse.pipe.d.ts +21 -0
  97. package/lib/services/advanced-aggregator/advanced-aggregator.service.d.ts +32 -0
  98. package/lib/tables.activated-table.service.d.ts +9 -0
  99. package/lib/tables.module.d.ts +7 -0
  100. package/package.json +51 -0
  101. package/public_api.d.ts +18 -0
  102. package/universis-ngx-tables.d.ts +12 -0
  103. package/universis-ngx-tables.metadata.json +1 -0
@@ -0,0 +1,4313 @@
1
+ import { at } from 'lodash';
2
+ import { getNativeName } from 'iso-639-1/build';
3
+ import * as jQuery_ from 'jquery';
4
+ import 'datatables.net';
5
+ import 'datatables.net-scroller';
6
+ import 'rxjs/add/observable/combineLatest';
7
+ import { HttpClient } from '@angular/common/http';
8
+ import { DatePipe, CommonModule } from '@angular/common';
9
+ import { ClientDataQueryable, ResponseError, TextUtils } from '@themost/client';
10
+ import { FormArray, FormBuilder, FormControl, FormsModule, ReactiveFormsModule } from '@angular/forms';
11
+ import { FormioModule } from 'angular-formio';
12
+ import { BsModalService, BsModalRef, ModalModule } from 'ngx-bootstrap/modal';
13
+ import { BsDropdownModule } from 'ngx-bootstrap/dropdown';
14
+ import { ProgressbarModule } from 'ngx-bootstrap/progressbar';
15
+ import { GroupByPipe, NgPipesModule } from 'ngx-pipes';
16
+ import { __awaiter, __generator, __values, __spread, __assign, __extends } from 'tslib';
17
+ import { Injectable, Pipe, EventEmitter, Input, Output, Component, ElementRef, ViewChild, ViewEncapsulation, Directive, HostListener, defineInjectable, inject, NgModule, CUSTOM_ELEMENTS_SCHEMA, ChangeDetectorRef, InjectionToken, Inject, Injector, ChangeDetectionStrategy } from '@angular/core';
18
+ import { RouterModalOkCancel, RouterModalModule } from '@universis/common/routing';
19
+ import { ActivatedRoute, Router, NavigationStart, RouterModule } from '@angular/router';
20
+ import { BehaviorSubject } from 'rxjs';
21
+ import { TranslateService, TranslatePipe, TranslateModule } from '@ngx-translate/core';
22
+ import { AngularDataContext } from '@themost/angular';
23
+ import { ServiceUrlPreProcessor, TranslatePreProcessor, AdvancedFormsModule } from '@universis/forms';
24
+ import { TemplatePipe, LoadingService, ErrorService, DIALOG_BUTTONS, ModalService, UserActivityService, ToastService, AppEventService, UserStorageService, ConfigurationService, SharedModule } from '@universis/common';
25
+
26
+ var AdvancedColumnFormatter = /** @class */ (function () {
27
+ function AdvancedColumnFormatter() {
28
+ }
29
+ return AdvancedColumnFormatter;
30
+ }());
31
+ var NestedPropertyFormatter = /** @class */ (function (_super) {
32
+ __extends(NestedPropertyFormatter, _super);
33
+ function NestedPropertyFormatter() {
34
+ return _super.call(this) || this;
35
+ }
36
+ NestedPropertyFormatter.prototype.render = function (data, type, row, meta) {
37
+ // get column
38
+ var column = meta.settings.aoColumns[meta.col];
39
+ if (column && column.data) {
40
+ return at(row, column.data.replace(/\//g, '.'));
41
+ }
42
+ return data;
43
+ };
44
+ return NestedPropertyFormatter;
45
+ }(AdvancedColumnFormatter));
46
+ var ButtonFormatter = /** @class */ (function (_super) {
47
+ __extends(ButtonFormatter, _super);
48
+ function ButtonFormatter() {
49
+ return _super.call(this) || this;
50
+ }
51
+ ButtonFormatter.prototype.render = function (data, type, row, meta) {
52
+ var _this = this;
53
+ if (data == null) {
54
+ return '';
55
+ }
56
+ // get column
57
+ var column = meta.settings.aoColumns[meta.col];
58
+ // get format options
59
+ var formatOptions = Object.assign({
60
+ buttonClass: 'btn btn-default'
61
+ }, this.formatOptions);
62
+ // get text content
63
+ var buttonText;
64
+ var buttonTitle = '';
65
+ if (formatOptions.buttonText) {
66
+ buttonText = this.injector.get(TranslateService).instant(formatOptions.buttonText);
67
+ }
68
+ else {
69
+ buttonText = formatOptions.buttonContent;
70
+ }
71
+ if (formatOptions.buttonTitle) {
72
+ buttonTitle = this.injector.get(TranslateService).instant(formatOptions.buttonTitle);
73
+ }
74
+ if (Array.isArray(this.formatOptions.commands)) {
75
+ var activatedRoute = this.injector.get(ActivatedRoute);
76
+ var router = this.injector.get(Router);
77
+ var commands = this.formatOptions.commands.map(function (command) {
78
+ if (typeof command === 'string') {
79
+ return new TemplatePipe().transform(command, row);
80
+ }
81
+ if (command.outlets) {
82
+ var commandOutlets_1 = {};
83
+ Object.keys(command.outlets).forEach(function (key) {
84
+ if (Object.prototype.hasOwnProperty.call(command.outlets, key)) {
85
+ var outlet = command.outlets[key];
86
+ if (Array.isArray(outlet)) {
87
+ Object.defineProperty(commandOutlets_1, key, {
88
+ enumerable: true,
89
+ configurable: true,
90
+ writable: true,
91
+ value: outlet.map(function (x) {
92
+ return new TemplatePipe().transform(x, row);
93
+ })
94
+ });
95
+ }
96
+ else {
97
+ Object.defineProperty(commandOutlets_1, key, {
98
+ enumerable: true,
99
+ configurable: true,
100
+ writable: true,
101
+ value: outlet
102
+ });
103
+ }
104
+ }
105
+ });
106
+ return {
107
+ outlets: commandOutlets_1
108
+ };
109
+ }
110
+ return command;
111
+ });
112
+ var queryParams_1 = {};
113
+ var replaceUrl = true;
114
+ if (this.formatOptions.navigationExtras && this.formatOptions.navigationExtras.queryParams) {
115
+ Object.keys(this.formatOptions.navigationExtras.queryParams).map(function (key) {
116
+ queryParams_1[key] = new TemplatePipe().transform(_this.formatOptions.navigationExtras.queryParams[key], row);
117
+ });
118
+ }
119
+ if (this.formatOptions.navigationExtras && typeof this.formatOptions.navigationExtras.replaceUrl !== 'undefined') {
120
+ replaceUrl = this.formatOptions.navigationExtras.replaceUrl;
121
+ }
122
+ var skipLocationChange = false;
123
+ if (this.formatOptions.navigationExtras && typeof this.formatOptions.navigationExtras.skipLocationChange !== 'undefined') {
124
+ skipLocationChange = this.formatOptions.navigationExtras.skipLocationChange;
125
+ }
126
+ var routerLink = router.createUrlTree(commands, {
127
+ relativeTo: activatedRoute,
128
+ queryParams: queryParams_1,
129
+ replaceUrl: replaceUrl,
130
+ skipLocationChange: skipLocationChange
131
+ }).toString();
132
+ return "<a class=\"" + formatOptions.buttonClass + "\" title=\"" + buttonTitle + "\" href=\"#" + routerLink + "\">" + buttonText + "</a>";
133
+ }
134
+ // and return button
135
+ var href = new TemplatePipe().transform(this.formatString, row);
136
+ return "<a class=\"" + formatOptions.buttonClass + "\" title=\"" + buttonTitle + "\" href=\"" + href + "\">" + buttonText + "</a>";
137
+ };
138
+ return ButtonFormatter;
139
+ }(AdvancedColumnFormatter));
140
+ var LinkFormatter = /** @class */ (function (_super) {
141
+ __extends(LinkFormatter, _super);
142
+ function LinkFormatter() {
143
+ return _super.call(this) || this;
144
+ }
145
+ LinkFormatter.prototype.render = function (data, type, row, meta) {
146
+ // get column
147
+ var column = meta.settings.aoColumns[meta.col];
148
+ if (column && column.data) {
149
+ return "<a href=\"" + (new TemplatePipe().transform(this.formatString, row)) + "\">" + data + "</a>";
150
+ }
151
+ return data;
152
+ };
153
+ return LinkFormatter;
154
+ }(AdvancedColumnFormatter));
155
+ var ActionLinkFormatter = /** @class */ (function (_super) {
156
+ __extends(ActionLinkFormatter, _super);
157
+ function ActionLinkFormatter() {
158
+ return _super.call(this) || this;
159
+ }
160
+ ActionLinkFormatter.prototype.render = function (data, type, row, meta) {
161
+ var _this = this;
162
+ // get column
163
+ var column = meta.settings.aoColumns[meta.col];
164
+ if (column && column.data) {
165
+ this.actions = this.actions || [];
166
+ var allowedActions = this.actions.filter(function (x) {
167
+ if (x.access && x.access.length > 0) {
168
+ var access = x.access;
169
+ access = access.filter(function (y) {
170
+ if (y.studentStatuses) {
171
+ return y.studentStatuses.find(function (z) { return z.alternateName === row.studentStatus; });
172
+ }
173
+ });
174
+ if (access && access.length > 0) {
175
+ return x;
176
+ }
177
+ }
178
+ else {
179
+ return x;
180
+ }
181
+ });
182
+ // return the dropdown menu with 3 dots
183
+ return new TemplatePipe().transform("<div class='dropdown details-control' data-id='" + data + "' data-type='student' >\n <a id=\"dropdownMenuButton-" + data + "\" data-toggle=\"dropdown\" aria-haspopup=\"true\" aria-expanded=\"false\">\n <span class=\"fa-2x text-dots\"></span></a>\n <div class=\"dropdown-menu\" aria-labelledby=\"dropdownMenuButton-" + data + "\">\n " + allowedActions.map(function (x) { return "<a data-name='" + x.name + "' class=\"dropdown-item\" href=\"" + x.href + "\">\n " + _this.injector.get(TranslateService).instant(new TemplatePipe().transform(x.title, ({ value: data }))) + "\n </a>"; })
184
+ .join('') + "\n </div>\n </div>", row);
185
+ }
186
+ return data;
187
+ };
188
+ return ActionLinkFormatter;
189
+ }(AdvancedColumnFormatter));
190
+ var SelectRowFormatter = /** @class */ (function (_super) {
191
+ __extends(SelectRowFormatter, _super);
192
+ function SelectRowFormatter() {
193
+ return _super.call(this) || this;
194
+ }
195
+ SelectRowFormatter.prototype.render = function (data, type, row, meta) {
196
+ // get column
197
+ var column = meta.settings.aoColumns[meta.col];
198
+ if (column && column.data) {
199
+ var _tpl = "<input class=\"checkbox checkbox-theme\" type=\"checkbox\"\n id=\"s-" + meta.row + "\" /><label for=\"s-" + meta.row + "\">&nbsp;</label>";
200
+ return new TemplatePipe().transform(_tpl, row);
201
+ }
202
+ return data;
203
+ };
204
+ return SelectRowFormatter;
205
+ }(AdvancedColumnFormatter));
206
+ var TemplateFormatter = /** @class */ (function (_super) {
207
+ __extends(TemplateFormatter, _super);
208
+ function TemplateFormatter() {
209
+ return _super.call(this) || this;
210
+ }
211
+ TemplateFormatter.prototype.render = function (data, type, row, meta) {
212
+ // get column
213
+ var column = meta.settings.aoColumns[meta.col];
214
+ if (column && column.data) {
215
+ return new TemplatePipe().transform(this.formatString, row);
216
+ }
217
+ return data;
218
+ };
219
+ return TemplateFormatter;
220
+ }(AdvancedColumnFormatter));
221
+ var TrueFalseFormatter = /** @class */ (function (_super) {
222
+ __extends(TrueFalseFormatter, _super);
223
+ function TrueFalseFormatter() {
224
+ return _super.call(this) || this;
225
+ }
226
+ TrueFalseFormatter.prototype.render = function (data, type, row, meta) {
227
+ return data ? this.injector.get(TranslateService).instant('TrueFalse.long.Yes') :
228
+ this.injector.get(TranslateService).instant('TrueFalse.long.No');
229
+ };
230
+ return TrueFalseFormatter;
231
+ }(AdvancedColumnFormatter));
232
+ var TranslationFormatter = /** @class */ (function (_super) {
233
+ __extends(TranslationFormatter, _super);
234
+ function TranslationFormatter() {
235
+ return _super.call(this) || this;
236
+ }
237
+ TranslationFormatter.prototype.render = function (data, type, row, meta) {
238
+ // get column
239
+ var column = meta.settings.aoColumns[meta.col];
240
+ if (column && data != null) {
241
+ return this.injector.get(TranslateService).instant(new TemplatePipe().transform(this.formatString, { value: data }));
242
+ }
243
+ return this.injector.get(TranslateService).instant('Unknown');
244
+ };
245
+ return TranslationFormatter;
246
+ }(AdvancedColumnFormatter));
247
+ var DateTimeFormatter = /** @class */ (function (_super) {
248
+ __extends(DateTimeFormatter, _super);
249
+ function DateTimeFormatter() {
250
+ return _super.call(this) || this;
251
+ }
252
+ DateTimeFormatter.prototype.render = function (data, type, row, meta) {
253
+ // get column
254
+ var column = meta.settings.aoColumns[meta.col];
255
+ if (column && column.data) {
256
+ var datePipe = new DatePipe(this.injector.get(TranslateService).currentLang);
257
+ if (typeof data === 'string' && /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\+\d{2}$/.test(data)) {
258
+ return datePipe.transform(new Date(data + ':00'), this.formatString);
259
+ }
260
+ return datePipe.transform(data, this.formatString);
261
+ }
262
+ return data;
263
+ };
264
+ return DateTimeFormatter;
265
+ }(AdvancedColumnFormatter));
266
+ var NgClassFormatter = /** @class */ (function (_super) {
267
+ __extends(NgClassFormatter, _super);
268
+ function NgClassFormatter() {
269
+ return _super.call(this) || this;
270
+ }
271
+ NgClassFormatter.prototype.render = function (data, type, row, meta) {
272
+ var e_1, _a;
273
+ // get column
274
+ var column = meta.settings.aoColumns[meta.col];
275
+ if (column && column.data) {
276
+ // get formatOptions
277
+ if (this.formatOptions) {
278
+ var ngClass = this.formatOptions.ngClass;
279
+ try {
280
+ // check condition for each key
281
+ for (var _b = __values(Object.keys(ngClass)), _c = _b.next(); !_c.done; _c = _b.next()) {
282
+ var key = _c.value;
283
+ var result = new TemplatePipe().transform(ngClass[key], row);
284
+ var fn = new Function("return " + result + ";");
285
+ // if condition returns true add class
286
+ if (fn() === true) {
287
+ return "<span class=\"" + key + "\">" + data + "</span>";
288
+ }
289
+ }
290
+ }
291
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
292
+ finally {
293
+ try {
294
+ if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
295
+ }
296
+ finally { if (e_1) throw e_1.error; }
297
+ }
298
+ }
299
+ return data;
300
+ }
301
+ return data;
302
+ };
303
+ return NgClassFormatter;
304
+ }(AdvancedColumnFormatter));
305
+ var LanguageFormatter = /** @class */ (function (_super) {
306
+ __extends(LanguageFormatter, _super);
307
+ function LanguageFormatter() {
308
+ return _super.call(this) || this;
309
+ }
310
+ LanguageFormatter.prototype.render = function (data, type, row, meta) {
311
+ if (data) {
312
+ return getNativeName(data);
313
+ }
314
+ return data;
315
+ };
316
+ return LanguageFormatter;
317
+ }(AdvancedColumnFormatter));
318
+
319
+ var AdvancedFilterValueProvider = /** @class */ (function () {
320
+ function AdvancedFilterValueProvider() {
321
+ this.values = {};
322
+ this._template = new TemplatePipe();
323
+ }
324
+ AdvancedFilterValueProvider.prototype.buildFilter = function (filter) {
325
+ if (filter) {
326
+ return this._template.transform(filter, this.values);
327
+ }
328
+ };
329
+ AdvancedFilterValueProvider.prototype.asyncBuildFilter = function (filter) {
330
+ return __awaiter(this, void 0, void 0, function () {
331
+ var _a, _b, _c;
332
+ return __generator(this, function (_d) {
333
+ switch (_d.label) {
334
+ case 0:
335
+ if (!filter) return [3 /*break*/, 2];
336
+ _b = (_a = this._template).transform;
337
+ _c = [filter];
338
+ return [4 /*yield*/, this.getValues()];
339
+ case 1: return [2 /*return*/, _b.apply(_a, _c.concat([_d.sent()]))];
340
+ case 2: return [2 /*return*/];
341
+ }
342
+ });
343
+ });
344
+ };
345
+ AdvancedFilterValueProvider.prototype.getValues = function () {
346
+ return __awaiter(this, void 0, void 0, function () {
347
+ return __generator(this, function (_a) {
348
+ return [2 /*return*/, this.values];
349
+ });
350
+ });
351
+ };
352
+ AdvancedFilterValueProvider.decorators = [
353
+ { type: Injectable, args: [{
354
+ providedIn: 'root'
355
+ },] }
356
+ ];
357
+ /** @nocollapse */
358
+ AdvancedFilterValueProvider.ctorParameters = function () { return []; };
359
+ AdvancedFilterValueProvider.ngInjectableDef = defineInjectable({ factory: function AdvancedFilterValueProvider_Factory() { return new AdvancedFilterValueProvider(); }, token: AdvancedFilterValueProvider, providedIn: "root" });
360
+ return AdvancedFilterValueProvider;
361
+ }());
362
+
363
+ // restore jquery import to avoid Cannot call a namespace ('jquery') error
364
+ var jQuery = jQuery_;
365
+ var DataTablesApi = jQuery.fn.dataTable.Api;
366
+ DataTablesApi.register('processing()', function (show) {
367
+ return this.iterator('table', function (ctx) {
368
+ ctx.oApi._fnProcessingDisplay(ctx, show);
369
+ });
370
+ });
371
+ var TableTranslationChangeDetector = /** @class */ (function (_super) {
372
+ __extends(TableTranslationChangeDetector, _super);
373
+ function TableTranslationChangeDetector() {
374
+ return _super !== null && _super.apply(this, arguments) || this;
375
+ }
376
+ TableTranslationChangeDetector.prototype.checkNoChanges = function () {
377
+ };
378
+ TableTranslationChangeDetector.prototype.detach = function () {
379
+ };
380
+ TableTranslationChangeDetector.prototype.detectChanges = function () {
381
+ };
382
+ TableTranslationChangeDetector.prototype.markForCheck = function () {
383
+ };
384
+ TableTranslationChangeDetector.prototype.reattach = function () {
385
+ };
386
+ return TableTranslationChangeDetector;
387
+ }(ChangeDetectorRef));
388
+ var COLUMN_FORMATTERS = new InjectionToken('column.formatters');
389
+ var ColumnFormatter = /** @class */ (function (_super) {
390
+ __extends(ColumnFormatter, _super);
391
+ function ColumnFormatter(injector) {
392
+ var _this = _super.call(this) || this;
393
+ _this.injector = injector;
394
+ return _this;
395
+ }
396
+ ColumnFormatter.prototype.render = function (data, type, row, meta) {
397
+ //
398
+ };
399
+ return ColumnFormatter;
400
+ }(AdvancedColumnFormatter));
401
+ function forceCast(input) {
402
+ return input;
403
+ }
404
+ var AdvancedTableConfiguration = /** @class */ (function () {
405
+ function AdvancedTableConfiguration() {
406
+ }
407
+ AdvancedTableConfiguration.cast = function (input, clone) {
408
+ if (clone) {
409
+ return forceCast(JSON.parse(JSON.stringify(input)));
410
+ }
411
+ return forceCast(input);
412
+ };
413
+ return AdvancedTableConfiguration;
414
+ }());
415
+ function getRandomIdentifier() {
416
+ return (Number(String(Math.random()).slice(2))).toString(36);
417
+ }
418
+ var AdvancedTableComponent = /** @class */ (function () {
419
+ function AdvancedTableComponent(_context, _columnFormatters, _activatedRoute, _translateService, _injector, _advancedFilterValueProvider, _element, _template, _loading, _http) {
420
+ var _this = this;
421
+ this._context = _context;
422
+ this._columnFormatters = _columnFormatters;
423
+ this._activatedRoute = _activatedRoute;
424
+ this._translateService = _translateService;
425
+ this._injector = _injector;
426
+ this._advancedFilterValueProvider = _advancedFilterValueProvider;
427
+ this._element = _element;
428
+ this._template = _template;
429
+ this._loading = _loading;
430
+ this._http = _http;
431
+ this._firstLoad = true;
432
+ this._showFooter = true;
433
+ this._showPaging = false;
434
+ this._id = getRandomIdentifier();
435
+ this.smartSelect = false;
436
+ this.configChanges = new BehaviorSubject(null);
437
+ this.height = 800;
438
+ this.showActions = true;
439
+ this.autoLoad = true;
440
+ this.load = new EventEmitter();
441
+ this.init = new EventEmitter();
442
+ this.reload = new EventEmitter();
443
+ this.select = new EventEmitter();
444
+ this.selectedItems = new EventEmitter();
445
+ this.scrollable = true;
446
+ this.serverSide = true;
447
+ this.lengthMenu = [50, 100, 200, 500];
448
+ this.paging = true;
449
+ this.pageLength = 25;
450
+ this.scrollY = 800;
451
+ this.scrollX = true;
452
+ /**
453
+ * Enables row selection. The defaulr value is false
454
+ */
455
+ this.selectable = false;
456
+ /**
457
+ * Enables or disable multiple selection. The default values is true.
458
+ */
459
+ this.multipleSelect = true;
460
+ /**
461
+ * Enables custom selection and hides select column. The default value is false
462
+ */
463
+ this.customSelect = false;
464
+ this.selected = [];
465
+ this.unselected = [];
466
+ // initialize translate pipe
467
+ this.translator = new TranslatePipe(this._translateService, new TableTranslationChangeDetector());
468
+ jQuery.fn.dataTable.ext.classes.sPageButton = 'btn';
469
+ jQuery.fn.dataTable.ext.classes.sPageButtonActive = 'btn btn-light';
470
+ this.reloadSubscription = this.reload.subscribe(function (data) {
471
+ _this.fetch();
472
+ });
473
+ }
474
+ Object.defineProperty(AdvancedTableComponent.prototype, "config", {
475
+ get: function () {
476
+ return this._config;
477
+ },
478
+ /**
479
+ * Gets or sets table configuration
480
+ */
481
+ set: function (value) {
482
+ this._config = value;
483
+ // raise subscription
484
+ this.configChanges.next(this._config);
485
+ },
486
+ enumerable: true,
487
+ configurable: true
488
+ });
489
+ Object.defineProperty(AdvancedTableComponent.prototype, "showFooter", {
490
+ get: function () {
491
+ return this._showFooter;
492
+ },
493
+ /**
494
+ * Indicates whether table footer will be visible or not
495
+ */
496
+ set: function (value) {
497
+ this._showFooter = value;
498
+ // show or hide footer
499
+ if (this._element && this._element.nativeElement) {
500
+ var element = this._element.nativeElement
501
+ .querySelector('.dataTables_info');
502
+ if (element == null) {
503
+ return;
504
+ }
505
+ if (value) {
506
+ element.classList.remove('d-none');
507
+ }
508
+ else {
509
+ element.classList.add('d-none');
510
+ }
511
+ }
512
+ },
513
+ enumerable: true,
514
+ configurable: true
515
+ });
516
+ Object.defineProperty(AdvancedTableComponent.prototype, "showPaging", {
517
+ get: function () {
518
+ return this._showPaging;
519
+ },
520
+ /**
521
+ * Indicates whether paging information will be visible or not
522
+ */
523
+ set: function (value) {
524
+ this._showPaging = value;
525
+ // show or hide footer
526
+ if (this._element && this._element.nativeElement) {
527
+ var element = this._element.nativeElement
528
+ .querySelector('.dataTables_paginate');
529
+ if (element == null) {
530
+ return;
531
+ }
532
+ if (value) {
533
+ jQuery(element).show();
534
+ }
535
+ else {
536
+ jQuery(element).hide();
537
+ }
538
+ }
539
+ },
540
+ enumerable: true,
541
+ configurable: true
542
+ });
543
+ Object.defineProperty(AdvancedTableComponent.prototype, "query", {
544
+ get: function () {
545
+ return this._query;
546
+ },
547
+ /**
548
+ * Gets or sets an active query for this table
549
+ */
550
+ set: function (value) {
551
+ this._query = value;
552
+ },
553
+ enumerable: true,
554
+ configurable: true
555
+ });
556
+ // simple search
557
+ AdvancedTableComponent.prototype.search = function (searchText) {
558
+ var _this = this;
559
+ this.query = this.query || this._context.model(this.config.model).asQueryable();
560
+ if (searchText && this.config.searchExpression) {
561
+ // validate search text in double quotes
562
+ if (/^"(.*?)"$/.test(searchText)) {
563
+ this.query.setParam('$filter', this._template.transform(this.config.searchExpression, {
564
+ text: searchText.replace(/^"|"$/g, '')
565
+ }));
566
+ }
567
+ else {
568
+ // try to split words
569
+ var words = searchText.split(' ');
570
+ // join words to a single filter
571
+ var filter = words.map(function (word) {
572
+ return _this._template.transform(_this.config.searchExpression, {
573
+ text: word
574
+ });
575
+ }).join(' and ');
576
+ // set filter
577
+ this.query.setParam('$filter', filter);
578
+ }
579
+ }
580
+ else {
581
+ // clear filter
582
+ this.query.setParam('$filter', null);
583
+ }
584
+ this._firstLoad = false;
585
+ this.dataTable.draw();
586
+ };
587
+ AdvancedTableComponent.prototype.fetch = function (clearSelected) {
588
+ // if data table is null
589
+ if (this.dataTable == null) {
590
+ // initialize data table
591
+ return this.ngOnInit();
592
+ }
593
+ // clear selection if parameter is not declared or it's true
594
+ if (clearSelected == null || clearSelected === true) {
595
+ // set smart select to false
596
+ this.smartSelect = false;
597
+ // clear selected items
598
+ if (this.selected.length) {
599
+ this.selected.splice(0, this.selected.length);
600
+ }
601
+ // clear unselected items
602
+ if (this.unselected.length) {
603
+ this.unselected.splice(0, this.unselected.length);
604
+ }
605
+ }
606
+ // otherwise load data only
607
+ this.dataTable.draw();
608
+ };
609
+ AdvancedTableComponent.prototype.destroy = function () {
610
+ if (this.dataTable) {
611
+ this.dataTable.destroy();
612
+ this._firstLoad = true;
613
+ jQuery(this.table.nativeElement).empty();
614
+ this.dataTable = null;
615
+ // clear selected items
616
+ if (this.selected.length) {
617
+ this.selected.splice(0, this.selected.length);
618
+ }
619
+ // clear unselected items
620
+ if (this.unselected.length) {
621
+ this.unselected.splice(0, this.unselected.length);
622
+ }
623
+ // set smart select to false
624
+ this.smartSelect = false;
625
+ }
626
+ };
627
+ /**
628
+ * Selects the specified data row
629
+ */
630
+ AdvancedTableComponent.prototype.selectRow = function (row, silent) {
631
+ if (row) {
632
+ // get row
633
+ var rowNode_1 = row.node();
634
+ // if multiple select is false
635
+ if (this.multipleSelect === false) {
636
+ if (this.customSelect === false) {
637
+ // enumerate row
638
+ this.dataTable.rows().nodes().each(function (node) {
639
+ if (node !== rowNode_1) {
640
+ jQuery(node).find(':checkbox').prop('checked', false);
641
+ }
642
+ });
643
+ }
644
+ else {
645
+ this.dataTable.rows('.selected').nodes().each(function (node) {
646
+ if (node !== rowNode_1) {
647
+ jQuery(node).removeClass('selected');
648
+ }
649
+ });
650
+ }
651
+ // clear selected
652
+ this.selected.splice(0, this.selected.length);
653
+ }
654
+ // if custom select mode is off
655
+ if (this.customSelect === false) {
656
+ jQuery(rowNode_1).find(':checkbox').prop('checked', true);
657
+ }
658
+ else {
659
+ // otherwise add class
660
+ jQuery(row.node()).addClass('selected');
661
+ }
662
+ // get row data
663
+ var key_1 = this.config.columns[0].property || this.config.columns[0].name;
664
+ var data_1 = row.data();
665
+ // search selected items
666
+ var findIndex = this.selected.findIndex(function (x) {
667
+ return x[key_1] === data_1[key_1];
668
+ });
669
+ if (findIndex >= 0) {
670
+ // remove previously selected row
671
+ this.selected.splice(findIndex, 1);
672
+ }
673
+ this.selected.push(data_1);
674
+ // validate unselected data
675
+ findIndex = this.unselected.findIndex(function (x) {
676
+ return x[key_1] === data_1[key_1];
677
+ });
678
+ if (findIndex >= 0) {
679
+ // remove previously selected row
680
+ this.unselected.splice(findIndex, 1);
681
+ }
682
+ if (silent) {
683
+ return;
684
+ }
685
+ this.selectedItems.emit(this.selected);
686
+ }
687
+ };
688
+ /**
689
+ * Unselects the specified data row if it's selected
690
+ */
691
+ AdvancedTableComponent.prototype.unSelectRow = function (row, silent) {
692
+ if (row) {
693
+ // if custom select mode is off
694
+ if (this.customSelect === false) {
695
+ jQuery(row.node()).find(':checkbox').prop('checked', false);
696
+ }
697
+ else {
698
+ // otherwise add class
699
+ jQuery(row.node()).removeClass('selected');
700
+ }
701
+ // get first column key
702
+ var key_2 = this.config.columns[0].property || this.config.columns[0].name;
703
+ var data = row.data();
704
+ var id_1 = data[key_2];
705
+ var findIndex = this.selected.findIndex(function (x) {
706
+ return x[key_2] === id_1;
707
+ });
708
+ if (findIndex >= 0) {
709
+ this.selected.splice(findIndex, 1);
710
+ if (this.smartSelect) {
711
+ // add this row to unselected rows
712
+ findIndex = this.unselected.findIndex(function (x) {
713
+ return x[key_2] === id_1;
714
+ });
715
+ if (findIndex < 0) {
716
+ this.unselected.push(data);
717
+ }
718
+ }
719
+ if (silent) {
720
+ return;
721
+ }
722
+ this.selectedItems.emit(this.selected);
723
+ }
724
+ }
725
+ };
726
+ AdvancedTableComponent.prototype.selectAny = function () {
727
+ var _this = this;
728
+ if (this.dataTable && this.selectable) {
729
+ // set smart select flag
730
+ this.smartSelect = true;
731
+ // select any row
732
+ this.dataTable.rows().every(function (index) {
733
+ var row = _this.dataTable.row(index);
734
+ _this.selectRow(row, true);
735
+ });
736
+ // emit selection event
737
+ this.selectedItems.emit(this.selected);
738
+ }
739
+ };
740
+ AdvancedTableComponent.prototype.selectNone = function () {
741
+ var _this = this;
742
+ if (this.dataTable && this.selectable) {
743
+ // set smart select flag
744
+ this.smartSelect = false;
745
+ this.unselected.splice(0, this.unselected.length);
746
+ // select any row
747
+ this.dataTable.rows().every(function (index) {
748
+ var row = _this.dataTable.row(index);
749
+ _this.unSelectRow(row, true);
750
+ });
751
+ this.selected.splice(0, this.selected.length);
752
+ // emit selection event
753
+ this.selectedItems.emit(this.selected);
754
+ }
755
+ };
756
+ AdvancedTableComponent.prototype.toggleSelectRow = function (row) {
757
+ if (row) {
758
+ var data = row.data();
759
+ // get first column key
760
+ var key_3 = this.config.columns[0].property || this.config.columns[0].name;
761
+ // get id
762
+ var id_2 = data[key_3];
763
+ // find if row is selected
764
+ var findIndex = this.selected.find(function (x) {
765
+ return x[key_3] === id_2;
766
+ });
767
+ // if row is selected
768
+ if (findIndex >= 0) {
769
+ // unselect
770
+ this.unSelectRow(row);
771
+ }
772
+ else {
773
+ this.selectRow(row);
774
+ }
775
+ }
776
+ };
777
+ // noinspection JSMethodCanBeStatic
778
+ /**
779
+ * Datatables column renderer for select checkbox
780
+ * @param data
781
+ * @param type
782
+ * @param row
783
+ * @param meta
784
+ * @private
785
+ */
786
+ AdvancedTableComponent.prototype._renderSelect = function (data, type, row, meta) {
787
+ // get column
788
+ var column = meta.settings.aoColumns[meta.col];
789
+ // render template
790
+ return this._template.transform("<input class=\"checkbox checkbox-theme s-row\" type=\"checkbox\"\n id=\"s-" + this._id + "-" + meta.row + "\" data-id=\"" + data + "\" /><label for=\"s-" + this._id + "-" + meta.row + "\">&nbsp;</label>", row);
791
+ };
792
+ AdvancedTableComponent.prototype.ngOnInit = function () {
793
+ var _this = this;
794
+ var self = this;
795
+ if (this.dataTable) {
796
+ this.destroy();
797
+ }
798
+ if (this.config) {
799
+ // parse properties
800
+ if (Object.prototype.hasOwnProperty.call(this.config, 'selectable')) {
801
+ this.selectable = this.config.selectable;
802
+ }
803
+ if (Object.prototype.hasOwnProperty.call(this.config, 'multipleSelect')) {
804
+ this.multipleSelect = this.config.multipleSelect;
805
+ }
806
+ // prepare configuration for columns
807
+ var tableColumns_1 = this.config.columns
808
+ // filter action link column
809
+ .filter(function (column) {
810
+ if (column.formatter && column.formatter === 'ActionLinkFormatter' && _this.showActions === false) {
811
+ return false;
812
+ }
813
+ return true;
814
+ }).map(function (column) {
815
+ // convert column to advance table column
816
+ return Object.assign(new ColumnFormatter(_this._injector), column);
817
+ }).map(function (column) {
818
+ var columnDefinition = {
819
+ data: column.property || column.name,
820
+ defaultContent: column.hasOwnProperty('defaultContent') ? column.defaultContent : '',
821
+ title: _this.translator.transform(column.title),
822
+ sortable: column.hasOwnProperty('sortable') ? column.sortable : true,
823
+ visible: column.hasOwnProperty('hidden') ? !column.hidden : true,
824
+ name: column.name
825
+ };
826
+ if (column.className) {
827
+ Object.assign(columnDefinition, {
828
+ className: column.className
829
+ });
830
+ }
831
+ else {
832
+ Object.assign(columnDefinition, {
833
+ className: ''
834
+ });
835
+ }
836
+ if (column.formatters) {
837
+ Object.assign(columnDefinition, {
838
+ render: function (data, type, row, meta) {
839
+ var result = data;
840
+ column.formatters.forEach(function (columnFormatter) {
841
+ var formatter = self._columnFormatters[columnFormatter.formatter];
842
+ if (formatter && typeof formatter.render === 'function') {
843
+ column.formatString = columnFormatter.formatString;
844
+ column.formatOptions = columnFormatter.formatOptions;
845
+ }
846
+ result = formatter.render.bind(column)(result, type, row, meta);
847
+ });
848
+ delete column.formatString;
849
+ delete column.formatOptions;
850
+ return result;
851
+ }
852
+ });
853
+ }
854
+ if (column.formatter) {
855
+ var formatter = self._columnFormatters[column.formatter];
856
+ if (formatter && typeof formatter.render === 'function') {
857
+ Object.assign(columnDefinition, {
858
+ render: formatter.render.bind(column)
859
+ });
860
+ }
861
+ }
862
+ return columnDefinition;
863
+ });
864
+ // get table element
865
+ var tableElement_1 = jQuery(this.table.nativeElement);
866
+ // allow selection
867
+ if (this.selectable) {
868
+ // get first column (as row primary key)
869
+ // todo::allow row primary key configuration
870
+ var firstColumn = this.config.columns[0];
871
+ // add select column
872
+ var selectColumnDefinition = {
873
+ className: 'text-center pl-4 pr-0',
874
+ data: firstColumn.property || firstColumn.name,
875
+ defaultContent: '',
876
+ title: '',
877
+ sortable: false,
878
+ visible: !this.customSelect,
879
+ name: firstColumn.name,
880
+ };
881
+ // assign renderer
882
+ Object.assign(selectColumnDefinition, {
883
+ render: this._renderSelect.bind(this)
884
+ });
885
+ // and finally add column
886
+ tableColumns_1.unshift(selectColumnDefinition);
887
+ // user interface additions
888
+ // handle page change event (a trick for firing draw.dt events)
889
+ tableElement_1
890
+ // for each page
891
+ .on('page.dt', function ($event) {
892
+ var info = _this.dataTable.page.info();
893
+ })
894
+ // handle draw events
895
+ .on('draw.dt', function () {
896
+ if (_this.customSelect) {
897
+ // enable row selection event
898
+ tableElement_1.find('tbody').on('click', 'tr', function () {
899
+ // select row
900
+ var row = self.dataTable.row(this);
901
+ // add row
902
+ self.select.emit(row);
903
+ });
904
+ }
905
+ tableElement_1.find('input.s-row').on('click', _this.onSelectionChange.bind(_this));
906
+ // make selection on current page
907
+ var key = _this.config.columns[0].property;
908
+ if (_this.selected.length > 0) {
909
+ // enumerate selected items
910
+ _this.selected.forEach(function (item) {
911
+ // find row identifier
912
+ var id = item[key];
913
+ // if identifier is defined
914
+ if (id != null) {
915
+ // try to find check element with this identifier in attribute data-id
916
+ tableElement_1.find("input[data-id='" + id + "']").prop('checked', true);
917
+ }
918
+ });
919
+ }
920
+ if (_this.smartSelect) {
921
+ // select rows that are not selected
922
+ // and do not included in unselected collection
923
+ tableElement_1.find('input[data-id]').each(function (index, element) {
924
+ // get data id
925
+ if (_this.unselected.findIndex(function (x) {
926
+ // tslint:disable-next-line:triple-equals
927
+ return x[key] == jQuery(element).attr('data-id');
928
+ }) < 0) {
929
+ _this.selectRow(_this.dataTable.row(index));
930
+ }
931
+ });
932
+ }
933
+ else if (_this.selected.length === 0) {
934
+ tableElement_1.find('input[data-id]').prop('checked', false);
935
+ }
936
+ });
937
+ }
938
+ // initialize data table
939
+ var settings = {
940
+ // set length menu
941
+ lengthMenu: [5, 10, 50, 100, 200, 500],
942
+ // hide length menu
943
+ lengthChange: false,
944
+ // enable search but hide search box (css)
945
+ searching: true,
946
+ // enable data processing
947
+ processing: true,
948
+ // enable getting server side data
949
+ serverSide: this.serverSide,
950
+ // enumerate table columns
951
+ columns: tableColumns_1,
952
+ order: [],
953
+ // set scroll x
954
+ scrollX: this.scrollX,
955
+ dom: 'Bfrtip',
956
+ autoWidth: false,
957
+ buttons: [
958
+ {
959
+ extend: 'excel',
960
+ filename: this.config.title,
961
+ className: 'd-none',
962
+ exportOptions: {
963
+ columns: 'th:not(:first-child)'
964
+ }
965
+ }
966
+ ],
967
+ // define server data callback
968
+ fnServerData: function (sSource, aoData, fnCallback, oSettings) {
969
+ // if method is invoked for the first time
970
+ if (self._firstLoad) {
971
+ // disabled first load flag
972
+ self._firstLoad = false;
973
+ // if auto load is disabled
974
+ if (self.autoLoad === false) {
975
+ var emptyDataSet = {
976
+ recordsTotal: 0,
977
+ recordsFiltered: 0,
978
+ data: []
979
+ };
980
+ // emit empty data
981
+ self.load.emit(emptyDataSet);
982
+ // return empty data
983
+ return fnCallback(emptyDataSet);
984
+ }
985
+ }
986
+ // get activated route params
987
+ var queryParams = self._activatedRoute.snapshot.queryParams;
988
+ // get columns
989
+ var columns = aoData[1].value;
990
+ // get order expression
991
+ var order = aoData[2].value;
992
+ // get skip records param
993
+ var skip = aoData[3].value;
994
+ // get page size param
995
+ var top = aoData[4].value;
996
+ // get search value
997
+ var searchText = aoData[5].value;
998
+ // get data queryable
999
+ var q = self._query instanceof ClientDataQueryable ? self._query : self._context.model(self.config.model).asQueryable();
1000
+ // apply paging params
1001
+ if (top) {
1002
+ q.take(top).skip(skip);
1003
+ }
1004
+ // apply order params
1005
+ if (order && order.length) {
1006
+ // get order query expression
1007
+ var orderByStr = order.map(function (expr) {
1008
+ return tableColumns_1[expr.column].name + ' ' + expr.dir || 'asc';
1009
+ }).join(',');
1010
+ // set order
1011
+ q.setParam('$orderby', orderByStr);
1012
+ }
1013
+ // configure $select parameter
1014
+ var select = self.config.columns.filter(function (column) {
1015
+ if (column.virtual === true) {
1016
+ return false;
1017
+ }
1018
+ return true;
1019
+ }).map(function (column) {
1020
+ if (column.property) {
1021
+ return column.name + ' as ' + column.property;
1022
+ }
1023
+ else {
1024
+ return column.name;
1025
+ }
1026
+ });
1027
+ q.select.apply(q, select);
1028
+ // configure $filter
1029
+ if (queryParams.$filter && queryParams.$filter.length) {
1030
+ // set route filter
1031
+ var qParams = q.getParams();
1032
+ q.setParam('$filter', null);
1033
+ var expressions = [queryParams.$filter];
1034
+ if (qParams.$filter) {
1035
+ expressions.push('(' + qParams.$filter + ')');
1036
+ }
1037
+ q.filter(expressions.join(' and '));
1038
+ }
1039
+ // check if query parameters contain filter
1040
+ if (queryParams.$expand && queryParams.$expand.length) {
1041
+ // set route $expand
1042
+ q.setParam('$expand', queryParams.$expand);
1043
+ }
1044
+ if (!q.getParams()['$orderby'] && self.config && self.config.defaults && self.config.defaults.orderBy) {
1045
+ q.setParam('$orderby', self.config.defaults.orderBy);
1046
+ }
1047
+ // append default filter
1048
+ if (self.config && self.config.defaults && self.config.defaults.filter) {
1049
+ return self._advancedFilterValueProvider.asyncBuildFilter(self.config.defaults.filter).then(function (defaultFilterString) {
1050
+ if (defaultFilterString) {
1051
+ var qParams = q.getParams();
1052
+ q.setParam('$filter', null);
1053
+ var expressions = [defaultFilterString];
1054
+ if (qParams.$filter) {
1055
+ expressions.push('(' + qParams.$filter + ')');
1056
+ }
1057
+ q.filter(expressions.join(' and '));
1058
+ }
1059
+ self.lastQueryParams = q.getParams();
1060
+ q.getList().then(function (items) {
1061
+ var dataSet = {
1062
+ recordsTotal: items.total,
1063
+ recordsFiltered: items.total,
1064
+ data: items.value
1065
+ };
1066
+ if (items.total === 0) {
1067
+ self.resetEmptyTable();
1068
+ }
1069
+ // emit load event
1070
+ self.load.emit(dataSet);
1071
+ // return data
1072
+ return fnCallback(dataSet);
1073
+ });
1074
+ }).catch(function (err) {
1075
+ console.error('TABLES', err);
1076
+ });
1077
+ }
1078
+ self.lastQueryParams = q.getParams();
1079
+ q.getList().then(function (items) {
1080
+ var dataSet = {
1081
+ recordsTotal: items.total,
1082
+ recordsFiltered: items.total,
1083
+ data: items.value
1084
+ };
1085
+ if (items.total === 0) {
1086
+ self.resetEmptyTable();
1087
+ }
1088
+ // emit load event
1089
+ self.load.emit(dataSet);
1090
+ // return data
1091
+ return fnCallback(dataSet);
1092
+ }).catch(function (err) {
1093
+ console.error('TABLES', err);
1094
+ });
1095
+ },
1096
+ language: Object.assign({}, self.translator.transform('Tables.DataTable'), { emptyTable: ' ', processing: ' ' })
1097
+ };
1098
+ if (this.scrollable) {
1099
+ // set continuous scrolling
1100
+ Object.assign(settings, {
1101
+ scrollY: this.scrollY,
1102
+ scrollCollapse: false,
1103
+ scroller: {
1104
+ loadingIndicator: false,
1105
+ displayBuffer: 10
1106
+ },
1107
+ });
1108
+ }
1109
+ else {
1110
+ Object.assign(settings, {
1111
+ paging: this.paging,
1112
+ pageLength: this.pageLength
1113
+ });
1114
+ }
1115
+ if (this.selectable) ;
1116
+ // handle init.dt event and emit local event
1117
+ this.dataTable = tableElement_1.DataTable(settings);
1118
+ tableElement_1.on('init.dt', function () {
1119
+ if (_this.dataTable == null) {
1120
+ return;
1121
+ }
1122
+ // restore default empty table html
1123
+ // (due to ng async binding)
1124
+ _this.init.emit(_this.dataTable);
1125
+ });
1126
+ // show or hide footer
1127
+ if (!this.showFooter) {
1128
+ this._element.nativeElement
1129
+ .querySelector('.dataTables_info').classList.add('d-none');
1130
+ }
1131
+ // show or hide pager
1132
+ if (this.showPaging) {
1133
+ this.showPaging = true;
1134
+ }
1135
+ }
1136
+ };
1137
+ Object.defineProperty(AdvancedTableComponent.prototype, "lastQuery", {
1138
+ get: function () {
1139
+ var _this = this;
1140
+ if (this.config == null) {
1141
+ return null;
1142
+ }
1143
+ if (this.lastQueryParams == null) {
1144
+ return null;
1145
+ }
1146
+ var q = this._context.model(this.config.model).asQueryable();
1147
+ Object.keys(this.lastQueryParams).forEach(function (key) {
1148
+ q.setParam(key, _this.lastQueryParams[key]);
1149
+ });
1150
+ // return query
1151
+ return q;
1152
+ },
1153
+ enumerable: true,
1154
+ configurable: true
1155
+ });
1156
+ /**
1157
+ * Fetches and updates a single row
1158
+ * @param find - Any object which is being converted to a query
1159
+ */
1160
+ AdvancedTableComponent.prototype.fetchOne = function (find) {
1161
+ var _this = this;
1162
+ if (find == null) {
1163
+ return;
1164
+ }
1165
+ if (this.dataTable == null) {
1166
+ return;
1167
+ }
1168
+ if (this.lastQueryParams == null) {
1169
+ return;
1170
+ }
1171
+ // get rows
1172
+ var rows = Array.from(this.dataTable.rows().data());
1173
+ if (rows && rows.length) {
1174
+ // find result
1175
+ var findKeys_1 = Object.keys(find);
1176
+ if (findKeys_1.length === 0) {
1177
+ // do nothing
1178
+ return;
1179
+ }
1180
+ // find row index by searching each property
1181
+ var rowIndex_1 = rows.findIndex(function (row) {
1182
+ return findKeys_1.map(function (key) {
1183
+ return row[key] === find[key];
1184
+ }).filter(function (res) {
1185
+ return res === false;
1186
+ }).length === 0;
1187
+ });
1188
+ // if row has been found
1189
+ if (rowIndex_1 >= 0) {
1190
+ var query_1 = this._context.model(this.config.model).asQueryable();
1191
+ // select attributes
1192
+ query_1.setParam('$select', this.lastQueryParams.$select);
1193
+ // apply filter for row
1194
+ findKeys_1.forEach(function (key) {
1195
+ var column = _this.config.columns.find(function (col) {
1196
+ return col.property === key || col.name === key;
1197
+ });
1198
+ if (column) {
1199
+ // get property or name
1200
+ var property = column.property || column.name;
1201
+ query_1.and(property).equal(find[key]);
1202
+ }
1203
+ else {
1204
+ query_1.and(key).equal(find[key]);
1205
+ }
1206
+ });
1207
+ // and finally get item
1208
+ return query_1.getItem().then(function (item) {
1209
+ // if item exists
1210
+ var row = _this.dataTable.row(rowIndex_1);
1211
+ var checked = jQuery(row.node()).find(':checkbox').prop('checked');
1212
+ if (item) {
1213
+ // redraw row
1214
+ row.data(item);
1215
+ jQuery(row.node()).find(':checkbox').on('click', _this.onSelectionChange.bind(_this));
1216
+ // if row is already selected
1217
+ if (checked) {
1218
+ _this.selectRow(row, true);
1219
+ }
1220
+ }
1221
+ return Promise.resolve();
1222
+ });
1223
+ }
1224
+ }
1225
+ return Promise.resolve();
1226
+ };
1227
+ AdvancedTableComponent.prototype.ngOnDestroy = function () {
1228
+ if (this.reloadSubscription) {
1229
+ this.reloadSubscription.unsubscribe();
1230
+ }
1231
+ };
1232
+ /**
1233
+ * Handle selection change
1234
+ * @param $event
1235
+ */
1236
+ AdvancedTableComponent.prototype.onSelectionChange = function ($event) {
1237
+ var input = $event.target;
1238
+ // get row from id
1239
+ var rowIndex = parseInt(/-(\d+)$/g.exec(input.id)[1], 10);
1240
+ // get row
1241
+ var row = this.dataTable.row(rowIndex).data();
1242
+ // get row identifier
1243
+ if (row) {
1244
+ var key_4 = this.config.columns[0].property;
1245
+ var id_3 = row[key_4];
1246
+ var findItemIndex = this.selected.findIndex(function (item) {
1247
+ return item[key_4] === id_3;
1248
+ });
1249
+ if (input.checked) {
1250
+ if (findItemIndex < 0) {
1251
+ // add row to selected rows
1252
+ this.selected.push(row);
1253
+ }
1254
+ }
1255
+ else {
1256
+ if (findItemIndex >= 0) {
1257
+ // remove selected item
1258
+ this.selected.splice(findItemIndex, 1);
1259
+ if (this.smartSelect) {
1260
+ // add row to unselected rows
1261
+ findItemIndex = this.unselected.findIndex(function (item) {
1262
+ return item[key_4] === id_3;
1263
+ });
1264
+ if (findItemIndex < 0) {
1265
+ this.unselected.push(row);
1266
+ }
1267
+ }
1268
+ }
1269
+ }
1270
+ }
1271
+ };
1272
+ AdvancedTableComponent.prototype.resetEmptyTable = function () {
1273
+ // this operation is important
1274
+ // due to ng data binding
1275
+ // empty table template has no translated text during ngOnInit()
1276
+ if (this.dataTable && this.dataTable.context[0]) {
1277
+ this.dataTable.context[0].oLanguage.sEmptyTable = this.emptyTable.nativeElement.innerHTML;
1278
+ }
1279
+ };
1280
+ AdvancedTableComponent.prototype.clearEmptyTable = function () {
1281
+ if (this.dataTable && this.dataTable.context[0]) {
1282
+ this.dataTable.context[0].oLanguage.sEmptyTable = '';
1283
+ }
1284
+ };
1285
+ AdvancedTableComponent.prototype.export = function () {
1286
+ var element = document.querySelector('.dt-buttons .buttons-excel');
1287
+ element.click();
1288
+ };
1289
+ AdvancedTableComponent.prototype.handleColumns = function (columnsToShow) {
1290
+ var table = this.dataTable;
1291
+ this.config.columns.slice(1).forEach(function (column, i) {
1292
+ if (!column.hidden) {
1293
+ if (columnsToShow.includes(column.name)) {
1294
+ // noinspection TypeScriptValidateJSTypes
1295
+ table.column(column.name + ':name').visible(true);
1296
+ }
1297
+ else {
1298
+ // noinspection TypeScriptValidateJSTypes
1299
+ table.column(column.name + ':name').visible(false);
1300
+ }
1301
+ }
1302
+ });
1303
+ };
1304
+ AdvancedTableComponent.prototype.getConfig = function () {
1305
+ return this.config;
1306
+ };
1307
+ AdvancedTableComponent.prototype.ngOnChanges = function (changes) {
1308
+ var _this = this;
1309
+ if (Object.prototype.hasOwnProperty.call(changes, 'configSrc')) {
1310
+ if (changes.configSrc != null) {
1311
+ // load table configuration on change
1312
+ if (changes.configSrc.currentValue && (changes.configSrc.currentValue != changes.configSrc.previousValue)) {
1313
+ this._http.get(changes.configSrc.currentValue).toPromise().then(function (config) {
1314
+ // set configuration
1315
+ _this.config = config;
1316
+ // fetch and redraw
1317
+ _this.fetch();
1318
+ }).catch(function (err) {
1319
+ console.error('TABLES', 'An error occurred while loading table configuration.');
1320
+ console.error(err);
1321
+ });
1322
+ }
1323
+ }
1324
+ }
1325
+ };
1326
+ AdvancedTableComponent.decorators = [
1327
+ { type: Component, args: [{
1328
+ selector: 'app-advanced-table',
1329
+ template: "\n <table #table class=\"dataTable\">\n </table>\n <div #emptyTable class=\"d-none\">\n <div>\n <div class=\"mt-4\">\n <div class=\"icon-circle bg-gray-300 border-gray-100\"></div>\n </div>\n <div class=\"mt-4\">\n <h4 class=\"font-3xl text-dark\" [translate]=\"'Tables.EmptyTableTitle'\"></h4>\n <p class=\"font-lg text-dark\" [translate]=\"'Tables.EmptyTableMessage'\"></p>\n </div>\n </div>\n </div>\n ",
1330
+ encapsulation: ViewEncapsulation.None,
1331
+ styles: ["table.dataTable thead .sorting{background-image:none}table.dataTable thead .sorting_asc{background-position:95% 60%;background-image:url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAwAAAAMCAYAAABWdVznAAAACXBIWXMAAAsSAAALEgHS3X78AAAAGXRFWHRTb2Z0d2FyZQB3d3cuaW5rc2NhcGUub3Jnm+48GgAAAEtJREFUKJFjYBgywAOKMQALFjE/BgaGTCibjYGBYRM+kz0ZGBh2MTAw8DAwMHAxMDBsY2BgCCBGMQzg1IRNMV5NuVAJXIALqmYwAgBBkAlPRCLcLwAAAABJRU5ErkJggg==)}table.dataTable thead .sorting_desc{background-position:95% 60%;background-image:url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAwAAAAMCAYAAABWdVznAAAACXBIWXMAAArzAAAK8wHvFRX1AAAAGXRFWHRTb2Z0d2FyZQB3d3cuaW5rc2NhcGUub3Jnm+48GgAAAFNJREFUKJHVzTEKgDAQRNGHZfBg2sSTeDMLKwXPYuVJbBKQQEyrH6bZ+cPyWWaElz4kR5cOJ1b0FXnBVRYjjmIUsGGqvX6OmnImYk+JLTkzpPyBGwrtCvfBe56nAAAAAElFTkSuQmCC)}table.dataTable thead th{color:#73818e;font-size:.75rem;font-weight:600;padding-top:16px;padding-bottom:4px;border-bottom:none;padding-left:8px}table.dataTable tbody tr:first-child td:first-child{border-radius:6px 0}table.dataTable tbody tr:first-child td:last-child{border-radius:0 6px}table.dataTable tbody tr{border-radius:6px}table.dataTable tbody tr td:first-child{border-left:1px solid #c2cfd6}table.dataTable tbody tr td:last-child{border-right:1px solid #c2cfd6}table.dataTable tbody tr td{padding-top:16px;padding-bottom:16px;border-top:1px solid #c2cfd6}table.dataTable tbody tr:last-child td:first-child{border-radius:0 0 0 6px}table.dataTable tbody tr:last-child td:last-child{border-radius:0 0 6px}table.dataTable tbody tr:last-child td{border-bottom:1px solid #c2cfd6}table.dataTable td.dataTables_empty{border:none!important}table.dataTable.no-footer{border-bottom:none}.dataTables_paginate .btn.previous{margin-right:8px}.dataTables_paginate .btn.next{margin-left:8px}.dataTables_info,.dataTables_paginate{margin-top:1rem}.dataTables_paginate span .btn{border-radius:1.5rem}.dataTables_filter{display:none}.dataTables_wrapper.no-footer .dataTables_scrollBody{border-bottom:0;overflow:auto}.dataTables_paginate{display:none}.dataTables_wrapper .dataTables_processing{background:0 0;top:-40%;color:#73818e}.text-decoration-line-through{text-decoration:line-through!important}tr.removed .checkbox+label{visibility:hidden}"]
1332
+ }] }
1333
+ ];
1334
+ /** @nocollapse */
1335
+ AdvancedTableComponent.ctorParameters = function () { return [
1336
+ { type: AngularDataContext },
1337
+ { type: undefined, decorators: [{ type: Inject, args: [COLUMN_FORMATTERS,] }] },
1338
+ { type: ActivatedRoute },
1339
+ { type: TranslateService },
1340
+ { type: Injector },
1341
+ { type: AdvancedFilterValueProvider },
1342
+ { type: ElementRef },
1343
+ { type: TemplatePipe },
1344
+ { type: LoadingService },
1345
+ { type: HttpClient }
1346
+ ]; };
1347
+ AdvancedTableComponent.propDecorators = {
1348
+ table: [{ type: ViewChild, args: ['table',] }],
1349
+ emptyTable: [{ type: ViewChild, args: ['emptyTable',] }],
1350
+ loadingTable: [{ type: ViewChild, args: ['loadingTable',] }],
1351
+ height: [{ type: Input }],
1352
+ showActions: [{ type: Input }],
1353
+ autoLoad: [{ type: Input }],
1354
+ load: [{ type: Output, args: ['load',] }],
1355
+ init: [{ type: Output, args: ['init',] }],
1356
+ reload: [{ type: Input, args: ['reload',] }],
1357
+ select: [{ type: Output, args: ['select',] }],
1358
+ selectedItems: [{ type: Output, args: ['selectedItems',] }],
1359
+ scrollable: [{ type: Input }],
1360
+ serverSide: [{ type: Input }],
1361
+ lengthMenu: [{ type: Input }],
1362
+ paging: [{ type: Input }],
1363
+ pageLength: [{ type: Input }],
1364
+ scrollY: [{ type: Input }],
1365
+ scrollX: [{ type: Input }],
1366
+ selectable: [{ type: Input }],
1367
+ multipleSelect: [{ type: Input }],
1368
+ customSelect: [{ type: Input }],
1369
+ selected: [{ type: Input }],
1370
+ configSrc: [{ type: Input }],
1371
+ config: [{ type: Input, args: ['config',] }],
1372
+ showFooter: [{ type: Input, args: ['showFooter',] }],
1373
+ showPaging: [{ type: Input, args: ['showPaging',] }],
1374
+ query: [{ type: Input, args: ['query',] }]
1375
+ };
1376
+ return AdvancedTableComponent;
1377
+ }());
1378
+
1379
+ var AdvancedListComponent = /** @class */ (function () {
1380
+ function AdvancedListComponent(_context, _translateService, _activatedRoute, _errorService, _toastService, _modalService, _userActivityService) {
1381
+ this._context = _context;
1382
+ this._translateService = _translateService;
1383
+ this._activatedRoute = _activatedRoute;
1384
+ this._errorService = _errorService;
1385
+ this._toastService = _toastService;
1386
+ this._modalService = _modalService;
1387
+ this._userActivityService = _userActivityService;
1388
+ this.allowSaveOption = true;
1389
+ }
1390
+ AdvancedListComponent.prototype.ngOnDestroy = function () {
1391
+ if (this.dataSubscription) {
1392
+ this.dataSubscription.unsubscribe();
1393
+ }
1394
+ if (this.reloadSubscription) {
1395
+ this.reloadSubscription.unsubscribe();
1396
+ }
1397
+ if (this.subscription) {
1398
+ this.subscription.unsubscribe();
1399
+ }
1400
+ };
1401
+ AdvancedListComponent.prototype.ngOnInit = function () {
1402
+ return __awaiter(this, void 0, void 0, function () {
1403
+ var metadata_1, err_1;
1404
+ var _this = this;
1405
+ return __generator(this, function (_a) {
1406
+ switch (_a.label) {
1407
+ case 0:
1408
+ _a.trys.push([0, 2, , 3]);
1409
+ return [4 /*yield*/, this._context.getMetadata()];
1410
+ case 1:
1411
+ metadata_1 = _a.sent();
1412
+ // get route data
1413
+ this.dataSubscription = this._activatedRoute.data.subscribe(function (routeData) {
1414
+ // get entityType
1415
+ var re = new RegExp("^" + routeData.model + "$", 'ig');
1416
+ var entitySet = metadata_1.EntityContainer.EntitySet.find(function (x) {
1417
+ return re.test(x.Name);
1418
+ });
1419
+ // if entity type is null
1420
+ if (entitySet == null) {
1421
+ // navigate to error
1422
+ return _this._errorService.navigateToError(new ResponseError('EntitySet Not Found', 404));
1423
+ }
1424
+ // get entity type
1425
+ var entityType = metadata_1.EntityType.find(function (x) {
1426
+ return x.Name === entitySet.EntityType;
1427
+ });
1428
+ if (entityType == null) {
1429
+ return _this._errorService.navigateToError(new ResponseError('EntityType Not Found', 404));
1430
+ }
1431
+ if (routeData.searchConfiguration) {
1432
+ if (Object.prototype.hasOwnProperty.call(routeData.searchConfiguration, 'allowSave')) {
1433
+ _this.allowSaveOption = routeData.searchConfiguration.allowSave;
1434
+ }
1435
+ _this.searchConfiguration = routeData.searchConfiguration;
1436
+ }
1437
+ if (routeData.tableConfiguration) {
1438
+ _this.tableConfiguration = routeData.tableConfiguration;
1439
+ }
1440
+ if (routeData.description) {
1441
+ _this.description = _this._translateService.instant(routeData.description);
1442
+ }
1443
+ if (routeData.longDescription) {
1444
+ _this.longDescription = _this._translateService.instant(routeData.longDescription);
1445
+ }
1446
+ if (routeData.category) {
1447
+ _this.category = _this._translateService.instant(routeData.category);
1448
+ }
1449
+ // clone default configuration
1450
+ var defaultConfiguration = AdvancedTableConfiguration.cast(_this.tableConfiguration, true);
1451
+ // correct edit button link
1452
+ var column = defaultConfiguration.columns.find(function (col) {
1453
+ return col.formatter === 'ButtonFormatter' && col.formatString === '(modal:edit)';
1454
+ });
1455
+ if (column) {
1456
+ var url_1 = [];
1457
+ _this._activatedRoute.snapshot.pathFromRoot.forEach(function (route) {
1458
+ url_1.push.apply(url_1, route.url);
1459
+ });
1460
+ column.formatString = "#/" + url_1.join('/') + "/(modal:${id}/edit)";
1461
+ }
1462
+ // create list configuration by assigning list entity set
1463
+ _this.table.config = Object.assign({
1464
+ model: entitySet.Name
1465
+ }, defaultConfiguration);
1466
+ // fetch data
1467
+ _this.table.fetch(true);
1468
+ // do reload by using hidden fragment e.g. /classes#reload
1469
+ _this.reloadSubscription = _this._activatedRoute.fragment.subscribe(function (fragment) {
1470
+ if (fragment && fragment === 'reload') {
1471
+ _this._toastService.show(_this.description, _this._translateService.instant('Settings.OperationCompleted'));
1472
+ _this.table.fetch(true);
1473
+ }
1474
+ });
1475
+ // finally add user activity
1476
+ _this._userActivityService.setItem({
1477
+ category: _this.category,
1478
+ description: _this.description,
1479
+ url: window.location.hash.substring(1),
1480
+ dateCreated: new Date
1481
+ });
1482
+ });
1483
+ return [3 /*break*/, 3];
1484
+ case 2:
1485
+ err_1 = _a.sent();
1486
+ console.error(err_1);
1487
+ return [2 /*return*/, this._errorService.showError(err_1)];
1488
+ case 3: return [2 /*return*/];
1489
+ }
1490
+ });
1491
+ });
1492
+ };
1493
+ /**
1494
+ * Data load event handler of advanced table component
1495
+ * @param {AdvancedTableDataResult} data
1496
+ */
1497
+ AdvancedListComponent.prototype.onDataLoad = function (data) {
1498
+ this.recordsTotal = data.recordsTotal;
1499
+ };
1500
+ /**
1501
+ * Remove selected items
1502
+ */
1503
+ AdvancedListComponent.prototype.remove = function () {
1504
+ var _this = this;
1505
+ if (this.table && this.table.selected && this.table.selected.length) {
1506
+ // get items to remove
1507
+ var items_1 = this.table.selected;
1508
+ return this._modalService.showWarningDialog(this._translateService.instant('Tables.RemoveItemsTitle'), this._translateService.instant('Tables.RemoveItemsMessage'), DIALOG_BUTTONS.OkCancel).then(function (result) {
1509
+ if (result === 'ok') {
1510
+ _this._context.model(_this.table.config.model).remove(items_1).then(function () {
1511
+ _this._toastService.show(_this.description + ':' + _this._translateService.instant('Tables.RemoveItemMessage.title'), _this._translateService.instant((items_1.length === 1 ?
1512
+ 'Tables.RemoveItemMessage.one' : 'Tables.RemoveItemMessage.many'), { value: items_1.length }));
1513
+ _this.table.fetch(true);
1514
+ }).catch(function (err) {
1515
+ _this._errorService.showError(err, {
1516
+ continueLink: '.'
1517
+ });
1518
+ });
1519
+ }
1520
+ });
1521
+ }
1522
+ };
1523
+ AdvancedListComponent.decorators = [
1524
+ { type: Component, args: [{
1525
+ selector: 'app-advanced-list',
1526
+ template: "<div>\n <div class=\"row\" *ngIf=\"description\">\n <div class=\"col-auto\">\n <h2>{{description}}</h2>\n <p *ngIf=\"longDescription\">{{longDescription}}</p>\n </div>\n </div>\n <div class=\"row\" *ngIf=\"searchConfiguration\">\n <div class=\"col-12\" [ngVar]=\"{}\" #filter=\"ngVar\">\n <app-advanced-table-search #advancedSearch [(filter)]=\"filter.value\" [collapsed]=\"true\" [table]=\"table\" [allowSave]=\"allowSaveOption\">\n <advanced-search>\n <app-advanced-search-form [form]=\"searchConfiguration\" (filterChange)=\"advancedSearch.asyncAdvancedSearch()\" #search [(filter)]=\"filter.value\"></app-advanced-search-form>\n </advanced-search>\n </app-advanced-table-search>\n </div>\n </div>\n <div class=\"row\">\n <div class=\"col-auto mt-4\">\n <div class=\"font-xl text-secondary\" *ngIf=\"recordsTotal > 1\">\n <span>{{recordsTotal}}</span><span>&nbsp;</span><span [translate]=\"'Tables.Items'\"></span>\n </div>\n <div class=\"font-xl text-secondary\" *ngIf=\"recordsTotal === 1\">\n <span>{{recordsTotal}}</span><span>&nbsp;</span><span [translate]=\"'Tables.Item'\"></span>\n </div>\n </div>\n <div class=\"pull-right ml-auto mr-3 mt-3\">\n <div class=\"font-lg btn-toolbar mt-3\">\n <a *ngIf=\"table && table.selected && table.selected.length\"\n class=\"text-danger text-decoration-none mr-2\" href=\"javascript:void(0)\" (click)=\"remove()\">\n <span>-</span><span>&nbsp;</span><span [translate]=\"'Tables.RemoveItem'\"></span>\n </a>\n <a class=\"text-indigo text-decoration-none\" [routerLink]=\"['.', { outlets:{ modal:'add'} }]\">\n <span>+</span><span>&nbsp;</span><span [translate]=\"'Tables.AddItem'\"></span>\n </a>\n </div>\n </div>\n </div>\n <div class=\"row\">\n <div class=\"col-12 mb-4\">\n <app-advanced-table [selectable]=\"true\" #table\n [autoLoad]=false\n [showFooter]=\"false\"\n (load)=\"onDataLoad($event)\" [height]=\"600\"></app-advanced-table>\n </div>\n </div>\n <router-modal></router-modal>\n</div>\n"
1527
+ }] }
1528
+ ];
1529
+ /** @nocollapse */
1530
+ AdvancedListComponent.ctorParameters = function () { return [
1531
+ { type: AngularDataContext },
1532
+ { type: TranslateService },
1533
+ { type: ActivatedRoute },
1534
+ { type: ErrorService },
1535
+ { type: ToastService },
1536
+ { type: ModalService },
1537
+ { type: UserActivityService }
1538
+ ]; };
1539
+ AdvancedListComponent.propDecorators = {
1540
+ entitySet: [{ type: Input, args: ['entitySet',] }],
1541
+ category: [{ type: Input, args: ['category',] }],
1542
+ description: [{ type: Input, args: ['description',] }],
1543
+ longDescription: [{ type: Input, args: ['longDescription',] }],
1544
+ tableConfiguration: [{ type: Input, args: ['tableConfiguration',] }],
1545
+ searchConfiguration: [{ type: Input, args: ['searchConfiguration',] }],
1546
+ table: [{ type: ViewChild, args: ['table',] }],
1547
+ allowSaveOption: [{ type: Input, args: ['allowSaveOption',] }]
1548
+ };
1549
+ return AdvancedListComponent;
1550
+ }());
1551
+
1552
+ var AdvancedRowActionComponent = /** @class */ (function (_super) {
1553
+ __extends(AdvancedRowActionComponent, _super);
1554
+ function AdvancedRowActionComponent(router, activatedRoute, _translateService, _context, _errorService, _modalService, _appEvent) {
1555
+ var _this = _super.call(this, router, activatedRoute) || this;
1556
+ _this._translateService = _translateService;
1557
+ _this._context = _context;
1558
+ _this._errorService = _errorService;
1559
+ _this._modalService = _modalService;
1560
+ _this._appEvent = _appEvent;
1561
+ _this.modalIcon = 'fas fa-project-diagram';
1562
+ _this.progressType = 'indigo';
1563
+ _this.errorMessage = 'Tables.Actions.CompletedWithErrors';
1564
+ _this.loading = false;
1565
+ _this.refresh = new EventEmitter();
1566
+ // set modal size
1567
+ _this.modalClass = 'modal-lg';
1568
+ // set modal title
1569
+ _this.modalTitle = 'Tables.Actions.Label';
1570
+ // disable ok button
1571
+ _this.okButtonDisabled = false;
1572
+ // set button text
1573
+ _this.okButtonText = 'Tables.Actions.Start';
1574
+ return _this;
1575
+ }
1576
+ Object.defineProperty(AdvancedRowActionComponent.prototype, "form", {
1577
+ get: function () {
1578
+ return this.formComponent;
1579
+ },
1580
+ enumerable: true,
1581
+ configurable: true
1582
+ });
1583
+ AdvancedRowActionComponent.prototype.ngOnInit = function () {
1584
+ var _this = this;
1585
+ this.refreshSubscription = this.refresh.subscribe(function (value) {
1586
+ if (value && value.progress) {
1587
+ var progress = 0;
1588
+ if (value.progress < 0) {
1589
+ progress = 0;
1590
+ }
1591
+ else if (value.progress > 100) {
1592
+ progress = 100;
1593
+ }
1594
+ else {
1595
+ progress = value.progress;
1596
+ }
1597
+ _this.progressComponent.value = progress;
1598
+ }
1599
+ });
1600
+ };
1601
+ AdvancedRowActionComponent.prototype.ngAfterViewInit = function () {
1602
+ var _this = this;
1603
+ if (this.formComponent && this.formComponent.form) {
1604
+ this.okButtonDisabled = true;
1605
+ this.invalidSubscription = this.formComponent.form.change.subscribe(function (event) {
1606
+ if (Object.prototype.hasOwnProperty.call(event, "isValid") && (event.changed != null)) {
1607
+ _this.okButtonDisabled = !event.isValid;
1608
+ }
1609
+ });
1610
+ }
1611
+ };
1612
+ AdvancedRowActionComponent.prototype.ngOnDestroy = function () {
1613
+ if (this.refreshSubscription) {
1614
+ this.refreshSubscription.unsubscribe();
1615
+ }
1616
+ if (this.executeSubscription) {
1617
+ this.executeSubscription.unsubscribe();
1618
+ }
1619
+ if (this.invalidSubscription) {
1620
+ this.invalidSubscription.unsubscribe();
1621
+ }
1622
+ };
1623
+ AdvancedRowActionComponent.prototype.cancel = function () {
1624
+ if (this.loading) {
1625
+ return;
1626
+ }
1627
+ // close
1628
+ if (this._modalService.modalRef) {
1629
+ return this._modalService.modalRef.hide();
1630
+ }
1631
+ };
1632
+ AdvancedRowActionComponent.prototype.ok = function () {
1633
+ return __awaiter(this, void 0, void 0, function () {
1634
+ var _this = this;
1635
+ return __generator(this, function (_a) {
1636
+ try {
1637
+ this.loading = true;
1638
+ this.lastError = null;
1639
+ if (this.formComponent && this.formComponent.form &&
1640
+ this.formComponent.form.formio && this.formComponent.form.formio.data) {
1641
+ // set data
1642
+ this.data = this.formComponent.form.formio.data;
1643
+ }
1644
+ // do action
1645
+ this.execute.subscribe(function (result) {
1646
+ _this.loading = false;
1647
+ _this.refresh.emit({
1648
+ progress: 100
1649
+ });
1650
+ if (result && result.errors && result.errors > 0) {
1651
+ // show message for partial success
1652
+ if (result.errors === 1) {
1653
+ _this.lastError = new Error(_this._translateService.instant(_this.errorMessage + ".Description.One"));
1654
+ }
1655
+ else {
1656
+ _this.lastError = new Error(_this._translateService.instant(_this.errorMessage + ".Description.Many", result));
1657
+ }
1658
+ _this.refresh.emit({
1659
+ progress: 1
1660
+ });
1661
+ return;
1662
+ }
1663
+ if (_this._modalService.modalRef) {
1664
+ _this._modalService.modalRef.hide();
1665
+ }
1666
+ }, function (err) {
1667
+ _this.loading = false;
1668
+ _this.lastError = err;
1669
+ _this.refresh.emit({
1670
+ progress: 0
1671
+ });
1672
+ });
1673
+ }
1674
+ catch (err) {
1675
+ this.loading = false;
1676
+ this.lastError = err;
1677
+ }
1678
+ return [2 /*return*/];
1679
+ });
1680
+ });
1681
+ };
1682
+ AdvancedRowActionComponent.decorators = [
1683
+ { type: Component, args: [{
1684
+ selector: 'app-advanced-row-action',
1685
+ template: "<div>\n <div class=\"modal-header\" *ngIf=\"modalTitle\">\n <h5 class=\"modal-title\">{{modalTitle | translate}}</h5>\n <button (click)=\"cancel()\" [disabled]=\"loading\"\n type=\"button\" class=\"close\" data-dismiss=\"modal\" aria-label=\"Cancel\">\n <span aria-hidden=\"true\">&times;</span>\n </button>\n </div>\n <div class=\"modal-body pt-0 mt-2 pb-0\">\n <div class=\"row\" *ngIf=\"lastError\">\n <div class=\"col-12\">\n <div class=\"alert alert-warning\" role=\"alert\">\n <span>{{ 'Tables.Actions.CompletedWithErrors.Title' | translate }}</span><br>\n <small *ngIf=\"lastError.status >= 0\" [translate]=\"'E' + lastError.status + '.message'\"></small>\n <small *ngIf=\"lastError.status == null\">{{lastError.message}}</small>\n </div>\n </div>\n </div>\n <div class=\"row\" *ngIf=\"description\">\n <div class=\"col-12 mb-3\">\n <div class=\"text-justify\">\n {{description | translate}}\n </div>\n </div>\n </div>\n <div class=\"row\">\n <div class=\"col-12\">\n <div *ngIf=\"items && items.length > 1\" [translate]=\"'Tables.Actions.ActionMessage.Many'\" [translateParams]=\"items\"></div>\n <div *ngIf=\"items && items.length === 1\" [translate]=\"'Tables.Actions.ActionMessage.One'\"></div>\n <div class=\"font-weight-bold text-danger\" *ngIf=\"items && items.length <= 0\" [translate]=\"'Tables.Actions.ActionMessage.None'\"></div>\n <div class=\"pt-2 font-weight-bold text-danger\" *ngIf=\"additionalMessage && items && items.length <= 0\">{{additionalMessage}}</div>\n </div>\n </div>\n <div class=\"row pt-3\" *ngIf=\"formTemplate\">\n <div class=\"col-12 mb-3\">\n <div>\n <advanced-form-edit #formComponent [formName]=\"formTemplate\" [(data)]=\"data\"></advanced-form-edit>\n </div>\n </div>\n </div>\n\n <div class=\"row mt-3\">\n <div class=\"col-12\">\n <progressbar #progress [type]=\"progressType\" [max]=\"100\">\n </progressbar>\n </div>\n </div>\n </div>\n\n <div class=\"modal-footer justify-content-end\">\n <button [disabled]=\"okButtonDisabled || loading || (items && items.length === 0)\" (click)=\"ok()\"\n type=\"button\" [ngClass]=\"okButtonClass\">\n {{okButtonText | translate}}\n </button>\n <button [disabled]=\"cancelButtonDisabled || loading\"\n (click)=\"cancel()\" type=\"button\" [ngClass]=\"cancelButtonClass\" data-dismiss=\"modal\">\n {{cancelButtonText | translate}}\n </button>\n </div>\n</div>\n",
1686
+ encapsulation: ViewEncapsulation.None,
1687
+ styles: ["\n .fa-1_5x {\n font-size: 1.5rem;\n }\n .form-control:disabled, .form-control[readonly] {\n background-color: inherit;\n }\n .form-check.checkbox {\n position: relative\n }\n "]
1688
+ }] }
1689
+ ];
1690
+ /** @nocollapse */
1691
+ AdvancedRowActionComponent.ctorParameters = function () { return [
1692
+ { type: Router },
1693
+ { type: ActivatedRoute },
1694
+ { type: TranslateService },
1695
+ { type: AngularDataContext },
1696
+ { type: ErrorService },
1697
+ { type: ModalService },
1698
+ { type: AppEventService }
1699
+ ]; };
1700
+ AdvancedRowActionComponent.propDecorators = {
1701
+ items: [{ type: Input }],
1702
+ modalIcon: [{ type: Input }],
1703
+ description: [{ type: Input }],
1704
+ formTemplate: [{ type: Input }],
1705
+ progressType: [{ type: Input }],
1706
+ data: [{ type: Output }],
1707
+ additionalMessage: [{ type: Input }],
1708
+ errorMessage: [{ type: Input }],
1709
+ progressComponent: [{ type: ViewChild, args: ['progress',] }],
1710
+ formComponent: [{ type: ViewChild, args: ['formComponent',] }],
1711
+ refresh: [{ type: Input }],
1712
+ execute: [{ type: Input }]
1713
+ };
1714
+ return AdvancedRowActionComponent;
1715
+ }(RouterModalOkCancel));
1716
+
1717
+ var AdvancedTableSearchBaseComponent = /** @class */ (function () {
1718
+ function AdvancedTableSearchBaseComponent() {
1719
+ this.filterChange = new EventEmitter();
1720
+ }
1721
+ Object.defineProperty(AdvancedTableSearchBaseComponent.prototype, "filter", {
1722
+ get: function () {
1723
+ return this._filter;
1724
+ },
1725
+ set: function (value) {
1726
+ this._filter = value;
1727
+ },
1728
+ enumerable: true,
1729
+ configurable: true
1730
+ });
1731
+ AdvancedTableSearchBaseComponent.prototype.onKeyEnter = function (event) {
1732
+ if (event.code === 'Enter') {
1733
+ this.filterChange.emit(this._filter);
1734
+ }
1735
+ };
1736
+ AdvancedTableSearchBaseComponent.propDecorators = {
1737
+ filterChange: [{ type: Output }],
1738
+ filter: [{ type: Input }]
1739
+ };
1740
+ return AdvancedTableSearchBaseComponent;
1741
+ }());
1742
+
1743
+ var AdvancedSearchFormComponent = /** @class */ (function (_super) {
1744
+ __extends(AdvancedSearchFormComponent, _super);
1745
+ function AdvancedSearchFormComponent(_context, _translateService, _activatedRoute, _http) {
1746
+ var _this = _super.call(this) || this;
1747
+ _this._context = _context;
1748
+ _this._translateService = _translateService;
1749
+ _this._activatedRoute = _activatedRoute;
1750
+ _this._http = _http;
1751
+ _this.form = {};
1752
+ _this.refreshForm = new EventEmitter();
1753
+ _this.submission = { data: {} };
1754
+ _this.loading = true;
1755
+ return _this;
1756
+ }
1757
+ AdvancedSearchFormComponent.prototype.ngOnChanges = function (changes) {
1758
+ var _this = this;
1759
+ if (Object.prototype.hasOwnProperty.call(changes, 'form')) {
1760
+ if (changes.form != null) {
1761
+ if (changes.form.currentValue &&
1762
+ changes.form.currentValue != changes.form.previousValue) {
1763
+ this.ngOnInit();
1764
+ }
1765
+ }
1766
+ }
1767
+ if (Object.prototype.hasOwnProperty.call(changes, 'formSrc')) {
1768
+ if (changes.formSrc != null) {
1769
+ if (changes.formSrc.currentValue &&
1770
+ changes.formSrc.currentValue != changes.formSrc.previousValue) {
1771
+ this._http.get(changes.formSrc.currentValue).toPromise().then(function (form) {
1772
+ // set form
1773
+ _this.form = form;
1774
+ // and init
1775
+ _this.ngOnInit();
1776
+ }).catch(function (err) {
1777
+ console.error('An error occurred while loading search configuration');
1778
+ console.error(err);
1779
+ });
1780
+ }
1781
+ }
1782
+ }
1783
+ if (Object.prototype.hasOwnProperty.call(changes, 'filter')) {
1784
+ if (changes.filter != null) {
1785
+ this.submission.data = changes.filter.currentValue || {};
1786
+ this.refreshForm.emit({
1787
+ submission: this.submission
1788
+ });
1789
+ }
1790
+ }
1791
+ };
1792
+ AdvancedSearchFormComponent.prototype.ngOnInit = function () {
1793
+ var _this = this;
1794
+ if (this.form) {
1795
+ new ServiceUrlPreProcessor(this._context).parse(this.form);
1796
+ new TranslatePreProcessor(this._translateService).parse(this.form);
1797
+ this.submission = {
1798
+ data: this.filter
1799
+ };
1800
+ this.refreshForm.emit({
1801
+ form: this.form
1802
+ });
1803
+ this.loading = false;
1804
+ this.filterSubscription = this.filterChange.subscribe(function (filter) {
1805
+ _this.submission.data = filter;
1806
+ _this.refreshForm.emit({
1807
+ submission: _this.submission
1808
+ });
1809
+ });
1810
+ }
1811
+ };
1812
+ AdvancedSearchFormComponent.prototype.onChange = function (event) {
1813
+ var _this = this;
1814
+ Object.keys(this.formComponent.submission.data).forEach(function (key) {
1815
+ if (Object.prototype.hasOwnProperty.call(_this.formComponent.submission.data, key)) {
1816
+ var value = _this.formComponent.submission.data[key];
1817
+ // the filter with type is a string and is not empty
1818
+ var isEmptyString = typeof value === 'string' && value.length === 0;
1819
+ if (!isEmptyString) {
1820
+ Object.defineProperty(_this.filter, key, {
1821
+ configurable: true,
1822
+ enumerable: true,
1823
+ value: value
1824
+ });
1825
+ }
1826
+ else {
1827
+ delete _this.filter[key];
1828
+ }
1829
+ }
1830
+ });
1831
+ };
1832
+ AdvancedSearchFormComponent.prototype.onFormLoad = function (form) {
1833
+ var currentLang = this._translateService.currentLang;
1834
+ this.formComponent.formio.i18next.options.resources[currentLang] = { translation: this._translateService.instant("Forms") };
1835
+ this.formComponent.formio.language = currentLang;
1836
+ };
1837
+ AdvancedSearchFormComponent.prototype.ngAfterViewInit = function () {
1838
+ //
1839
+ };
1840
+ AdvancedSearchFormComponent.prototype.ngOnDestroy = function () {
1841
+ if (this.filterSubscription) {
1842
+ this.filterSubscription.unsubscribe();
1843
+ }
1844
+ };
1845
+ AdvancedSearchFormComponent.decorators = [
1846
+ { type: Component, args: [{
1847
+ selector: 'app-advanced-search-form',
1848
+ template: "\n <div class=\"p-4\">\n <formio #formioComponent class=\"formio-search\" (keydown)=\"onKeyEnter($event)\" (change)=\"onChange($event)\" (formLoad)=\"onFormLoad($event)\"\n [refresh]=\"refreshForm\" [submission]=\"submission\" [form]=\"form\"></formio>\n </div>\n ",
1849
+ encapsulation: ViewEncapsulation.None,
1850
+ styles: ["formio.formio-search .form-group{margin-bottom:0}formio.formio-search .form-group .col-form-label{font-size:90%;padding-top:4px;padding-bottom:4px}.choices__list.choices__list--single .choices__item:first-child.choices__item--selectable{width:85%;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}"]
1851
+ }] }
1852
+ ];
1853
+ /** @nocollapse */
1854
+ AdvancedSearchFormComponent.ctorParameters = function () { return [
1855
+ { type: AngularDataContext },
1856
+ { type: TranslateService },
1857
+ { type: ActivatedRoute },
1858
+ { type: HttpClient }
1859
+ ]; };
1860
+ AdvancedSearchFormComponent.propDecorators = {
1861
+ formComponent: [{ type: ViewChild, args: ['formioComponent',] }],
1862
+ form: [{ type: Input }],
1863
+ formSrc: [{ type: Input }],
1864
+ refreshForm: [{ type: Output }]
1865
+ };
1866
+ return AdvancedSearchFormComponent;
1867
+ }(AdvancedTableSearchBaseComponent));
1868
+
1869
+ var AdvancedTableConfigurationResolver = /** @class */ (function () {
1870
+ function AdvancedTableConfigurationResolver(_http) {
1871
+ this._http = _http;
1872
+ }
1873
+ AdvancedTableConfigurationResolver.prototype.resolve = function (route, state) {
1874
+ // get list
1875
+ var list = route.data.list || route.params.list;
1876
+ // get model
1877
+ var model = route.data.model || route.params.model;
1878
+ // get configuration
1879
+ return this._http.get("assets/lists/" + model + "/" + list + ".json").toPromise();
1880
+ };
1881
+ AdvancedTableConfigurationResolver.decorators = [
1882
+ { type: Injectable }
1883
+ ];
1884
+ /** @nocollapse */
1885
+ AdvancedTableConfigurationResolver.ctorParameters = function () { return [
1886
+ { type: HttpClient }
1887
+ ]; };
1888
+ return AdvancedTableConfigurationResolver;
1889
+ }());
1890
+ var AdvancedSearchConfigurationResolver = /** @class */ (function () {
1891
+ function AdvancedSearchConfigurationResolver(_http) {
1892
+ this._http = _http;
1893
+ }
1894
+ AdvancedSearchConfigurationResolver.prototype.resolve = function (route, state) {
1895
+ // get list
1896
+ var list = route.data.list || route.params.list;
1897
+ // get model
1898
+ var model = route.data.model || route.params.model;
1899
+ // get configuration
1900
+ return this._http.get("assets/lists/" + model + "/search." + list + ".json").toPromise();
1901
+ };
1902
+ AdvancedSearchConfigurationResolver.decorators = [
1903
+ { type: Injectable }
1904
+ ];
1905
+ /** @nocollapse */
1906
+ AdvancedSearchConfigurationResolver.ctorParameters = function () { return [
1907
+ { type: HttpClient }
1908
+ ]; };
1909
+ return AdvancedSearchConfigurationResolver;
1910
+ }());
1911
+
1912
+ var AdvancedTableSearchComponent = /** @class */ (function (_super) {
1913
+ __extends(AdvancedTableSearchComponent, _super);
1914
+ function AdvancedTableSearchComponent(_context, _activatedRoute, datePipe, _modalService, _userStorage, _translate, _advancedSearchValueProvider, _template, _router, _modal) {
1915
+ var _this = _super.call(this) || this;
1916
+ _this._context = _context;
1917
+ _this._activatedRoute = _activatedRoute;
1918
+ _this.datePipe = datePipe;
1919
+ _this._modalService = _modalService;
1920
+ _this._userStorage = _userStorage;
1921
+ _this._translate = _translate;
1922
+ _this._advancedSearchValueProvider = _advancedSearchValueProvider;
1923
+ _this._template = _template;
1924
+ _this._router = _router;
1925
+ _this._modal = _modal;
1926
+ _this.collapsed = true;
1927
+ _this.allowSave = true;
1928
+ _this.showMore = true;
1929
+ _this.mergeQueryParams = true;
1930
+ _this.viewChange = new EventEmitter();
1931
+ _this.userSearchList = [];
1932
+ _this.selectedList = null;
1933
+ return _this;
1934
+ }
1935
+ Object.defineProperty(AdvancedTableSearchComponent.prototype, "text", {
1936
+ get: function () {
1937
+ if (this.searchText) {
1938
+ return this.searchText.nativeElement.value;
1939
+ }
1940
+ },
1941
+ set: function (value) {
1942
+ if (this.searchText) {
1943
+ this.searchText.nativeElement.value = value;
1944
+ }
1945
+ },
1946
+ enumerable: true,
1947
+ configurable: true
1948
+ });
1949
+ AdvancedTableSearchComponent.prototype.ngOnInit = function () {
1950
+ var _this = this;
1951
+ this.configChangesSubscription = this.table.configChanges.subscribe(function (config) {
1952
+ if (config == null) {
1953
+ return;
1954
+ }
1955
+ // load user searches
1956
+ _this.loadUserSearchList().then(function () {
1957
+ // if search component merges query params
1958
+ // (uses queryParams to apply filter)
1959
+ if (_this.mergeQueryParams) {
1960
+ _this.queryParamSubscription = _this._activatedRoute.queryParams.subscribe(function (queryParams) {
1961
+ _this.applyQueryParams(queryParams);
1962
+ });
1963
+ }
1964
+ });
1965
+ });
1966
+ };
1967
+ /**
1968
+ * Applies query given by the queryParams of the activated route
1969
+ * @param queryParams
1970
+ */
1971
+ AdvancedTableSearchComponent.prototype.applyQueryParams = function (queryParams) {
1972
+ var _this = this;
1973
+ this.filter = {};
1974
+ if (Object.prototype.hasOwnProperty.call(queryParams, 'q')) {
1975
+ // set collapsed
1976
+ this.collapsed = true;
1977
+ // search text
1978
+ this.text = queryParams.q;
1979
+ return this.table.search(this.text);
1980
+ }
1981
+ else {
1982
+ this.text = '';
1983
+ }
1984
+ var filterParams = Object.assign({}, queryParams);
1985
+ if (Object.prototype.hasOwnProperty.call(queryParams, 's')) {
1986
+ // set collapsed
1987
+ this.collapsed = false;
1988
+ // find user search by name
1989
+ if (this.userSearchList) {
1990
+ this.selectedList = this.userSearchList.find(function (item) {
1991
+ return item.name === queryParams.s;
1992
+ });
1993
+ if (this.selectedList) {
1994
+ filterParams = this.selectedList.filter;
1995
+ }
1996
+ }
1997
+ }
1998
+ else {
1999
+ this.selectedList = null;
2000
+ }
2001
+ Object.keys(filterParams).filter(function (key) {
2002
+ // search criteria
2003
+ if (_this.table && _this.table.config && _this.table.config.criteria) {
2004
+ return _this.table.config.criteria.find(function (item) {
2005
+ return item.name === key;
2006
+ });
2007
+ }
2008
+ }).forEach(function (key) {
2009
+ var value = filterParams[key];
2010
+ if (TextUtils.isNumber(value)) {
2011
+ value = parseFloat(filterParams[key]);
2012
+ }
2013
+ if (_this.filter[key] !== value) {
2014
+ // set value
2015
+ Object.defineProperty(_this.filter, key, {
2016
+ configurable: true,
2017
+ enumerable: true,
2018
+ writable: true,
2019
+ value: value
2020
+ });
2021
+ }
2022
+ if (_this.filter[key] != null) {
2023
+ _this.collapsed = false;
2024
+ }
2025
+ });
2026
+ // call filterChange event to apply change to advanced search children
2027
+ this.filterChange.emit(this.filter);
2028
+ // apply query
2029
+ this.getQuery().then(function (query) {
2030
+ // if table query is null
2031
+ if (_this.table.query == null) {
2032
+ // set query
2033
+ _this.table.query = query;
2034
+ }
2035
+ else {
2036
+ if (query != null) {
2037
+ var params = query.getParams();
2038
+ // otherwise set filter params
2039
+ _this.table.query.setParam('$filter', params.$filter);
2040
+ }
2041
+ else {
2042
+ _this.table.query.setParam('$filter', null);
2043
+ }
2044
+ }
2045
+ // and finally fetch data
2046
+ _this.table.fetch(true);
2047
+ });
2048
+ };
2049
+ AdvancedTableSearchComponent.prototype.ngOnDestroy = function () {
2050
+ if (this.queryParamSubscription) {
2051
+ this.queryParamSubscription.unsubscribe();
2052
+ }
2053
+ if (this.configChangesSubscription) {
2054
+ this.configChangesSubscription.unsubscribe();
2055
+ }
2056
+ };
2057
+ AdvancedTableSearchComponent.prototype.ngAfterViewInit = function () {
2058
+ };
2059
+ AdvancedTableSearchComponent.prototype.onSearchKeyDown = function (event) {
2060
+ if (this.table && event.keyCode === 13) {
2061
+ // get search text
2062
+ var searchText = event.target.value;
2063
+ // merge query params ?
2064
+ if (this.mergeQueryParams) {
2065
+ var queryParams_1 = {
2066
+ q: searchText
2067
+ };
2068
+ if (this.table.config && this.table.config.criteria) {
2069
+ this.table.config.criteria.forEach(function (item) {
2070
+ Object.defineProperty(queryParams_1, item.name, {
2071
+ configurable: true,
2072
+ enumerable: true,
2073
+ writable: true,
2074
+ value: null
2075
+ });
2076
+ });
2077
+ }
2078
+ // try to apply filter by appending query params
2079
+ return this._router.navigate([], {
2080
+ relativeTo: this._activatedRoute,
2081
+ queryParams: queryParams_1,
2082
+ queryParamsHandling: 'merge'
2083
+ });
2084
+ }
2085
+ // otherwise do search
2086
+ this.table.search(searchText);
2087
+ return false;
2088
+ }
2089
+ };
2090
+ AdvancedTableSearchComponent.prototype.transformDate = function (date) {
2091
+ date = this.datePipe.transform(date, 'MM/dd/yyyy'); // whatever format you need.
2092
+ return date;
2093
+ };
2094
+ AdvancedTableSearchComponent.prototype.convertToString = function (nameFilter) {
2095
+ var name = '';
2096
+ if (nameFilter != null) {
2097
+ name = nameFilter.toString();
2098
+ }
2099
+ return name;
2100
+ };
2101
+ // Load saved criteria searches user has stored before
2102
+ AdvancedTableSearchComponent.prototype.loadUserSearchList = function () {
2103
+ var _this = this;
2104
+ this.storageKey = 'tables/' + this.table.config.model + '/searches';
2105
+ return this._userStorage.getItem(this.storageKey).then(function (data) {
2106
+ var list = data.value || [];
2107
+ // if table configuration has pre-defined searches
2108
+ if (_this.table && _this.table.config.searches && _this.table.config.searches.length) {
2109
+ // add pre-defined lists
2110
+ list.push.apply(list, _this.table.config.searches.map(function (x) {
2111
+ x.readOnly = true; // as readonly
2112
+ x.name = _this._translate.instant(x.name);
2113
+ return x;
2114
+ }));
2115
+ }
2116
+ // set user search list
2117
+ _this.userSearchList = list;
2118
+ return Promise.resolve();
2119
+ }).catch(function (err) {
2120
+ // DO NOT THROW ERROR
2121
+ // todo: notify component for this error in order to disable some actions
2122
+ console.error('An error occurred while getting user search list');
2123
+ console.error(err);
2124
+ return Promise.resolve();
2125
+ });
2126
+ };
2127
+ AdvancedTableSearchComponent.prototype.onSelectUserSearch = function (event) {
2128
+ if (this.selectedList) {
2129
+ var listFound = this.searchInListByName(this.selectedList.name);
2130
+ if (listFound) {
2131
+ if (this.mergeQueryParams) {
2132
+ var queryParams_2 = { q: null, s: this.selectedList.name };
2133
+ // clear criteria if any
2134
+ this.table.config.criteria.forEach(function (item) {
2135
+ if (Object.prototype.hasOwnProperty.call(queryParams_2, item.name) === false) {
2136
+ // set null value
2137
+ Object.defineProperty(queryParams_2, item.name, {
2138
+ configurable: true,
2139
+ enumerable: true,
2140
+ writable: true,
2141
+ value: null
2142
+ });
2143
+ }
2144
+ });
2145
+ return this._router.navigate([], {
2146
+ relativeTo: this._activatedRoute,
2147
+ queryParams: queryParams_2,
2148
+ queryParamsHandling: 'merge'
2149
+ });
2150
+ }
2151
+ this.selectedList = listFound;
2152
+ this.filter = this.selectedList.filter;
2153
+ this.filterChange.emit(this.filter);
2154
+ return true;
2155
+ }
2156
+ }
2157
+ else {
2158
+ return this._router.navigate([], {
2159
+ relativeTo: this._activatedRoute,
2160
+ queryParams: { s: null },
2161
+ queryParamsHandling: 'merge'
2162
+ });
2163
+ }
2164
+ return false;
2165
+ };
2166
+ AdvancedTableSearchComponent.prototype.searchInListByName = function (name) {
2167
+ if (Array.isArray(this.userSearchList)) {
2168
+ var listFound = this.userSearchList.find(function (x) { return x.name === name; });
2169
+ if (listFound) {
2170
+ return listFound;
2171
+ }
2172
+ else {
2173
+ return false;
2174
+ }
2175
+ }
2176
+ };
2177
+ // Update list item contents with given content (Search by object name property)
2178
+ AdvancedTableSearchComponent.prototype.updateSavedSearchListItemByName = function (name, newItem) {
2179
+ var itemInList = this.userSearchList.find(function (x) { return x.name === name; });
2180
+ var index = this.userSearchList.indexOf(itemInList);
2181
+ this.userSearchList[index] = newItem;
2182
+ this.selectedList = this.userSearchList[index];
2183
+ };
2184
+ // Update list item contents with given content (Search by object)
2185
+ AdvancedTableSearchComponent.prototype.updateSavedSearchListItemByObject = function (itemInList, newItem) {
2186
+ var index = this.userSearchList.indexOf(itemInList);
2187
+ this.userSearchList[index] = newItem;
2188
+ this.selectedList = this.userSearchList[index];
2189
+ };
2190
+ // Delete list item from list
2191
+ AdvancedTableSearchComponent.prototype.deleteItemFromSavedSearchListByObject = function (itemInList) {
2192
+ this.userSearchList = this.userSearchList.filter(function (item) { return item !== itemInList; });
2193
+ this.selectedList = null;
2194
+ this.filter = {};
2195
+ this.advancedSearch(true);
2196
+ this.uploadListOnUserStorage();
2197
+ };
2198
+ // User chose to save its advanced form search criteria
2199
+ AdvancedTableSearchComponent.prototype.saveSearch = function (templateToLoad, newList) {
2200
+ if (newList === void 0) { newList = true; }
2201
+ if (this.table.config.model) {
2202
+ // Set the corresponding key to its list and show a confirmation modal window
2203
+ this.storageKey = "tables/" + this.table.config.model + "/searches";
2204
+ if (this.filter && Object.keys(this.filter).length) {
2205
+ // User wants to save an existing list from the dropdown
2206
+ if (!newList && this.selectedList) {
2207
+ var newItem = { 'name': this.selectedList.name, 'filter': __assign({}, this.filter) };
2208
+ this.updateSavedSearchListItemByObject(this.selectedList, newItem);
2209
+ this.uploadListOnUserStorage();
2210
+ // User wants to save a new list
2211
+ }
2212
+ else {
2213
+ this.modalRef = this._modalService.show(templateToLoad);
2214
+ }
2215
+ }
2216
+ else {
2217
+ // User did not define any criteria
2218
+ this._modal.showWarningDialog(this._translate.instant('AdvancedSearch.Modal.Title'), this._translate.instant('AdvancedSearch.Modal.EmptyCriteriaList'), DIALOG_BUTTONS.Ok);
2219
+ }
2220
+ }
2221
+ else {
2222
+ this._modal.showWarningDialog(this._translate.instant('AdvancedSearch.Modal.Title'), this._translate.instant('AdvancedSearch.Modal.NoListDefined'), DIALOG_BUTTONS.Ok);
2223
+ }
2224
+ };
2225
+ // User Accepted => Save list and Close modal
2226
+ AdvancedTableSearchComponent.prototype.confirmModal = function (saveFormName) {
2227
+ // name given and list name is unique
2228
+ if (saveFormName && !(this.searchInListByName(saveFormName))) {
2229
+ var newInsertedValue = { 'name': saveFormName, 'filter': __assign({}, this.filter) };
2230
+ if (this.userSearchList && this.userSearchList.length !== 0) {
2231
+ this.userSearchList.push(newInsertedValue);
2232
+ this.storageValue = this.userSearchList;
2233
+ this.selectedList = newInsertedValue;
2234
+ }
2235
+ else {
2236
+ this.storageValue = [newInsertedValue];
2237
+ this.userSearchList = this.storageValue;
2238
+ this.selectedList = newInsertedValue;
2239
+ }
2240
+ this.uploadListOnUserStorage();
2241
+ this.modalRef.hide();
2242
+ }
2243
+ else if (saveFormName && (this.searchInListByName(saveFormName))) {
2244
+ // User should insert a different name cause this one is already in use
2245
+ alert(this._translate.instant('AdvancedSearch.Modal.TitleOnListAlreadyCreated'));
2246
+ }
2247
+ else {
2248
+ // User did not insert any text
2249
+ alert(this._translate.instant('AdvancedSearch.Modal.TitleOnUserError'));
2250
+ }
2251
+ };
2252
+ // User declined => Close modal
2253
+ AdvancedTableSearchComponent.prototype.closeModal = function () {
2254
+ this.modalRef.hide();
2255
+ };
2256
+ // Upload user's criteria on User Storage
2257
+ AdvancedTableSearchComponent.prototype.uploadListOnUserStorage = function () {
2258
+ this._userStorage.setItem(this.storageKey, this.userSearchList.filter(function (x) {
2259
+ return !x.readOnly;
2260
+ }));
2261
+ };
2262
+ /**
2263
+ * @deprecated This method is going to be deprecated. Use search() method instead.
2264
+ * @param {*} event
2265
+ */
2266
+ AdvancedTableSearchComponent.prototype.asyncAdvancedSearch = function (event) {
2267
+ return __awaiter(this, void 0, void 0, function () {
2268
+ var query, queryParams_3;
2269
+ return __generator(this, function (_a) {
2270
+ switch (_a.label) {
2271
+ case 0:
2272
+ if (!(this.table && this.table.config && Array.isArray(this.table.config.criteria))) return [3 /*break*/, 2];
2273
+ return [4 /*yield*/, this.getQuery()];
2274
+ case 1:
2275
+ query = _a.sent();
2276
+ if (this.mergeQueryParams) {
2277
+ this.selectedList = null;
2278
+ queryParams_3 = Object.assign({ q: null, s: null }, this.filter);
2279
+ // enumerate criteria
2280
+ this.table.config.criteria.forEach(function (item) {
2281
+ if (Object.prototype.hasOwnProperty.call(queryParams_3, item.name) === false) {
2282
+ // set null value
2283
+ Object.defineProperty(queryParams_3, item.name, {
2284
+ configurable: true,
2285
+ enumerable: true,
2286
+ writable: true,
2287
+ value: null
2288
+ });
2289
+ }
2290
+ });
2291
+ return [2 /*return*/, this._router.navigate([], {
2292
+ relativeTo: this._activatedRoute,
2293
+ queryParams: queryParams_3,
2294
+ queryParamsHandling: 'merge'
2295
+ })];
2296
+ }
2297
+ if (this.table.query) {
2298
+ this.table.query.setParam('$filter', query.getParams()['$filter']);
2299
+ }
2300
+ else {
2301
+ this.table.query = query;
2302
+ }
2303
+ this.table.fetch();
2304
+ _a.label = 2;
2305
+ case 2: return [2 /*return*/];
2306
+ }
2307
+ });
2308
+ });
2309
+ };
2310
+ AdvancedTableSearchComponent.prototype.search = function () {
2311
+ return this.asyncAdvancedSearch().then(function () {
2312
+ // do nothing
2313
+ });
2314
+ };
2315
+ AdvancedTableSearchComponent.prototype.getQuery = function () {
2316
+ return __awaiter(this, void 0, void 0, function () {
2317
+ var expressions_1, values_1, query;
2318
+ var _this = this;
2319
+ return __generator(this, function (_a) {
2320
+ switch (_a.label) {
2321
+ case 0:
2322
+ // on simple search return null
2323
+ if (this.collapsed) {
2324
+ return [2 /*return*/, null];
2325
+ }
2326
+ if (!(this.table && this.table.config && Array.isArray(this.table.config.criteria))) return [3 /*break*/, 2];
2327
+ expressions_1 = [];
2328
+ return [4 /*yield*/, this._advancedSearchValueProvider.getValues()];
2329
+ case 1:
2330
+ values_1 = _a.sent();
2331
+ this.table.config.criteria.forEach(function (x) {
2332
+ if (Object.prototype.hasOwnProperty.call(_this.filter, x.name)) {
2333
+ var nameFilter = _this.convertToString(_this.filter[x.name]);
2334
+ if (nameFilter.includes('GMT')) {
2335
+ var newDate = _this.transformDate(_this.filter[x.name]);
2336
+ expressions_1.push(_this._template.transform(x.filter, {
2337
+ value: newDate
2338
+ }));
2339
+ }
2340
+ else if (_this.filter[x.name] !== 'undefined') {
2341
+ expressions_1.push(_this._template.transform(x.filter, Object.assign({
2342
+ value: _this.filter[x.name]
2343
+ }, values_1)));
2344
+ }
2345
+ }
2346
+ });
2347
+ query = void 0;
2348
+ if (expressions_1 || expressions_1.length) {
2349
+ // create client query
2350
+ query = this._context.model(this.table.config.model).asQueryable();
2351
+ query.setParam('filter', expressions_1.join(' and '));
2352
+ }
2353
+ else {
2354
+ query = this._context.model(this.table.config.model).asQueryable();
2355
+ }
2356
+ return [2 /*return*/, query];
2357
+ case 2: return [2 /*return*/];
2358
+ }
2359
+ });
2360
+ });
2361
+ };
2362
+ AdvancedTableSearchComponent.prototype.advancedSearch = function (event) {
2363
+ return this.asyncAdvancedSearch(event);
2364
+ };
2365
+ AdvancedTableSearchComponent.prototype.clear = function () {
2366
+ if (this.mergeQueryParams) {
2367
+ this.selectedList = null;
2368
+ var queryParams_4 = { q: null, s: null };
2369
+ // enumerate criteria
2370
+ this.table.config.criteria.forEach(function (item) {
2371
+ if (Object.prototype.hasOwnProperty.call(queryParams_4, item.name) === false) {
2372
+ // set null value
2373
+ Object.defineProperty(queryParams_4, item.name, {
2374
+ configurable: true,
2375
+ enumerable: true,
2376
+ writable: true,
2377
+ value: null
2378
+ });
2379
+ }
2380
+ });
2381
+ return this._router.navigate([], {
2382
+ relativeTo: this._activatedRoute,
2383
+ queryParams: queryParams_4,
2384
+ queryParamsHandling: 'merge'
2385
+ });
2386
+ }
2387
+ else {
2388
+ // clear filter
2389
+ this.filter = {};
2390
+ // clear list
2391
+ this.selectedList = null;
2392
+ // raise filter change event
2393
+ this.filterChange.emit(this.filter);
2394
+ }
2395
+ };
2396
+ Object.defineProperty(AdvancedTableSearchComponent.prototype, "viewState", {
2397
+ /**
2398
+ * Gets the view state of search control
2399
+ */
2400
+ get: function () {
2401
+ return {
2402
+ advancedView: !this.collapsed
2403
+ };
2404
+ },
2405
+ enumerable: true,
2406
+ configurable: true
2407
+ });
2408
+ /**
2409
+ * Switches view between simple and advanced search
2410
+ */
2411
+ AdvancedTableSearchComponent.prototype.toggleView = function () {
2412
+ return __awaiter(this, void 0, void 0, function () {
2413
+ return __generator(this, function (_a) {
2414
+ this.collapsed = !this.collapsed;
2415
+ // emit event for view status change
2416
+ this.viewChange.emit(this.viewState);
2417
+ return [2 /*return*/];
2418
+ });
2419
+ });
2420
+ };
2421
+ AdvancedTableSearchComponent.decorators = [
2422
+ { type: Component, args: [{
2423
+ selector: 'app-advanced-table-search',
2424
+ template: "<div class=\"s--list-navbar d-none d-sm-block\">\n\n <div id=\"collapse-header\" [ngClass]=\"{'show':collapsed}\" class=\"collapse multi-collapse\">\n <form class=\"form-inline p-3 col\">\n <div class=\"form-group col-7\" [ngClass]= \"{ 'col-12': !showMore }\">\n <label class=\"pr-3\" for=\"searchText\" [translate]=\"'Tables.Search'\"></label>\n <input (keydown)=\"onSearchKeyDown($event)\" spellcheck=\"false\" type=\"text\" id=\"searchText\" name=\"searchText\"\n class=\"form-control col text-left\" placeholder=\"{{ 'Tables.SearchPlaceholder' | translate }}\" #searchText>\n </div>\n <div *ngIf=\"showMore\" class=\"col-5 text-right text-secondary\" id=\"heading3\">\n <button class=\"d-inline-block btn btn-link collapsed float-right text-secondary text-decoration-none\"\n type=\"button\" (click)=\"toggleView();\">\n <span class=\"d-none d-sm-inline\" [translate]=\"'AdvancedSearch.More'\"></span>\n <i class=\"ml-2 pt-1 fa fa-chevron-down\"></i>\n </button>\n </div>\n </form>\n </div>\n\n <div id=\"collapse3\" [ngClass]=\"{'show':!collapsed}\" class=\"collapse multi-collapse\" aria-labelledby=\"heading3\">\n <div class=\"row\">\n <div class=\"col-sm-12\">\n <div id=\"advanced-form\">\n <ng-content select=\"advanced-search\"></ng-content>\n <hr class=\"mt-0 mb-0\" width=\"97%\">\n <div class=\"row\">\n <div class=\"col-sm-12\">\n <div class=\"form-inline pb-3 pt-3 pr-1 pl-1 col\">\n\n <div class=\"form-group col-4\">\n <div class=\"d-flex flex-row w-100\" *ngIf=\"allowSave\">\n <label class=\"pr-3 d-none\" [translate]=\"'AdvancedSearch.SavedSearches'\"></label>\n <select *ngIf=\"userSearchList\" class=\"custom-select text-secondary flex col-12\" (change)=\"onSelectUserSearch($event)\" [(ngModel)]=\"selectedList\">\n <option [ngValue]=\"null\" [translate]=\"'AdvancedSearch.Choose'\"></option>\n <option *ngFor=\"let item of userSearchList\" [ngValue]=\"item\">{{ item.name }}</option>\n </select>\n <select *ngIf=\"!userSearchList\" class=\"custom-select flex col-6\">\n <option [value]=\"null\" [translate]=\"'AdvancedSearch.Choose'\"></option>\n </select>\n </div>\n </div>\n\n <div class=\"col-3 d-flex flex-row w-100\">\n <div class=\"btn-group\" *ngIf=\"allowSave\" dropdown>\n <button type=\"button\" class=\"btn btn-sm btn-primary\" (click)=\"saveSearch(templateToUse, ( (selectedList && selectedList.readOnly) ? true : false ) )\" [translate]=\"'AdvancedSearch.SaveCurrentSearch'\"></button>\n <button type=\"button\" dropdownToggle class=\"btn btn-sm btn-primary dropdown-toggle dropdown-toggle-split\" data-toggle=\"dropdown\" aria-haspopup=\"true\" aria-expanded=\"false\">\n <span class=\"sr-only\" [translate]=\"'AdvancedSearch.ToggleDropdown'\"></span>\n </button>\n\n <div class=\"dropdown-menu\" *dropdownMenu>\n <a [ngClass]=\"{'disabled': selectedList && selectedList.readOnly}\" class=\"dropdown-item\" (click)=\"saveSearch(templateToUse, false)\" [translate]=\"'AdvancedSearch.Save'\" href=\"javascript:void(0)\"></a>\n <a class=\"dropdown-item\" (click)=\"saveSearch(templateToUse)\" [translate]=\"'AdvancedSearch.SaveAs'\" href=\"javascript:void(0)\"></a>\n <div class=\"dropdown-divider\"></div>\n <a [ngClass]=\"{'disabled': selectedList && selectedList.readOnly}\" class=\"dropdown-item\" (click)=\"deleteItemFromSavedSearchListByObject(selectedList)\" [translate]=\"'AdvancedSearch.Delete'\" href=\"javascript:void(0)\"></a>\n </div>\n </div>\n </div>\n\n <div class=\"col-5 text-right text-secondary\">\n <button type=\"button\" class=\"btn btn-light text-secondary pl-2 pr-2 mr-2\" (click)=\"clear()\">\n <i class=\"fa fa-eraser\"></i>\n </button>\n <button type=\"button\" class=\"btn btn-success pl-4 pr-4 mr-2\" (click)=\"advancedSearch($event);\"\n [translate]=\"'Tables.Search'\"></button>\n <button class=\"d-inline-block btn btn-link collapsed float-right text-secondary text-decoration-none\"\n type=\"button\" (click)=\"toggleView();\">\n <span class=\"d-none d-sm-inline\" [translate]=\"'AdvancedSearch.Less'\"></span>\n <i class=\"ml-2 pt-1 fa fa-chevron-up\"></i>\n </button>\n </div>\n\n </div>\n </div>\n </div>\n </div>\n </div>\n </div>\n </div>\n\n <ng-template #templateToUse>\n <div class=\"modal-header\">\n <h4 class=\"modal-title pull-left\" [translate]=\"'AdvancedSearch.Modal.Title'\"></h4>\n <button type=\"button\" class=\"close pull-right\" aria-label=\"Close\" (click)=\"modalRef.hide()\">\n <span aria-hidden=\"true\">&times;</span>\n </button>\n </div>\n <div class=\"modal-body mt-0 mb-0 text-center\">\n <div>\n <p class=\"text-secondary text-left\" [translate]=\"'AdvancedSearch.Modal.Help'\"></p>\n </div>\n <form class=\"p-3 text-center\" #newListForm=\"ngForm\" >\n <div [ngVar]=\"{ name: ( selectedList?.name ? ( selectedList?.name + ' (1)' ) : null ) }\" #model=\"ngVar\">\n <input [(ngModel)]=\"model.value.name\" [required]=\"true\" id=\"newListName\" name=\"newListName\" type=\"text\" class=\"form-control\" placeholder=\"{{ 'AdvancedSearch.Modal.SaveNamePlaceholder' | translate }}\"/>\n <div class=\"btn-group mt-4\">\n <button [disabled]=\"newListForm.invalid\" type=\"button\" class=\"btn btn-primary\" (click)=\"confirmModal(model.value.name)\" [translate]=\"'AdvancedSearch.Modal.Accept'\"></button>\n <button type=\"button\" class=\"btn btn-gray-300 text-white\" (click)=\"closeModal()\" [translate]=\"'AdvancedSearch.Modal.Close'\"></button>\n </div>\n </div>\n </form>\n </div>\n </ng-template>\n\n</div>\n",
2425
+ encapsulation: ViewEncapsulation.None
2426
+ }] }
2427
+ ];
2428
+ /** @nocollapse */
2429
+ AdvancedTableSearchComponent.ctorParameters = function () { return [
2430
+ { type: AngularDataContext },
2431
+ { type: ActivatedRoute },
2432
+ { type: DatePipe },
2433
+ { type: BsModalService },
2434
+ { type: UserStorageService },
2435
+ { type: TranslateService },
2436
+ { type: AdvancedFilterValueProvider },
2437
+ { type: TemplatePipe },
2438
+ { type: Router },
2439
+ { type: ModalService }
2440
+ ]; };
2441
+ AdvancedTableSearchComponent.propDecorators = {
2442
+ table: [{ type: Input }],
2443
+ collapsed: [{ type: Input }],
2444
+ allowSave: [{ type: Input }],
2445
+ showMore: [{ type: Input }],
2446
+ mergeQueryParams: [{ type: Input }],
2447
+ searchText: [{ type: ViewChild, args: ['searchText',] }],
2448
+ viewChange: [{ type: Output, args: ['viewChange',] }]
2449
+ };
2450
+ return AdvancedTableSearchComponent;
2451
+ }(AdvancedTableSearchBaseComponent));
2452
+
2453
+ var FORMATTERS = {
2454
+ ActionLinkFormatter: new ActionLinkFormatter(),
2455
+ ButtonFormatter: new ButtonFormatter(),
2456
+ DateTimeFormatter: new DateTimeFormatter(),
2457
+ LanguageFormatter: new LanguageFormatter(),
2458
+ LinkFormatter: new LinkFormatter(),
2459
+ NestedPropertyFormatter: new NestedPropertyFormatter(),
2460
+ NgClassFormatter: new NgClassFormatter(),
2461
+ SelectRowFormatter: new SelectRowFormatter(),
2462
+ TemplateFormatter: new TemplateFormatter(),
2463
+ TranslationFormatter: new TranslationFormatter(),
2464
+ TrueFalseFormatter: new TrueFalseFormatter()
2465
+ };
2466
+
2467
+ // important: export this const due to AOT compilation errors
2468
+ // see more https://angular.io/guide/aot-metadata-errors#only-initialized-variables
2469
+ var AdvancedTableModalBaseTemplate = "\n<div>\n <!-- search -->\n <div class=\"row mt-3\">\n <div class=\"col-12 col-lg-3\">\n <div class=\"input-group mb-3\">\n <input spellcheck=\"false\" type=\"text\"\n (keyup)=\"onKeyUp($event)\" [(ngModel)]=\"searchText\"\n class=\"form-control bg-gray-100 border-0\"\n placeholder=\"{{'Tables.SearchPlaceholder' | translate}}\" aria-label=\"Search\" aria-describedby=\"basic-addon2\">\n <div class=\"input-group-append\">\n <button class=\"btn btn-default bg-gray-100 border-0\" type=\"button\">\n <i class=\"fa fa-search text-secondary\"></i>\n </button>\n </div>\n </div>\n </div>\n <div #emptyTable class=\"d-none\">\n <div>\n <div class=\"mt-4\">\n <div class=\"icon-circle bg-gray-300 border-gray-100\"></div>\n </div>\n <div class=\"mt-4\">\n <h4 class=\"font-3xl text-dark\" [translate]=\"'Tables.EmptyTableTitle'\"></h4>\n <p class=\"font-lg text-dark\" [translate]=\"'Tables.EmptyTableMessage'\"></p>\n </div>\n\n </div>\n </div>\n <div class=\"col-12 col-lg-5\">\n <div class=\"btn-toolbar\">\n <button class=\"btn btn-gray-100\">\n <i class=\"fa fa-sliders-h pr-2 text-secondary\" aria-hidden=\"true\"></i>{{'Tables.Filters' | translate}}\n </button>\n <div #dropdownFilter class=\"dropdown ml-3\" dropdown>\n <button class=\"btn btn-gray-100 dropdown-toggle\"\n type=\"button\" id=\"dropdownDefaultFilters\"\n data-toggle=\"dropdown\" dropdownToggle>\n {{ this.defaultFilter.name | translate }}\n </button>\n <div class=\"dropdown-menu\" aria-labelledby=\"dropdownDefaultFilters\" *dropdownMenu>\n <a class=\"dropdown-item\" *ngFor=\"let filter of defaultFilters\" (click)=\"advancedSearch(filter.filter ? filter : '')\">\n {{ filter.name | translate }}\n </a>\n </div>\n </div>\n </div>\n </div>\n <div class=\"col text-lg-right mt-3 mt-lg-0\">\n <button [disabled]=\"true\" class=\"btn rounded-pill btn-outline-theme\">\n <span class=\"pr-2 font-lg\">+</span><span [translate]=\"'Tables.AddItem'\"></span>\n </button>\n </div>\n </div>\n <div class=\"row\">\n <div class=\"col-12\" [ngClass]=\"{ 'component-loading': loading}\">\n <app-advanced-table #advancedTable (init)=\"onTableInit($event)\"\n (load)=\"onDataLoad($event)\"\n [selectable]=\"true\"\n [multipleSelect]=\"true\"\n [scrollX]=\"false\" [scrollY]=\"320\"\n [pageLength]=\"pageLength\"\n [scrollable]=\"false\" [showFooter]=\"false\"\n [showActions]=\"false\" [lengthMenu]=\"lengthMenu\"\n [config]=\"tableConfig\" [configSrc]=\"tableConfigSrc\"></app-advanced-table>\n </div>\n </div>\n <div class=\"row mt-3 table-custom-pager\">\n <div class=\"col-12 d-flex\" *ngIf=\"recordsTotal\">\n <div class=\"mt-2 ml-auto mr-3 text-secondary\" [translate]=\"'Tables.RecordsPerPage'\"></div>\n <div #dropdownLength class=\"dropdown mr-3\" dropdown>\n <button class=\"btn btn-gray-100 dropdown-toggle\"\n type=\"button\" id=\"dropdownPageSize\" data-toggle=\"dropdown\"\n dropdownToggle>\n {{pageLength}}\n </button>\n <div class=\"dropdown-menu\" aria-labelledby=\"dropdownPageSize\" *dropdownMenu>\n <button (click)=\"setLength(item)\"\n class=\"dropdown-item dropdown-item-theme\"\n type=\"button\" *ngFor=\"let item of lengthMenu\">{{item}}</button>\n </div>\n </div>\n <div class=\"mt-2 mr-2\" [translate]=\"'Tables.PageInfo'\" [translateParams]=\"pageInfo\"></div>\n <button [disabled]=\"pageInfo && pageInfo.page === 0\" class=\"btn text-nowrap\" (click)=\"firstPage()\">\n <i class=\"fa fa-chevron-left text-color-theme\"></i>\n <i class=\"fa fa-chevron-left text-color-theme\"></i>\n </button>\n <button [disabled]=\"pageInfo && pageInfo.page===0\" class=\"btn\" (click)=\"previousPage()\">\n <i class=\"fa fa-chevron-left text-color-theme\"></i>\n </button>\n <button [disabled]=\"pageInfo && pageInfo.page===pageInfo.pages-1\" class=\"btn\" (click)=\"nextPage()\">\n <i class=\"fa fa-chevron-right text-color-theme\"></i>\n </button>\n <button [disabled]=\"pageInfo && pageInfo.page===pageInfo.pages-1\" class=\"btn text-nowrap\" (click)=\"lastPage()\">\n <i class=\"fa fa-chevron-right text-color-theme\"></i>\n <i class=\"fa fa-chevron-right text-color-theme\"></i>\n </button>\n </div>\n </div>\n </div>\n";
2470
+ var AdvancedTableModalBaseComponent = /** @class */ (function (_super) {
2471
+ __extends(AdvancedTableModalBaseComponent, _super);
2472
+ function AdvancedTableModalBaseComponent(_router, _activatedRoute, _context, advancedFilterValueProvider, datePipe) {
2473
+ var _this = _super.call(this, _router, _activatedRoute) || this;
2474
+ _this._context = _context;
2475
+ _this.advancedFilterValueProvider = advancedFilterValueProvider;
2476
+ _this.datePipe = datePipe;
2477
+ _this.pageLength = 25;
2478
+ _this.lengthMenu = [5, 10, 25, 50, 100];
2479
+ _this.recordsTotal = 0;
2480
+ _this.loading = false;
2481
+ _this.recordsFiltered = 0;
2482
+ _this.defaultFilters = [AdvancedTableModalBaseComponent.DEFAULT_ALL_FILTER];
2483
+ _this.defaultFilter = AdvancedTableModalBaseComponent.DEFAULT_ALL_FILTER;
2484
+ _this.pageInfo = {
2485
+ serverSide: true
2486
+ };
2487
+ _this.modalClass = 'modal-xl modal-table';
2488
+ _this._template = new TemplatePipe();
2489
+ return _this;
2490
+ }
2491
+ AdvancedTableModalBaseComponent.prototype.ngAfterViewInit = function () {
2492
+ //
2493
+ };
2494
+ AdvancedTableModalBaseComponent.prototype._getInputs = function (componentType) {
2495
+ var props = componentType.__prop__metadata__;
2496
+ var inputs = [];
2497
+ if (props == null) {
2498
+ return inputs;
2499
+ }
2500
+ Object.keys(props).forEach(function (prop) {
2501
+ var member = props[prop][0];
2502
+ if (member.ngMetadataName === 'Input') {
2503
+ inputs.push(prop);
2504
+ }
2505
+ });
2506
+ return inputs.sort();
2507
+ };
2508
+ AdvancedTableModalBaseComponent.prototype.hasInputs = function () {
2509
+ return [];
2510
+ };
2511
+ AdvancedTableModalBaseComponent.prototype.ngOnInit = function () {
2512
+ var _this = this;
2513
+ this.okButtonText = 'Tables.Apply';
2514
+ this.cancelButtonText = 'Tables.Cancel';
2515
+ // get route data
2516
+ this.subscription = this.activatedRoute.data.subscribe(function (data) {
2517
+ // set modal title if any
2518
+ if (data.title) {
2519
+ _this.modalTitle = data.title;
2520
+ }
2521
+ if (data.config) {
2522
+ _this.tableConfig = data.config;
2523
+ }
2524
+ if (_this.tableConfig) {
2525
+ _this.defaultFilters.push.apply(_this.defaultFilters, _this.tableConfig.searches);
2526
+ }
2527
+ // important: use hasInputs due to AOT compilation. Metadata properties cannot be used (e.g. @Input())
2528
+ // because there are empty during runtime
2529
+ // so we need to define manually input properties that are going to be bind through this process
2530
+ // bind all inputs
2531
+ var inputs = _this.hasInputs();
2532
+ inputs.forEach(function (input) {
2533
+ if (Object.prototype.hasOwnProperty.call(data, input)) {
2534
+ _this[input] = data[input];
2535
+ }
2536
+ });
2537
+ _this.configChangesSubscription = _this.advancedTable.configChanges.subscribe(function (config) {
2538
+ if (_this.tableConfig) {
2539
+ // reset default filter
2540
+ _this.defaultFilter = AdvancedTableModalBaseComponent.DEFAULT_ALL_FILTER;
2541
+ // init filter
2542
+ _this.defaultFilters = [AdvancedTableModalBaseComponent.DEFAULT_ALL_FILTER];
2543
+ // add extra filters
2544
+ _this.defaultFilters.push.apply(_this.defaultFilters, _this.tableConfig.searches);
2545
+ }
2546
+ });
2547
+ });
2548
+ };
2549
+ AdvancedTableModalBaseComponent.prototype.cancel = function () {
2550
+ return this.close();
2551
+ };
2552
+ AdvancedTableModalBaseComponent.prototype.ok = function () {
2553
+ return this.close();
2554
+ };
2555
+ AdvancedTableModalBaseComponent.prototype.ngOnDestroy = function () {
2556
+ if (this.subscription) {
2557
+ this.subscription.unsubscribe();
2558
+ }
2559
+ };
2560
+ AdvancedTableModalBaseComponent.prototype.onDataLoad = function (data) {
2561
+ this.recordsTotal = data.recordsTotal;
2562
+ this.recordsFiltered = data.recordsFiltered;
2563
+ // get first page info (because page is not going to be fired for first page)
2564
+ if (data.recordsTotal > 0 && this.pageInfo.recordsTotal === 0) {
2565
+ this.pageInfo.recordsTotal = data.recordsTotal;
2566
+ }
2567
+ };
2568
+ AdvancedTableModalBaseComponent.prototype.previousPage = function () {
2569
+ // go to next page
2570
+ // noinspection TypeScriptValidateJSTypes
2571
+ this.advancedTable.dataTable.page('previous').draw('page');
2572
+ };
2573
+ AdvancedTableModalBaseComponent.prototype.nextPage = function () {
2574
+ // go to next page
2575
+ // noinspection TypeScriptValidateJSTypes
2576
+ this.advancedTable.dataTable.page('next').draw('page');
2577
+ };
2578
+ AdvancedTableModalBaseComponent.prototype.onTableInit = function (dataTable) {
2579
+ var self = this;
2580
+ // get initial page info
2581
+ var initialPageInfo = dataTable.page.info();
2582
+ initialPageInfo.start += 1;
2583
+ self.pageInfo = initialPageInfo;
2584
+ // change emptyTableMessage
2585
+ dataTable.context[0].oLanguage.sEmptyTable = this.emptyTable.nativeElement.innerHTML;
2586
+ // bind page change event
2587
+ dataTable.on('page.dt', function () {
2588
+ var pageInfo = dataTable.page.info();
2589
+ pageInfo.start += 1;
2590
+ self.pageInfo = pageInfo;
2591
+ });
2592
+ // bind draw change event
2593
+ dataTable.on('draw.dt', function () {
2594
+ // for future use
2595
+ self.loading = false;
2596
+ var pageInfo = dataTable.page.info();
2597
+ pageInfo.start += 1;
2598
+ self.pageInfo = pageInfo;
2599
+ });
2600
+ };
2601
+ AdvancedTableModalBaseComponent.prototype.firstPage = function () {
2602
+ // go to first page
2603
+ // noinspection TypeScriptValidateJSTypes
2604
+ this.advancedTable.dataTable.page('first').draw('page');
2605
+ };
2606
+ AdvancedTableModalBaseComponent.prototype.lastPage = function () {
2607
+ // go to last page
2608
+ // noinspection TypeScriptValidateJSTypes
2609
+ this.advancedTable.dataTable.page('last').draw('page');
2610
+ };
2611
+ AdvancedTableModalBaseComponent.prototype.setLength = function (value) {
2612
+ this.pageLength = value;
2613
+ this.advancedTable.dataTable.page.len(value).draw();
2614
+ };
2615
+ AdvancedTableModalBaseComponent.prototype.onKeyUp = function (event) {
2616
+ if (event.code === 'Enter') {
2617
+ // loading
2618
+ this.loading = true;
2619
+ this.advancedTable.search(event.target.value);
2620
+ }
2621
+ };
2622
+ /**
2623
+ *
2624
+ * Reads the modal table and returns a list of filters to use in the table
2625
+ * query.
2626
+ *
2627
+ * @param tableConfig {object} The table configuration from json file
2628
+ * @param defaultFilterValues {object} A list of default filters
2629
+ * @param {object} searchItem The searchItem to use
2630
+ *
2631
+ */
2632
+ AdvancedTableModalBaseComponent.prototype.getFilters = function (tableConfig, defaultFilterValues, searchItem) {
2633
+ if (defaultFilterValues === void 0) { defaultFilterValues = {}; }
2634
+ // Do nothing in absence of configuration.
2635
+ if (!tableConfig || !Array.isArray(tableConfig.criteria)) {
2636
+ console.warn('No table configuration available', this.tableConfig);
2637
+ return [];
2638
+ }
2639
+ var matchedCriterion = tableConfig.criteria.find(function (criterion) {
2640
+ return Object.prototype.hasOwnProperty.call(searchItem.filter, criterion.name);
2641
+ });
2642
+ if (!matchedCriterion) {
2643
+ return [];
2644
+ }
2645
+ var criterionSafeName = matchedCriterion.name !== null
2646
+ ? matchedCriterion.name.toString()
2647
+ : '';
2648
+ var applicableFilter;
2649
+ // Raw dates should be transformed to a specific format
2650
+ if (criterionSafeName.includes('GMT')) {
2651
+ var newDate = this.datePipe.transform(criterionSafeName, 'MM/dd/yyyy');
2652
+ applicableFilter = this._template.transform(matchedCriterion.filter, {
2653
+ value: newDate
2654
+ });
2655
+ }
2656
+ else if (criterionSafeName !== 'undefined') {
2657
+ applicableFilter = (this._template.transform(matchedCriterion.filter, Object.assign({
2658
+ value: matchedCriterion.filter
2659
+ }, defaultFilterValues)));
2660
+ }
2661
+ else {
2662
+ applicableFilter = '';
2663
+ }
2664
+ return [applicableFilter];
2665
+ };
2666
+ /**
2667
+ *
2668
+ * Runs a filter against the modal table
2669
+ *
2670
+ * @param {object} filter The filter to use in the search
2671
+ *
2672
+ */
2673
+ AdvancedTableModalBaseComponent.prototype.advancedSearch = function (filter) {
2674
+ return __awaiter(this, void 0, void 0, function () {
2675
+ var defaultFilterValues, err_1, expressions, predefinedCriteria, query;
2676
+ return __generator(this, function (_a) {
2677
+ switch (_a.label) {
2678
+ case 0:
2679
+ // Do nothing in absence of configuration.
2680
+ if (!this.tableConfig && !Array.isArray(this.tableConfig.criteria)) {
2681
+ console.warn('No table configuration available', this.tableConfig);
2682
+ return [2 /*return*/];
2683
+ }
2684
+ _a.label = 1;
2685
+ case 1:
2686
+ _a.trys.push([1, 3, , 4]);
2687
+ return [4 /*yield*/, this.advancedFilterValueProvider.getValues()];
2688
+ case 2:
2689
+ defaultFilterValues = _a.sent();
2690
+ return [3 /*break*/, 4];
2691
+ case 3:
2692
+ err_1 = _a.sent();
2693
+ defaultFilterValues = {};
2694
+ return [3 /*break*/, 4];
2695
+ case 4:
2696
+ expressions = [];
2697
+ if (filter) {
2698
+ this.defaultFilter = filter;
2699
+ predefinedCriteria = this.getFilters(this.tableConfig, defaultFilterValues, filter);
2700
+ }
2701
+ else {
2702
+ // Empty a falsy filter resets the results
2703
+ this.defaultFilter = AdvancedTableModalBaseComponent.DEFAULT_ALL_FILTER;
2704
+ }
2705
+ // search filter is applied separately, there is no need to add here.
2706
+ expressions.push(predefinedCriteria);
2707
+ query = this._context.model(this.advancedTable.config.model).asQueryable();
2708
+ query.setParam('filter', expressions.join(' and ')).prepare();
2709
+ this.advancedTable.query = query;
2710
+ this.advancedTable.fetch();
2711
+ return [2 /*return*/];
2712
+ }
2713
+ });
2714
+ });
2715
+ };
2716
+ AdvancedTableModalBaseComponent.DEFAULT_ALL_FILTER = {
2717
+ name: 'Tables.All',
2718
+ filter: null
2719
+ };
2720
+ AdvancedTableModalBaseComponent.decorators = [
2721
+ { type: Component, args: [{
2722
+ selector: 'app-advanced-table-modal',
2723
+ template: AdvancedTableModalBaseTemplate,
2724
+ styles: ["\n\n "]
2725
+ }] }
2726
+ ];
2727
+ /** @nocollapse */
2728
+ AdvancedTableModalBaseComponent.ctorParameters = function () { return [
2729
+ { type: Router },
2730
+ { type: ActivatedRoute },
2731
+ { type: AngularDataContext },
2732
+ { type: AdvancedFilterValueProvider },
2733
+ { type: DatePipe }
2734
+ ]; };
2735
+ AdvancedTableModalBaseComponent.propDecorators = {
2736
+ advancedTable: [{ type: ViewChild, args: ['advancedTable',] }],
2737
+ emptyTable: [{ type: ViewChild, args: ['emptyTable',] }],
2738
+ dropdownFilter: [{ type: ViewChild, args: ['dropdownFilter',] }],
2739
+ dropdownLength: [{ type: ViewChild, args: ['dropdownLength',] }],
2740
+ tableConfig: [{ type: Input, args: ['tableConfig',] }],
2741
+ tableConfigSrc: [{ type: Input, args: ['tableConfigSrc',] }],
2742
+ pageLength: [{ type: Input, args: ['pageLength',] }],
2743
+ searchText: [{ type: Input, args: ['searchText',] }],
2744
+ lengthMenu: [{ type: Input, args: ['lengthMenu',] }],
2745
+ defaultFilter: [{ type: Input, args: ['defaultFilter',] }]
2746
+ };
2747
+ return AdvancedTableModalBaseComponent;
2748
+ }(RouterModalOkCancel));
2749
+
2750
+ var AdvancedSelectComponent = /** @class */ (function (_super) {
2751
+ __extends(AdvancedSelectComponent, _super);
2752
+ function AdvancedSelectComponent(router, activatedRoute, context, advancedFilterValueProvider, datePipe, _modalRef) {
2753
+ var _this = _super.call(this, router, activatedRoute, context, advancedFilterValueProvider, datePipe) || this;
2754
+ _this._modalRef = _modalRef;
2755
+ _this.dismiss = new EventEmitter();
2756
+ return _this;
2757
+ }
2758
+ AdvancedSelectComponent.prototype.ok = function () {
2759
+ return __awaiter(this, void 0, void 0, function () {
2760
+ return __generator(this, function (_a) {
2761
+ this._modalRef.hide();
2762
+ this.dismiss.emit('ok');
2763
+ return [2 /*return*/];
2764
+ });
2765
+ });
2766
+ };
2767
+ AdvancedSelectComponent.prototype.cancel = function () {
2768
+ return __awaiter(this, void 0, void 0, function () {
2769
+ return __generator(this, function (_a) {
2770
+ this._modalRef.hide();
2771
+ this.dismiss.emit('cancel');
2772
+ return [2 /*return*/];
2773
+ });
2774
+ });
2775
+ };
2776
+ AdvancedSelectComponent.decorators = [
2777
+ { type: Component, args: [{
2778
+ selector: 'app-advanced-select',
2779
+ template: "<div class=\"modal-header\" *ngIf=\"modalTitle\">\n <h5 class=\"modal-title\">{{modalTitle | translate}}</h5>\n <button [disabled]=\"cancelButtonDisabled\" (click)=\"cancel()\" type=\"button\" class=\"close\" data-dismiss=\"modal\"\n aria-label=\"Cancel\">\n <span aria-hidden=\"true\">&times;</span>\n </button>\n</div>\n<div class=\"modal-body\">\n <div>\n <!-- search -->\n <div class=\"row mt-3\">\n <div class=\"col-12 col-lg-3\">\n <div class=\"input-group mb-3\">\n <input spellcheck=\"false\" type=\"text\" (keyup)=\"onKeyUp($event)\" [(ngModel)]=\"searchText\"\n class=\"form-control bg-gray-100 border-0\" placeholder=\"{{'Tables.SearchPlaceholder' | translate}}\"\n aria-label=\"Search\" aria-describedby=\"basic-addon2\">\n <div class=\"input-group-append\">\n <button class=\"btn btn-default bg-gray-100 border-0\" type=\"button\">\n <i class=\"fa fa-search text-secondary\"></i>\n </button>\n </div>\n </div>\n </div>\n <div #emptyTable class=\"d-none\">\n <div>\n <div class=\"mt-4\">\n <div class=\"icon-circle bg-gray-300 border-gray-100\"></div>\n </div>\n <div class=\"mt-4\">\n <h4 class=\"font-3xl text-dark\" [translate]=\"'Tables.EmptyTableTitle'\"></h4>\n <p class=\"font-lg text-dark\" [translate]=\"'Tables.EmptyTableMessage'\"></p>\n </div>\n\n </div>\n </div>\n <div class=\"col-12 col-lg-5\">\n <div class=\"btn-toolbar\">\n <button class=\"btn btn-gray-100\">\n <i class=\"fa fa-sliders-h pr-2 text-secondary\" aria-hidden=\"true\"></i>{{'Tables.Filters' | translate}}\n </button>\n <div class=\"dropdown ml-3\" dropdown>\n <button dropdownToggle class=\"btn btn-gray-100 dropdown-toggle\" type=\"button\" id=\"dropdownDefaultFilters\"\n data-toggle=\"dropdown\">\n {{ this.defaultFilter.name | translate }}\n </button>\n <div class=\"dropdown-menu\" aria-labelledby=\"dropdownDefaultFilters\" *dropdownMenu>\n <a class=\"dropdown-item\" *ngFor=\"let filter of defaultFilters\"\n (click)=\"advancedSearch(filter.filter ? filter : '')\">\n {{ filter.name | translate }}\n </a>\n </div>\n </div>\n </div>\n </div>\n <div class=\"col text-lg-right mt-3 mt-lg-0\">\n <button [disabled]=\"true\" class=\"btn rounded-pill btn-outline-theme\">\n <span class=\"pr-2 font-lg\">+</span><span [translate]=\"'Tables.AddItem'\"></span>\n </button>\n </div>\n </div>\n <div class=\"row\">\n <div class=\"col-12\" [ngClass]=\"{ 'component-loading': loading}\">\n <app-advanced-table #advancedTable (init)=\"onTableInit($event)\" (load)=\"onDataLoad($event)\"\n [selectable]=\"true\" [multipleSelect]=\"true\" [scrollX]=\"false\" [scrollY]=\"320\" [pageLength]=\"pageLength\"\n [scrollable]=\"false\" [showFooter]=\"false\" [showActions]=\"false\" [lengthMenu]=\"lengthMenu\"\n [config]=\"tableConfig\" [configSrc]=\"tableConfigSrc\"></app-advanced-table>\n </div>\n </div>\n <div class=\"row mt-3 table-custom-pager\">\n <div class=\"col-12 d-flex\" *ngIf=\"recordsTotal\">\n <div class=\"mt-2 ml-auto mr-3 text-secondary\" [translate]=\"'Tables.RecordsPerPage'\"></div>\n <div class=\"dropdown mr-3\" dropdown>\n <button dropdownToggle class=\"btn btn-gray-100 dropdown-toggle\" type=\"button\" id=\"dropdownPageSize\"\n data-toggle=\"dropdown\">\n {{pageLength}}\n </button>\n <div class=\"dropdown-menu\" aria-labelledby=\"dropdownPageSize\" *dropdownMenu>\n <button (click)=\"setLength(item)\" class=\"dropdown-item dropdown-item-theme\" type=\"button\"\n *ngFor=\"let item of lengthMenu\">{{item}}</button>\n </div>\n </div>\n <div class=\"mt-2 mr-2\" [translate]=\"'Tables.PageInfo'\" [translateParams]=\"pageInfo\"></div>\n <button [disabled]=\"pageInfo && pageInfo.page === 0\" class=\"btn text-nowrap\" (click)=\"firstPage()\">\n <i class=\"fa fa-chevron-left text-color-theme\"></i>\n <i class=\"fa fa-chevron-left text-color-theme\"></i>\n </button>\n <button [disabled]=\"pageInfo && pageInfo.page===0\" class=\"btn\" (click)=\"previousPage()\">\n <i class=\"fa fa-chevron-left text-color-theme\"></i>\n </button>\n <button [disabled]=\"pageInfo && pageInfo.page===pageInfo.pages-1\" class=\"btn\" (click)=\"nextPage()\">\n <i class=\"fa fa-chevron-right text-color-theme\"></i>\n </button>\n <button [disabled]=\"pageInfo && pageInfo.page===pageInfo.pages-1\" class=\"btn text-nowrap\"\n (click)=\"lastPage()\">\n <i class=\"fa fa-chevron-right text-color-theme\"></i>\n <i class=\"fa fa-chevron-right text-color-theme\"></i>\n </button>\n </div>\n </div>\n </div>\n</div>\n<div class=\"modal-footer justify-content-end\">\n <button [disabled]=\"okButtonDisabled\" (click)=\"ok()\" type=\"button\" [ngClass]=\"okButtonClass\">\n {{okButtonText | translate}}\n </button>\n <button [disabled]=\"cancelButtonDisabled\" (click)=\"cancel()\" type=\"button\" [ngClass]=\"cancelButtonClass\"\n data-dismiss=\"modal\">\n {{ cancelButtonText | translate}}\n </button>\n</div>\n",
2780
+ encapsulation: ViewEncapsulation.None,
2781
+ styles: ["\n .modal-table .dataTables_wrapper {\n height: 50vh;\n overflow-y: auto;\n }\n "]
2782
+ }] }
2783
+ ];
2784
+ /** @nocollapse */
2785
+ AdvancedSelectComponent.ctorParameters = function () { return [
2786
+ { type: Router },
2787
+ { type: ActivatedRoute },
2788
+ { type: AngularDataContext },
2789
+ { type: AdvancedFilterValueProvider },
2790
+ { type: DatePipe },
2791
+ { type: BsModalRef }
2792
+ ]; };
2793
+ return AdvancedSelectComponent;
2794
+ }(AdvancedTableModalBaseComponent));
2795
+
2796
+ var AdvancedSelectService = /** @class */ (function () {
2797
+ function AdvancedSelectService(_modal) {
2798
+ this._modal = _modal;
2799
+ //
2800
+ }
2801
+ AdvancedSelectService.prototype.select = function (initialState) {
2802
+ var _this = this;
2803
+ return new Promise(function (resolve, reject) {
2804
+ try {
2805
+ var modalRef = _this._modal.openModalComponent(AdvancedSelectComponent, {
2806
+ class: 'modal-xl modal-table',
2807
+ ignoreBackdropClick: true,
2808
+ animated: true,
2809
+ initialState: initialState
2810
+ });
2811
+ var componentRef_1 = modalRef.content;
2812
+ componentRef_1.dismiss.subscribe(function (result) {
2813
+ return resolve({
2814
+ result: result,
2815
+ items: componentRef_1.advancedTable.selected
2816
+ });
2817
+ });
2818
+ }
2819
+ catch (err) {
2820
+ return reject(err);
2821
+ }
2822
+ });
2823
+ };
2824
+ AdvancedSelectService.decorators = [
2825
+ { type: Injectable }
2826
+ ];
2827
+ /** @nocollapse */
2828
+ AdvancedSelectService.ctorParameters = function () { return [
2829
+ { type: ModalService }
2830
+ ]; };
2831
+ return AdvancedSelectService;
2832
+ }());
2833
+
2834
+ var ActivatedTableService = /** @class */ (function () {
2835
+ function ActivatedTableService(_router, _activatedRoute) {
2836
+ var _this = this;
2837
+ this._router = _router;
2838
+ this._activatedRoute = _activatedRoute;
2839
+ _router.events.forEach(function (event) {
2840
+ if (event instanceof NavigationStart) {
2841
+ if (_this._activeTable) {
2842
+ _this._activeTable = null;
2843
+ }
2844
+ }
2845
+ });
2846
+ }
2847
+ Object.defineProperty(ActivatedTableService.prototype, "activeTable", {
2848
+ get: function () {
2849
+ return this._activeTable;
2850
+ },
2851
+ set: function (tableComponent) {
2852
+ this._activeTable = tableComponent;
2853
+ },
2854
+ enumerable: true,
2855
+ configurable: true
2856
+ });
2857
+ ActivatedTableService.decorators = [
2858
+ { type: Injectable, args: [{
2859
+ providedIn: 'root'
2860
+ },] }
2861
+ ];
2862
+ /** @nocollapse */
2863
+ ActivatedTableService.ctorParameters = function () { return [
2864
+ { type: Router },
2865
+ { type: ActivatedRoute }
2866
+ ]; };
2867
+ ActivatedTableService.ngInjectableDef = defineInjectable({ factory: function ActivatedTableService_Factory() { return new ActivatedTableService(inject(Router), inject(ActivatedRoute)); }, token: ActivatedTableService, providedIn: "root" });
2868
+ return ActivatedTableService;
2869
+ }());
2870
+
2871
+ var MAX_EXPORT_ITEMS = 500;
2872
+ var BtnExpDirective = /** @class */ (function () {
2873
+ function BtnExpDirective(_activatedTable, _context, _config, _translate, _loadingService, _errorService) {
2874
+ this._activatedTable = _activatedTable;
2875
+ this._context = _context;
2876
+ this._config = _config;
2877
+ this._translate = _translate;
2878
+ this._loadingService = _loadingService;
2879
+ this._errorService = _errorService;
2880
+ }
2881
+ BtnExpDirective.prototype.clickEvent = function (event) {
2882
+ return __awaiter(this, void 0, void 0, function () {
2883
+ var lastQuery, tableConfig, serviceHeaders, queryModel, query, queryParams, maxExportItems, url;
2884
+ return __generator(this, function (_a) {
2885
+ event.preventDefault();
2886
+ event.stopPropagation();
2887
+ if (this._activatedTable.activeTable) {
2888
+ lastQuery = this._activatedTable.activeTable.lastQuery;
2889
+ tableConfig = this._activatedTable.activeTable.config;
2890
+ serviceHeaders = this._context.getService().getHeaders();
2891
+ queryModel = lastQuery.getModel();
2892
+ query = this._context.model(queryModel).asQueryable();
2893
+ queryParams = lastQuery.getParams();
2894
+ query = this.constructQuery(query, queryParams, tableConfig, serviceHeaders);
2895
+ maxExportItems = 1000;
2896
+ if (maxExportItems && typeof maxExportItems === 'number' && maxExportItems > 0) {
2897
+ query.skip(0).take(maxExportItems);
2898
+ }
2899
+ else {
2900
+ query.skip(0).take(MAX_EXPORT_ITEMS);
2901
+ }
2902
+ url = this.constructURL(query);
2903
+ this.downloadFile(url, query.getService().getHeaders(), query.getModel());
2904
+ }
2905
+ return [2 /*return*/];
2906
+ });
2907
+ });
2908
+ };
2909
+ /**
2910
+ * Sets the parameters to the query based on
2911
+ * the active filters of the activated table
2912
+ * @param {ClientDataQueryable} query
2913
+ * @param params: The filters of the last query of the activated table
2914
+ * @return ClientDataQueryable
2915
+ */
2916
+ BtnExpDirective.prototype.setParams = function (query, params) {
2917
+ if (params && typeof params === 'object') {
2918
+ Object.keys(params).forEach(function (key) {
2919
+ query.setParam(key, params[key]);
2920
+ });
2921
+ }
2922
+ return query;
2923
+ };
2924
+ /**
2925
+ * Sets the headers to the query based on
2926
+ * the default headers of the DataContext
2927
+ * and appending the accept header to get
2928
+ * an xlsx file from the API
2929
+ * @param {ClientDataQueryable} query
2930
+ * @param {Headers} headers: The headers to append to the query
2931
+ * @return ClientDataQueryable
2932
+ */
2933
+ BtnExpDirective.prototype.setHeaders = function (query, headers) {
2934
+ Object.keys(headers).forEach(function (key) {
2935
+ if (headers.hasOwnProperty(key)) {
2936
+ query.getService().setHeader(key, headers[key]);
2937
+ }
2938
+ });
2939
+ // sets a header to accept xlsx files
2940
+ query.getService().setHeader('Accept', 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
2941
+ return query;
2942
+ };
2943
+ /**
2944
+ * Constructs the select parameter of the
2945
+ * ClientDataQuery by replacing the target name
2946
+ * of the field based on the localized translation
2947
+ * of that property on the advanced tabled
2948
+ * @param {ClientDataQueryable} query
2949
+ * @param tableConfig: The configuration of the activated table
2950
+ * @return ClientDataQueryable
2951
+ */
2952
+ BtnExpDirective.prototype.constructQueryParam = function (query, tableConfig) {
2953
+ var _this = this;
2954
+ var selectQuery = query.getParams().$select;
2955
+ var selectQueryArray = selectQuery.split(',');
2956
+ selectQueryArray = selectQueryArray.map(function (select) {
2957
+ var e_1, _a, e_2, _b;
2958
+ var words = select.split(' ');
2959
+ if (words.length === 3) {
2960
+ if (tableConfig && tableConfig.columns) {
2961
+ try {
2962
+ for (var _c = __values(tableConfig.columns), _d = _c.next(); !_d.done; _d = _c.next()) {
2963
+ var column = _d.value;
2964
+ if (column.property === words[2] && column.title) {
2965
+ words[2] = "\"" + _this._translate.instant(column.title) + "\"";
2966
+ }
2967
+ else if (column.property === words[2]) {
2968
+ words[2] = "\"" + _this._translate.instant(words[2]) + "\"";
2969
+ }
2970
+ }
2971
+ }
2972
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
2973
+ finally {
2974
+ try {
2975
+ if (_d && !_d.done && (_a = _c.return)) _a.call(_c);
2976
+ }
2977
+ finally { if (e_1) throw e_1.error; }
2978
+ }
2979
+ }
2980
+ }
2981
+ if (words.length === 1) {
2982
+ if (tableConfig && tableConfig.columns) {
2983
+ try {
2984
+ for (var _e = __values(tableConfig.columns), _f = _e.next(); !_f.done; _f = _e.next()) {
2985
+ var column = _f.value;
2986
+ if (column.name === words[0] && column.title) {
2987
+ words[0] = words[0] + " as \"" + _this._translate.instant(column.title) + "\"";
2988
+ break;
2989
+ }
2990
+ else if (column.name === words[0] && column.property) {
2991
+ words[0] = words[0] + " as \"" + _this._translate.instant(column.property) + "\"";
2992
+ break;
2993
+ }
2994
+ else if (words[0] === column.name && words[0] === "id" && column.hidden) {
2995
+ break;
2996
+ }
2997
+ else if (words[0] == column.name || words[0] === column.property) {
2998
+ words[0] = words[0] + " as \"" + _this._translate.instant(words[0]) + "\"";
2999
+ }
3000
+ }
3001
+ }
3002
+ catch (e_2_1) { e_2 = { error: e_2_1 }; }
3003
+ finally {
3004
+ try {
3005
+ if (_f && !_f.done && (_b = _e.return)) _b.call(_e);
3006
+ }
3007
+ finally { if (e_2) throw e_2.error; }
3008
+ }
3009
+ }
3010
+ return words[0];
3011
+ }
3012
+ return words.join(' ');
3013
+ });
3014
+ selectQuery = selectQueryArray.join(',');
3015
+ query.setParam('$select', selectQuery);
3016
+ return query;
3017
+ };
3018
+ /**
3019
+ * Constructs the fetch URL based the query parameters
3020
+ * @param {ClientDataQueryable} query
3021
+ * @return String
3022
+ */
3023
+ BtnExpDirective.prototype.constructURL = function (query) {
3024
+ var baseURL = query.getService().getBase();
3025
+ var url = baseURL.endsWith('/') ? (baseURL + query.getModel() + '?') : (baseURL + '/' + query.getModel() + '?');
3026
+ Object.keys(query.getParams()).forEach(function (key, index) {
3027
+ if (index === 0) {
3028
+ url += key + '=' + query.getParams()[key];
3029
+ }
3030
+ else {
3031
+ url += '&' + key + '=' + query.getParams()[key];
3032
+ }
3033
+ });
3034
+ return url;
3035
+ };
3036
+ /**
3037
+ * Constructs the query by setting the parameters of the
3038
+ * advanced table's active filters, sets the necessary headers
3039
+ * and build the select parameter of the query
3040
+ * @param {ClientDataQueryable} query
3041
+ * @param params: The filters of the last query of the activated table
3042
+ * @param tableConfig: The configuration of the activated table
3043
+ * @param {Headers} headers: The headers to append to the query
3044
+ * @return ClientDataQueryable
3045
+ */
3046
+ BtnExpDirective.prototype.constructQuery = function (query, params, tableConfig, headers) {
3047
+ var _query = this.setParams(query, params);
3048
+ _query = this.setHeaders(_query, headers);
3049
+ _query = this.constructQueryParam(_query, tableConfig);
3050
+ return _query;
3051
+ };
3052
+ /**
3053
+ * Fetches and saves the xlsx file
3054
+ * @param {String} url
3055
+ * @param {Headers} serviceHeaders: The headers to append to the query
3056
+ * @param modelName: The model name of the advanced table
3057
+ */
3058
+ BtnExpDirective.prototype.downloadFile = function (url, serviceHeaders, modelName) {
3059
+ var _this = this;
3060
+ this._loadingService.showLoading();
3061
+ fetch(encodeURI(url), {
3062
+ headers: serviceHeaders,
3063
+ credentials: 'include'
3064
+ }).then(function (response) {
3065
+ if (response && !response.ok) {
3066
+ throw new ResponseError(response.statusText, response.status);
3067
+ }
3068
+ return response.blob();
3069
+ }).then(function (blob) {
3070
+ var objectUrl = window.URL.createObjectURL(blob);
3071
+ var a = document.createElement('a');
3072
+ document.body.appendChild(a);
3073
+ a.setAttribute('style', 'display: none');
3074
+ a.href = objectUrl;
3075
+ var downloadName = modelName + ".xlsx";
3076
+ a.download = downloadName;
3077
+ // this adds support for IE and MS Edge (up to version 44.19041)
3078
+ if (window.navigator && window.navigator.msSaveOrOpenBlob) {
3079
+ window.navigator.msSaveOrOpenBlob(blob, downloadName);
3080
+ }
3081
+ else {
3082
+ // for all other browsers
3083
+ a.click();
3084
+ }
3085
+ window.URL.revokeObjectURL(objectUrl);
3086
+ a.remove();
3087
+ _this._loadingService.hideLoading();
3088
+ }).catch(function (err) {
3089
+ _this._loadingService.hideLoading();
3090
+ _this._errorService.showError(err, {
3091
+ continueLink: '.'
3092
+ });
3093
+ });
3094
+ };
3095
+ BtnExpDirective.decorators = [
3096
+ { type: Directive, args: [{
3097
+ selector: '.universis-btn-export'
3098
+ },] }
3099
+ ];
3100
+ /** @nocollapse */
3101
+ BtnExpDirective.ctorParameters = function () { return [
3102
+ { type: ActivatedTableService },
3103
+ { type: AngularDataContext },
3104
+ { type: ConfigurationService },
3105
+ { type: TranslateService },
3106
+ { type: LoadingService },
3107
+ { type: ErrorService }
3108
+ ]; };
3109
+ BtnExpDirective.propDecorators = {
3110
+ clickEvent: [{ type: HostListener, args: ['click', ['$event'],] }]
3111
+ };
3112
+ return BtnExpDirective;
3113
+ }());
3114
+
3115
+ var AdvancedTableSettingsComponent = /** @class */ (function () {
3116
+ function AdvancedTableSettingsComponent(_context, _activatedRoute, elRef, modalService, userStorage, formBuilder, _activatedTable) {
3117
+ this._context = _context;
3118
+ this._activatedRoute = _activatedRoute;
3119
+ this.elRef = elRef;
3120
+ this.modalService = modalService;
3121
+ this.userStorage = userStorage;
3122
+ this.formBuilder = formBuilder;
3123
+ this._activatedTable = _activatedTable;
3124
+ this.params = this._activatedRoute.params;
3125
+ this.columns = [];
3126
+ }
3127
+ AdvancedTableSettingsComponent.prototype.ngOnInit = function () {
3128
+ };
3129
+ AdvancedTableSettingsComponent.prototype.ngAfterViewInit = function () {
3130
+ var _this = this;
3131
+ this.activeTableConfig = this._activatedTable.activeTable.getConfig();
3132
+ this.storageKey = 'registrar/settings/' + this.activeTableConfig.title + '/table/columns';
3133
+ this.form = this.formBuilder.group({ columns: new FormArray([], this.minSelectedColumns(1)) });
3134
+ this.userStorage.getItem(this.storageKey).then(function (data) {
3135
+ if (data) {
3136
+ _this.savedTableSettings = data.value;
3137
+ if (_this.savedTableSettings) {
3138
+ if (_this._activatedTable.activeTable) {
3139
+ _this._activatedTable.activeTable.handleColumns(_this.savedTableSettings);
3140
+ }
3141
+ }
3142
+ _this.addCheckboxes();
3143
+ }
3144
+ });
3145
+ };
3146
+ AdvancedTableSettingsComponent.prototype.addCheckboxes = function () {
3147
+ var _this = this;
3148
+ this.tableColumns = this.activeTableConfig.columns.slice(1);
3149
+ this.tableColumns.forEach(function (column, i) {
3150
+ if (!column.hidden) {
3151
+ var control = {
3152
+ id: column.name,
3153
+ name: column.title
3154
+ };
3155
+ _this.columns.push(control);
3156
+ }
3157
+ });
3158
+ if (this.savedTableSettings) {
3159
+ this.columns.forEach(function (column, i) {
3160
+ column.check = false;
3161
+ column.check = _this.savedTableSettings.includes(column.id);
3162
+ });
3163
+ this.columns.map(function (column, i) {
3164
+ var control = new FormControl(column.check);
3165
+ _this.form.controls.columns.push(control);
3166
+ });
3167
+ }
3168
+ };
3169
+ AdvancedTableSettingsComponent.prototype.openTableSettings = function (table_settings_modal) {
3170
+ this.modalRef = this.modalService.show(table_settings_modal);
3171
+ };
3172
+ AdvancedTableSettingsComponent.prototype.saveTableSettings = function () {
3173
+ var _this = this;
3174
+ var selectedColumnsIds = this.form.value.columns
3175
+ .map(function (v, i) { return v ? _this.columns[i].id : null; })
3176
+ .filter(function (v) { return v !== null; });
3177
+ this.userStorage.setItem(this.storageKey, selectedColumnsIds);
3178
+ if (this._activatedTable.activeTable) {
3179
+ this._activatedTable.activeTable.handleColumns(selectedColumnsIds);
3180
+ }
3181
+ this.modalRef.hide();
3182
+ };
3183
+ AdvancedTableSettingsComponent.prototype.dismiss = function () {
3184
+ this.modalRef.hide();
3185
+ };
3186
+ AdvancedTableSettingsComponent.prototype.minSelectedColumns = function (min) {
3187
+ if (min === void 0) { min = 1; }
3188
+ var validator = function (formArray) {
3189
+ var totalSelected = formArray.controls
3190
+ .map(function (control) { return control.value; })
3191
+ .reduce(function (prev, next) { return next ? prev + next : prev; }, 0);
3192
+ return totalSelected >= min ? null : { required: true };
3193
+ };
3194
+ return validator;
3195
+ };
3196
+ AdvancedTableSettingsComponent.decorators = [
3197
+ { type: Component, args: [{
3198
+ selector: 'app-advanced-table-settings',
3199
+ template: "<i class=\"fa fa-edit fa-lg advanced-table-settings\" (click)=\"openTableSettings(modal_settings_template)\"></i>\r\n<ng-template #modal_settings_template>\r\n <div class=\"modal-header\">\r\n <h3 class=\"modal-title\" [translate]=\"'Tables.ColumnDisplay'\"></h3>\r\n <button type=\"button\" class=\"close pull-right\" aria-label=\"Close\" (click)=\"dismiss()\">\r\n <span aria-hidden=\"true\">&times;</span>\r\n </button>\r\n </div>\r\n\r\n <form class=\"form-group p-3 text-left\" [formGroup]=\"form\" (ngSubmit)=\"saveTableSettings()\">\r\n <div class=\"modal-body\">\r\n <p [translate]=\"'Tables.ColumnDisplayInfo'\"></p>\r\n <!-- <div *ngFor=\"let column of form.controls.columns.controls; let i = index\">\r\n <div formArrayName=\"columns\">\r\n <input class=\"checkbox checkbox-primary\" type=\"checkbox\" [formControlName]=\"i\" id=\"checkbox{{i}}\">\r\n <label for=\"checkbox{{i}}\">\r\n {{columns[i].name | translate}}\r\n </label>\r\n </div>\r\n </div> -->\r\n </div>\r\n <div class=\"modal-footer\">\r\n <button type=\"button\" class=\"btn btn-light\" (click)=\"dismiss()\" [translate]=\"'Tables.Cancel'\"> </button>\r\n <button type=\"submit\" class=\"btn btn-success\" [translate]=\"'Tables.Save'\"></button>\r\n </div>\r\n </form>\r\n</ng-template>\r\n",
3200
+ encapsulation: ViewEncapsulation.None
3201
+ }] }
3202
+ ];
3203
+ /** @nocollapse */
3204
+ AdvancedTableSettingsComponent.ctorParameters = function () { return [
3205
+ { type: AngularDataContext },
3206
+ { type: ActivatedRoute },
3207
+ { type: ElementRef },
3208
+ { type: BsModalService },
3209
+ { type: UserStorageService },
3210
+ { type: FormBuilder },
3211
+ { type: ActivatedTableService }
3212
+ ]; };
3213
+ AdvancedTableSettingsComponent.propDecorators = {
3214
+ table: [{ type: Input }],
3215
+ modal_settings_template: [{ type: ViewChild, args: ['modal_settings_template',] }]
3216
+ };
3217
+ return AdvancedTableSettingsComponent;
3218
+ }());
3219
+
3220
+ var TABLES_EL = {
3221
+ "Tables": {
3222
+ "Export": "Εξαγωγή",
3223
+ "More": "Περισσότερα",
3224
+ "Search": "Αναζήτηση",
3225
+ "SearchPlaceholder": "Αναζήτηση...",
3226
+ "GroupBy": "Ομαδοποίηση ανά",
3227
+ "DataTable": {
3228
+ "paginate": {
3229
+ "first": "Πρώτη σελίδα",
3230
+ "last": "Τελεταία σελίδα",
3231
+ "next": "Επόμενη",
3232
+ "previous": "Προηγούμενη"
3233
+ },
3234
+ "info": "Εμφάνιση _START_ έως _END_ από _TOTAL_ εγγραφές",
3235
+ "infoEmpty": "Δεν βρέθηκαν εγγραφές",
3236
+ "loading": "Εμφάνιση δεδομένων...",
3237
+ "processing": "Παραλαβή δεδομένων...",
3238
+ "emptyTable": "Δεν βρέθηκαν αποτελέσματα."
3239
+ },
3240
+ "ColumnDisplay": "Επιλογή Εμφάνισης στηλών",
3241
+ "ColumnDisplayInfo": "Επιλέξτε τις στήλες που θέλετε να εμφανίζονται.",
3242
+ "Save": "Εφαρμογή",
3243
+ "Apply": "Εφαρμογή",
3244
+ "Cancel": "Ακύρωση",
3245
+ "RecordsPerPage": "Εγγραφές ανά σελίδα",
3246
+ "PageInfo": "{{start}}-{{end}} από {{recordsTotal}}",
3247
+ "SearchListPlaceholder": "Αναζητήστε στη λίστα...",
3248
+ "Filters": "Φίλτρα",
3249
+ "All": "Όλα",
3250
+ "AddItem": "Προσθήκη στοιχείου",
3251
+ "EmptyTableTitle": "Δεν βρέθηκαν αποτελέσματα.",
3252
+ "EmptyTableMessage": "Προσπαθήστε να χρησιμοποιήσετε άλλες λέξεις κλειδιά.",
3253
+ "RemoveItem": "Διαγραφή στοιχείου",
3254
+ "Items": "στοιχεία",
3255
+ "Item": "στοιχείο",
3256
+ "AddItemMessage": {
3257
+ "title": "Προσθήκη στοιχείων",
3258
+ "one": "Ένα νέο στοιχείο προστέθηκε με επιτυχία.",
3259
+ "many": "{{value}} νέα στοιχεία προστέθηκαν με επιτυχία."
3260
+ },
3261
+ "RemoveItemMessage": {
3262
+ "title": "Αφαίρεση στοιχείων",
3263
+ "one": "Ένα στοιχείο αφαιρέθηκε με επιτυχία.",
3264
+ "many": "{{value}} στοιχεία αφαιρέθηκαν με επιτυχία."
3265
+ },
3266
+ "RemoveItemsTitle": "Διαγραφή στοιχείου",
3267
+ "RemoveItemsMessage": "Πρόκειται να διαγράψετε ένα ή περισσότερα στοιχεία. Θέλετε να προχωρήσετε?",
3268
+ "SelectAll": "Επιλογή όλων",
3269
+ "ClearSelection": "Αναίρεση επιλογής",
3270
+ "Actions": {
3271
+ "Label": "Επεξεργασία",
3272
+ "Start": "Έναρξη",
3273
+ "ActionMessage": {
3274
+ "None": "Δεν έχετε επιλέξει κανένα στοιχείο που να ακολουθεί τις προϋποθέσεις της ενέργειας.",
3275
+ "One": "Έχετε επιλέξει ένα στοιχείο που ακολουθεί τις προϋποθέσεις της ενέργειας. Πατήστε το πλήκτρο Έναρξη για να ξεκινήσει η διαδικασία.",
3276
+ "Many": "Έχετε επιλέξει {{length}} στοιχεία που ακολουθούν τις προϋποθέσεις της ενέργειας. Πατήστε το πλήκτρο Έναρξη για να ξεκινήσει η διαδικασία."
3277
+ },
3278
+ "CompletedWithErrors": {
3279
+ "Title": "Η διαδικασία ολοκληρώθηκε με σφάλματα.",
3280
+ "Description": {
3281
+ "One": "Ένα στοιχείο δεν ανανεώθηκε λόγω ενός σφάλματος που συνέβη κατά την εκτέλεση της διαδικασίας.",
3282
+ "Many": "{{errors}} στοιχεία δεν ανανεώθηκαν λόγω ενός σφάλματος που συνέβη κατά την εκτέλεση της διαδικασίας."
3283
+ }
3284
+ },
3285
+ "CompletedWithSuccess": {
3286
+ "Title": "Η διαδικασία ολοκληρώθηκε με επιτυχία."
3287
+ }
3288
+ }
3289
+ },
3290
+ "TrueFalse": {
3291
+ "long": {
3292
+ "Yes": "Ναι",
3293
+ "No": "Όχι"
3294
+ }
3295
+ },
3296
+ "AdvancedSearch": {
3297
+ "Choose": "<Επιλέξτε μια αναζήτηση>",
3298
+ "ChooseDate": "Επιλογή ημερομηνίας",
3299
+ "SavedSearches": "Αποθηκευμένες αναζητήσεις",
3300
+ "ToggleDropdown": "Εμφάνιση λίστας",
3301
+ "SaveCurrentSearch": "Αποθήκευση αναζήτησης",
3302
+ "SaveAs": "Αποθήκευση ως",
3303
+ "Save": "Αποθήκευση",
3304
+ "Delete": "Διαγραφή",
3305
+ "More": "Περισσότερα",
3306
+ "Less": "Λιγότερα",
3307
+ "Modal": {
3308
+ "Title": "Αποθήκευση κριτηρίων αναζήτησης",
3309
+ "Help": "Ορίστε έναν τίτλο για τα επιλεγμένα κριτήρια αναζήτησης. Αυτός ο τίτλος θα σας βοηθήσει να τα χρησιμοποιήσετε ξανά στο μέλλον.",
3310
+ "TitleOnUserError": "Παρακαλώ εισάγετε έναν τίτλο",
3311
+ "TitleOnListAlreadyCreated": "Το όνομα αυτό χρησιμοποιείται ήδη. Διαλέξτε ένα διαφορετικό.",
3312
+ "NoListDefined": "Δεν έχει οριστεί το σημείο αποθήκευσης της λίστας",
3313
+ "EmptyCriteriaList": "Δεν έχετε καθορίσει κανένα κριτήριο για αποθήκευση",
3314
+ "SaveNameLabel": "Ονομασία λίστας",
3315
+ "SaveNamePlaceholder": "Εισάγετε έναν τίτλο",
3316
+ "Accept": "Αποθήκευση",
3317
+ "Decline": "Απόρριψη",
3318
+ "Close": "Κλείσιμο"
3319
+ }
3320
+ }
3321
+ };
3322
+
3323
+ var TABLES_EN = {
3324
+ "Tables": {
3325
+ "Export": "Export",
3326
+ "More": "More",
3327
+ "Search": "Search",
3328
+ "SearchPlaceholder": "Search...",
3329
+ "GroupBy": "Group by",
3330
+ "DataTable": {
3331
+ "paginate": {
3332
+ "first": "First",
3333
+ "last": "Last",
3334
+ "next": "Next",
3335
+ "previous": "Previous"
3336
+ },
3337
+ "info": "Showing _START_ to _END_ of _TOTAL_ entries",
3338
+ "infoEmpty": "Showing 0 to 0 of 0 entries",
3339
+ "processing": "Processing data...",
3340
+ "emptyTable": "There are no matching records."
3341
+ },
3342
+ "ColumnDisplay": "Column Display",
3343
+ "ColumnDisplayInfo": "Επιλέξτε τις στήλες που θέλετε να εμφανίζονται.",
3344
+ "Save": "Save",
3345
+ "Apply": "Apply",
3346
+ "Cancel": "Cancel",
3347
+ "RecordsPerPage": "Items per page",
3348
+ "PageInfo": "{{start}}-{{end}} of {{recordsTotal}}",
3349
+ "SearchListPlaceHolder": "Search in list...",
3350
+ "Filters": "Filters",
3351
+ "All": "All",
3352
+ "AddItem": "Add item",
3353
+ "EmptyTableTitle": "There are no matching records.",
3354
+ "EmptyTableMessage": "Please try to use other keywords or search parameters.",
3355
+ "RemoveItem": "Remove item",
3356
+ "Items": "items",
3357
+ "Item": "item",
3358
+ "AddItemMessage": {
3359
+ "title": "Add item",
3360
+ "one": "A new item has been added successfully.",
3361
+ "many": "{{value}} new items have been added successfully."
3362
+ },
3363
+ "RemoveItemMessage": {
3364
+ "title": "Remove items",
3365
+ "one": "An item has been successfully removed.",
3366
+ "many": "{{value}} items have been successfully removed."
3367
+ },
3368
+ "RemoveItemsTitle": "Remove items",
3369
+ "RemoveItemsMessage": "You are going to remove one or more instructor courses. Do you want to proceed?",
3370
+ "SelectAll": "Select all",
3371
+ "ClearSelection": "Clear selection",
3372
+ "Actions": {
3373
+ "Label": "Edit",
3374
+ "Start": "Start",
3375
+ "ActionMessage": {
3376
+ "None": "There is no selected item that meets action requirements.",
3377
+ "One": "You have selected one item that meets action requirements.",
3378
+ "Many": "You have selected {{length}} items that meet action requirements."
3379
+ },
3380
+ "CompletedWithErrors": {
3381
+ "Title": "The operation was completed with errors.",
3382
+ "Description": {
3383
+ "One": "One item has not been updated due to an error occurred while executing process.",
3384
+ "Many": "{{errors}} items have not been updated due to an error occurred while executing process."
3385
+ }
3386
+ },
3387
+ "CompletedWithSuccess": {
3388
+ "Title": "The operation was completed successfully."
3389
+ }
3390
+ }
3391
+ },
3392
+ "TrueFalse": {
3393
+ "long": {
3394
+ "Yes": "Yes",
3395
+ "No": "No"
3396
+ }
3397
+ },
3398
+ "AdvancedSearch": {
3399
+ "Choose": "<Select a saved search>",
3400
+ "ChooseDate": "Choose date",
3401
+ "SavedSearches": "Saved searches",
3402
+ "ToggleDropdown": "Toggle Dropdown",
3403
+ "SaveCurrentSearch": "Save search",
3404
+ "SaveAs": "Save as...",
3405
+ "Save": "Save",
3406
+ "Delete": "Remove",
3407
+ "More": "More",
3408
+ "Less": "Less",
3409
+ "Modal": {
3410
+ "Title": "Save current search criteria",
3411
+ "Help": "Please add a title for the given search criteria. This title will help you to use those criteria again in the future.",
3412
+ "TitleOnUserError": "Please use a valid name for your list",
3413
+ "TitleOnListAlreadyCreated": "Name already in use. Please choose a different one",
3414
+ "NoListDefined": "Cannot define user storage key.",
3415
+ "EmptyCriteriaList": "Please define search criteria before save.",
3416
+ "SaveNameLabel": "List name",
3417
+ "SaveNamePlaceholder": "Type a title here...",
3418
+ "Accept": "Save",
3419
+ "Decline": "Decline",
3420
+ "Close": "Close"
3421
+ }
3422
+ }
3423
+ };
3424
+
3425
+ var SimpleHeaderToolsComponent = /** @class */ (function () {
3426
+ function SimpleHeaderToolsComponent() {
3427
+ }
3428
+ SimpleHeaderToolsComponent.decorators = [
3429
+ { type: Component, args: [{
3430
+ selector: 'table-simple-header-tools',
3431
+ template: "\n <ng-content></ng-content>\n "
3432
+ }] }
3433
+ ];
3434
+ return SimpleHeaderToolsComponent;
3435
+ }());
3436
+ var TableSimpleHeaderComponent = /** @class */ (function () {
3437
+ function TableSimpleHeaderComponent() {
3438
+ }
3439
+ TableSimpleHeaderComponent.prototype.ngOnChanges = function (changes) {
3440
+ var _this = this;
3441
+ if (changes.table) {
3442
+ if (changes.table.currentValue == null) {
3443
+ if (this.dataLoadSubscription) {
3444
+ this.dataLoadSubscription.unsubscribe();
3445
+ return;
3446
+ }
3447
+ }
3448
+ if (changes.table.currentValue != changes.table.previousValue) {
3449
+ this.dataLoadSubscription = changes.table.currentValue.load.subscribe(function (data) {
3450
+ _this.recordsTotal = data.recordsTotal;
3451
+ });
3452
+ }
3453
+ }
3454
+ };
3455
+ TableSimpleHeaderComponent.prototype.ngOnDestroy = function () {
3456
+ if (this.dataLoadSubscription) {
3457
+ this.dataLoadSubscription.unsubscribe();
3458
+ }
3459
+ };
3460
+ TableSimpleHeaderComponent.prototype.ngOnInit = function () {
3461
+ //
3462
+ };
3463
+ TableSimpleHeaderComponent.decorators = [
3464
+ { type: Component, args: [{
3465
+ selector: 'app-table-simple-header',
3466
+ template: "<div class=\"row\">\n <div class=\"col-auto mt-4\">\n <div class=\"font-xl text-secondary\" *ngIf=\"recordsTotal === 0\">\n <span>&nbsp;</span>\n </div>\n <div class=\"font-xl text-secondary\" *ngIf=\"recordsTotal > 1\">\n <span>{{recordsTotal}}</span><span>&nbsp;</span><span [translate]=\"'Tables.Items'\"></span>\n </div>\n <div class=\"font-xl text-secondary\" *ngIf=\"recordsTotal === 1\">\n <span>{{recordsTotal}}</span><span>&nbsp;</span><span [translate]=\"'Tables.Item'\"></span>\n </div>\n </div>\n <div class=\"pull-right ml-auto mr-3 mt-3\">\n <div class=\"font-lg btn-toolbar mt-2\">\n <ng-content select=\"table-simple-header-tools\"></ng-content>\n </div>\n </div>\n</div>\n\n"
3467
+ }] }
3468
+ ];
3469
+ /** @nocollapse */
3470
+ TableSimpleHeaderComponent.ctorParameters = function () { return []; };
3471
+ TableSimpleHeaderComponent.propDecorators = {
3472
+ table: [{ type: Input }]
3473
+ };
3474
+ return TableSimpleHeaderComponent;
3475
+ }());
3476
+
3477
+ var AdvancedTableNotNullError = /** @class */ (function (_super) {
3478
+ __extends(AdvancedTableNotNullError, _super);
3479
+ function AdvancedTableNotNullError() {
3480
+ return _super.call(this, 'Advanced table component cannot be empty at this context.') || this;
3481
+ }
3482
+ return AdvancedTableNotNullError;
3483
+ }(Error));
3484
+ var AdvancedTableEditorDirective = /** @class */ (function () {
3485
+ function AdvancedTableEditorDirective(table) {
3486
+ this.table = table;
3487
+ this.dirty = false;
3488
+ this.dirtyChange = new EventEmitter(false);
3489
+ //
3490
+ }
3491
+ /**
3492
+ * Add rows to table and mark them as added rows
3493
+ */
3494
+ AdvancedTableEditorDirective.prototype.add = function () {
3495
+ var addItems = [];
3496
+ for (var _i = 0; _i < arguments.length; _i++) {
3497
+ addItems[_i] = arguments[_i];
3498
+ }
3499
+ if (this.table == null) {
3500
+ throw new AdvancedTableNotNullError();
3501
+ }
3502
+ // decorate items
3503
+ var key = this.table.config.columns[0].property || this.table.config.columns[0].name;
3504
+ for (var index = 0; index < addItems.length; index++) {
3505
+ var element = addItems[index];
3506
+ var tr = this.table.dataTable.rows(':has(input[data-id="' + element[key] + '"])').nodes().to$();
3507
+ if (tr.hasClass('removed')) {
3508
+ tr.toggleClass('removed text-gray-400 text-decoration-line-through');
3509
+ }
3510
+ else {
3511
+ this.table.dataTable.rows.add([element]);
3512
+ tr = this.table.dataTable.rows(':has(input[data-id="' + element[key] + '"])').nodes().to$();
3513
+ tr.toggleClass('added font-weight-bold text-success');
3514
+ }
3515
+ }
3516
+ this.table.dataTable.draw();
3517
+ // find removed
3518
+ var removedLength = this.table.dataTable.rows('.removed')[0].length;
3519
+ // find added
3520
+ var addedLength = this.table.dataTable.rows('.added')[0].length;
3521
+ // and emit event
3522
+ var items = this.table.dataTable.rows().data();
3523
+ this.table.load.emit({
3524
+ data: items,
3525
+ recordsFiltered: items.length - removedLength,
3526
+ recordsTotal: items.length - removedLength
3527
+ });
3528
+ this.dirty = (removedLength > 0 || addedLength > 0);
3529
+ this.dirtyChange.emit(this.dirty);
3530
+ };
3531
+ /**
3532
+ * Marks rows as removed rows
3533
+ */
3534
+ AdvancedTableEditorDirective.prototype.remove = function () {
3535
+ var removeItems = [];
3536
+ for (var _i = 0; _i < arguments.length; _i++) {
3537
+ removeItems[_i] = arguments[_i];
3538
+ }
3539
+ if (this.table == null) {
3540
+ throw new AdvancedTableNotNullError();
3541
+ }
3542
+ // get key
3543
+ var key = this.table.config.columns[0].property || this.table.config.columns[0].name;
3544
+ var _loop_1 = function (index) {
3545
+ var element = removeItems[index];
3546
+ var tr = this_1.table.dataTable.rows(':has(input[data-id="' + element[key] + '"])').nodes().to$();
3547
+ // if row is marked as added
3548
+ if (tr.hasClass('added')) {
3549
+ // remove this dirty row
3550
+ this_1.table.dataTable.rows(tr).remove();
3551
+ }
3552
+ else {
3553
+ // otherwise unmarked row
3554
+ tr.toggleClass('removed text-gray-400 text-decoration-line-through');
3555
+ }
3556
+ // check if item is selected
3557
+ var selectedIndex = this_1.table.selected.findIndex(function (item) {
3558
+ return item[key] === element[key];
3559
+ });
3560
+ // and remove it from selected collection
3561
+ if (selectedIndex >= 0) {
3562
+ this_1.table.selected.splice(selectedIndex, 1);
3563
+ }
3564
+ };
3565
+ var this_1 = this;
3566
+ // loop items
3567
+ for (var index = 0; index < removeItems.length; index++) {
3568
+ _loop_1(index);
3569
+ }
3570
+ // re-draw table
3571
+ this.table.dataTable.draw();
3572
+ // get number of table items
3573
+ var items = this.table.dataTable.rows().data();
3574
+ // get number of removed items
3575
+ var removedLength = this.table.dataTable.rows('.removed')[0].length;
3576
+ // get number of added items
3577
+ var addedLength = this.table.dataTable.rows('.added')[0].length;
3578
+ // refresh
3579
+ this.table.load.emit({
3580
+ data: items,
3581
+ recordsFiltered: items.length - removedLength,
3582
+ recordsTotal: items.length - removedLength
3583
+ });
3584
+ this.dirty = (removedLength > 0 || addedLength > 0);
3585
+ this.dirtyChange.emit(this.dirty);
3586
+ };
3587
+ AdvancedTableEditorDirective.prototype.set = function (items) {
3588
+ if (this.table == null) {
3589
+ throw new AdvancedTableNotNullError();
3590
+ }
3591
+ // clear rows
3592
+ this.table.selected = [];
3593
+ this.table.dataTable.clear();
3594
+ // set items
3595
+ this.table.dataTable.rows.add(items).draw();
3596
+ this.table.load.emit({
3597
+ data: items,
3598
+ recordsFiltered: items.length,
3599
+ recordsTotal: items.length
3600
+ });
3601
+ };
3602
+ /**
3603
+ * Undo changes
3604
+ */
3605
+ AdvancedTableEditorDirective.prototype.undo = function () {
3606
+ if (this.table == null) {
3607
+ throw new AdvancedTableNotNullError();
3608
+ }
3609
+ // reset removed rows
3610
+ this.table.dataTable.rows('.removed').nodes().to$().toggleClass('removed text-gray-400 text-decoration-line-through');
3611
+ // remove added rows
3612
+ this.table.dataTable.rows('.added').remove();
3613
+ // clear selected items
3614
+ this.table.selected = [];
3615
+ var items = this.table.dataTable.rows().data();
3616
+ this.table.dataTable.draw();
3617
+ this.table.load.emit({
3618
+ data: items,
3619
+ recordsFiltered: items.length,
3620
+ recordsTotal: items.length
3621
+ });
3622
+ this.dirty = false;
3623
+ this.dirtyChange.emit(this.dirty);
3624
+ };
3625
+ AdvancedTableEditorDirective.prototype.rows = function () {
3626
+ if (this.table == null) {
3627
+ throw new AdvancedTableNotNullError();
3628
+ }
3629
+ return Array.from(this.table.dataTable.rows(':not(.removed)').data());
3630
+ };
3631
+ AdvancedTableEditorDirective.decorators = [
3632
+ { type: Directive, args: [{
3633
+ selector: '[tableEditor]'
3634
+ },] }
3635
+ ];
3636
+ /** @nocollapse */
3637
+ AdvancedTableEditorDirective.ctorParameters = function () { return [
3638
+ { type: AdvancedTableComponent }
3639
+ ]; };
3640
+ AdvancedTableEditorDirective.propDecorators = {
3641
+ dirtyChange: [{ type: Output }]
3642
+ };
3643
+ return AdvancedTableEditorDirective;
3644
+ }());
3645
+
3646
+ var AdvancedAggregatorService = /** @class */ (function () {
3647
+ function AdvancedAggregatorService(_context, _template) {
3648
+ this._context = _context;
3649
+ this._template = _template;
3650
+ }
3651
+ /**
3652
+ *
3653
+ * Formats and executes the data query
3654
+ *
3655
+ * @param {string} model The target model
3656
+ * @param {object} fixedParams Pairs of parameters to always be applied
3657
+ * @param {string} queryStatement The default query to use for fetching the data (e.g. expands etc)
3658
+ * @param {Array<string>} filters A list of filter expressions to append at the query
3659
+ * @param {string} searchTemplate The template to use for searching expressions
3660
+ * @param {string} searchValue The value of the user search
3661
+ *
3662
+ * @returns {Promise<any>} The response of the query execution
3663
+ */
3664
+ AdvancedAggregatorService.prototype.fetchData = function (model, fixedParams, queryStatement, filters, searchTemplate, searchValue) {
3665
+ if (queryStatement === void 0) { queryStatement = ''; }
3666
+ return __awaiter(this, void 0, void 0, function () {
3667
+ var e_1, _a, query, filterExpressions, _b, _c, param, evaluatedSearch, words;
3668
+ var _this = this;
3669
+ return __generator(this, function (_d) {
3670
+ query = this._context.model(model).asQueryable();
3671
+ if (!fixedParams || typeof fixedParams !== 'object') {
3672
+ fixedParams = {};
3673
+ }
3674
+ filterExpressions = [];
3675
+ if (fixedParams) {
3676
+ try {
3677
+ for (_b = __values(Object.keys(fixedParams)), _c = _b.next(); !_c.done; _c = _b.next()) {
3678
+ param = _c.value;
3679
+ filterExpressions.push(param + " eq " + fixedParams[param]);
3680
+ }
3681
+ }
3682
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
3683
+ finally {
3684
+ try {
3685
+ if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
3686
+ }
3687
+ finally { if (e_1) throw e_1.error; }
3688
+ }
3689
+ }
3690
+ if (filters && Array.isArray(filters)) {
3691
+ filterExpressions = __spread(filterExpressions, filters);
3692
+ }
3693
+ if (searchTemplate && searchValue) {
3694
+ evaluatedSearch = void 0;
3695
+ if (/^"(.*?)"$/.test(searchValue)) { // validate search text in double quotes
3696
+ evaluatedSearch = this._template.transform(searchTemplate, __assign({}, fixedParams, { text: searchValue.replace(/^"|"$/g, '') }));
3697
+ }
3698
+ else {
3699
+ words = searchValue.split(' ');
3700
+ // join words to a single filter
3701
+ evaluatedSearch = words.map(function (word) {
3702
+ return _this._template.transform(searchTemplate, __assign({}, fixedParams, { text: word }));
3703
+ }).join(' and ');
3704
+ }
3705
+ filterExpressions.push(evaluatedSearch);
3706
+ }
3707
+ query.setParam('$filter', filterExpressions.join(' and '));
3708
+ return [2 /*return*/, query.expand(queryStatement).take(-1).getItems()];
3709
+ });
3710
+ });
3711
+ };
3712
+ /**
3713
+ *
3714
+ * Formats the received data to use flat keys
3715
+ *
3716
+ * @param config The applied configuration
3717
+ * @param data The raw data
3718
+ *
3719
+ * @returns {Array<any>} The flat-key object list
3720
+ *
3721
+ */
3722
+ AdvancedAggregatorService.prototype.formatData = function (config, data) {
3723
+ try {
3724
+ return data.map(function (entry) {
3725
+ var entryObject = {};
3726
+ for (var i = 0; i < config.columns.length; i++) {
3727
+ var keys = config.columns[i].name.split('/');
3728
+ var helperObject = entry[keys[0]];
3729
+ if (helperObject && keys.length > 1) {
3730
+ for (var i_1 = 1; i_1 < keys.length; i_1++) {
3731
+ if (helperObject === undefined || helperObject === null) {
3732
+ break;
3733
+ }
3734
+ else {
3735
+ helperObject = helperObject[keys[i_1]] !== undefined && helperObject[keys[i_1]] !== null
3736
+ ? helperObject[keys[i_1]]
3737
+ : undefined;
3738
+ }
3739
+ }
3740
+ }
3741
+ entryObject[config.columns[i].name] = helperObject;
3742
+ }
3743
+ if (entry.subitems) {
3744
+ entryObject.subitems = entry.subitems;
3745
+ }
3746
+ return entryObject;
3747
+ });
3748
+ }
3749
+ catch (err) {
3750
+ console.error(err);
3751
+ }
3752
+ };
3753
+ AdvancedAggregatorService.decorators = [
3754
+ { type: Injectable, args: [{
3755
+ providedIn: 'root'
3756
+ },] }
3757
+ ];
3758
+ /** @nocollapse */
3759
+ AdvancedAggregatorService.ctorParameters = function () { return [
3760
+ { type: AngularDataContext },
3761
+ { type: TemplatePipe }
3762
+ ]; };
3763
+ AdvancedAggregatorService.ngInjectableDef = defineInjectable({ factory: function AdvancedAggregatorService_Factory() { return new AdvancedAggregatorService(inject(AngularDataContext), inject(TemplatePipe)); }, token: AdvancedAggregatorService, providedIn: "root" });
3764
+ return AdvancedAggregatorService;
3765
+ }());
3766
+
3767
+ /**
3768
+ *
3769
+ * @class AdvancedAggregatorComponent
3770
+ * @classdesc An advanced list with the capability of aggregate data based on configurable filters
3771
+ *
3772
+ */
3773
+ var AdvancedAggregatorComponent = /** @class */ (function () {
3774
+ function AdvancedAggregatorComponent(_changeDetector, _advancedAggregatorService, _loadingService) {
3775
+ this._changeDetector = _changeDetector;
3776
+ this._advancedAggregatorService = _advancedAggregatorService;
3777
+ this._loadingService = _loadingService;
3778
+ this.groups = [];
3779
+ this.eventHandler = new EventEmitter();
3780
+ }
3781
+ Object.defineProperty(AdvancedAggregatorComponent.prototype, "config", {
3782
+ get: function () {
3783
+ return this._config;
3784
+ },
3785
+ set: function (value) {
3786
+ this._config = value;
3787
+ },
3788
+ enumerable: true,
3789
+ configurable: true
3790
+ });
3791
+ Object.defineProperty(AdvancedAggregatorComponent.prototype, "aggregators", {
3792
+ get: function () {
3793
+ return this._aggregators;
3794
+ },
3795
+ set: function (value) {
3796
+ this._aggregators = value;
3797
+ },
3798
+ enumerable: true,
3799
+ configurable: true
3800
+ });
3801
+ Object.defineProperty(AdvancedAggregatorComponent.prototype, "postProcessors", {
3802
+ get: function () {
3803
+ return this._postProcessors;
3804
+ },
3805
+ set: function (value) {
3806
+ this._postProcessors = value;
3807
+ },
3808
+ enumerable: true,
3809
+ configurable: true
3810
+ });
3811
+ AdvancedAggregatorComponent.prototype.ngOnInit = function () {
3812
+ return __awaiter(this, void 0, void 0, function () {
3813
+ var _this = this;
3814
+ return __generator(this, function (_a) {
3815
+ this.selectedGroups$.subscribe(function (data) {
3816
+ _this.groups = data;
3817
+ _this._changeDetector.markForCheck();
3818
+ });
3819
+ this.filters$.subscribe(function (filters) { return __awaiter(_this, void 0, void 0, function () {
3820
+ var err_1;
3821
+ return __generator(this, function (_a) {
3822
+ switch (_a.label) {
3823
+ case 0:
3824
+ _a.trys.push([0, 2, , 3]);
3825
+ return [4 /*yield*/, this.fetch(filters)];
3826
+ case 1:
3827
+ _a.sent();
3828
+ return [3 /*break*/, 3];
3829
+ case 2:
3830
+ err_1 = _a.sent();
3831
+ console.error(err_1);
3832
+ return [3 /*break*/, 3];
3833
+ case 3: return [2 /*return*/];
3834
+ }
3835
+ });
3836
+ }); });
3837
+ return [2 /*return*/];
3838
+ });
3839
+ });
3840
+ };
3841
+ AdvancedAggregatorComponent.prototype.ngOnDestroy = function () {
3842
+ return __awaiter(this, void 0, void 0, function () {
3843
+ return __generator(this, function (_a) {
3844
+ this.selectedGroups$.unsubscribe();
3845
+ this.filters$.unsubscribe();
3846
+ return [2 /*return*/];
3847
+ });
3848
+ });
3849
+ };
3850
+ /**
3851
+ *
3852
+ * Retrieves the data
3853
+ *
3854
+ */
3855
+ AdvancedAggregatorComponent.prototype.fetch = function (filters) {
3856
+ return __awaiter(this, void 0, void 0, function () {
3857
+ var data, i, err_2;
3858
+ return __generator(this, function (_a) {
3859
+ switch (_a.label) {
3860
+ case 0:
3861
+ _a.trys.push([0, 6, 7, 8]);
3862
+ this._loadingService.showLoading();
3863
+ return [4 /*yield*/, this._advancedAggregatorService.fetchData(this.config.model, this.params, this.config.query, filters.filters, this.searchExpression, filters.text)];
3864
+ case 1:
3865
+ data = _a.sent();
3866
+ if (!(this.postProcessors && Object.keys(this.postProcessors).length > 0 && this.config.postProcessors && this.config.postProcessors.length > 0)) return [3 /*break*/, 5];
3867
+ i = 0;
3868
+ _a.label = 2;
3869
+ case 2:
3870
+ if (!(i < this.config.postProcessors.length)) return [3 /*break*/, 5];
3871
+ return [4 /*yield*/, this.postProcessors[this.config.postProcessors[i].name](data)];
3872
+ case 3:
3873
+ data = _a.sent();
3874
+ _a.label = 4;
3875
+ case 4:
3876
+ i++;
3877
+ return [3 /*break*/, 2];
3878
+ case 5:
3879
+ this.body = this._advancedAggregatorService.formatData(this.config, data);
3880
+ this._changeDetector.markForCheck();
3881
+ return [3 /*break*/, 8];
3882
+ case 6:
3883
+ err_2 = _a.sent();
3884
+ console.error(err_2);
3885
+ return [3 /*break*/, 8];
3886
+ case 7:
3887
+ this._loadingService.hideLoading();
3888
+ return [7 /*endfinally*/];
3889
+ case 8: return [2 /*return*/];
3890
+ }
3891
+ });
3892
+ });
3893
+ };
3894
+ /**
3895
+ *
3896
+ * Triggers the event handler event
3897
+ *
3898
+ * @param {*} event The event data
3899
+ *
3900
+ */
3901
+ AdvancedAggregatorComponent.prototype.onActionEvent = function (event) {
3902
+ this.eventHandler.emit(event);
3903
+ };
3904
+ AdvancedAggregatorComponent.decorators = [
3905
+ { type: Component, args: [{
3906
+ selector: 'app-advanced-aggregator',
3907
+ template: "<ng-container *ngIf=\"config && body\">\n <div class=\"w-100 text-center\" *ngIf=\"body && body.length === 0\">\n <div>\n <div class=\"mt-4\">\n <div class=\"icon-circle bg-gray-300 border-gray-100\"></div>\n </div>\n <div class=\"mt-4\">\n <h4 class=\"font-3xl text-dark\" [translate]=\"'Tables.EmptyTableTitle'\"></h4>\n <p class=\"font-lg text-dark\" [translate]=\"'Tables.EmptyTableMessage'\"></p>\n </div>\n </div>\n </div>\n <ng-container *ngIf=\"groups.length === 0\">\n <div class=\"row mt-4\">\n <app-advanced-aggregator-list [body]=\"body\" [config]=\"config\" (clickEvent)=\"onActionEvent($event)\" class=\"col-12\">\n </app-advanced-aggregator-list>\n <div *ngIf=\"config.aggregators && config.aggregators.length > 0\"\n class=\"footer-text text-dark font-weight-normal text-right font-sm mt-3 mr-2 w-100\">\n <div *ngFor=\"let aggregator of config.aggregators\">\n <span *ngIf=\"aggregator.label\"> {{ aggregator.label | translate }} </span>:\n <span class=\"font-weight-bold\"> {{ body | callAggregator: aggregators: aggregator.name }}\n </span>\n </div>\n </div>\n </div>\n </ng-container>\n <ng-container *ngIf=\"groups.length === 1\">\n <ng-container *ngFor=\"let group of body | groupBy: groups[0].name | keyvalue\">\n <div class=\"row mt-4\">\n <h4 class=\"col text-secondary\"> {{ groups[0].title | aggregatorListTitle: group.key }} </h4>\n <app-advanced-aggregator-list [body]=\"group.value\" [config]=\"config\" (clickEvent)=\"onActionEvent($event)\"\n class=\"col-12\">\n </app-advanced-aggregator-list>\n </div>\n\n <!-- Footer for the group -->\n <div *ngIf=\"config.aggregators && config.aggregators.length > 0\"\n class=\"footer-text text-dark font-weight-normal text-right font-sm mt-3 mr-2 w-100\">\n <div *ngFor=\"let aggregator of config.aggregators\">\n <span *ngIf=\"aggregator.label\"> {{ aggregator.label | translate }} </span>:\n <span class=\"font-weight-bold\"> {{ group.value | callAggregator: aggregators: aggregator.name }} </span>\n </div>\n </div>\n </ng-container>\n </ng-container>\n <ng-container *ngIf=\"groups.length > 1\">\n <ng-container *ngFor=\"let group of body | groupBy: groups[0].name | keyvalue\">\n <div class=\"row mt-4\">\n <h4 class=\"col text-secondary\"> {{ groups[0].title | aggregatorListTitle: group.key }} </h4>\n <div *ngFor=\"let subgroup of group.value | groupBy: groups[1].name | keyvalue\" class=\"col-12 ml-4 pl-4\">\n <div class=\"row mt-4\">\n <h6 class=\"col-12 text-secondary\"> {{ groups[1].title | aggregatorListTitle: subgroup.key }} </h6>\n <app-advanced-aggregator-list [body]=\"subgroup.value\" [config]=\"config\" (clickEvent)=\"onActionEvent($event)\"\n class=\"col-12\">\n </app-advanced-aggregator-list>\n </div>\n\n <!-- Footer for each subgroup -->\n <div *ngIf=\"config.aggregators && config.aggregators.length > 0\"\n class=\"footer-text text-dark font-weight-normal text-right font-sm mt-3 mr-2 w-100\">\n <div *ngFor=\"let aggregator of config.aggregators\">\n <span *ngIf=\"aggregator.label\"> {{ aggregator.label | translate }} </span>:\n <span class=\"font-weight-bold\"> {{ subgroup.value | callAggregator: aggregators: aggregator.name }}\n </span>\n </div>\n </div>\n </div>\n </div>\n </ng-container>\n </ng-container>\n</ng-container>",
3908
+ changeDetection: ChangeDetectionStrategy.OnPush
3909
+ }] }
3910
+ ];
3911
+ /** @nocollapse */
3912
+ AdvancedAggregatorComponent.ctorParameters = function () { return [
3913
+ { type: ChangeDetectorRef },
3914
+ { type: AdvancedAggregatorService },
3915
+ { type: LoadingService }
3916
+ ]; };
3917
+ AdvancedAggregatorComponent.propDecorators = {
3918
+ config: [{ type: Input, args: ['config',] }],
3919
+ aggregators: [{ type: Input, args: ['aggregators',] }],
3920
+ postProcessors: [{ type: Input, args: ['postProcessors',] }],
3921
+ params: [{ type: Input, args: ['params',] }],
3922
+ selectedGroups$: [{ type: Input, args: ['selectedGroups',] }],
3923
+ filters$: [{ type: Input, args: ['filters',] }],
3924
+ searchExpression: [{ type: Input, args: ['searchExpression',] }],
3925
+ eventHandler: [{ type: Output }]
3926
+ };
3927
+ return AdvancedAggregatorComponent;
3928
+ }());
3929
+
3930
+ var Lengths;
3931
+ (function (Lengths) {
3932
+ Lengths["XL"] = "xl";
3933
+ Lengths["LG"] = "lg";
3934
+ Lengths["MD"] = "md";
3935
+ Lengths["SM"] = "sm";
3936
+ Lengths["XS"] = "xs";
3937
+ })(Lengths || (Lengths = {}));
3938
+ var AdvancedAggregatorListComponent = /** @class */ (function () {
3939
+ function AdvancedAggregatorListComponent(_template) {
3940
+ this._template = _template;
3941
+ this.clickEvent = new EventEmitter();
3942
+ }
3943
+ AdvancedAggregatorListComponent.prototype.ngOnInit = function () {
3944
+ var _this = this;
3945
+ this.config.columns.forEach(function (x) {
3946
+ x.length = Object.values(Lengths).includes(x.length) ? _this._template.transform("sis--list-group-item_" + x.length + "_column", x) :
3947
+ !x.length ? 'sis--list-group-item_sm_column' : x.length;
3948
+ });
3949
+ };
3950
+ /**
3951
+ *
3952
+ * Triggers the output event emitter
3953
+ *
3954
+ * @param type The type of the event as it's declared in the configuration
3955
+ * @param item The value of the current item
3956
+ * }
3957
+ */
3958
+ AdvancedAggregatorListComponent.prototype.callCallback = function (type, data) {
3959
+ this.clickEvent.emit({
3960
+ type: type,
3961
+ data: data
3962
+ });
3963
+ };
3964
+ AdvancedAggregatorListComponent.decorators = [
3965
+ { type: Component, args: [{
3966
+ selector: 'app-advanced-aggregator-list',
3967
+ template: "<div id=\"group-list\" class=\"flex-column\" *ngIf=\"config && config.columns\">\n <ul class=\"sis--list-group sis--list-group-header\">\n <li class=\"sis--list-group-item text-wrap\">\n <div class=\"d-flex justify-content-center align-items-center\" *ngIf=\"body && body.length > 0\">\n <div *ngIf=\"config.actions && config.actions.length > 0\" class=\"sis--list-group-item_sm_column\"></div>\n <div *ngFor=\"let column of config.columns; let i = index\" class=\"text-left\"\n [class]=\"config.columns[i].length\"\n [translate]=\"config.columns[i].type === 'action' ? '' : column.title\" [ngClass]=\"{\n 'd-none': config.columns[i].hidden\n }\"></div>\n </div>\n </li>\n </ul>\n\n <!-- The list of entries -->\n <ul class=\"sis--list-group sis--list-group-body\" *ngIf=\"body && body.length > 0\">\n <li class=\"sis--list-group-item text-wrap\" *ngFor=\"let entry of body | orderBy: config.orderBy\">\n <div class=\"d-flex justify-content-center align-items-center list-color\">\n <!-- The list of actions -->\n <div *ngIf=\"config.actions && config.actions.length > 0\" class=\"sis--list-group-item_sm_column text-left pr-0\">\n <button *ngFor=\"let action of config.actions\" (click)=\"callCallback(action.identifier, entry)\"\n [title]=\"(action.title ? action.title : '') | translate \" class=\"btn btn-default px-0\">\n <i [class]=\"'fas text-indigo ml-2 ' + 'fa-' + action.icon\"></i>\n </button>\n </div>\n <!-- The list of data -->\n <div *ngFor=\"let column of config.columns; let i=index\" [class]=\"config.columns[i].length\" class=\"text-left\"\n [ngClass]=\"{\n 'text-truncate': config.columns[i].hasOwnProperty('truncate') && config.columns[i].truncate,\n 'd-none': config.columns[i].hidden,\n 'd-md-block': !config.columns[i].hidden\n }\"\n [title]=\"config.columns[i].hasOwnProperty('truncate') && config.columns[i].truncate ? entry[column.name] : ''\">\n <span class=\"text-secondary\"\n *ngIf=\"!config.columns[i].hasOwnProperty('type') || (config.columns[i].hasOwnProperty('type') && config.columns[i].type === 'text')\"\n [ngClass]=\"{\n 'font-xs': config.columns[i].variant !== 'primary',\n 'text-body': config.columns[i].variant === 'primary',\n 'text-success': config.columns[i].variant === 'redGreen' && config.columns[i].hasOwnProperty('condition') && entry[config.columns[i].condition],\n 'text-danger': config.columns[i].variant === 'redGreen' && config.columns[i].hasOwnProperty('condition') && !entry[config.columns[i].condition],\n 'font-lg': config.columns[i].variant === 'redGreen' && entry[column.name] && entry[column.name].length > 3,\n 'font-2xl': config.columns[i].variant === 'redGreen' && entry[column.name] && entry[column.name].length <= 3\n }\">\n {{entry[column.name] || '-'}}\n </span>\n\n <span *ngIf=\"config.columns[i].type === 'boolean'\">\n <i class=\"fa font-lg\" [ngClass]=\"{\n 'fa-check text-success': entry[column.name].toString() === config.columns[i].trueValue,\n 'fa-times text-danger': entry[column.name].toString() !== config.columns[i].trueValue && config.columns[i].variant !== 'checkOrDash'\n }\"></i>\n <span\n *ngIf=\"entry[column.name].toString() !== config.columns[i].trueValue && config.columns[i].variant === 'checkOrDash'\"\n class=\"text-secondary font-xs\">-</span>\n </span>\n </div>\n </div>\n <ul *ngIf=\"entry && entry.subitems\">\n <li *ngFor=\"let subitem of entry.subitems\" class=\"d-flex justify-content-center align-items-center list-color\">\n <div class=\"text-left\"></div>\n <div *ngFor=\"let column of config.columns; let i=index\" [class]=\"config.column[i].length\" class=\"text-left\"\n [ngClass]=\"{\n 'text-truncate': config.columns[i].hasOwnProperty('truncate') && config.columns[i].truncate,\n 'd-none': config.columns[i].hidden,\n 'd-md-block': !config.columns[i].hidden\n }\"\n [title]=\"config.columns[i].hasOwnProperty('truncate') && config.columns[i].truncate ? entry[column.name] : ''\">\n <span class=\"text-secondary\"\n *ngIf=\"!config.columns[i].hasOwnProperty('type') || (config.columns[i].hasOwnProperty('type') && config.columns[i].type === 'text')\"\n [ngClass]=\"{\n 'font-xs': config.columns[i].variant !== 'primary',\n 'text-body': config.columns[i].variant === 'primary',\n 'text-success': config.columns[i].variant === 'redGreen' && config.columns[i].hasOwnProperty('condition') && subitem[config.columns[i].condition],\n 'text-danger': config.columns[i].variant === 'redGreen' && config.columns[i].hasOwnProperty('condition') && !subitem[config.columns[i].condition],\n 'font-lg': config.columns[i].variant === 'redGreen' && subitem[column.name] && subitem[column.name].length > 3,\n 'font-2xl': config.columns[i].variant === 'redGreen' && subitem[column.name] && subitem[column.name].length <= 3\n }\">\n {{subitem[column.name] || '-'}}\n </span>\n </div>\n </li>\n </ul>\n </li>\n </ul>\n</div>\n"
3968
+ }] }
3969
+ ];
3970
+ /** @nocollapse */
3971
+ AdvancedAggregatorListComponent.ctorParameters = function () { return [
3972
+ { type: TemplatePipe }
3973
+ ]; };
3974
+ AdvancedAggregatorListComponent.propDecorators = {
3975
+ config: [{ type: Input }],
3976
+ body: [{ type: Input }],
3977
+ clickEvent: [{ type: Output }]
3978
+ };
3979
+ return AdvancedAggregatorListComponent;
3980
+ }());
3981
+
3982
+ /**
3983
+ *
3984
+ * @class AdvancedAggregatorPipe
3985
+ * @classdesc Given a list of items runs a user defined function against that list
3986
+ *
3987
+ */
3988
+ var AdvancedAggregatorPipe = /** @class */ (function () {
3989
+ function AdvancedAggregatorPipe() {
3990
+ }
3991
+ /**
3992
+ *
3993
+ * @override
3994
+ *
3995
+ * @param items The list of items to run the aggregator against
3996
+ * @param functionPool The functions that are available from the list caller
3997
+ * @param functionName The name of the function to be called
3998
+ *
3999
+ * @returns {string} The value to show at the UI
4000
+ *
4001
+ */
4002
+ AdvancedAggregatorPipe.prototype.transform = function (items, functionPool, functionName) {
4003
+ if (Array.isArray(items) && functionName && functionName in functionPool) {
4004
+ return functionPool[functionName](items);
4005
+ }
4006
+ else {
4007
+ return '-';
4008
+ }
4009
+ };
4010
+ AdvancedAggregatorPipe.decorators = [
4011
+ { type: Pipe, args: [{
4012
+ name: 'callAggregator'
4013
+ },] }
4014
+ ];
4015
+ return AdvancedAggregatorPipe;
4016
+ }());
4017
+
4018
+ /**
4019
+ *
4020
+ * @class ParseTitlePipe
4021
+ * @classdesc Given a title of an aggregator list, translates and evaluates the parameter if any
4022
+ *
4023
+ */
4024
+ var ParseTitlePipe = /** @class */ (function () {
4025
+ function ParseTitlePipe(_translateService) {
4026
+ this._translateService = _translateService;
4027
+ }
4028
+ /**
4029
+ *
4030
+ * @override
4031
+ *
4032
+ * @param {string} title The title of the list
4033
+ * @param {string} key The current list key that is being used
4034
+ *
4035
+ */
4036
+ ParseTitlePipe.prototype.transform = function (title, key) {
4037
+ var _this = this;
4038
+ if (!title) {
4039
+ return '';
4040
+ }
4041
+ else {
4042
+ if (key === undefined || key === null || key === 'undefined' || key === 'null') {
4043
+ key = this._translateService.instant('Tables.NotDefined');
4044
+ }
4045
+ return title.split(' ')
4046
+ .map(function (part) { return _this._translateService.instant(part); })
4047
+ .map(function (part) { return part.replace('${param}', key); })
4048
+ .join(' ');
4049
+ }
4050
+ };
4051
+ ParseTitlePipe.decorators = [
4052
+ { type: Pipe, args: [{
4053
+ name: 'aggregatorListTitle'
4054
+ },] }
4055
+ ];
4056
+ /** @nocollapse */
4057
+ ParseTitlePipe.ctorParameters = function () { return [
4058
+ { type: TranslateService }
4059
+ ]; };
4060
+ return ParseTitlePipe;
4061
+ }());
4062
+
4063
+ var AddItemsComponent = /** @class */ (function (_super) {
4064
+ __extends(AddItemsComponent, _super);
4065
+ function AddItemsComponent(router, activatedRoute, _errorService, _modalService, _appEvent, _toastService, _loadingService, _translateService, _context) {
4066
+ var _this = _super.call(this, router, activatedRoute) || this;
4067
+ _this._errorService = _errorService;
4068
+ _this._modalService = _modalService;
4069
+ _this._appEvent = _appEvent;
4070
+ _this._toastService = _toastService;
4071
+ _this._loadingService = _loadingService;
4072
+ _this._translateService = _translateService;
4073
+ _this._context = _context;
4074
+ _this.loading = false;
4075
+ _this.items = [];
4076
+ _this.messages = [];
4077
+ // set modal size
4078
+ _this.modalClass = 'modal-lg';
4079
+ _this.okButtonDisabled = true;
4080
+ return _this;
4081
+ }
4082
+ AddItemsComponent.prototype.ngOnInit = function () {
4083
+ var _this = this;
4084
+ this.selectedSubscription = this.selectComponent.advancedTable.selectedItems.subscribe(function (items) {
4085
+ if (_this.formName == null) {
4086
+ _this.okButtonDisabled = items.length === 0;
4087
+ }
4088
+ });
4089
+ if (this.formName != null) {
4090
+ this.formChangeSubscription = this.formComponent.form.change.subscribe(function (event) {
4091
+ if (Object.prototype.hasOwnProperty.call(event, 'isValid')) {
4092
+ // enable or disable button based on form status
4093
+ _this.okButtonDisabled = (!event.isValid);
4094
+ }
4095
+ });
4096
+ }
4097
+ if (this.target) {
4098
+ var target = this.target;
4099
+ }
4100
+ };
4101
+ AddItemsComponent.prototype.cancel = function () {
4102
+ this.clearMessages();
4103
+ if (this.loading) {
4104
+ return;
4105
+ }
4106
+ // close
4107
+ if (this._modalService.modalRef) {
4108
+ return this._modalService.modalRef.hide();
4109
+ }
4110
+ };
4111
+ AddItemsComponent.prototype.ngOnDestroy = function () {
4112
+ if (this.formLoadSubscription) {
4113
+ this.formLoadSubscription.unsubscribe();
4114
+ }
4115
+ if (this.formChangeSubscription) {
4116
+ this.formChangeSubscription.unsubscribe();
4117
+ }
4118
+ if (this.selectedSubscription) {
4119
+ this.selectedSubscription.unsubscribe();
4120
+ }
4121
+ };
4122
+ Object.defineProperty(AddItemsComponent.prototype, "formData", {
4123
+ get: function () {
4124
+ if (this.formComponent === null) {
4125
+ return null;
4126
+ }
4127
+ return this.formComponent.form.formio.data;
4128
+ },
4129
+ enumerable: true,
4130
+ configurable: true
4131
+ });
4132
+ AddItemsComponent.prototype.ok = function () {
4133
+ var _this = this;
4134
+ try {
4135
+ this.clearMessages();
4136
+ return new Promise(function (resolve, reject) {
4137
+ _this.loading = false;
4138
+ _this.lastError = null;
4139
+ // set courses
4140
+ _this.items = _this.selectComponent.advancedTable.selected;
4141
+ // execute add
4142
+ _this.executeSubscription = _this.execute.subscribe(function (result) {
4143
+ _this.loading = false;
4144
+ if (_this.executeSubscription) {
4145
+ _this.executeSubscription.unsubscribe();
4146
+ }
4147
+ // close modal
4148
+ if (_this._modalService.modalRef) {
4149
+ _this._modalService.modalRef.hide();
4150
+ }
4151
+ return resolve();
4152
+ }, function (err) {
4153
+ _this.loading = false;
4154
+ // ensure that loading is hidden
4155
+ _this._loadingService.hideLoading();
4156
+ // set last error
4157
+ _this.lastError = err;
4158
+ return resolve();
4159
+ });
4160
+ });
4161
+ }
4162
+ catch (err) {
4163
+ this.loading = false;
4164
+ this._loadingService.hideLoading();
4165
+ this.lastError = err;
4166
+ }
4167
+ };
4168
+ AddItemsComponent.prototype.onChange = function ($event) { };
4169
+ AddItemsComponent.prototype.clearMessages = function () {
4170
+ this.messages = [];
4171
+ };
4172
+ AddItemsComponent.prototype.onFilterChange = function (event) { };
4173
+ AddItemsComponent.decorators = [
4174
+ { type: Component, args: [{
4175
+ selector: 'app-add-items',
4176
+ template: "<div>\n <div class=\"modal-header\" *ngIf=\"modalTitle\">\n <h5 class=\"modal-title\">{{modalTitle | translate}}</h5>\n <button (click)=\"cancel()\" [disabled]=\"loading\"\n type=\"button\" class=\"close\" data-dismiss=\"modal\" aria-label=\"Cancel\">\n <span aria-hidden=\"true\">&times;</span>\n </button>\n </div>\n <div class=\"modal-body pt-0\">\n <div class=\"row\" *ngIf=\"lastError\">\n <div class=\"alert alert-danger col-12\" role=\"alert\">\n <span [translate]=\"'E' + (lastError.statusCode || 500) + '.title'\"></span><br>\n <small *ngIf=\"lastError.statusCode >= 0\" [translate]=\"'E' + (lastError.statusCode || 500) + '.message'\"></small>\n <small *ngIf=\"lastError.statusCode == null\">{{lastError.message}}</small>\n </div>\n </div>\n <div class=\"row d-none\" *ngIf=\"items\">\n <div class=\"col-12\">\n <p [translate]=\"'StudyPrograms.AddCoursesHelp'\" [translateParams]=\"items\" ></p>\n </div>\n </div>\n <div class=\"row mt-3\">\n <div class=\"col-12\">\n <ng-container>\n <ul style=\"margin-left: -24px\" class=\"nav nav-tabs mb-1\" id=\"myTab\" role=\"tablist\">\n <li class=\"nav-item\" *ngIf=\"tableConfiguration\">\n <a class=\"nav-link active\" id=\"courses-tab\" data-toggle=\"tab\" href=\"#courses\" role=\"tab\" aria-controls=\"home\" aria-selected=\"true\" [translate]=\"'AddItems.SelectCourses'\" ></a>\n </li>\n <li class=\"nav-item\" *ngIf=\"formName\">\n <a class=\"nav-link\" [ngClass]=\"{ 'disabled': !(selectComponent.advancedTable.selected && selectComponent.advancedTable.selected.length) }\" id=\"attributes-tab\" data-toggle=\"tab\" href=\"#attributes\" role=\"tab\" aria-controls=\"profile\" aria-selected=\"false\" [translate]=\"'AddItems.EditAttributes'\"></a>\n </li>\n <li class=\"nav-item\" *ngIf=\"messages && messages.length > 0\">\n <a class=\"nav-link\" id=\"messages-tab\" data-toggle=\"tab\" href=\"#messages\" role=\"tab\" aria-controls=\"profile\" aria-selected=\"false\" [translate]=\"'AddItems.Messages'\"></a>\n </li>\n </ul>\n <div class=\"tab-content border-0\" id=\"myTabContent\">\n <div class=\"tab-pane fade show active\" id=\"courses\" role=\"tabpanel\" aria-labelledby=\"home-tab\">\n <app-advanced-table-modal #selectComponent (filter)=\"onFilterChange($event)\" [tableConfig]=\"tableConfiguration\"></app-advanced-table-modal>\n </div>\n <div class=\"tab-pane fade\" id=\"attributes\" role=\"tabpanel\" aria-labelledby=\"profile-tab\"\n [ngClass]=\"{'invisible':(formName == null)}\">\n<!-- <advanced-form-edit #formComponent [formName]=\"formName\" ></advanced-form-edit>-->\n </div>\n <div class=\"tab-pane fade\" id=\"messages\" role=\"tabpanel\" aria-labelledby=\"profile-tab\"\n [ngClass]=\"{'invisible':(messages == null)}\">\n <ul *ngIf=\"messages && messages.length>0\" class=\"sis--list-group sis--list-group-header\">\n <li class=\"sis--list-group-item\">\n <div class=\"d-flex justify-content-center align-items-center\">\n <div class=\"sis--list-group-item_lg_column\" [translate]=\"'AddItems.Messages'\"></div>\n </div>\n </li>\n </ul>\n <ul class=\"sis--list-group sis--list-group-body\">\n <li *ngFor=\"let message of messages\" class=\"sis--list-group-item\">\n <div class=\"d-flex justify-content-center align-items-center list-color\">\n <div class=\"sis--list-group-item_lg_column\">{{ message?.message }}</div>\n </div>\n </li>\n </ul>\n <div *ngIf=\"messages && messages.length>0\">\n <button [disabled]=\"loading\" (click)=\"clearMessages()\" type=\"button\" class=\"btn btn-indigo mt-3\">\n {{'Clear' | translate}}\n </button>\n </div>\n </div>\n </div>\n </ng-container>\n </div>\n </div>\n </div>\n <div class=\"modal-footer justify-content-end\">\n <button [disabled]=\"okButtonDisabled || loading || !(selectComponent.advancedTable.selected && selectComponent.advancedTable.selected.length) \" (click)=\"ok()\"\n type=\"button\" [ngClass]=\"okButtonClass\">\n {{'OK' | translate}}\n </button>\n <button [disabled]=\"cancelButtonDisabled || loading\"\n (click)=\"cancel()\" type=\"button\" [ngClass]=\"cancelButtonClass\" data-dismiss=\"modal\">\n {{'Cancel' | translate}}\n </button>\n </div>\n</div>\n"
4177
+ }] }
4178
+ ];
4179
+ /** @nocollapse */
4180
+ AddItemsComponent.ctorParameters = function () { return [
4181
+ { type: Router },
4182
+ { type: ActivatedRoute },
4183
+ { type: ErrorService },
4184
+ { type: ModalService },
4185
+ { type: AppEventService },
4186
+ { type: ToastService },
4187
+ { type: LoadingService },
4188
+ { type: TranslateService },
4189
+ { type: AngularDataContext }
4190
+ ]; };
4191
+ AddItemsComponent.propDecorators = {
4192
+ execute: [{ type: Input }],
4193
+ items: [{ type: Input }],
4194
+ target: [{ type: Input }],
4195
+ tableConfiguration: [{ type: Input }],
4196
+ formName: [{ type: Input }],
4197
+ messages: [{ type: Input }],
4198
+ formComponent: [{ type: ViewChild, args: ['formComponent',] }],
4199
+ selectComponent: [{ type: ViewChild, args: ['selectComponent',] }]
4200
+ };
4201
+ return AddItemsComponent;
4202
+ }(RouterModalOkCancel));
4203
+
4204
+ var ɵ0 = FORMATTERS;
4205
+ var TablesModule = /** @class */ (function () {
4206
+ function TablesModule(_translateService) {
4207
+ this._translateService = _translateService;
4208
+ this.ngOnInit().catch(function (err) {
4209
+ console.error('An error occurred while loading tables module');
4210
+ console.error(err);
4211
+ });
4212
+ }
4213
+ TablesModule.prototype.ngOnInit = function () {
4214
+ return __awaiter(this, void 0, void 0, function () {
4215
+ return __generator(this, function (_a) {
4216
+ this._translateService.setTranslation('en', TABLES_EN, true);
4217
+ this._translateService.setTranslation('el', TABLES_EL, true);
4218
+ return [2 /*return*/];
4219
+ });
4220
+ });
4221
+ };
4222
+ TablesModule.decorators = [
4223
+ { type: NgModule, args: [{
4224
+ imports: [
4225
+ CommonModule,
4226
+ SharedModule,
4227
+ TranslateModule,
4228
+ FormsModule,
4229
+ ReactiveFormsModule,
4230
+ RouterModule,
4231
+ RouterModalModule,
4232
+ FormioModule,
4233
+ AdvancedFormsModule,
4234
+ SharedModule,
4235
+ ModalModule,
4236
+ BsDropdownModule,
4237
+ ProgressbarModule,
4238
+ NgPipesModule
4239
+ ],
4240
+ providers: [DatePipe, TemplatePipe,
4241
+ {
4242
+ provide: COLUMN_FORMATTERS,
4243
+ useValue: ɵ0
4244
+ },
4245
+ AdvancedTableConfigurationResolver,
4246
+ AdvancedSearchConfigurationResolver,
4247
+ AdvancedSelectService,
4248
+ AdvancedAggregatorService,
4249
+ GroupByPipe
4250
+ ],
4251
+ declarations: [
4252
+ AdvancedTableComponent,
4253
+ AdvancedTableSearchComponent,
4254
+ BtnExpDirective,
4255
+ AdvancedTableSettingsComponent,
4256
+ AdvancedTableModalBaseComponent,
4257
+ AdvancedSearchFormComponent,
4258
+ AdvancedListComponent,
4259
+ AdvancedRowActionComponent,
4260
+ TableSimpleHeaderComponent,
4261
+ SimpleHeaderToolsComponent,
4262
+ AdvancedSelectComponent,
4263
+ AdvancedTableEditorDirective,
4264
+ AdvancedAggregatorComponent,
4265
+ AdvancedAggregatorListComponent,
4266
+ AdvancedAggregatorPipe,
4267
+ ParseTitlePipe,
4268
+ AddItemsComponent
4269
+ ],
4270
+ exports: [
4271
+ AdvancedTableComponent,
4272
+ AdvancedTableSearchComponent,
4273
+ BtnExpDirective,
4274
+ AdvancedTableSettingsComponent,
4275
+ AdvancedSearchFormComponent,
4276
+ AdvancedListComponent,
4277
+ AdvancedRowActionComponent,
4278
+ TableSimpleHeaderComponent,
4279
+ SimpleHeaderToolsComponent,
4280
+ AdvancedSelectComponent,
4281
+ AdvancedTableEditorDirective,
4282
+ AdvancedAggregatorComponent,
4283
+ AdvancedAggregatorListComponent,
4284
+ AddItemsComponent
4285
+ ],
4286
+ entryComponents: [
4287
+ AdvancedTableModalBaseComponent,
4288
+ AdvancedTableSettingsComponent,
4289
+ AdvancedRowActionComponent,
4290
+ AdvancedSelectComponent,
4291
+ AddItemsComponent
4292
+ ],
4293
+ schemas: [CUSTOM_ELEMENTS_SCHEMA]
4294
+ },] }
4295
+ ];
4296
+ /** @nocollapse */
4297
+ TablesModule.ctorParameters = function () { return [
4298
+ { type: TranslateService }
4299
+ ]; };
4300
+ return TablesModule;
4301
+ }());
4302
+
4303
+ /*
4304
+ * Public API Surface of tables
4305
+ */
4306
+
4307
+ /**
4308
+ * Generated bundle index. Do not edit.
4309
+ */
4310
+
4311
+ export { AdvancedFilterValueProvider as ɵb, AdvancedTableSearchBaseComponent as ɵa, AdvancedTableSettingsComponent as ɵe, SimpleHeaderToolsComponent as ɵf, TableSimpleHeaderComponent as ɵg, BtnExpDirective as ɵd, AdvancedAggregatorPipe as ɵh, ParseTitlePipe as ɵi, AdvancedAggregatorService as ɵc, AdvancedListComponent, AdvancedRowActionComponent, AdvancedSearchFormComponent, AdvancedTableConfigurationResolver, AdvancedSearchConfigurationResolver, AdvancedColumnFormatter, NestedPropertyFormatter, ButtonFormatter, LinkFormatter, ActionLinkFormatter, SelectRowFormatter, TemplateFormatter, TrueFalseFormatter, TranslationFormatter, DateTimeFormatter, NgClassFormatter, LanguageFormatter, COLUMN_FORMATTERS, AdvancedTableConfiguration, AdvancedTableComponent, AdvancedTableSearchComponent, FORMATTERS, AdvancedTableModalBaseTemplate, AdvancedTableModalBaseComponent, AdvancedSelectComponent, AdvancedSelectService, TablesModule, ɵ0, ActivatedTableService, AdvancedTableNotNullError, AdvancedTableEditorDirective, AdvancedAggregatorComponent, AdvancedAggregatorListComponent, AddItemsComponent };
4312
+
4313
+ //# sourceMappingURL=universis-ngx-tables.js.map