@universis/ngx-tables 0.6.21 → 0.7.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (35) hide show
  1. package/bundles/universis-ngx-tables.umd.js +246 -10
  2. package/bundles/universis-ngx-tables.umd.js.map +1 -1
  3. package/bundles/universis-ngx-tables.umd.min.js +1 -1
  4. package/bundles/universis-ngx-tables.umd.min.js.map +1 -1
  5. package/esm2015/lib/actions/table.actions.js +28 -0
  6. package/esm2015/lib/components/advanced-table/advanced-table-search.component.js +8 -2
  7. package/esm2015/lib/components/advanced-table/advanced-table.component.js +31 -3
  8. package/esm2015/lib/directives/advance-search-state.directive.js +88 -0
  9. package/esm2015/lib/directives/advance-table-state.directive.js +59 -0
  10. package/esm2015/lib/reducers/index.js +31 -0
  11. package/esm2015/lib/tables.module.js +13 -4
  12. package/esm2015/public_api.js +1 -1
  13. package/esm2015/universis-ngx-tables.js +4 -1
  14. package/esm5/lib/actions/table.actions.js +34 -0
  15. package/esm5/lib/components/advanced-table/advanced-table-search.component.js +8 -2
  16. package/esm5/lib/components/advanced-table/advanced-table.component.js +31 -3
  17. package/esm5/lib/directives/advance-search-state.directive.js +96 -0
  18. package/esm5/lib/directives/advance-table-state.directive.js +62 -0
  19. package/esm5/lib/reducers/index.js +33 -0
  20. package/esm5/lib/tables.module.js +13 -4
  21. package/esm5/public_api.js +1 -1
  22. package/esm5/universis-ngx-tables.js +4 -1
  23. package/fesm2015/universis-ngx-tables.js +229 -12
  24. package/fesm2015/universis-ngx-tables.js.map +1 -1
  25. package/fesm5/universis-ngx-tables.js +240 -13
  26. package/fesm5/universis-ngx-tables.js.map +1 -1
  27. package/lib/actions/table.actions.d.ts +24 -0
  28. package/lib/components/advanced-table/advanced-table-search.component.d.ts +4 -0
  29. package/lib/components/advanced-table/advanced-table.component.d.ts +4 -0
  30. package/lib/directives/advance-search-state.directive.d.ts +16 -0
  31. package/lib/directives/advance-table-state.directive.d.ts +11 -0
  32. package/lib/reducers/index.d.ts +23 -0
  33. package/package.json +4 -1
  34. package/universis-ngx-tables.d.ts +3 -0
  35. package/universis-ngx-tables.metadata.json +1 -1
@@ -9,7 +9,6 @@ import { ClientDataQueryable, ResponseError, TextUtils } from '@themost/client';
9
9
  import { BehaviorSubject } from 'rxjs';
10
10
  import { AngularDataContext } from '@themost/angular';
11
11
  import { __awaiter } from 'tslib';
12
- import { Injectable, Directive, Output, EventEmitter, Pipe, Component, Input, ViewChild, ViewEncapsulation, ChangeDetectorRef, ElementRef, Inject, InjectionToken, Injector, NgModule, CUSTOM_ELEMENTS_SCHEMA, defineInjectable, inject, HostListener, ChangeDetectionStrategy } from '@angular/core';
13
12
  import { DatePipe, CommonModule } from '@angular/common';
14
13
  import { TranslateService, TranslatePipe, TranslateModule } from '@ngx-translate/core';
15
14
  import { FormArray, FormBuilder, FormControl, FormsModule, ReactiveFormsModule } from '@angular/forms';
@@ -21,6 +20,9 @@ import { ActivatedRoute, Router, NavigationStart, RouterModule } from '@angular/
21
20
  import { BsModalRef, BsModalService, ModalModule } from 'ngx-bootstrap/modal';
22
21
  import { ProgressbarModule } from 'ngx-bootstrap/progressbar';
