@sumaris-net/ngx-components 1.0.7 → 1.1.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 (29) hide show
  1. package/bundles/sumaris-net.ngx-components.umd.js +105 -52
  2. package/bundles/sumaris-net.ngx-components.umd.js.map +1 -1
  3. package/bundles/sumaris-net.ngx-components.umd.min.js +2 -2
  4. package/bundles/sumaris-net.ngx-components.umd.min.js.map +1 -1
  5. package/doc/changelog.md +1 -0
  6. package/esm2015/src/app/core/form/entity-editor.class.js +1 -1
  7. package/esm2015/src/app/core/form/form.utils.js +2 -2
  8. package/esm2015/src/app/core/graphql/graphql.service.js +6 -3
  9. package/esm2015/src/app/core/services/account.service.js +2 -2
  10. package/esm2015/src/app/core/services/base-graphql-service.class.js +3 -3
  11. package/esm2015/src/app/core/services/local-settings.service.js +5 -3
  12. package/esm2015/src/app/core/services/model/config.model.js +2 -2
  13. package/esm2015/src/app/core/services/model/entity.model.js +2 -2
  14. package/esm2015/src/app/core/services/pipes/department-to-string.pipe.js +2 -2
  15. package/esm2015/src/app/core/services/storage/entity-store.class.js +3 -3
  16. package/esm2015/src/app/shared/dates.js +9 -1
  17. package/esm2015/src/app/shared/form/field.component.js +2 -2
  18. package/esm2015/src/app/shared/functions.js +1 -1
  19. package/esm2015/src/app/shared/pipes/form.pipes.js +56 -5
  20. package/esm2015/src/app/shared/pipes/translate-context.pipe.js +7 -28
  21. package/esm2015/src/app/shared/shared-routing.module.js +21 -11
  22. package/fesm2015/sumaris-net.ngx-components.js +104 -52
  23. package/fesm2015/sumaris-net.ngx-components.js.map +1 -1
  24. package/package.json +1 -1
  25. package/src/app/shared/dates.d.ts +3 -1
  26. package/src/app/shared/pipes/form.pipes.d.ts +14 -3
  27. package/src/app/shared/pipes/translate-context.pipe.d.ts +2 -7
  28. package/src/app/shared/shared-routing.module.d.ts +7 -0
  29. package/sumaris-net.ngx-components.metadata.json +1 -1
@@ -2489,6 +2489,14 @@
2489
2489
  DateUtils.max = function (date1, date2) {
2490
2490
  return !date1 ? date2 : (!date2 || date1.isSameOrAfter(date2) ? date1 : date2);
2491
2491
  };
2492
+ DateUtils.equals = function (date1, date2) {
2493
+ return DateUtils.isSame(date1, date2);
2494
+ };
2495
+ DateUtils.isSame = function (date1, date2, granularity) {
2496
+ var d1 = fromDateISOString(date1);
2497
+ var d2 = fromDateISOString(date2);
2498
+ return (!d1 && !d2) || d1.isSame(d2, granularity);
2499
+ };
2492
2500
  return DateUtils;
2493
2501
  }());
2494
2502
  function toDateISOString(value) {
@@ -2945,39 +2953,19 @@
2945
2953
  ]; };
2946
2954
 
2947
2955
  var TranslateContextPipe = /** @class */ (function () {
2948
- function TranslateContextPipe(translate, _ref) {
2956
+ function TranslateContextPipe(translate) {
2949
2957
  this.translate = translate;
2950
- this._ref = _ref;
2951
- this.value = '';
2952
- this.lastKey = null;
2953
- this.lastSuffix = null;
2954
- this.lastParams = [];
2955
2958
  }
2956
2959
  TranslateContextPipe.prototype.transform = function (query) {
2957
2960
  var params = [];
2958
2961
  for (var _i = 1; _i < arguments.length; _i++) {
2959
2962
  params[_i - 1] = arguments[_i];
2960
2963
  }
2961
- if (!query || !query.length) {
2964
+ if (!query || !query.length)
2962
2965
  return query;
2963
- }
2964
2966
  var suffix = params && params.length ? params[0] : '';
2965
2967
  params = suffix && params.slice(1);
2966
- // if we ask another time for the same key, return the last value
2967
- if (equalsOrNil(query, this.lastKey)
2968
- && equals(suffix, this.lastSuffix)
2969
- && equals(params, this.lastParams)) {
2970
- return this.value;
2971
- }
2972
- // store the query, in case it changes
2973
- this.lastKey = query;
2974
- // store the params, in case they change
2975
- this.lastParams = params;
2976
- // store the params, in case they change
2977
- this.lastSuffix = suffix;
2978
- // set the value
2979
- this.value = this.translate.instant(query, suffix, params);
2980
- return this.value;
2968
+ return this.translate.instant(query, suffix, params);
2981
2969
  };
2982
2970
  return TranslateContextPipe;
2983
2971
  }());
@@ -2988,8 +2976,7 @@
2988
2976
  },] }
