@angular-generic-table/core 5.0.0-rc.1 → 5.0.0-rc.12
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.
- package/angular-generic-table-core.d.ts +1 -3
- package/esm2020/angular-generic-table-core.mjs +5 -0
- package/esm2020/lib/core.component.mjs +161 -0
- package/esm2020/lib/core.module.mjs +40 -0
- package/esm2020/lib/core.service.mjs +14 -0
- package/esm2020/lib/enums/order.enum.mjs +6 -0
- package/esm2020/lib/gt-delta/gt-delta.component.mjs +115 -0
- package/esm2020/lib/models/gt-pagination.mjs +2 -0
- package/esm2020/lib/models/table-column.interface.mjs +2 -0
- package/esm2020/lib/models/table-config.interface.mjs +2 -0
- package/esm2020/lib/models/table-info.interface.mjs +2 -0
- package/esm2020/lib/models/table-meta.interface.mjs +2 -0
- package/esm2020/lib/models/table-row.interface.mjs +2 -0
- package/esm2020/lib/models/table-sort.interface.mjs +2 -0
- package/esm2020/lib/pagination/pagination.component.mjs +98 -0
- package/esm2020/lib/pagination/pagination.module.mjs +18 -0
- package/esm2020/lib/pipes/capital-case.pipe.mjs +17 -0
- package/esm2020/lib/pipes/dash-case.pipe.mjs +17 -0
- package/esm2020/lib/pipes/dynamic.pipe.mjs +25 -0
- package/esm2020/lib/pipes/highlight.pipe.mjs +48 -0
- package/esm2020/lib/pipes/sort-class.pipe.mjs +22 -0
- package/esm2020/lib/utilities/utilities.mjs +53 -0
- package/esm2020/public-api.mjs +16 -0
- package/fesm2015/angular-generic-table-core.mjs +610 -0
- package/fesm2015/angular-generic-table-core.mjs.map +1 -0
- package/fesm2020/angular-generic-table-core.mjs +603 -0
- package/fesm2020/angular-generic-table-core.mjs.map +1 -0
- package/lib/core.component.d.ts +20 -18
- package/lib/core.module.d.ts +12 -0
- package/lib/core.service.d.ts +3 -0
- package/lib/gt-delta/gt-delta.component.d.ts +20 -0
- package/lib/models/gt-pagination.d.ts +10 -0
- package/lib/models/table-column.interface.d.ts +13 -1
- package/lib/models/table-config.interface.d.ts +12 -3
- package/lib/models/table-meta.interface.d.ts +8 -0
- package/lib/models/table-row.interface.d.ts +2 -1
- package/lib/pagination/pagination.component.d.ts +24 -0
- package/lib/pagination/pagination.module.d.ts +8 -0
- package/lib/pipes/capital-case.pipe.d.ts +7 -0
- package/lib/pipes/dash-case.pipe.d.ts +3 -0
- package/lib/pipes/dynamic.pipe.d.ts +9 -0
- package/lib/pipes/highlight.pipe.d.ts +3 -0
- package/lib/pipes/sort-class.pipe.d.ts +4 -1
- package/lib/utilities/utilities.d.ts +1 -0
- package/package.json +21 -9
- package/public-api.d.ts +9 -0
- package/scss/index.scss +259 -0
- package/angular-generic-table-core.metadata.json +0 -1
- package/bundles/angular-generic-table-core.umd.js +0 -594
- package/bundles/angular-generic-table-core.umd.js.map +0 -1
- package/bundles/angular-generic-table-core.umd.min.js +0 -2
- package/bundles/angular-generic-table-core.umd.min.js.map +0 -1
- package/esm2015/angular-generic-table-core.js +0 -8
- package/esm2015/lib/core.component.js +0 -107
- package/esm2015/lib/core.module.js +0 -16
- package/esm2015/lib/core.service.js +0 -13
- package/esm2015/lib/enums/order.enum.js +0 -6
- package/esm2015/lib/models/table-column.interface.js +0 -2
- package/esm2015/lib/models/table-config.interface.js +0 -2
- package/esm2015/lib/models/table-info.interface.js +0 -2
- package/esm2015/lib/models/table-row.interface.js +0 -2
- package/esm2015/lib/models/table-sort.interface.js +0 -2
- package/esm2015/lib/pipes/dash-case.pipe.js +0 -13
- package/esm2015/lib/pipes/highlight.pipe.js +0 -44
- package/esm2015/lib/pipes/sort-class.pipe.js +0 -12
- package/esm2015/lib/utilities/utilities.js +0 -25
- package/esm2015/public-api.js +0 -7
- package/fesm2015/angular-generic-table-core.js +0 -234
- package/fesm2015/angular-generic-table-core.js.map +0 -1
|
@@ -0,0 +1,610 @@
|
|
|
1
|
+
import * as i0 from '@angular/core';
|
|
2
|
+
import { Injectable, Pipe, Injector, Component, ChangeDetectionStrategy, Input, NgModule } from '@angular/core';
|
|
3
|
+
import { ReplaySubject, Subject, isObservable, of, combineLatest, EMPTY, BehaviorSubject } from 'rxjs';
|
|
4
|
+
import { startWith, map, switchMap, shareReplay, withLatestFrom, pluck } from 'rxjs/operators';
|
|
5
|
+
import * as i1 from '@angular/common';
|
|
6
|
+
import { CommonModule } from '@angular/common';
|
|
7
|
+
|
|
8
|
+
class CoreService {
|
|
9
|
+
constructor() { }
|
|
10
|
+
}
|
|
11
|
+
CoreService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.3.11", ngImport: i0, type: CoreService, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
|
|
12
|
+
CoreService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "13.3.11", ngImport: i0, type: CoreService, providedIn: 'root' });
|
|
13
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.3.11", ngImport: i0, type: CoreService, decorators: [{
|
|
14
|
+
type: Injectable,
|
|
15
|
+
args: [{
|
|
16
|
+
providedIn: 'root',
|
|
17
|
+
}]
|
|
18
|
+
}], ctorParameters: function () { return []; } });
|
|
19
|
+
|
|
20
|
+
var Order;
|
|
21
|
+
(function (Order) {
|
|
22
|
+
Order["ASC"] = "asc";
|
|
23
|
+
Order["DESC"] = "desc";
|
|
24
|
+
})(Order || (Order = {}));
|
|
25
|
+
|
|
26
|
+
let dashed;
|
|
27
|
+
dashed = (s) => s.replace(/[A-Z]/g, (m) => '-' + m.toLowerCase());
|
|
28
|
+
let capitalize;
|
|
29
|
+
capitalize = (s) => (s.charAt(0).toUpperCase() + s.slice(1))
|
|
30
|
+
.replace(/_/g, ' ')
|
|
31
|
+
.replace(/([A-Z][a-z]+)/g, ' $1')
|
|
32
|
+
.replace(/([A-Z]{2,})/g, ' $1')
|
|
33
|
+
.replace(/\s{2,}/g, ' ')
|
|
34
|
+
.trim();
|
|
35
|
+
let chunk;
|
|
36
|
+
chunk = (array, chunkSize) => {
|
|
37
|
+
if (chunkSize < 0) {
|
|
38
|
+
throw new Error('Invalid chunk size');
|
|
39
|
+
}
|
|
40
|
+
if (chunkSize === 0 && !chunkSize) {
|
|
41
|
+
return [array];
|
|
42
|
+
}
|
|
43
|
+
const CHUNK = [];
|
|
44
|
+
for (let i = 0, len = array.length; i < len; i += chunkSize) {
|
|
45
|
+
CHUNK.push(array.slice(i, i + chunkSize));
|
|
46
|
+
}
|
|
47
|
+
return CHUNK;
|
|
48
|
+
};
|
|
49
|
+
let search;
|
|
50
|
+
search = (text, caseSensitive, data, config) => {
|
|
51
|
+
if (config.columns) {
|
|
52
|
+
const searchColumns = Object.keys(config.columns).filter(
|
|
53
|
+
// @ts-ignore
|
|
54
|
+
(key) => {
|
|
55
|
+
var _a, _b;
|
|
56
|
+
return config.columns &&
|
|
57
|
+
!((_a = config.columns[key]) === null || _a === void 0 ? void 0 : _a.hidden) &&
|
|
58
|
+
((_b = config.columns[key]) === null || _b === void 0 ? void 0 : _b.search) !== false;
|
|
59
|
+
});
|
|
60
|
+
const FILTERED = [];
|
|
61
|
+
for (let i = 0; i < data.length; i++) {
|
|
62
|
+
const row = data[i];
|
|
63
|
+
const match = Object.entries(row)
|
|
64
|
+
.filter(([key, value]) => searchColumns.indexOf(key) !== -1)
|
|
65
|
+
.reduce((acc, [key, value], index) => {
|
|
66
|
+
return (acc +
|
|
67
|
+
(index === 0 ? '' : ' ? ') +
|
|
68
|
+
(caseSensitive ? value + '' : (value + '').toLowerCase()));
|
|
69
|
+
}, '')
|
|
70
|
+
.indexOf(text) !== -1;
|
|
71
|
+
if (match) {
|
|
72
|
+
FILTERED[FILTERED.length] = row;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
return FILTERED;
|
|
76
|
+
}
|
|
77
|
+
else {
|
|
78
|
+
return data;
|
|
79
|
+
}
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
class DashCasePipe {
|
|
83
|
+
transform(s) {
|
|
84
|
+
return dashed(s);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
DashCasePipe.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.3.11", ngImport: i0, type: DashCasePipe, deps: [], target: i0.ɵɵFactoryTarget.Pipe });
|
|
88
|
+
DashCasePipe.ɵpipe = i0.ɵɵngDeclarePipe({ minVersion: "12.0.0", version: "13.3.11", ngImport: i0, type: DashCasePipe, name: "dashCase" });
|
|
89
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.3.11", ngImport: i0, type: DashCasePipe, decorators: [{
|
|
90
|
+
type: Pipe,
|
|
91
|
+
args: [{
|
|
92
|
+
name: 'dashCase',
|
|
93
|
+
}]
|
|
94
|
+
}] });
|
|
95
|
+
|
|
96
|
+
class SortClassPipe {
|
|
97
|
+
transform(selection, property, aria = false) {
|
|
98
|
+
return (selection === null || selection === void 0 ? void 0 : selection.sortBy) === property
|
|
99
|
+
? !aria
|
|
100
|
+
? 'gt-sort-' + selection.sortByOrder
|
|
101
|
+
: selection.sortByOrder + 'ending'
|
|
102
|
+
: !aria
|
|
103
|
+
? ''
|
|
104
|
+
: null;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
SortClassPipe.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.3.11", ngImport: i0, type: SortClassPipe, deps: [], target: i0.ɵɵFactoryTarget.Pipe });
|
|
108
|
+
SortClassPipe.ɵpipe = i0.ɵɵngDeclarePipe({ minVersion: "12.0.0", version: "13.3.11", ngImport: i0, type: SortClassPipe, name: "sortClass" });
|
|
109
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.3.11", ngImport: i0, type: SortClassPipe, decorators: [{
|
|
110
|
+
type: Pipe,
|
|
111
|
+
args: [{
|
|
112
|
+
name: 'sortClass',
|
|
113
|
+
}]
|
|
114
|
+
}] });
|
|
115
|
+
|
|
116
|
+
class CapitalCasePipe {
|
|
117
|
+
transform(s) {
|
|
118
|
+
return capitalize(s);
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
CapitalCasePipe.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.3.11", ngImport: i0, type: CapitalCasePipe, deps: [], target: i0.ɵɵFactoryTarget.Pipe });
|
|
122
|
+
CapitalCasePipe.ɵpipe = i0.ɵɵngDeclarePipe({ minVersion: "12.0.0", version: "13.3.11", ngImport: i0, type: CapitalCasePipe, name: "capitalCase" });
|
|
123
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.3.11", ngImport: i0, type: CapitalCasePipe, decorators: [{
|
|
124
|
+
type: Pipe,
|
|
125
|
+
args: [{
|
|
126
|
+
name: 'capitalCase',
|
|
127
|
+
}]
|
|
128
|
+
}] });
|
|
129
|
+
|
|
130
|
+
class HighlightPipe {
|
|
131
|
+
transform(text, searchTerm) {
|
|
132
|
+
if (!searchTerm) {
|
|
133
|
+
return text;
|
|
134
|
+
}
|
|
135
|
+
const haystackAlwaysString = text + '';
|
|
136
|
+
let highlightedText = haystackAlwaysString; // fallback
|
|
137
|
+
let searchPattern;
|
|
138
|
+
try {
|
|
139
|
+
searchPattern = new RegExp('(' +
|
|
140
|
+
// @ts-ignore
|
|
141
|
+
searchTerm
|
|
142
|
+
.toLowerCase()
|
|
143
|
+
.match(/".*?"|[^ ]+/g) // extract words
|
|
144
|
+
.map((needle) => needle.replace(/"(.*?)"/, '$1') // strip away '"'
|
|
145
|
+
)
|
|
146
|
+
.join('|') + // combine words
|
|
147
|
+
')', 'ig');
|
|
148
|
+
}
|
|
149
|
+
catch (error) {
|
|
150
|
+
return highlightedText;
|
|
151
|
+
}
|
|
152
|
+
const containsTagPattern = /(<.*?>)(.*)(<\/.*?>)/gi;
|
|
153
|
+
const containsTagMatches = containsTagPattern.exec(haystackAlwaysString);
|
|
154
|
+
if (containsTagMatches) {
|
|
155
|
+
// tag exists in haystack
|
|
156
|
+
highlightedText =
|
|
157
|
+
containsTagMatches[1] +
|
|
158
|
+
containsTagMatches[2].replace(searchPattern, '<span class="gt-highlight-search">$1</span>') +
|
|
159
|
+
containsTagMatches[3];
|
|
160
|
+
}
|
|
161
|
+
else {
|
|
162
|
+
highlightedText = haystackAlwaysString.replace(searchPattern, '<span class="gt-highlight-search">$1</span>');
|
|
163
|
+
}
|
|
164
|
+
return highlightedText;
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
HighlightPipe.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.3.11", ngImport: i0, type: HighlightPipe, deps: [], target: i0.ɵɵFactoryTarget.Pipe });
|
|
168
|
+
HighlightPipe.ɵpipe = i0.ɵɵngDeclarePipe({ minVersion: "12.0.0", version: "13.3.11", ngImport: i0, type: HighlightPipe, name: "highlight" });
|
|
169
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.3.11", ngImport: i0, type: HighlightPipe, decorators: [{
|
|
170
|
+
type: Pipe,
|
|
171
|
+
args: [{
|
|
172
|
+
name: 'highlight',
|
|
173
|
+
}]
|
|
174
|
+
}] });
|
|
175
|
+
|
|
176
|
+
class DynamicPipe {
|
|
177
|
+
constructor(injector) {
|
|
178
|
+
this.injector = injector;
|
|
179
|
+
}
|
|
180
|
+
transform(value, requiredPipe, pipeArgs) {
|
|
181
|
+
const injector = Injector.create({
|
|
182
|
+
name: 'DynamicPipe',
|
|
183
|
+
parent: this.injector,
|
|
184
|
+
providers: [{ provide: requiredPipe }],
|
|
185
|
+
});
|
|
186
|
+
const pipe = injector.get(requiredPipe);
|
|
187
|
+
return pipe.transform(value, ...(pipeArgs || []));
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
DynamicPipe.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.3.11", ngImport: i0, type: DynamicPipe, deps: [{ token: i0.Injector }], target: i0.ɵɵFactoryTarget.Pipe });
|
|
191
|
+
DynamicPipe.ɵpipe = i0.ɵɵngDeclarePipe({ minVersion: "12.0.0", version: "13.3.11", ngImport: i0, type: DynamicPipe, name: "dynamicPipe" });
|
|
192
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.3.11", ngImport: i0, type: DynamicPipe, decorators: [{
|
|
193
|
+
type: Pipe,
|
|
194
|
+
args: [{
|
|
195
|
+
name: 'dynamicPipe',
|
|
196
|
+
}]
|
|
197
|
+
}], ctorParameters: function () { return [{ type: i0.Injector }]; } });
|
|
198
|
+
|
|
199
|
+
class CoreComponent {
|
|
200
|
+
constructor() {
|
|
201
|
+
this._loading$ = new ReplaySubject(1);
|
|
202
|
+
this.sortBy$ = new Subject();
|
|
203
|
+
// tslint:disable-next-line:variable-name
|
|
204
|
+
this._searchBy$ = new ReplaySubject(1);
|
|
205
|
+
this.searchBy$ = this._searchBy$.pipe(startWith(''), map((value) => (isObservable(value) ? value : of(value))), switchMap((obs) => obs), shareReplay(1));
|
|
206
|
+
// tslint:disable-next-line:variable-name
|
|
207
|
+
this._tableConfig$ = new ReplaySubject(1);
|
|
208
|
+
this.tableConfig$ = this._tableConfig$.pipe(map((value) => (isObservable(value) ? value : of(value))), switchMap((obs) => obs), shareReplay(1));
|
|
209
|
+
this._data$ = new ReplaySubject(1);
|
|
210
|
+
this.data$ = this._data$.pipe(map((value) => (isObservable(value) ? value : of(value))), switchMap((obs) => combineLatest([obs])), withLatestFrom(this.tableConfig$), map(([[data], config]) => {
|
|
211
|
+
// if columns or rows contains config for mapTo...
|
|
212
|
+
if ((config.columns &&
|
|
213
|
+
!!Object.values(config.columns).find((column) => !!column.mapTo)) ||
|
|
214
|
+
(config.rows &&
|
|
215
|
+
!!Object.values(config.rows).find((column) => !!column.mapTo))) {
|
|
216
|
+
// ...map data to new keys on row...
|
|
217
|
+
data = data.map((row) => {
|
|
218
|
+
const newKeys = Object.entries(config.columns || config.rows || [])
|
|
219
|
+
.filter(([key, value]) => !!value.mapTo) // add keys for columns with mapTo config...
|
|
220
|
+
.reduce((previousValue, currentValue) => {
|
|
221
|
+
var _a;
|
|
222
|
+
return (Object.assign(Object.assign({}, previousValue), {
|
|
223
|
+
// tslint:disable-next-line:no-non-null-assertion
|
|
224
|
+
[currentValue[0]]: this.nestedValue(row, currentValue[1].mapTo.path, (_a = currentValue[1].mapTo) === null || _a === void 0 ? void 0 : _a.missingValue) }));
|
|
225
|
+
}, {});
|
|
226
|
+
return Object.assign(Object.assign({}, row), newKeys);
|
|
227
|
+
});
|
|
228
|
+
}
|
|
229
|
+
return { data, config };
|
|
230
|
+
}), switchMap((obs) => combineLatest([
|
|
231
|
+
of(obs),
|
|
232
|
+
this.sortBy$.pipe(startWith(EMPTY)),
|
|
233
|
+
this.searchBy$,
|
|
234
|
+
])), map(([table, sortBy, searchBy]) => {
|
|
235
|
+
var _a;
|
|
236
|
+
// create a new array reference and sort new array (prevent mutating existing state)
|
|
237
|
+
table.data = [...table.data];
|
|
238
|
+
return !sortBy
|
|
239
|
+
? searchBy
|
|
240
|
+
? search(searchBy, false, table.data, table.config)
|
|
241
|
+
: table.data
|
|
242
|
+
: (_a = (searchBy
|
|
243
|
+
? search(searchBy, false, table.data, table.config)
|
|
244
|
+
: table.data)) === null || _a === void 0 ? void 0 : _a.sort((a, b) => {
|
|
245
|
+
// TODO: improve logic
|
|
246
|
+
const typed = sortBy;
|
|
247
|
+
return a[typed.sortBy] > b[typed.sortBy]
|
|
248
|
+
? typed.sortByOrder === Order.ASC
|
|
249
|
+
? 1
|
|
250
|
+
: -1
|
|
251
|
+
: b[typed.sortBy] > a[typed.sortBy]
|
|
252
|
+
? typed.sortByOrder === Order.ASC
|
|
253
|
+
? -1
|
|
254
|
+
: 1
|
|
255
|
+
: 0;
|
|
256
|
+
});
|
|
257
|
+
}), shareReplay(1));
|
|
258
|
+
this.table$ = combineLatest([
|
|
259
|
+
this.data$,
|
|
260
|
+
this.tableConfig$,
|
|
261
|
+
]).pipe(map(([sorted, config]) => {
|
|
262
|
+
// if pagination is disabled...
|
|
263
|
+
if (!config.pagination || config.pagination.length === 0) {
|
|
264
|
+
// ...return unaltered array
|
|
265
|
+
return {
|
|
266
|
+
data: [sorted],
|
|
267
|
+
config,
|
|
268
|
+
info: { records: sorted.length, pageTotal: 1 },
|
|
269
|
+
};
|
|
270
|
+
}
|
|
271
|
+
// return record set
|
|
272
|
+
return {
|
|
273
|
+
data: chunk(sorted, +(config.pagination.length || 0)),
|
|
274
|
+
config,
|
|
275
|
+
info: {
|
|
276
|
+
records: sorted.length,
|
|
277
|
+
pageTotal: Math.ceil(sorted.length / +(config.pagination.length || 0)),
|
|
278
|
+
},
|
|
279
|
+
};
|
|
280
|
+
}), shareReplay(1));
|
|
281
|
+
this._currentPage$ = new BehaviorSubject(0);
|
|
282
|
+
this.currentPage$ = combineLatest([this._currentPage$, this.table$]).pipe(map(([page, table]) => {
|
|
283
|
+
var _a, _b;
|
|
284
|
+
// determine last page
|
|
285
|
+
const lastPage = Math.ceil(table.info.records /
|
|
286
|
+
(((_b = (_a = table.config) === null || _a === void 0 ? void 0 : _a.pagination) === null || _b === void 0 ? void 0 : _b.length) || table.info.records)) - 1;
|
|
287
|
+
// determine max/min position
|
|
288
|
+
return +page < 0 ? 0 : +page > lastPage ? lastPage : +page;
|
|
289
|
+
}), shareReplay(1));
|
|
290
|
+
this.colspan$ = this.tableConfig$.pipe(switchMap((config) => config.columns
|
|
291
|
+
? of(Object.values(config.columns || config.rows || {}).filter((value) => value.hidden !== true).length)
|
|
292
|
+
: this.data$.pipe(map((data) => data.length + 1))));
|
|
293
|
+
this.columnOrder = (a, b) => {
|
|
294
|
+
return (a.value.order || 0) - (b.value.order || 0);
|
|
295
|
+
};
|
|
296
|
+
}
|
|
297
|
+
set loading(isLoading) {
|
|
298
|
+
this._loading$.next(isLoading);
|
|
299
|
+
}
|
|
300
|
+
set page(page) {
|
|
301
|
+
this._currentPage$.next(page);
|
|
302
|
+
}
|
|
303
|
+
set search(string) {
|
|
304
|
+
this._searchBy$.next(string);
|
|
305
|
+
}
|
|
306
|
+
set config(config) {
|
|
307
|
+
this._tableConfig$.next(config);
|
|
308
|
+
}
|
|
309
|
+
set data(data) {
|
|
310
|
+
this._data$.next(data);
|
|
311
|
+
}
|
|
312
|
+
get loading$() {
|
|
313
|
+
return this._loading$.pipe(startWith(false), map((value) => (isObservable(value) ? value : of(value))), switchMap((obs) => obs), shareReplay(1));
|
|
314
|
+
}
|
|
315
|
+
sort(property) {
|
|
316
|
+
var _a, _b;
|
|
317
|
+
const newSortOrder = ((_a = this._sortBy) === null || _a === void 0 ? void 0 : _a.sortBy) !== property ||
|
|
318
|
+
((_b = this._sortBy) === null || _b === void 0 ? void 0 : _b.sortByOrder) === Order.DESC ||
|
|
319
|
+
!this._sortBy.sortByOrder
|
|
320
|
+
? Order.ASC
|
|
321
|
+
: Order.DESC;
|
|
322
|
+
const newSortBy = {
|
|
323
|
+
sortBy: property,
|
|
324
|
+
sortByOrder: newSortOrder,
|
|
325
|
+
};
|
|
326
|
+
this.sortBy$.next(newSortBy);
|
|
327
|
+
this._sortBy = newSortBy;
|
|
328
|
+
}
|
|
329
|
+
nestedValue(object, mapTo, missingValue = null) {
|
|
330
|
+
const levels = mapTo.split('.');
|
|
331
|
+
return levels.reduce((previousValue, currentValue, index) => previousValue[currentValue] ||
|
|
332
|
+
(index === levels.length - 1 ? missingValue : {}), object);
|
|
333
|
+
}
|
|
334
|
+
}
|
|
335
|
+
CoreComponent.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.3.11", ngImport: i0, type: CoreComponent, deps: [], target: i0.ɵɵFactoryTarget.Component });
|
|
336
|
+
CoreComponent.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "12.0.0", version: "13.3.11", type: CoreComponent, selector: "angular-generic-table", inputs: { loading: "loading", page: "page", search: "search", config: "config", data: "data" }, ngImport: i0, template: "<table\n [ngClass]=\"(tableConfig$ | async)?.class || 'table'\"\n [class.table-mobile]=\"(tableConfig$ | async)?.mobileLayout\"\n [class.table-horizontal]=\"(tableConfig$ | async)?.rows\"\n [class.table-loading]=\"loading$ | async\"\n [class.gt-sticky-row-header]=\"\n (tableConfig$ | async)?.stickyHeaders?.row && (tableConfig$ | async)?.rows\n \"\n [class.gt-sticky-column-header]=\"\n (tableConfig$ | async)?.stickyHeaders?.column\n \"\n [attr.aria-busy]=\"(loading$ | async) === true ? true : null\"\n>\n <thead>\n <tr\n *ngIf=\"{\n config: (tableConfig$ | async)!,\n isLoading: loading$ | async\n } as table\"\n >\n <ng-container\n *ngFor=\"let column of table?.config?.columns | keyvalue: columnOrder\"\n >\n <th\n *ngIf=\"!column.value?.hidden\"\n ngClass=\"{{ (column.key | dashCase) + '-column' }} {{\n column.value.class\n }}\"\n [class.disabled]=\"table.isLoading\"\n [attr.aria-sort]=\"sortBy$ | async | sortClass: column.key:true\"\n [class.gt-sortable]=\"true\"\n scope=\"col\"\n >\n <button\n *ngIf=\"column.value?.sortable\"\n class=\"gt-sort\"\n (click)=\"\n table.isLoading || !column.value?.sortable || sort(column.key)\n \"\n >\n <span *ngIf=\"column.value?.header !== false\">{{\n column.value?.header || column.key | capitalCase\n }}</span>\n </button>\n <span\n *ngIf=\"!column.value?.sortable && column.value?.header !== false\"\n >{{ column.value?.header || column.key | capitalCase }}</span\n >\n </th>\n </ng-container>\n <ng-container\n *ngIf=\"\n ((table?.config?.rows | keyvalue: columnOrder) || [])[0] as headerRow\n \"\n >\n <th\n class=\"row-header\"\n [attr.aria-sort]=\"sortBy$ | async | sortClass: headerRow.key:true\"\n ngClass=\"{{ headerRow.value?.sortable ? 'sort ' : '' }} {{\n sortBy$ | async | sortClass: headerRow.key\n }} {{ (headerRow.key | dashCase) + '-column' }}\"\n (click)=\"\n table.isLoading || !headerRow.value?.sortable || sort(headerRow.key)\n \"\n scope=\"col\"\n >\n <ng-container *ngIf=\"headerRow?.value?.header !== false\">{{\n headerRow?.value?.header || headerRow.key | capitalCase\n }}</ng-container>\n </th>\n <th\n *ngFor=\"let column of ((table$ | async)?.data || [])[0]\"\n ngClass=\"{{ headerRow.value?.class }}\"\n >\n <ng-container\n [ngTemplateOutlet]=\"\n (table.config?.rows || {})[headerRow.key].templateRef\n ? templateRef\n : (table.config?.rows || {})[headerRow.key].transform\n ? transformData\n : rawData\n \"\n [ngTemplateOutletContext]=\"{\n row: column,\n column: headerRow,\n transform: (table.config?.rows || {})[headerRow.key].transform,\n templateRef: (table.config?.rows || {})[headerRow.key]\n .templateRef,\n index: 0\n }\"\n >\n </ng-container>\n </th>\n </ng-container>\n </tr>\n </thead>\n <tbody *ngIf=\"loading$ | async; else tableContent\">\n <tr>\n <td class=\"p-0\" [colSpan]=\"colspan$ | async\">\n <ng-content select=\".table-loading\"></ng-content>\n </td>\n </tr>\n </tbody>\n</table>\n<ng-template #tableContent>\n <ng-container *ngIf=\"(table$ | async)! as table\">\n <tbody *ngIf=\"(table!.data![0] || table!.data!).length > 0; else noData\">\n <ng-container *ngIf=\"table.config.columns\">\n <tr\n *ngFor=\"\n let row of table!.data![(currentPage$ | async) || 0];\n let i = index\n \"\n [attr.id]=\"'tableRow_' + i\"\n >\n <ng-container\n *ngFor=\"let column of table.config?.columns | keyvalue: columnOrder\"\n >\n <td\n *ngIf=\"!column.value?.hidden\"\n ngClass=\"{{ (column.key | dashCase) + '-column' }} {{\n column.value?.class\n }}\"\n [attr.data-label]=\"\n table.config?.mobileLayout && column.value?.mobileHeader\n ? column.value?.mobileHeader !== true\n ? column.value?.mobileHeader\n : (column.value?.header || column.key | capitalCase)\n : null\n \"\n >\n <ng-container\n [ngTemplateOutlet]=\"\n (searchBy$ | async) &&\n !(table.config?.columns || {})[column.key].templateRef\n ? highlighted\n : (table.config?.columns || {})[column.key].templateRef\n ? templateRef\n : (table.config?.columns || {})[column.key].transform\n ? transformData\n : rawData\n \"\n [ngTemplateOutletContext]=\"{\n row: row,\n column: column,\n search: (searchBy$ | async),\n transform: (table.config?.columns || {})[column.key]\n .transform,\n templateRef: (table.config?.columns || {})[column.key]\n .templateRef,\n index: i,\n data: table.data[(currentPage$ | async) || 0]\n }\"\n ></ng-container>\n </td>\n </ng-container>\n </tr>\n </ng-container>\n <ng-container *ngIf=\"table.config.rows\">\n <ng-container\n *ngFor=\"\n let row of table?.config?.rows | keyvalue: columnOrder | slice: 1;\n let i = index\n \"\n >\n <tr\n *ngIf=\"!row.value?.hidden\"\n [attr.id]=\"'tableRow_' + i\"\n ngClass=\"{{ (row.key | dashCase) + '-row' }}\"\n >\n <th class=\"row-header\" scope=\"row\">\n {{ row.value?.header || row.key | capitalCase }}\n </th>\n <td\n *ngFor=\"let column of (table?.data || [])[0]; let y = index\"\n ngClass=\"{{ row.value?.class }}\"\n >\n <ng-container\n [ngTemplateOutlet]=\"\n (table.config?.rows || {})[row.key].templateRef\n ? templateRef\n : (table.config?.rows || {})[row.key].transform\n ? transformData\n : rawData\n \"\n [ngTemplateOutletContext]=\"{\n row: column,\n column: row,\n transform: (table.config?.rows || {})[row.key].transform,\n templateRef: (table.config?.rows || {})[row.key].templateRef,\n index: table.config?.rows ? y : i,\n data: table.data[(currentPage$ | async) || 0]\n }\"\n >\n </ng-container>\n </td>\n </tr>\n </ng-container>\n </ng-container>\n </tbody>\n </ng-container>\n</ng-template>\n<ng-template #noData>\n <tbody>\n <tr>\n <td class=\"p-0\" [colSpan]=\"colspan$ | async\">\n <ng-content select=\".table-no-data\"></ng-content>\n </td>\n </tr>\n </tbody>\n</ng-template>\n<ng-template #highlighted let-row=\"row\" let-column=\"column\" let-search=\"search\">\n <div [innerHTML]=\"row[column.key] | highlight: search\"></div>\n</ng-template>\n<ng-template #rawData let-row=\"row\" let-column=\"column\">\n {{ row[column.key] }}\n</ng-template>\n<ng-template\n #transformData\n let-row=\"row\"\n let-column=\"column\"\n let-transform=\"transform\"\n let-data=\"data\"\n>\n {{ row[column.key] | dynamicPipe: transform.pipe:transform?.args }}\n</ng-template>\n<ng-template\n #templateRef\n let-row=\"row\"\n let-column=\"column\"\n let-index=\"index\"\n let-templateRef=\"templateRef\"\n let-data=\"data\"\n>\n <ng-container\n [ngTemplateOutlet]=\"templateRef\"\n [ngTemplateOutletContext]=\"{\n row: row,\n col: column,\n index: index,\n data: data\n }\"\n ></ng-container>\n</ng-template>\n", directives: [{ type: i1.NgClass, selector: "[ngClass]", inputs: ["class", "ngClass"] }, { type: i1.NgIf, selector: "[ngIf]", inputs: ["ngIf", "ngIfThen", "ngIfElse"] }, { type: i1.NgForOf, selector: "[ngFor][ngForOf]", inputs: ["ngForOf", "ngForTrackBy", "ngForTemplate"] }, { type: i1.NgTemplateOutlet, selector: "[ngTemplateOutlet]", inputs: ["ngTemplateOutletContext", "ngTemplateOutlet"] }], pipes: { "async": i1.AsyncPipe, "keyvalue": i1.KeyValuePipe, "dashCase": DashCasePipe, "sortClass": SortClassPipe, "capitalCase": CapitalCasePipe, "slice": i1.SlicePipe, "highlight": HighlightPipe, "dynamicPipe": DynamicPipe }, changeDetection: i0.ChangeDetectionStrategy.OnPush });
|
|
337
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.3.11", ngImport: i0, type: CoreComponent, decorators: [{
|
|
338
|
+
type: Component,
|
|
339
|
+
args: [{ selector: 'angular-generic-table', styles: [], changeDetection: ChangeDetectionStrategy.OnPush, template: "<table\n [ngClass]=\"(tableConfig$ | async)?.class || 'table'\"\n [class.table-mobile]=\"(tableConfig$ | async)?.mobileLayout\"\n [class.table-horizontal]=\"(tableConfig$ | async)?.rows\"\n [class.table-loading]=\"loading$ | async\"\n [class.gt-sticky-row-header]=\"\n (tableConfig$ | async)?.stickyHeaders?.row && (tableConfig$ | async)?.rows\n \"\n [class.gt-sticky-column-header]=\"\n (tableConfig$ | async)?.stickyHeaders?.column\n \"\n [attr.aria-busy]=\"(loading$ | async) === true ? true : null\"\n>\n <thead>\n <tr\n *ngIf=\"{\n config: (tableConfig$ | async)!,\n isLoading: loading$ | async\n } as table\"\n >\n <ng-container\n *ngFor=\"let column of table?.config?.columns | keyvalue: columnOrder\"\n >\n <th\n *ngIf=\"!column.value?.hidden\"\n ngClass=\"{{ (column.key | dashCase) + '-column' }} {{\n column.value.class\n }}\"\n [class.disabled]=\"table.isLoading\"\n [attr.aria-sort]=\"sortBy$ | async | sortClass: column.key:true\"\n [class.gt-sortable]=\"true\"\n scope=\"col\"\n >\n <button\n *ngIf=\"column.value?.sortable\"\n class=\"gt-sort\"\n (click)=\"\n table.isLoading || !column.value?.sortable || sort(column.key)\n \"\n >\n <span *ngIf=\"column.value?.header !== false\">{{\n column.value?.header || column.key | capitalCase\n }}</span>\n </button>\n <span\n *ngIf=\"!column.value?.sortable && column.value?.header !== false\"\n >{{ column.value?.header || column.key | capitalCase }}</span\n >\n </th>\n </ng-container>\n <ng-container\n *ngIf=\"\n ((table?.config?.rows | keyvalue: columnOrder) || [])[0] as headerRow\n \"\n >\n <th\n class=\"row-header\"\n [attr.aria-sort]=\"sortBy$ | async | sortClass: headerRow.key:true\"\n ngClass=\"{{ headerRow.value?.sortable ? 'sort ' : '' }} {{\n sortBy$ | async | sortClass: headerRow.key\n }} {{ (headerRow.key | dashCase) + '-column' }}\"\n (click)=\"\n table.isLoading || !headerRow.value?.sortable || sort(headerRow.key)\n \"\n scope=\"col\"\n >\n <ng-container *ngIf=\"headerRow?.value?.header !== false\">{{\n headerRow?.value?.header || headerRow.key | capitalCase\n }}</ng-container>\n </th>\n <th\n *ngFor=\"let column of ((table$ | async)?.data || [])[0]\"\n ngClass=\"{{ headerRow.value?.class }}\"\n >\n <ng-container\n [ngTemplateOutlet]=\"\n (table.config?.rows || {})[headerRow.key].templateRef\n ? templateRef\n : (table.config?.rows || {})[headerRow.key].transform\n ? transformData\n : rawData\n \"\n [ngTemplateOutletContext]=\"{\n row: column,\n column: headerRow,\n transform: (table.config?.rows || {})[headerRow.key].transform,\n templateRef: (table.config?.rows || {})[headerRow.key]\n .templateRef,\n index: 0\n }\"\n >\n </ng-container>\n </th>\n </ng-container>\n </tr>\n </thead>\n <tbody *ngIf=\"loading$ | async; else tableContent\">\n <tr>\n <td class=\"p-0\" [colSpan]=\"colspan$ | async\">\n <ng-content select=\".table-loading\"></ng-content>\n </td>\n </tr>\n </tbody>\n</table>\n<ng-template #tableContent>\n <ng-container *ngIf=\"(table$ | async)! as table\">\n <tbody *ngIf=\"(table!.data![0] || table!.data!).length > 0; else noData\">\n <ng-container *ngIf=\"table.config.columns\">\n <tr\n *ngFor=\"\n let row of table!.data![(currentPage$ | async) || 0];\n let i = index\n \"\n [attr.id]=\"'tableRow_' + i\"\n >\n <ng-container\n *ngFor=\"let column of table.config?.columns | keyvalue: columnOrder\"\n >\n <td\n *ngIf=\"!column.value?.hidden\"\n ngClass=\"{{ (column.key | dashCase) + '-column' }} {{\n column.value?.class\n }}\"\n [attr.data-label]=\"\n table.config?.mobileLayout && column.value?.mobileHeader\n ? column.value?.mobileHeader !== true\n ? column.value?.mobileHeader\n : (column.value?.header || column.key | capitalCase)\n : null\n \"\n >\n <ng-container\n [ngTemplateOutlet]=\"\n (searchBy$ | async) &&\n !(table.config?.columns || {})[column.key].templateRef\n ? highlighted\n : (table.config?.columns || {})[column.key].templateRef\n ? templateRef\n : (table.config?.columns || {})[column.key].transform\n ? transformData\n : rawData\n \"\n [ngTemplateOutletContext]=\"{\n row: row,\n column: column,\n search: (searchBy$ | async),\n transform: (table.config?.columns || {})[column.key]\n .transform,\n templateRef: (table.config?.columns || {})[column.key]\n .templateRef,\n index: i,\n data: table.data[(currentPage$ | async) || 0]\n }\"\n ></ng-container>\n </td>\n </ng-container>\n </tr>\n </ng-container>\n <ng-container *ngIf=\"table.config.rows\">\n <ng-container\n *ngFor=\"\n let row of table?.config?.rows | keyvalue: columnOrder | slice: 1;\n let i = index\n \"\n >\n <tr\n *ngIf=\"!row.value?.hidden\"\n [attr.id]=\"'tableRow_' + i\"\n ngClass=\"{{ (row.key | dashCase) + '-row' }}\"\n >\n <th class=\"row-header\" scope=\"row\">\n {{ row.value?.header || row.key | capitalCase }}\n </th>\n <td\n *ngFor=\"let column of (table?.data || [])[0]; let y = index\"\n ngClass=\"{{ row.value?.class }}\"\n >\n <ng-container\n [ngTemplateOutlet]=\"\n (table.config?.rows || {})[row.key].templateRef\n ? templateRef\n : (table.config?.rows || {})[row.key].transform\n ? transformData\n : rawData\n \"\n [ngTemplateOutletContext]=\"{\n row: column,\n column: row,\n transform: (table.config?.rows || {})[row.key].transform,\n templateRef: (table.config?.rows || {})[row.key].templateRef,\n index: table.config?.rows ? y : i,\n data: table.data[(currentPage$ | async) || 0]\n }\"\n >\n </ng-container>\n </td>\n </tr>\n </ng-container>\n </ng-container>\n </tbody>\n </ng-container>\n</ng-template>\n<ng-template #noData>\n <tbody>\n <tr>\n <td class=\"p-0\" [colSpan]=\"colspan$ | async\">\n <ng-content select=\".table-no-data\"></ng-content>\n </td>\n </tr>\n </tbody>\n</ng-template>\n<ng-template #highlighted let-row=\"row\" let-column=\"column\" let-search=\"search\">\n <div [innerHTML]=\"row[column.key] | highlight: search\"></div>\n</ng-template>\n<ng-template #rawData let-row=\"row\" let-column=\"column\">\n {{ row[column.key] }}\n</ng-template>\n<ng-template\n #transformData\n let-row=\"row\"\n let-column=\"column\"\n let-transform=\"transform\"\n let-data=\"data\"\n>\n {{ row[column.key] | dynamicPipe: transform.pipe:transform?.args }}\n</ng-template>\n<ng-template\n #templateRef\n let-row=\"row\"\n let-column=\"column\"\n let-index=\"index\"\n let-templateRef=\"templateRef\"\n let-data=\"data\"\n>\n <ng-container\n [ngTemplateOutlet]=\"templateRef\"\n [ngTemplateOutletContext]=\"{\n row: row,\n col: column,\n index: index,\n data: data\n }\"\n ></ng-container>\n</ng-template>\n" }]
|
|
340
|
+
}], propDecorators: { loading: [{
|
|
341
|
+
type: Input
|
|
342
|
+
}], page: [{
|
|
343
|
+
type: Input
|
|
344
|
+
}], search: [{
|
|
345
|
+
type: Input
|
|
346
|
+
}], config: [{
|
|
347
|
+
type: Input
|
|
348
|
+
}], data: [{
|
|
349
|
+
type: Input
|
|
350
|
+
}] } });
|
|
351
|
+
|
|
352
|
+
class GtDeltaComponent {
|
|
353
|
+
constructor() {
|
|
354
|
+
this.Math = Math;
|
|
355
|
+
this.Number = Number;
|
|
356
|
+
this.data = [];
|
|
357
|
+
this.index = 0;
|
|
358
|
+
this.classes = {
|
|
359
|
+
span: 'gt-delta',
|
|
360
|
+
positive: 'text-success',
|
|
361
|
+
negative: 'text-danger',
|
|
362
|
+
};
|
|
363
|
+
this.key = 'value';
|
|
364
|
+
this.notApplicableValue = 'n/a';
|
|
365
|
+
this.initialValue = '-';
|
|
366
|
+
}
|
|
367
|
+
}
|
|
368
|
+
GtDeltaComponent.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.3.11", ngImport: i0, type: GtDeltaComponent, deps: [], target: i0.ɵɵFactoryTarget.Component });
|
|
369
|
+
GtDeltaComponent.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "12.0.0", version: "13.3.11", type: GtDeltaComponent, selector: "gt-delta", inputs: { data: "data", index: "index", baseIndex: "baseIndex", classes: "classes", key: "key", notApplicableValue: "notApplicableValue", initialValue: "initialValue" }, ngImport: i0, template: `<span
|
|
370
|
+
*ngIf="{
|
|
371
|
+
value:
|
|
372
|
+
index === 0
|
|
373
|
+
? initialValue
|
|
374
|
+
: ((baseIndex === undefined
|
|
375
|
+
? data[index - 1][key]
|
|
376
|
+
: data[baseIndex][key]) -
|
|
377
|
+
data[index][key]) /
|
|
378
|
+
-Math.abs(
|
|
379
|
+
baseIndex === undefined
|
|
380
|
+
? data[index - 1][key]
|
|
381
|
+
: data[baseIndex][key]
|
|
382
|
+
)
|
|
383
|
+
} as delta"
|
|
384
|
+
[class]="[
|
|
385
|
+
classes.span,
|
|
386
|
+
!delta.value || !Number.isFinite(delta.value)
|
|
387
|
+
? null
|
|
388
|
+
: delta.value > 0
|
|
389
|
+
? classes.positive
|
|
390
|
+
: classes.negative
|
|
391
|
+
]"
|
|
392
|
+
[class.gt-delta-positive]="delta.value > 0 && Number.isFinite(delta.value)"
|
|
393
|
+
[class.gt-delta-negative]="delta.value < 0"
|
|
394
|
+
>{{
|
|
395
|
+
Number.isFinite(delta.value)
|
|
396
|
+
? (delta.value | percent)
|
|
397
|
+
: delta.value === initialValue
|
|
398
|
+
? initialValue
|
|
399
|
+
: notApplicableValue
|
|
400
|
+
}}</span
|
|
401
|
+
>`, isInline: true, styles: [":host{display:inline-block}\n"], directives: [{ type: i1.NgIf, selector: "[ngIf]", inputs: ["ngIf", "ngIfThen", "ngIfElse"] }], pipes: { "percent": i1.PercentPipe }, changeDetection: i0.ChangeDetectionStrategy.OnPush });
|
|
402
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.3.11", ngImport: i0, type: GtDeltaComponent, decorators: [{
|
|
403
|
+
type: Component,
|
|
404
|
+
args: [{
|
|
405
|
+
selector: 'gt-delta',
|
|
406
|
+
template: `<span
|
|
407
|
+
*ngIf="{
|
|
408
|
+
value:
|
|
409
|
+
index === 0
|
|
410
|
+
? initialValue
|
|
411
|
+
: ((baseIndex === undefined
|
|
412
|
+
? data[index - 1][key]
|
|
413
|
+
: data[baseIndex][key]) -
|
|
414
|
+
data[index][key]) /
|
|
415
|
+
-Math.abs(
|
|
416
|
+
baseIndex === undefined
|
|
417
|
+
? data[index - 1][key]
|
|
418
|
+
: data[baseIndex][key]
|
|
419
|
+
)
|
|
420
|
+
} as delta"
|
|
421
|
+
[class]="[
|
|
422
|
+
classes.span,
|
|
423
|
+
!delta.value || !Number.isFinite(delta.value)
|
|
424
|
+
? null
|
|
425
|
+
: delta.value > 0
|
|
426
|
+
? classes.positive
|
|
427
|
+
: classes.negative
|
|
428
|
+
]"
|
|
429
|
+
[class.gt-delta-positive]="delta.value > 0 && Number.isFinite(delta.value)"
|
|
430
|
+
[class.gt-delta-negative]="delta.value < 0"
|
|
431
|
+
>{{
|
|
432
|
+
Number.isFinite(delta.value)
|
|
433
|
+
? (delta.value | percent)
|
|
434
|
+
: delta.value === initialValue
|
|
435
|
+
? initialValue
|
|
436
|
+
: notApplicableValue
|
|
437
|
+
}}</span
|
|
438
|
+
>`,
|
|
439
|
+
styles: [
|
|
440
|
+
`
|
|
441
|
+
:host {
|
|
442
|
+
display: inline-block;
|
|
443
|
+
}
|
|
444
|
+
`,
|
|
445
|
+
],
|
|
446
|
+
changeDetection: ChangeDetectionStrategy.OnPush,
|
|
447
|
+
}]
|
|
448
|
+
}], ctorParameters: function () { return []; }, propDecorators: { data: [{
|
|
449
|
+
type: Input
|
|
450
|
+
}], index: [{
|
|
451
|
+
type: Input
|
|
452
|
+
}], baseIndex: [{
|
|
453
|
+
type: Input
|
|
454
|
+
}], classes: [{
|
|
455
|
+
type: Input
|
|
456
|
+
}], key: [{
|
|
457
|
+
type: Input
|
|
458
|
+
}], notApplicableValue: [{
|
|
459
|
+
type: Input
|
|
460
|
+
}], initialValue: [{
|
|
461
|
+
type: Input
|
|
462
|
+
}] } });
|
|
463
|
+
|
|
464
|
+
class GenericTableCoreModule {
|
|
465
|
+
}
|
|
466
|
+
GenericTableCoreModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.3.11", ngImport: i0, type: GenericTableCoreModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
|
|
467
|
+
GenericTableCoreModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "12.0.0", version: "13.3.11", ngImport: i0, type: GenericTableCoreModule, declarations: [CoreComponent,
|
|
468
|
+
SortClassPipe,
|
|
469
|
+
DashCasePipe,
|
|
470
|
+
HighlightPipe,
|
|
471
|
+
CapitalCasePipe,
|
|
472
|
+
CapitalCasePipe,
|
|
473
|
+
DynamicPipe,
|
|
474
|
+
GtDeltaComponent], imports: [CommonModule], exports: [CoreComponent, GtDeltaComponent] });
|
|
475
|
+
GenericTableCoreModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "13.3.11", ngImport: i0, type: GenericTableCoreModule, imports: [[CommonModule]] });
|
|
476
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.3.11", ngImport: i0, type: GenericTableCoreModule, decorators: [{
|
|
477
|
+
type: NgModule,
|
|
478
|
+
args: [{
|
|
479
|
+
declarations: [
|
|
480
|
+
CoreComponent,
|
|
481
|
+
SortClassPipe,
|
|
482
|
+
DashCasePipe,
|
|
483
|
+
HighlightPipe,
|
|
484
|
+
CapitalCasePipe,
|
|
485
|
+
CapitalCasePipe,
|
|
486
|
+
DynamicPipe,
|
|
487
|
+
GtDeltaComponent,
|
|
488
|
+
],
|
|
489
|
+
imports: [CommonModule],
|
|
490
|
+
exports: [CoreComponent, GtDeltaComponent],
|
|
491
|
+
}]
|
|
492
|
+
}] });
|
|
493
|
+
|
|
494
|
+
class PaginationComponent {
|
|
495
|
+
constructor() {
|
|
496
|
+
this.table$ = new ReplaySubject(1);
|
|
497
|
+
this._ariaLabels = {
|
|
498
|
+
nav: 'Table pagination',
|
|
499
|
+
button: 'Go to page ',
|
|
500
|
+
};
|
|
501
|
+
this._classes = {
|
|
502
|
+
ul: 'pagination',
|
|
503
|
+
li: 'page-item',
|
|
504
|
+
button: 'page-link',
|
|
505
|
+
};
|
|
506
|
+
this._paginationLength = 5;
|
|
507
|
+
this.pagination$ = this.table$.pipe(switchMap((core) => combineLatest([core === null || core === void 0 ? void 0 : core.table$.pipe(pluck('info')), core === null || core === void 0 ? void 0 : core.currentPage$])), map(([info, currentPage]) => this.generateList(info.pageTotal, currentPage)));
|
|
508
|
+
}
|
|
509
|
+
get paginationLength() {
|
|
510
|
+
return this._paginationLength;
|
|
511
|
+
}
|
|
512
|
+
set paginationLength(value) {
|
|
513
|
+
this._paginationLength = +value;
|
|
514
|
+
}
|
|
515
|
+
get classes() {
|
|
516
|
+
return this._classes;
|
|
517
|
+
}
|
|
518
|
+
set classes(value) {
|
|
519
|
+
this._classes = value;
|
|
520
|
+
}
|
|
521
|
+
get ariaLabels() {
|
|
522
|
+
return this._ariaLabels;
|
|
523
|
+
}
|
|
524
|
+
set ariaLabels(value) {
|
|
525
|
+
this._ariaLabels = value;
|
|
526
|
+
}
|
|
527
|
+
get table() {
|
|
528
|
+
return this._table;
|
|
529
|
+
}
|
|
530
|
+
set table(value) {
|
|
531
|
+
this._table = value;
|
|
532
|
+
this.table$.next(value);
|
|
533
|
+
}
|
|
534
|
+
generateList(pages, currentPosition) {
|
|
535
|
+
const middle = Math.floor(this.paginationLength / 2);
|
|
536
|
+
const length = pages < this.paginationLength ? pages : this.paginationLength;
|
|
537
|
+
return Array.from({ length }, (_, i) => {
|
|
538
|
+
if (i === 0) {
|
|
539
|
+
return 1;
|
|
540
|
+
}
|
|
541
|
+
else if (pages < this.paginationLength) {
|
|
542
|
+
return i + 1;
|
|
543
|
+
}
|
|
544
|
+
else if (i + 1 === length) {
|
|
545
|
+
return pages;
|
|
546
|
+
}
|
|
547
|
+
else if (currentPosition > middle && currentPosition < pages - middle) {
|
|
548
|
+
return i + currentPosition - (middle - 1);
|
|
549
|
+
}
|
|
550
|
+
else if (currentPosition > middle &&
|
|
551
|
+
currentPosition < pages - (middle - 1)) {
|
|
552
|
+
return i + currentPosition - middle;
|
|
553
|
+
}
|
|
554
|
+
else if (currentPosition > middle &&
|
|
555
|
+
currentPosition === pages - (middle - 1)) {
|
|
556
|
+
return i + currentPosition - (middle + 1);
|
|
557
|
+
}
|
|
558
|
+
else if (currentPosition > middle && currentPosition === pages - 1) {
|
|
559
|
+
return i + currentPosition - (middle + 2);
|
|
560
|
+
}
|
|
561
|
+
else {
|
|
562
|
+
return i + 1;
|
|
563
|
+
}
|
|
564
|
+
});
|
|
565
|
+
}
|
|
566
|
+
goto(page) {
|
|
567
|
+
if (this.table) {
|
|
568
|
+
this.table.page = page - 1;
|
|
569
|
+
}
|
|
570
|
+
}
|
|
571
|
+
}
|
|
572
|
+
PaginationComponent.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.3.11", ngImport: i0, type: PaginationComponent, deps: [], target: i0.ɵɵFactoryTarget.Component });
|
|
573
|
+
PaginationComponent.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "12.0.0", version: "13.3.11", type: PaginationComponent, selector: "angular-generic-table-pagination", inputs: { paginationLength: "paginationLength", classes: "classes", ariaLabels: "ariaLabels", table: "table" }, ngImport: i0, template: "<ng-container\n *ngIf=\"{\n links: pagination$ | async,\n currentPosition: table?.currentPage$ | async\n } as pagination\"\n>\n <nav\n *ngIf=\"pagination.links && pagination.links.length > 1\"\n role=\"navigation\"\n [attr.aria-label]=\"ariaLabels?.nav\"\n class=\"gt-pagination\"\n [class]=\"classes?.nav\"\n >\n <ul [class]=\"classes?.ul\">\n <ng-container\n *ngFor=\"\n let position of pagination!.links;\n let i = index;\n let last = last\n \"\n >\n <li\n [class]=\"classes?.li\"\n [class.active]=\"position === (pagination!.currentPosition || 0) + 1\"\n >\n <button\n [class]=\"classes?.button\"\n [attr.aria-label]=\"ariaLabels.button + position\"\n (click)=\"goto(position)\"\n >\n {{ position }}\n </button>\n </li>\n <li\n [class]=\"classes?.li\"\n class=\"gt-ellipsis\"\n *ngIf=\"position + 1 !== pagination!.links![i + 1] && !last\"\n >\n <button [class]=\"classes?.button\" disabled tabindex=\"-1\"></button>\n </li>\n </ng-container>\n </ul>\n </nav>\n</ng-container>\n", directives: [{ type: i1.NgIf, selector: "[ngIf]", inputs: ["ngIf", "ngIfThen", "ngIfElse"] }, { type: i1.NgForOf, selector: "[ngFor][ngForOf]", inputs: ["ngForOf", "ngForTrackBy", "ngForTemplate"] }], pipes: { "async": i1.AsyncPipe }, changeDetection: i0.ChangeDetectionStrategy.OnPush });
|
|
574
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.3.11", ngImport: i0, type: PaginationComponent, decorators: [{
|
|
575
|
+
type: Component,
|
|
576
|
+
args: [{ selector: 'angular-generic-table-pagination', changeDetection: ChangeDetectionStrategy.OnPush, template: "<ng-container\n *ngIf=\"{\n links: pagination$ | async,\n currentPosition: table?.currentPage$ | async\n } as pagination\"\n>\n <nav\n *ngIf=\"pagination.links && pagination.links.length > 1\"\n role=\"navigation\"\n [attr.aria-label]=\"ariaLabels?.nav\"\n class=\"gt-pagination\"\n [class]=\"classes?.nav\"\n >\n <ul [class]=\"classes?.ul\">\n <ng-container\n *ngFor=\"\n let position of pagination!.links;\n let i = index;\n let last = last\n \"\n >\n <li\n [class]=\"classes?.li\"\n [class.active]=\"position === (pagination!.currentPosition || 0) + 1\"\n >\n <button\n [class]=\"classes?.button\"\n [attr.aria-label]=\"ariaLabels.button + position\"\n (click)=\"goto(position)\"\n >\n {{ position }}\n </button>\n </li>\n <li\n [class]=\"classes?.li\"\n class=\"gt-ellipsis\"\n *ngIf=\"position + 1 !== pagination!.links![i + 1] && !last\"\n >\n <button [class]=\"classes?.button\" disabled tabindex=\"-1\"></button>\n </li>\n </ng-container>\n </ul>\n </nav>\n</ng-container>\n" }]
|
|
577
|
+
}], propDecorators: { paginationLength: [{
|
|
578
|
+
type: Input
|
|
579
|
+
}], classes: [{
|
|
580
|
+
type: Input
|
|
581
|
+
}], ariaLabels: [{
|
|
582
|
+
type: Input
|
|
583
|
+
}], table: [{
|
|
584
|
+
type: Input
|
|
585
|
+
}] } });
|
|
586
|
+
|
|
587
|
+
class GenericTablePaginationModule {
|
|
588
|
+
}
|
|
589
|
+
GenericTablePaginationModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.3.11", ngImport: i0, type: GenericTablePaginationModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
|
|
590
|
+
GenericTablePaginationModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "12.0.0", version: "13.3.11", ngImport: i0, type: GenericTablePaginationModule, declarations: [PaginationComponent], imports: [CommonModule], exports: [PaginationComponent] });
|
|
591
|
+
GenericTablePaginationModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "13.3.11", ngImport: i0, type: GenericTablePaginationModule, imports: [[CommonModule]] });
|
|
592
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.3.11", ngImport: i0, type: GenericTablePaginationModule, decorators: [{
|
|
593
|
+
type: NgModule,
|
|
594
|
+
args: [{
|
|
595
|
+
declarations: [PaginationComponent],
|
|
596
|
+
imports: [CommonModule],
|
|
597
|
+
exports: [PaginationComponent],
|
|
598
|
+
}]
|
|
599
|
+
}] });
|
|
600
|
+
|
|
601
|
+
/*
|
|
602
|
+
* Public API Surface of core
|
|
603
|
+
*/
|
|
604
|
+
|
|
605
|
+
/**
|
|
606
|
+
* Generated bundle index. Do not edit.
|
|
607
|
+
*/
|
|
608
|
+
|
|
609
|
+
export { CoreComponent, CoreService, GenericTableCoreModule, GenericTablePaginationModule, GtDeltaComponent, PaginationComponent };
|
|
610
|
+
//# sourceMappingURL=angular-generic-table-core.mjs.map
|