23
22
  import { GroupByPipe, NgPipesModule } from 'ngx-pipes';
23
+ import { Injectable, Directive, Optional, Input, Output, EventEmitter, Pipe, Component, ViewChild, ViewEncapsulation, ChangeDetectorRef, ElementRef, Inject, InjectionToken, Injector, NgModule, CUSTOM_ELEMENTS_SCHEMA, defineInjectable, inject, HostListener, ChangeDetectionStrategy } from '@angular/core';
24
+ import { createFeatureSelector, createSelector, select, Store, StoreModule } from '@ngrx/store';
25
+ import { first } from 'rxjs/operators';
24
26
 
25
27
  class AdvancedColumnFormatter {
26
28
  static template(expr) {
@@ -542,6 +544,7 @@ class AdvancedTableComponent {
542
544
  this.select = new EventEmitter();
543
545
  this.draw = new EventEmitter();
544
546
  this.page = new EventEmitter();
547
+ this.order = new EventEmitter();
545
548
  this.scroll = new EventEmitter();
546
549
  this.selectedItems = new EventEmitter();
547
550
  this.scrollable = true;
@@ -549,6 +552,7 @@ class AdvancedTableComponent {
549
552
  this.lengthMenu = [50, 100, 200, 500];
550
553
  this.paging = true;
551
554
  this.pageLength = 25;
555
+ this.stateSave = false;
552
556
  this.scrollY = 800;
553
557
  this.scrollX = true;
554
558
  /**
@@ -1045,7 +1049,14 @@ class AdvancedTableComponent {
1045
1049
  }, 0);
1046
1050
  }
1047
1051
  });
1048
- tableElement.on('draw.dt', (event) => {
1052
+ tableElement.on('order.dt', (event) => {
1053
+ if (this.dataTable) {
1054
+ const order = this.dataTable.order();
1055
+ if (order && order.length) {
1056
+ this.order.emit(order);
1057
+ }
1058
+ }
1059
+ }).on('draw.dt', (event) => {
1049
1060
  this.draw.emit();
1050
1061
  if (this.dataTable) {
1051
1062
  const info = this.dataTable.page.info();
@@ -1204,7 +1215,7 @@ class AdvancedTableComponent {
1204
1215
  q.setParam('$orderby', orderByStr);
1205
1216
  }
1206
1217
  // configure $select parameter
1207
- const select = self.config.columns.filter((column) => {
1218
+ const select$$1 = self.config.columns.filter((column) => {
1208
1219
  if (column.virtual === true) {
1209
1220
  return false;
1210
1221
  }
@@ -1217,7 +1228,7 @@ class AdvancedTableComponent {
1217
1228
  return column.name;
1218
1229
  }
1219
1230
  });
1220
- q.select.apply(q, select);
1231
+ q.select.apply(q, select$$1);
1221
1232
  // configure $filter
1222
1233
  if (queryParams.$filter && queryParams.$filter.length) {
1223
1234
  // set route filter
@@ -1294,6 +1305,20 @@ class AdvancedTableComponent {
1294
1305
  },
1295
1306
  language: Object.assign({}, self.translator.transform('Tables.DataTable'), { emptyTable: ' ' }),
1296
1307
  };
1308
+ const stateSettings = {
1309
+ stateSave: this.stateSave
1310
+ };
1311
+ if (this.stateLoadCallback) {
1312
+ Object.assign(stateSettings, {
1313
+ stateLoadCallback: this.stateLoadCallback
1314
+ });
1315
+ }
1316
+ if (this.stateSaveCallback) {
1317
+ Object.assign(stateSettings, {
1318
+ stateSaveCallback: this.stateSaveCallback
1319
+ });
1320
+ }
1321
+ Object.assign(settings, stateSettings);
1297
1322
  if (this.scrollable) {
1298
1323
  // set continuous scrolling
1299
1324
  Object.assign(settings, {
@@ -1328,8 +1353,8 @@ class AdvancedTableComponent {
1328
1353
  });
1329
1354
  }
1330
1355
  });
1331
- this.init.emit();
1332
1356
  }).DataTable(settings);
1357
+ this.init.emit();
1333
1358
  // show or hide header
1334
1359
  if (!this.showHeader) {
1335
1360
  this._element.nativeElement
@@ -1598,6 +1623,7 @@ AdvancedTableComponent.propDecorators = {
1598
1623
  select: [{ type: Output, args: ['select',] }],
1599
1624
  draw: [{ type: Output, args: ['draw',] }],
1600
1625
  page: [{ type: Output, args: ['page',] }],
1626
+ order: [{ type: Output, args: ['order',] }],
1601
1627
  scroll: [{ type: Output, args: ['scroll',] }],
1602
1628
  selectedItems: [{ type: Output, args: ['selectedItems',] }],
1603
1629
  scrollable: [{ type: Input }],
@@ -1605,6 +1631,9 @@ AdvancedTableComponent.propDecorators = {
1605
1631
  lengthMenu: [{ type: Input }],
1606
1632
  paging: [{ type: Input }],
1607
1633
  pageLength: [{ type: Input }],
1634
+ stateSave: [{ type: Input }],
1635
+ stateLoadCallback: [{ type: Input }],
1636
+ stateSaveCallback: [{ type: Input }],
1608
1637
  scrollY: [{ type: Input }],
1609
1638
  scrollX: [{ type: Input }],
1610
1639
  selectable: [{ type: Input }],
@@ -2745,6 +2774,7 @@ class AdvancedTableSearchComponent extends AdvancedTableSearchBaseComponent {
2745
2774
  this.showMore = true;
2746
2775
  this.mergeQueryParams = false;
2747
2776
  this.viewChange = new EventEmitter();
2777
+ this.listChange = new EventEmitter();
2748
2778
  this.userSearchList = [];
2749
2779
  this.selectedList = null;
2750
2780
  }
@@ -2892,6 +2922,9 @@ class AdvancedTableSearchComponent extends AdvancedTableSearchBaseComponent {
2892
2922
  queryParamsHandling: 'merge',
2893
2923
  });
2894
2924
  }
2925
+ this.filterChange.emit({
2926
+ q: searchText
2927
+ });
2895
2928
  // otherwise do search
2896
2929
  this.table.search(searchText);
2897
2930
  return false;
@@ -3102,6 +3135,7 @@ class AdvancedTableSearchComponent extends AdvancedTableSearchBaseComponent {
3102
3135
  else {
3103
3136
  this.table.query = query;
3104
3137
  }
3138
+ this.filterChange.emit(this.filter);
3105
3139
  this.table.fetch();
3106
3140
  }
3107
3141
  });
@@ -3230,7 +3264,8 @@ AdvancedTableSearchComponent.propDecorators = {
3230
3264
  showMore: [{ type: Input }],
3231
3265
  mergeQueryParams: [{ type: Input }],
3232
3266
  searchText: [{ type: ViewChild, args: ['searchText',] }],
3233
- viewChange: [{ type: Output, args: ['viewChange',] }]
3267
+ viewChange: [{ type: Output, args: ['viewChange',] }],
3268
+ listChange: [{ type: Output, args: ['listChange',] }]
3234
3269
  };
3235
3270
 
3236
3271
  const FORMATTERS = {
@@ -3527,8 +3562,8 @@ class BtnExpDirective {
3527
3562
  constructQueryParam(query, tableConfig) {
3528
3563
  let selectQuery = query.getParams().$select;
3529
3564
  let selectQueryArray = selectQuery.split(',');
3530
- selectQueryArray = selectQueryArray.map((select) => {
3531
- const words = select.split(' ');
3565
+ selectQueryArray = selectQueryArray.map((select$$1) => {
3566
+ const words = select$$1.split(' ');
3532
3567
  if (words.length === 3) {
3533
3568
  if (tableConfig && tableConfig.columns) {
3534
3569
  for (const column of tableConfig.columns) {
@@ -4355,6 +4390,183 @@ const TABLES_EN = {
4355
4390
  }
4356
4391
  };
4357
4392
 
4393
+ var TableActionTypes;
4394
+ (function (TableActionTypes) {
4395
+ TableActionTypes["LoadFilter"] = "[Table] Load Filter";
4396
+ TableActionTypes["AppendFilter"] = "[Table] Append Filter";
4397
+ TableActionTypes["AppendState"] = "[Table] Append State";
4398
+ })(TableActionTypes || (TableActionTypes = {}));
4399
+ class AppendFilter {
4400
+ constructor(id, filter) {
4401
+ this.id = id;
4402
+ this.filter = filter;
4403
+ this.type = TableActionTypes.AppendFilter;
4404
+ }
4405
+ }
4406
+ class AppendState {
4407
+ constructor(id, data) {
4408
+ this.id = id;
4409
+ this.data = data;
4410
+ this.type = TableActionTypes.AppendState;
4411
+ }
4412
+ }
4413
+
4414
+ const initialState = {};
4415
+ function tableReducer(state = initialState, action) {
4416
+ switch (action.type) {
4417
+ case TableActionTypes.LoadFilter:
4418
+ return state[action.id];
4419
+ case TableActionTypes.AppendFilter:
4420
+ state[action.id] = Object.assign({}, state[action.id], { filter: action.filter });
4421
+ return state;
4422
+ case TableActionTypes.AppendState:
4423
+ state[action.id] = Object.assign({}, state[action.id], { table: action.data });
4424
+ return state;
4425
+ default:
4426
+ return state;
4427
+ }
4428
+ }
4429
+ const tableReducers = {
4430
+ tables: tableReducer,
4431
+ };
4432
+ const featureName = 'tables';
4433
+ const getTablesState = createFeatureSelector(featureName);
4434
+ const selectTable = createSelector(getTablesState, (state, props) => {
4435
+ return state.tables[props.id];
4436
+ });
4437
+
4438
+ class AdvancedTableState {
4439
+ constructor(table, store) {
4440
+ this.table = table;
4441
+ this.store = store;
4442
+ }
4443
+ ngOnInit() {
4444
+ if (this.store == null) {
4445
+ return;
4446
+ }
4447
+ this.table.stateSave = true;
4448
+ this.table.stateLoadCallback = (settings, callback) => {
4449
+ this.store.pipe(select(selectTable, { id: this.tableState }), first()).subscribe((state) => {
4450
+ return callback(state && state.table);
4451
+ });
4452
+ };
4453
+ let firstDraw = true;
4454
+ this.table.draw.subscribe(() => {
4455
+ if (firstDraw === false) {
4456
+ return;
4457
+ }
4458
+ if (this.table.dataTable == null) {
4459
+ return;
4460
+ }
4461
+ firstDraw = false;
4462
+ const loadeStateSettings = this.table.dataTable.settings()[0];
4463
+ const scrollerSettings = loadeStateSettings.oSavedState &&
4464
+ loadeStateSettings.oSavedState.scroller;
4465
+ if (scrollerSettings && scrollerSettings.topRow) {
4466
+ const scroller = this.table.dataTable.scroller();
4467
+ scroller.scrollToRow(scrollerSettings.topRow, true);
4468
+ }
4469
+ });
4470
+ this.table.stateSaveCallback = (settings, data) => {
4471
+ this.store.dispatch(new AppendState(this.tableState, data));
4472
+ };
4473
+ }
4474
+ }
4475
+ AdvancedTableState.decorators = [
4476
+ { type: Directive, args: [{
4477
+ // tslint:disable-next-line: directive-selector
4478
+ selector: '[tableState]',
4479
+ },] }
4480
+ ];
4481
+ /** @nocollapse */
4482
+ AdvancedTableState.ctorParameters = () => [
4483
+ { type: AdvancedTableComponent },
4484
+ { type: Store, decorators: [{ type: Optional }] }
4485
+ ];
4486
+ AdvancedTableState.propDecorators = {
4487
+ tableState: [{ type: Input }]
4488
+ };
4489
+
4490
+ class AdvancedTableSearchComponentNotNull extends Error {
4491
+ constructor() {
4492
+ super('Advanced table search component cannot be empty at this context.');
4493
+ }
4494
+ }
4495
+ class AdvancedSearchState {
4496
+ constructor(search, store) {
4497
+ this.search = search;
4498
+ this.store = store;
4499
+ }
4500
+ ngOnInit() {
4501
+ if (this.store == null) {
4502
+ return;
4503
+ }
4504
+ if (this.search == null) {
4505
+ throw new AdvancedTableSearchComponentNotNull();
4506
+ }
4507
+ if (this.search.table) {
4508
+ // set auto load to false
4509
+ this.search.table.autoLoad = false;
4510
+ // handle filtering
4511
+ this.search.filterChange.subscribe((filter) => {
4512
+ this.onSearchFilter(filter);
4513
+ });
4514
+ // handle table state (via directive)
4515
+ const tableState = new AdvancedTableState(this.search.table, this.store);
4516
+ tableState.tableState = this.searchState;
4517
+ tableState.ngOnInit();
4518
+ // handle table init
4519
+ this.search.table.init.subscribe(() => {
4520
+ return this.onTableInit();
4521
+ });
4522
+ }
4523
+ }
4524
+ onTableInit() {
4525
+ this.store.pipe(select(selectTable, { id: this.searchState }), first()).subscribe((state) => {
4526
+ // use order
4527
+ if (state) {
4528
+ if (state.order && state.order.length) {
4529
+ this.search.table.dataTable.order(state.order);
4530
+ }
4531
+ // use text search
4532
+ if (state.filter && state.filter.q) {
4533
+ this.search.text = state.filter.q;
4534
+ this.search.collapsed = true;
4535
+ return this.search.table.search(this.search.text);
4536
+ }
4537
+ // use predefined search
4538
+ if (state.filter && state.filter.s) {
4539
+ this.search.selectedList = this.search.userSearchList.find((item) => {
4540
+ return item.name === state.filter.s;
4541
+ });
4542
+ return this.search.search();
4543
+ }
4544
+ if (state.filter) {
4545
+ this.search.filter = state.filter;
4546
+ }
4547
+ return this.search.search();
4548
+ }
4549
+ });
4550
+ }
4551
+ onSearchFilter(filter) {
4552
+ this.store.dispatch(new AppendFilter(this.searchState, filter));
4553
+ }
4554
+ }
4555
+ AdvancedSearchState.decorators = [
4556
+ { type: Directive, args: [{
4557
+ // tslint:disable-next-line: directive-selector
4558
+ selector: '[searchState]',
4559
+ },] }
4560
+ ];
4561
+ /** @nocollapse */
4562
+ AdvancedSearchState.ctorParameters = () => [
4563
+ { type: AdvancedTableSearchComponent },
4564
+ { type: Store, decorators: [{ type: Optional }] }
4565
+ ];
4566
+ AdvancedSearchState.propDecorators = {
4567
+ searchState: [{ type: Input }]
4568
+ };
4569
+
4358
4570
  const ɵ0 = FORMATTERS;
4359
4571
  class TablesModule {
4360
4572
  constructor(_translateService) {
@@ -4386,7 +4598,8 @@ TablesModule.decorators = [
4386
4598
  SharedModule,
4387
4599
  ModalModule,
4388
4600
  ProgressbarModule,
4389
- NgPipesModule
4601
+ NgPipesModule,
4602
+ StoreModule.forFeature(featureName, tableReducers)
4390
4603
  ],
4391
4604
  providers: [DatePipe, TemplatePipe,
4392
4605
  {
@@ -4416,7 +4629,9 @@ TablesModule.decorators = [
4416
4629
  AdvancedAggregatorListComponent,
4417
4630
  AdvancedAggregatorPipe,
4418
4631
  ParseTitlePipe,
4419
- AddItemsComponent
4632
+ AddItemsComponent,
4633
+ AdvancedSearchState,
4634
+ AdvancedTableState
4420
4635
  ],
4421
4636
  exports: [
4422
4637
  AdvancedTableComponent,
@@ -4432,7 +4647,9 @@ TablesModule.decorators = [
4432
4647
  AdvancedTableEditorDirective,
4433
4648
  AdvancedAggregatorComponent,
4434
4649
  AdvancedAggregatorListComponent,
4435
- AddItemsComponent
4650
+ AddItemsComponent,
4651
+ AdvancedSearchState,
4652
+ AdvancedTableState
4436
4653
  ],
4437
4654
  entryComponents: [
4438
4655
  AdvancedTableModalBaseComponent,
@@ -4457,6 +4674,6 @@ TablesModule.ctorParameters = () => [
4457
4674
  * Generated bundle index. Do not edit.
4458
4675
  */
4459
4676
 
4460
- export { AdvancedListComponent, AdvancedRowActionComponent, AdvancedSearchFormComponent, AdvancedSelectComponent, AdvancedSelectService, AdvancedTableConfigurationResolver, AdvancedSearchConfigurationResolver, AdvancedColumnFormatter, NestedPropertyFormatter, ButtonFormatter, LinkFormatter, ActionLinkFormatter, ActionButtonFormatter, ActionSplitButtonFormatter, SelectRowFormatter, TemplateFormatter, TrueFalseFormatter, TranslationFormatter, DateTimeFormatter, NgClassFormatter, LanguageFormatter, COLUMN_FORMATTERS, AdvancedTableConfiguration, AdvancedTableComponent, AdvancedTableSettingsComponent, AdvancedTableSearchBaseComponent, AdvancedTableSearchComponent, FORMATTERS, AdvancedFilterValueProvider, AdvancedTableModalBaseTemplate, AdvancedTableModalBaseComponent, SimpleHeaderToolsComponent, TableSimpleHeaderComponent, AdvancedTableNotNullError, AdvancedTableEditorDirective, BtnExpDirective, AdvancedAggregatorComponent, AdvancedAggregatorListComponent, AddItemsComponent, AdvancedAggregatorPipe, ParseTitlePipe, AdvancedAggregatorService, TablesModule, ɵ0, ActivatedTableService };
4677
+ export { AdvancedSearchState as ɵe, AdvancedTableState as ɵf, featureName as ɵd, tableReducer as ɵa, tableReducers as ɵc, AdvancedListComponent, AdvancedRowActionComponent, AdvancedSearchFormComponent, AdvancedSelectComponent, AdvancedSelectService, AdvancedTableConfigurationResolver, AdvancedSearchConfigurationResolver, AdvancedColumnFormatter, NestedPropertyFormatter, ButtonFormatter, LinkFormatter, ActionLinkFormatter, ActionButtonFormatter, ActionSplitButtonFormatter, SelectRowFormatter, TemplateFormatter, TrueFalseFormatter, TranslationFormatter, DateTimeFormatter, NgClassFormatter, LanguageFormatter, COLUMN_FORMATTERS, AdvancedTableConfiguration, AdvancedTableComponent, AdvancedTableSettingsComponent, AdvancedTableSearchBaseComponent, AdvancedTableSearchComponent, FORMATTERS, AdvancedFilterValueProvider, AdvancedTableModalBaseTemplate, AdvancedTableModalBaseComponent, SimpleHeaderToolsComponent, TableSimpleHeaderComponent, AdvancedTableNotNullError, AdvancedTableEditorDirective, BtnExpDirective, AdvancedAggregatorComponent, AdvancedAggregatorListComponent, AddItemsComponent, AdvancedAggregatorPipe, ParseTitlePipe, AdvancedAggregatorService, TablesModule, ɵ0, ActivatedTableService };
4461
4678
 
4462
4679
  //# sourceMappingURL=universis-ngx-tables.js.map