2989
2977
  ];
2990
2978
  TranslateContextPipe.ctorParameters = function () { return [
2991
- { type: TranslateContextService },
2992
- { type: i0.ChangeDetectorRef }
2979
+ { type: TranslateContextService }
2993
2980
  ]; };
2994
2981
  var TranslatablePipe = /** @class */ (function () {
2995
2982
  function TranslatablePipe() {
@@ -3735,7 +3722,7 @@
3735
3722
  source = source.split('|');
3736
3723
  }
3737
3724
  // Skip if value is not an array
3738
- if (!(source instanceof Array) || control.length === 0) {
3725
+ if (!Array.isArray(source) || control.length === 0) {
3739
3726
  if (isNotEmptyArray(source))
3740
3727
  console.warn("WARN: please resize the FormArray '" + path + "' to the same length of the input array");
3741
3728
  return [];
@@ -4216,21 +4203,72 @@
4216
4203
  ]; };
4217
4204
 
4218
4205
  var FormErrorTranslatePipe = /** @class */ (function () {
4219
- function FormErrorTranslatePipe(adapter) {
4206
+ function FormErrorTranslatePipe(adapter, _ref) {
4220
4207
  this.adapter = adapter;
4208
+ this._ref = _ref;
4209
+ this.value = '';
4210
+ this._lastForm = null;
4211
+ this._lastOptions = null;
4221
4212
  }
4222
4213
  FormErrorTranslatePipe.prototype.transform = function (form, opts) {
4223
- return this.adapter.translateErrors(form, opts);
4214
+ var _this = this;
4215
+ if (!form) {
4216
+ this._dispose();
4217
+ return '';
4218
+ }
4219
+ // if we ask another time for the same form and opts, return the last value
4220
+ if (form === this._lastForm && equals(opts, this._lastOptions)) {
4221
+ return this.value;
4222
+ }
4223
+ // store the query, in case it changes
4224
+ this._lastForm = form;
4225
+ // store the params, in case they change
4226
+ this._lastOptions = opts;
4227
+ // set the value
4228
+ this._updateValue(form, opts);
4229
+ // if there is a subscription to onLangChange, clean it
4230
+ this._dispose();
4231
+ // subscribe to onTranslationChange event, in case the translations change
4232
+ if (!this._onFormStatusChange) {
4233
+ this._onFormStatusChange = form.statusChanges.subscribe(function (status) {
4234
+ _this._updateValue(form, opts, status);
4235
+ });
4236
+ }
4237
+ return this.value;
4238
+ };
4239
+ FormErrorTranslatePipe.prototype.ngOnDestroy = function () {
4240
+ this._dispose();
4241
+ };
4242
+ FormErrorTranslatePipe.prototype._updateValue = function (form, opts, status) {
4243
+ if (status === 'INVALID' || form.invalid) {
4244
+ this.value = this.adapter.translateErrors(form, opts);
4245
+ this._ref.markForCheck();
4246
+ }
4247
+ else if (this.value !== undefined) {
4248
+ this.value = undefined;
4249
+ this._ref.markForCheck();
4250
+ }
4251
+ };
4252
+ /**
4253
+ * Clean any existing subscription to change events
4254
+ */
4255
+ FormErrorTranslatePipe.prototype._dispose = function () {
4256
+ if (typeof this._onFormStatusChange !== 'undefined') {
4257
+ this._onFormStatusChange.unsubscribe();
4258
+ this._onFormStatusChange = undefined;
4259
+ }
4224
4260
  };
4225
4261
  return FormErrorTranslatePipe;
4226
4262
  }());
4227
4263
  FormErrorTranslatePipe.decorators = [
4228
4264
  { type: i0.Pipe, args: [{
4229
4265
  name: 'translateFormError',
4266
+ pure: false
4230
4267
  },] }
4231
4268
  ];
4232
4269
  FormErrorTranslatePipe.ctorParameters = function () { return [
4233
- { type: FormErrorTranslator }
4270
+ { type: FormErrorTranslator },
4271
+ { type: i0.ChangeDetectorRef }
4234
4272
  ]; };
4235
4273
 
4236
4274
  var SharedPipesModule = /** @class */ (function () {
@@ -8626,7 +8664,7 @@
8626
8664
  };
8627
8665
  AppFormField.prototype.computeValuesFromToken = function (token) {
8628
8666
  var values = this.injector.get(token);
8629
- return values instanceof Array ? values : [];
8667
+ return Array.isArray(values) ? values : [];
8630
8668
  };
8631
8669
  AppFormField.prototype.checkAndResolveFormControl = function () {
8632
8670
  var _this = this;
@@ -9844,7 +9882,7 @@
9844
9882
  }, {});
9845
9883
  };
9846
9884
  EntityUtils.getMapAsArray = function (source) {
9847
- if (source instanceof Array)
9885
+ if (Array.isArray(source))
9848
9886
  return source;
9849
9887
  return Object.getOwnPropertyNames(source || {})
9850
9888
  .map(function (key) { return ({
@@ -10843,7 +10881,7 @@
10843
10881
  case 2:
10844
10882
  data = Object.assign(Object.assign({}, this._data), settings);
10845
10883
  if (equals(data, this._data))
10846
- return [2 /*return*/]; // SKip if same
10884
+ return [2 /*return*/]; // Skip if no changes
10847
10885
  this._data = data;
10848
10886
  if (!(opts && opts.persistImmediate)) return [3 /*break*/, 4];
10849
10887
  return [4 /*yield*/, this.persistLocally(true)];
@@ -10924,9 +10962,11 @@
10924
10962
  if (!feature)
10925
10963
  return; // Not found
10926
10964
  if (typeof feature === 'string') {
10965
+ var lastSyncDate = feature.substring(featurePrefix.length);
10966
+ console.debug("[" + featureName + "] Last synchronization date: " + lastSyncDate);
10927
10967
  return {
10928
10968
  name: featureName,
10929
- lastSyncDate: feature.substring(featurePrefix.length)
10969
+ lastSyncDate: lastSyncDate
10930
10970
  };
10931
10971
  }
10932
10972
  return feature;
@@ -12348,8 +12388,8 @@
12348
12388
  ])];
12349
12389
  case 1:
12350
12390
  res = _a.sent();
12351
- values = res[0] && res[0] instanceof Array ? res[0] : null;
12352
- ids = res[1] && res[1] instanceof Array ? res[1] : null;
12391
+ values = res[0] && Array.isArray(res[0]) ? res[0] : null;
12392
+ ids = res[1] && Array.isArray(res[1]) ? res[1] : null;
12353
12393
  migration = false;
12354
12394
  if (!this.isByIdMode) return [3 /*break*/, 5];
12355
12395
  if (!isNotNil(ids)) return [3 /*break*/, 3];
@@ -13947,7 +13987,7 @@
13947
13987
  .pipe(operators.catchError(function (error) { return _this.onApolloError(error, opts.error); }), operators.first()).toPromise()];
13948
13988
  case 5:
13949
13989
  res = _b.sent();
13950
- if (res.errors instanceof Array) {
13990
+ if (Array.isArray(res.errors)) {
13951
13991
  throw res.errors[0];
13952
13992
  }
13953
13993
  return [2 /*return*/, res.data];
@@ -14511,7 +14551,10 @@
14511
14551
  var message = err && err.message || err;
14512
14552
  if (typeof message === 'string' && message.trim().indexOf('{"code":') === 0) {
14513
14553
  try {
14514
- error = JSON.parse(err.message);
14554
+ error = JSON.parse(message
14555
+ // Remove special characters before parsing (e.g. SQL errors from an Oracle database)
14556
+ .replace('\n', ' ')
14557
+ .replace('\r', ''));
14515
14558
  }
14516
14559
  catch (parseError) {
14517
14560
  console.error('Unable to parse error as JSON: ', parseError);
@@ -14618,7 +14661,7 @@
14618
14661
  if (!queries.length)
14619
14662
  return;
14620
14663
  queries.forEach(function (query) {
14621
- if (opts.data instanceof Array) {
14664
+ if (Array.isArray(opts.data)) {
14622
14665
  // Filter values, if a filter function exists
14623
14666
  var data = query.insertFilterFn ? opts.data.filter(function (i) { return query.insertFilterFn(i); }) : opts.data;
14624
14667
  if (isNotEmptyArray(data)) {
@@ -14656,7 +14699,7 @@
14656
14699
  return;
14657
14700
  console.debug("[base-data-service] Removing data from watching queries: ", queries);
14658
14701
  return queries.map(function (query) {
14659
- if (opts.ids instanceof Array) {
14702
+ if (Array.isArray(opts.ids)) {
14660
14703
  return _this.graphql.removeFromCachedQueryByIds(cache, {
14661
14704
  query: query.query,
14662
14705
  variables: query.variables,
@@ -15573,7 +15616,7 @@
15573
15616
  }
15574
15617
  });
15575
15618
  // Add log when closing WS
15576
- subscription.add(function () { return console.debug('[account] [WS] Stop listening account changes'); });
15619
+ subscription.add(function () { return console.debug('[account] [WS] Stop listening changes'); });
15577
15620
  return subscription;
15578
15621
  };
15579
15622
  Object.defineProperty(AccountService.prototype, "additionalFields", {
@@ -16054,7 +16097,7 @@
16054
16097
  this.comments = source.comments;
16055
16098
  this.creationDate = fromDateISOString(source.creationDate);
16056
16099
  this.statusId = source.statusId;
16057
- if (source.properties && source.properties instanceof Array) {
16100
+ if (source.properties && Array.isArray(source.properties)) {
16058
16101
  this.properties = EntityUtils.getPropertyArrayAsObject(source.properties);
16059
16102
  }
16060
16103
  else {
@@ -17668,20 +17711,30 @@
17668
17711
  function CustomReuseStrategy() {
17669
17712
  return _super !== null && _super.apply(this, arguments) || this;
17670
17713
  }
17714
+ /**
17715
+ * Force to reuse the route when:
17716
+ * - path change from [/new] -> [/:id]
17717
+ * - or path change from [/new] -> [/new?id=:id]
17718
+ * @param future
17719
+ * @param curr
17720
+ */
17671
17721
  CustomReuseStrategy.prototype.shouldReuseRoute = function (future, curr) {
17672
17722
  var result = _super.prototype.shouldReuseRoute.call(this, future, curr);
17673
- // Force to reuse the route when:
17674
- // - path change from [/new] -> [/:id]
17675
- // - or path change from [/new] -> [/new?id=:id]
17723
+ // Is sam route config
17676
17724
  if (!result && future.routeConfig && future.routeConfig === curr.routeConfig) {
17725
+ // Read the parameter name, where id is stored
17677
17726
  var pathIdParam = future.routeConfig.data && future.routeConfig.data.pathIdParam || 'id';
17678
- var futureId = future.params[pathIdParam] === 'new' ?
17679
- (future.queryParams[pathIdParam] || future.queryParams['id']) : future.params[pathIdParam];
17680
- var currId = curr.params[pathIdParam] === 'new' ?
17681
- (curr.queryParams[pathIdParam] || curr.queryParams['id']) : curr.params[pathIdParam];
17682
- return futureId === currId &&
17683
- // Always reload 'new' page
17684
- currId !== 'new';
17727
+ // Read the current route id
17728
+ var currId = curr.params[pathIdParam] === 'new'
17729
+ ? (curr.queryParams[pathIdParam] || curr.queryParams['id'] || 'new') // e.g. path like '/new/?id=<ID>'
17730
+ : curr.params[pathIdParam]; // e.g. path like '/<ID>'
17731
+ // Read the future route id
17732
+ var futureId = future.params[pathIdParam] === 'new'
17733
+ ? (future.queryParams[pathIdParam] || future.queryParams['id'] || 'new') // e.g. path like '/new/?id=<ID>'
17734
+ : future.params[pathIdParam]; // e.g. path like '/<ID>'
17735
+ // Reuse if same ID, but never when 'new' expected
17736
+ return futureId !== 'new' && currId !== 'new'
17737
+ && futureId === currId;
17685
17738
  }
17686
17739
  return result;
17687
17740
  };
@@ -22189,7 +22242,7 @@
22189
22242
  function DepartmentToStringPipe() {
22190
22243
  }
22191
22244
  DepartmentToStringPipe.prototype.transform = function (value, separator) {
22192
- if (value instanceof Array)
22245
+ if (Array.isArray(value))
22193
22246
  return departmentsToString(value, separator);
22194
22247
  return departmentToString(value);
22195
22248
  };