@universis/ngx-tables 0.7.6 → 0.7.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,7 +1,6 @@
1
1
  import { getNativeName } from 'iso-639-1/build';
2
2
  import * as jQuery_ from 'jquery';
3
3
  import 'datatables.net';
4
- import { template, at } from 'lodash';
5
4
  import 'datatables.net-scroller';
6
5
  import 'rxjs/add/observable/combineLatest';
7
6
  import { HttpClient } from '@angular/common/http';
@@ -15,14 +14,15 @@ import { TemplatePipe, LoadingService, ErrorService, DIALOG_BUTTONS, ModalServic
15
14
  import { RouterModalOkCancel, RouterModalModule } from '@universis/common/routing';
16
15
  import { ServiceUrlPreProcessor, TranslatePreProcessor, AdvancedFormsModule } from '@universis/forms';
17
16
  import { FormioModule } from 'angular-formio';
18
- import { ActivatedRoute, Router, NavigationStart, RouterModule } from '@angular/router';
19
17
  import { BsModalRef, BsModalService, ModalModule } from 'ngx-bootstrap/modal';
20
18
  import { ProgressbarModule } from 'ngx-bootstrap/progressbar';
21
19
  import { GroupByPipe, NgPipesModule } from 'ngx-pipes';
20
+ import { template, at, cloneDeep } from 'lodash';
22
21
  import { __extends, __awaiter, __generator, __values, __assign, __spread } from 'tslib';
23
22
  import { Injectable, Directive, Optional, Input, Pipe, Component, ElementRef, ViewChild, ViewEncapsulation, EventEmitter, Output, NgModule, CUSTOM_ELEMENTS_SCHEMA, defineInjectable, inject, HostListener, ChangeDetectorRef, InjectionToken, Inject, Injector, ChangeDetectionStrategy } from '@angular/core';
23
+ import { ActivatedRoute, Router, NavigationStart, NavigationEnd, RouterModule } from '@angular/router';
24
24
  import { createFeatureSelector, createSelector, select, Store } from '@ngrx/store';
25
- import { first } from 'rxjs/operators';
25
+ import { first, filter } from 'rxjs/operators';
26
26
 
27
27
  var AdvancedColumnFormatter = /** @class */ (function () {
28
28
  function AdvancedColumnFormatter() {
@@ -481,20 +481,20 @@ var AdvancedFilterValueProvider = /** @class */ (function () {
481
481
  this.values = {};
482
482
  this._template = new TemplatePipe();
483
483
  }
484
- AdvancedFilterValueProvider.prototype.buildFilter = function (filter) {
485
- if (filter) {
486
- return this._template.transform(filter, this.values);
484
+ AdvancedFilterValueProvider.prototype.buildFilter = function (filter$$1) {
485
+ if (filter$$1) {
486
+ return this._template.transform(filter$$1, this.values);
487
487
  }
488
488
  };
489
- AdvancedFilterValueProvider.prototype.asyncBuildFilter = function (filter) {
489
+ AdvancedFilterValueProvider.prototype.asyncBuildFilter = function (filter$$1) {
490
490
  return __awaiter(this, void 0, void 0, function () {
491
491
  var _a, _b, _c;
492
492
  return __generator(this, function (_d) {
493
493
  switch (_d.label) {
494
494
  case 0:
495
- if (!filter) return [3 /*break*/, 2];
495
+ if (!filter$$1) return [3 /*break*/, 2];
496
496
  _b = (_a = this._template).transform;
497
- _c = [filter];
497
+ _c = [filter$$1];
498
498
  return [4 /*yield*/, this.getValues()];
499
499
  case 1: return [2 /*return*/, _b.apply(_a, _c.concat([_d.sent()]))];
500
500
  case 2: return [2 /*return*/];
@@ -767,13 +767,13 @@ var AdvancedTableComponent = /** @class */ (function () {
767
767
  // try to split words
768
768
  var words = searchText.split(' ');
769
769
  // join words to a single filter
770
- var filter = words.map(function (word) {
770
+ var filter$$1 = words.map(function (word) {
771
771
  return _this._template.transform(_this.config.searchExpression, {
772
772
  text: word,
773
773
  });
774
774
  }).join(' and ');
775
775
  // set filter
776
- this.query.setParam('$filter', filter);
776
+ this.query.setParam('$filter', filter$$1);
777
777
  }
778
778
  }
779
779
  else {
@@ -1663,6 +1663,7 @@ var AdvancedTableComponent = /** @class */ (function () {
1663
1663
  this._http.get(changes.configSrc.currentValue).toPromise().then(function (config) {
1664
1664
  // set configuration
1665
1665
  _this.config = config;
1666
+ _this.destroy();
1666
1667
  // fetch and redraw
1667
1668
  _this.fetch();
1668
1669
  }).catch(function (err) {
@@ -1673,6 +1674,12 @@ var AdvancedTableComponent = /** @class */ (function () {
1673
1674
  }
1674
1675
  }
1675
1676
  };
1677
+ AdvancedTableComponent.prototype.reset = function (load) {
1678
+ this.query = null;
1679
+ this.destroy();
1680
+ this.autoLoad = !!load;
1681
+ this.ngOnInit();
1682
+ };
1676
1683
  AdvancedTableComponent.decorators = [
1677
1684
  { type: Component, args: [{
1678
1685
  // tslint:disable-next-line: component-selector
@@ -2169,8 +2176,8 @@ var AdvancedSearchFormComponent = /** @class */ (function (_super) {
2169
2176
  form: this.form
2170
2177
  });
2171
2178
  this.loading = false;
2172
- this.filterSubscription = this.filterChange.subscribe(function (filter) {
2173
- _this.submission.data = filter;
2179
+ this.filterSubscription = this.filterChange.subscribe(function (filter$$1) {
2180
+ _this.submission.data = filter$$1;
2174
2181
  _this.refreshForm.emit({
2175
2182
  submission: _this.submission
2176
2183
  });
@@ -2449,7 +2456,7 @@ var AdvancedTableModalBaseComponent = /** @class */ (function (_super) {
2449
2456
  * @param {object} filter The filter to use in the search
2450
2457
  *
2451
2458
  */
2452
- AdvancedTableModalBaseComponent.prototype.advancedSearch = function (filter) {
2459
+ AdvancedTableModalBaseComponent.prototype.advancedSearch = function (filter$$1) {
2453
2460
  return __awaiter(this, void 0, void 0, function () {
2454
2461
  var defaultFilterValues, err_1, expressions, predefinedCriteria, query;
2455
2462
  return __generator(this, function (_a) {
@@ -2473,9 +2480,9 @@ var AdvancedTableModalBaseComponent = /** @class */ (function (_super) {
2473
2480
  return [3 /*break*/, 4];
2474
2481
  case 4:
2475
2482
  expressions = [];
2476
- if (filter) {
2477
- this.defaultFilter = filter;
2478
- predefinedCriteria = this.getFilters(this.tableConfig, defaultFilterValues, filter);
2483
+ if (filter$$1) {
2484
+ this.defaultFilter = filter$$1;
2485
+ predefinedCriteria = this.getFilters(this.tableConfig, defaultFilterValues, filter$$1);
2479
2486
  }
2480
2487
  else {
2481
2488
  // Empty a falsy filter resets the results
@@ -4623,9 +4630,9 @@ var TableActionTypes;
4623
4630
  TableActionTypes["AppendState"] = "[Table] Append State";
4624
4631
  })(TableActionTypes || (TableActionTypes = {}));
4625
4632
  var AppendFilter = /** @class */ (function () {
4626
- function AppendFilter(id, filter) {
4633
+ function AppendFilter(id, filter$$1) {
4627
4634
  this.id = id;
4628
- this.filter = filter;
4635
+ this.filter = filter$$1;
4629
4636
  this.type = TableActionTypes.AppendFilter;
4630
4637
  }
4631
4638
  return AppendFilter;
@@ -4650,7 +4657,7 @@ function tableReducer(state, action) {
4650
4657
  case TableActionTypes.LoadFilter:
4651
4658
  return state[action.id];
4652
4659
  case TableActionTypes.AppendFilter:
4653
- state[action.id] = __assign({}, state[action.id], { filter: action.filter });
4660
+ state[action.id] = __assign({}, state[action.id], { filter: cloneDeep(action.filter) });
4654
4661
  return state;
4655
4662
  case TableActionTypes.AppendState:
4656
4663
  state[action.id] = __assign({}, state[action.id], { table: action.data });
@@ -4746,19 +4753,23 @@ var AdvancedSearchState = /** @class */ (function () {
4746
4753
  // set auto load to false
4747
4754
  this.search.table.autoLoad = false;
4748
4755
  // handle filtering
4749
- this.search.filterChange.subscribe(function (filter) {
4750
- _this.onSearchFilter(filter);
4756
+ this.filterChangeSubscription = this.search.filterChange.subscribe(function (filter$$1) {
4757
+ _this.onSearchFilter(filter$$1);
4751
4758
  });
4752
- // handle table state (via directive)
4753
- var tableState = new AdvancedTableState(this.search.table, this.store);
4754
- tableState.tableState = this.searchState;
4755
- tableState.ngOnInit();
4759
+ // apply table state
4760
+ this.applyTableState();
4756
4761
  // handle table init
4757
- this.search.table.init.subscribe(function () {
4762
+ this.tableInitSubscription = this.search.table.init.subscribe(function () {
4758
4763
  return _this.onTableInit();
4759
4764
  });
4760
4765
  }
4761
4766
  };
4767
+ AdvancedSearchState.prototype.applyTableState = function () {
4768
+ // handle table state (via directive)
4769
+ var tableState = new AdvancedTableState(this.search.table, this.store);
4770
+ tableState.tableState = this.searchState;
4771
+ tableState.ngOnInit();
4772
+ };
4762
4773
  AdvancedSearchState.prototype.onTableInit = function () {
4763
4774
  var _this = this;
4764
4775
  this.store.pipe(select(selectTable, { id: this.searchState }), first()).subscribe(function (state) {
@@ -4781,14 +4792,30 @@ var AdvancedSearchState = /** @class */ (function () {
4781
4792
  return _this.search.search();
4782
4793
  }
4783
4794
  if (state.filter) {
4784
- _this.search.filter = state.filter;
4795
+ if (Object.keys(state.filter).length) {
4796
+ // set collapsed to false (advanced search)
4797
+ _this.search.collapsed = false;
4798
+ _this.search.filter = state.filter;
4799
+ return _this.search.search();
4800
+ }
4785
4801
  }
4802
+ // ensure empty filter at this moment
4803
+ // because search() function triggers a store dispatch
4804
+ _this.search.filter = {};
4786
4805
  return _this.search.search();
4787
4806
  }
4788
4807
  });
4789
4808
  };
4790
- AdvancedSearchState.prototype.onSearchFilter = function (filter) {
4791
- this.store.dispatch(new AppendFilter(this.searchState, filter));
4809
+ AdvancedSearchState.prototype.onSearchFilter = function (filter$$1) {
4810
+ this.store.dispatch(new AppendFilter(this.searchState, filter$$1));
4811
+ };
4812
+ AdvancedSearchState.prototype.ngOnDestroy = function () {
4813
+ if (this.filterChangeSubscription) {
4814
+ this.filterChangeSubscription.unsubscribe();
4815
+ }
4816
+ if (this.tableInitSubscription) {
4817
+ this.tableInitSubscription.unsubscribe();
4818
+ }
4792
4819
  };
4793
4820
  AdvancedSearchState.decorators = [
4794
4821
  { type: Directive, args: [{
@@ -4807,6 +4834,68 @@ var AdvancedSearchState = /** @class */ (function () {
4807
4834
  return AdvancedSearchState;
4808
4835
  }());
4809
4836
 
4837
+ var AdvancedSearchRouterState = /** @class */ (function (_super) {
4838
+ __extends(AdvancedSearchRouterState, _super);
4839
+ function AdvancedSearchRouterState(search, store, _router) {
4840
+ var _this =
4841
+ // call super constructor
4842
+ _super.call(this, search, store) || this;
4843
+ _this.search = search;
4844
+ _this.store = store;
4845
+ _this._router = _router;
4846
+ _this._enteringState = true;
4847
+ _this._applyState = false;
4848
+ // set search state dynamically according to route
4849
+ _this._routerSubscription = _this._router.events
4850
+ .pipe(filter(function (event) {
4851
+ return event instanceof NavigationStart || event instanceof NavigationEnd;
4852
+ }))
4853
+ .subscribe(function (event) {
4854
+ // capture urls regarding tab changing while the component is active
4855
+ if (event instanceof NavigationStart && !_this._enteringState) {
4856
+ // set search state
4857
+ _this.searchState = event.url;
4858
+ // toogle applyState
4859
+ _this._applyState = true;
4860
+ }
4861
+ // capture url of the first activation of the component (e.g. coming from another route)
4862
+ if (event instanceof NavigationEnd && _this._enteringState) {
4863
+ // set search state
4864
+ _this.searchState = event.urlAfterRedirects;
4865
+ // toggle enteringState
4866
+ _this._enteringState = false;
4867
+ }
4868
+ if (_this._applyState) {
4869
+ // apply new table state
4870
+ _super.prototype.applyTableState.call(_this);
4871
+ _this._applyState = false;
4872
+ }
4873
+ });
4874
+ return _this;
4875
+ }
4876
+ AdvancedSearchRouterState.prototype.ngOnDestroy = function () {
4877
+ // destroy own subscriptions
4878
+ if (this._routerSubscription) {
4879
+ this._routerSubscription.unsubscribe();
4880
+ }
4881
+ // destroy parent subscriptions
4882
+ return _super.prototype.ngOnDestroy.call(this);
4883
+ };
4884
+ AdvancedSearchRouterState.decorators = [
4885
+ { type: Directive, args: [{
4886
+ // tslint:disable-next-line: directive-selector
4887
+ selector: "[routerSearchState]",
4888
+ },] }
4889
+ ];
4890
+ /** @nocollapse */
4891
+ AdvancedSearchRouterState.ctorParameters = function () { return [
4892
+ { type: AdvancedTableSearchComponent },
4893
+ { type: Store, decorators: [{ type: Optional }] },
4894
+ { type: Router }
4895
+ ]; };
4896
+ return AdvancedSearchRouterState;
4897
+ }(AdvancedSearchState));
4898
+
4810
4899
  var ɵ0 = FORMATTERS;
4811
4900
  var TablesModule = /** @class */ (function () {
4812
4901
  function TablesModule(_translateService) {
@@ -4872,7 +4961,8 @@ var TablesModule = /** @class */ (function () {
4872
4961
  ParseTitlePipe,
4873
4962
  AddItemsComponent,
4874
4963
  AdvancedSearchState,
4875
- AdvancedTableState
4964
+ AdvancedTableState,
4965
+ AdvancedSearchRouterState
4876
4966
  ],
4877
4967
  exports: [
4878
4968
  AdvancedTableComponent,
@@ -4890,7 +4980,8 @@ var TablesModule = /** @class */ (function () {
4890
4980
  AdvancedAggregatorListComponent,
4891
4981
  AddItemsComponent,
4892
4982
  AdvancedSearchState,
4893
- AdvancedTableState
4983
+ AdvancedTableState,
4984
+ AdvancedSearchRouterState
4894
4985
  ],
4895
4986
  entryComponents: [
4896
4987
  AdvancedTableModalBaseComponent,
@@ -4917,6 +5008,6 @@ var TablesModule = /** @class */ (function () {
4917
5008
  * Generated bundle index. Do not edit.
4918
5009
  */
4919
5010
 
4920
- export { AdvancedSearchState as ɵa, AdvancedTableState 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, initialState, tableInitialState, tableReducer, tableReducers, featureName, getTablesState, selectTable };
5011
+ export { AdvancedSearchState as ɵa, AdvancedTableState as ɵc, AdvancedSearchRouterState as ɵd, 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, initialState, tableInitialState, tableReducer, tableReducers, featureName, getTablesState, selectTable };
4921
5012
 
4922
5013
  //# sourceMappingURL=universis-ngx-tables.js.map