@sumaris-net/ngx-components 1.20.2 → 1.20.5

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 (33) hide show
  1. package/bundles/sumaris-net.ngx-components.umd.js +253 -46
  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 +11 -0
  6. package/esm2015/public_api.js +7 -3
  7. package/esm2015/src/app/core/install/install-upgrade-card.component.js +3 -2
  8. package/esm2015/src/app/core/services/platform.service.js +3 -2
  9. package/esm2015/src/app/shared/directives/autotitle.directive.js +27 -0
  10. package/esm2015/src/app/shared/directives/directives.module.js +6 -3
  11. package/esm2015/src/app/shared/file/csv.utils.js +90 -0
  12. package/esm2015/src/app/shared/file/file.utils.js +63 -0
  13. package/esm2015/src/app/shared/file/uri.utils.js +23 -0
  14. package/esm2015/src/app/shared/functions.js +3 -1
  15. package/esm2015/src/app/shared/pipes/form.pipes.js +21 -24
  16. package/esm2015/src/app/shared/pipes/pipes.module.js +7 -4
  17. package/esm2015/src/app/shared/pipes/property.pipes.js +98 -0
  18. package/esm2015/src/app/shared/upload-file/testing/upload-file.testing.js +2 -2
  19. package/fesm2015/sumaris-net.ngx-components.js +235 -44
  20. package/fesm2015/sumaris-net.ngx-components.js.map +1 -1
  21. package/package.json +1 -1
  22. package/public_api.d.ts +6 -2
  23. package/src/app/shared/directives/autotitle.directive.d.ts +7 -0
  24. package/src/app/shared/file/csv.utils.d.ts +18 -0
  25. package/src/app/shared/{files.d.ts → file/file.utils.d.ts} +3 -9
  26. package/src/app/shared/file/uri.utils.d.ts +7 -0
  27. package/src/app/shared/pipes/form.pipes.d.ts +1 -1
  28. package/src/app/shared/pipes/property.pipes.d.ts +22 -0
  29. package/src/theme/_mixins.scss +2 -0
  30. package/sumaris-net.ngx-components.metadata.json +1 -1
  31. package/esm2015/src/app/shared/files.js +0 -84
  32. package/esm2015/src/app/shared/pipes/properties.pipe.js +0 -20
  33. package/src/app/shared/pipes/properties.pipe.d.ts +0 -7
@@ -576,6 +576,8 @@
576
576
  function joinPropertiesPath(obj, properties, separator) {
577
577
  if (!obj)
578
578
  throw new Error('Could not display an undefined entity.');
579
+ if (!properties)
580
+ throw new Error('Missing \'properties\' argument');
579
581
  return properties
580
582
  .map(function (path) { return getPropertyByPath(obj, path); })
581
583
  .filter(isNotNilOrBlank)
@@ -3344,26 +3346,6 @@
3344
3346
  { type: i0.Injectable }
3345
3347
  ];
3346
3348
 
3347
- var PropertyGetPipe = /** @class */ (function () {
3348
- function PropertyGetPipe() {
3349
- }
3350
- PropertyGetPipe.prototype.transform = function (obj, args) {
3351
- return getPropertyByPath(obj,
3352
- // Path
3353
- args && (typeof args === 'string' ? args : args.key),
3354
- // Default value
3355
- args && args.defaultValue);
3356
- };
3357
- return PropertyGetPipe;
3358
- }());
3359
- PropertyGetPipe.ɵprov = i0.ɵɵdefineInjectable({ factory: function PropertyGetPipe_Factory() { return new PropertyGetPipe(); }, token: PropertyGetPipe, providedIn: "root" });
3360
- PropertyGetPipe.decorators = [
3361
- { type: i0.Pipe, args: [{
3362
- name: 'propertyGet'
3363
- },] },
3364
- { type: i0.Injectable, args: [{ providedIn: 'root' },] }
3365
- ];
3366
-
3367
3349
  var NgInitDirective = /** @class */ (function () {
3368
3350
  function NgInitDirective() {
3369
3351
  this.ngInit = new i0.EventEmitter();
@@ -4737,10 +4719,9 @@
4737
4719
  * Clean any existing subscription to change events
4738
4720
  */
4739
4721
  FormErrorTranslatePipe.prototype._dispose = function () {
4740
- if (typeof this._onFormStatusChanges !== 'undefined') {
4741
- this._onFormStatusChanges.unsubscribe();
4742
- this._onFormStatusChanges = undefined;
4743
- }
4722
+ var _a;
4723
+ (_a = this._onFormStatusChanges) === null || _a === void 0 ? void 0 : _a.unsubscribe();
4724
+ this._onFormStatusChanges = undefined;
4744
4725
  };
4745
4726
  return FormErrorTranslatePipe;
4746
4727
  }());
@@ -4833,23 +4814,24 @@
4833
4814
  this.value = control === null || control === void 0 ? void 0 : control.value;
4834
4815
  // if there is a subscription to onLangChange, clean it
4835
4816
  this._dispose();
4836
- // subscribe to valueChanges event, in case control value change
4837
- if (!this._onControlValueChanges && control) {
4817
+ if (control) {
4818
+ // subscribe to valueChanges event
4838
4819
  this._onControlValueChanges = control.valueChanges.subscribe(function (value) {
4839
4820
  if (value !== _this.value) {
4840
4821
  _this.value = value;
4841
4822
  _this._ref.markForCheck();
4842
4823
  }
4843
4824
  });
4844
- }
4845
- if (listenStatusChanges && !this._onControlStatusChanges && control) {
4846
- this._onControlStatusChanges = control.statusChanges.subscribe(function (status) {
4847
- var value = control.value;
4848
- if (value !== _this.value) {
4849
- _this.value = value;
4850
- _this._ref.markForCheck();
4851
- }
4852
- });
4825
+ // subscribe to statusChanges event
4826
+ if (listenStatusChanges) {
4827
+ this._onControlStatusChanges = control.statusChanges.subscribe(function (status) {
4828
+ var value = control.value;
4829
+ if (value !== _this.value) {
4830
+ _this.value = value;
4831
+ _this._ref.markForCheck();
4832
+ }
4833
+ });
4834
+ }
4853
4835
  }
4854
4836
  return this.value;
4855
4837
  };
@@ -4860,14 +4842,11 @@
4860
4842
  * Clean any existing subscription to change events
4861
4843
  */
4862
4844
  FormGetValuePipe.prototype._dispose = function () {
4863
- if (typeof this._onControlValueChanges !== 'undefined') {
4864
- this._onControlValueChanges.unsubscribe();
4865
- this._onControlValueChanges = undefined;
4866
- }
4867
- if (typeof this._onControlStatusChanges !== 'undefined') {
4868
- this._onControlStatusChanges.unsubscribe();
4869
- this._onControlStatusChanges = undefined;
4870
- }
4845
+ var _a, _b;
4846
+ (_a = this._onControlValueChanges) === null || _a === void 0 ? void 0 : _a.unsubscribe();
4847
+ this._onControlValueChanges = undefined;
4848
+ (_b = this._onControlStatusChanges) === null || _b === void 0 ? void 0 : _b.unsubscribe();
4849
+ this._onControlStatusChanges = undefined;
4871
4850
  };
4872
4851
  return FormGetValuePipe;
4873
4852
  }());
@@ -4882,6 +4861,109 @@
4882
4861
  { type: i0.ChangeDetectorRef }
4883
4862
  ]; };
4884
4863
 
4864
+ var PropertyGetPipe = /** @class */ (function () {
4865
+ function PropertyGetPipe() {
4866
+ }
4867
+ PropertyGetPipe.prototype.transform = function (obj, args) {
4868
+ return getPropertyByPath(obj,
4869
+ // Path
4870
+ args && (typeof args === 'string' ? args : args.key),
4871
+ // Default value
4872
+ args && args.defaultValue);
4873
+ };
4874
+ return PropertyGetPipe;
4875
+ }());
4876
+ PropertyGetPipe.decorators = [
4877
+ { type: i0.Pipe, args: [{
4878
+ name: 'propertyGet'
4879
+ },] }
4880
+ ];
4881
+ var PropertyFormatPipe = /** @class */ (function () {
4882
+ function PropertyFormatPipe(dateFormat, translate) {
4883
+ this.dateFormat = dateFormat;
4884
+ this.translate = translate;
4885
+ }
4886
+ PropertyFormatPipe.prototype.ngOnDestroy = function () {
4887
+ var _a;
4888
+ (_a = this._subscription) === null || _a === void 0 ? void 0 : _a.unsubscribe();
4889
+ };
4890
+ PropertyFormatPipe.prototype.transform = function (obj, keyOrDefinition) {
4891
+ var _a, _b;
4892
+ if (!obj)
4893
+ return '';
4894
+ var definition = keyOrDefinition && (typeof keyOrDefinition === 'object') && keyOrDefinition;
4895
+ var key = (definition === null || definition === void 0 ? void 0 : definition.key) || keyOrDefinition;
4896
+ if (!key) {
4897
+ // Should never occur
4898
+ console.warn('Invalid use of pipe \'formatProperty\': missing key or definition');
4899
+ return '';
4900
+ }
4901
+ var value = obj[key];
4902
+ if (isNil(value))
4903
+ return value;
4904
+ var type = (definition === null || definition === void 0 ? void 0 : definition.type) || typeof value;
4905
+ switch (type) {
4906
+ case 'date':
4907
+ return this.dateFormat.transform(value);
4908
+ case 'dateTime':
4909
+ return this.dateFormat.transform(value, { time: true });
4910
+ case 'enum':
4911
+ {
4912
+ // DEBUG
4913
+ // console.debug('formatProperty by definition (type='enum', key=' +definition.key+ '):', value );
4914
+ var item = (definition.values || [value]).find(function (item) { return (isNotNil(item.key) ? item.key : item) === value; });
4915
+ return item.value || item;
4916
+ }
4917
+ case 'entity':
4918
+ {
4919
+ if ((_a = definition.autocomplete) === null || _a === void 0 ? void 0 : _a.displayWith) {
4920
+ return definition.autocomplete.displayWith(value);
4921
+ }
4922
+ return joinPropertiesPath(obj, ((_b = definition.autocomplete) === null || _b === void 0 ? void 0 : _b.attributes) || ['label', 'name']) || undefined;
4923
+ }
4924
+ case 'boolean':
4925
+ return (obj === 1 || obj === true || obj === 'true') ? this.i18nYes : this.i18nNo;
4926
+ case 'integer':
4927
+ case 'double':
4928
+ case 'string':
4929
+ default:
4930
+ return value;
4931
+ }
4932
+ };
4933
+ Object.defineProperty(PropertyFormatPipe.prototype, "i18nYes", {
4934
+ get: function () {
4935
+ if (!this._i18nYes) {
4936
+ this._i18nYes = this.translate.instant('COMMON.YES');
4937
+ }
4938
+ return this._i18nYes;
4939
+ },
4940
+ enumerable: false,
4941
+ configurable: true
4942
+ });
4943
+ Object.defineProperty(PropertyFormatPipe.prototype, "i18nNo", {
4944
+ get: function () {
4945
+ if (!this._i18nNo) {
4946
+ this._i18nNo = this.translate.instant('COMMON.NO');
4947
+ }
4948
+ return this._i18nNo;
4949
+ },
4950
+ enumerable: false,
4951
+ configurable: true
4952
+ });
4953
+ return PropertyFormatPipe;
4954
+ }());
4955
+ PropertyFormatPipe.ɵprov = i0.ɵɵdefineInjectable({ factory: function PropertyFormatPipe_Factory() { return new PropertyFormatPipe(i0.ɵɵinject(DateFormatPipe), i0.ɵɵinject(i1$2.TranslateService)); }, token: PropertyFormatPipe, providedIn: "root" });
4956
+ PropertyFormatPipe.decorators = [
4957
+ { type: i0.Pipe, args: [{
4958
+ name: 'propertyFormat'
4959
+ },] },
4960
+ { type: i0.Injectable, args: [{ providedIn: 'root' },] }
4961
+ ];
4962
+ PropertyFormatPipe.ctorParameters = function () { return [
4963
+ { type: DateFormatPipe },
4964
+ { type: i1$2.TranslateService }
4965
+ ]; };
4966
+
4885
4967
  var SharedPipesModule = /** @class */ (function () {
4886
4968
  function SharedPipesModule() {
4887
4969
  }
@@ -4896,6 +4978,7 @@
4896
4978
  ],
4897
4979
  declarations: [
4898
4980
  PropertyGetPipe,
4981
+ PropertyFormatPipe,
4899
4982
  DateFormatPipe,
4900
4983
  DateDiffDurationPipe,
4901
4984
  DurationPipe,
@@ -4932,10 +5015,12 @@
4932
5015
  FormGetControlPipe,
4933
5016
  FormGetArrayPipe,
4934
5017
  FormGetGroupPipe,
4935
- FormGetValuePipe
5018
+ FormGetValuePipe,
5019
+ PropertyFormatPipe
4936
5020
  ],
4937
5021
  exports: [
4938
5022
  PropertyGetPipe,
5023
+ PropertyFormatPipe,
4939
5024
  DateFormatPipe,
4940
5025
  DateFromNowPipe,
4941
5026
  DateDiffDurationPipe,
@@ -5143,6 +5228,33 @@
5143
5228
  ondrop: [{ type: i0.HostListener, args: ['drop', ['$event'],] }]
5144
5229
  };
5145
5230
 
5231
+ var compatibleTagNames = ['ion-label', 'mat-label'];
5232
+ var AutoTitleDirective = /** @class */ (function () {
5233
+ function AutoTitleDirective(elementRef) {
5234
+ var _a;
5235
+ this.elementRef = elementRef;
5236
+ // Check compatible tag
5237
+ if (compatibleTagNames.includes((_a = elementRef.nativeElement.tagName) === null || _a === void 0 ? void 0 : _a.toLowerCase())) {
5238
+ this.element = elementRef.nativeElement;
5239
+ }
5240
+ }
5241
+ AutoTitleDirective.prototype.ngAfterContentChecked = function () {
5242
+ // Update title if different
5243
+ if (this.element && this.element.title !== this.element.textContent) {
5244
+ this.element.title = this.element.textContent;
5245
+ }
5246
+ };
5247
+ return AutoTitleDirective;
5248
+ }());
5249
+ AutoTitleDirective.decorators = [
5250
+ { type: i0.Directive, args: [{
5251
+ selector: '[appAutoTitle]',
5252
+ },] }
5253
+ ];
5254
+ AutoTitleDirective.ctorParameters = function () { return [
5255
+ { type: i0.ElementRef, decorators: [{ type: i0.Inject, args: [i0.ElementRef,] }] }
5256
+ ]; };
5257
+
5146
5258
  var SharedDirectivesModule = /** @class */ (function () {
5147
5259
  function SharedDirectivesModule() {
5148
5260
  }
@@ -5157,12 +5269,14 @@
5157
5269
  declarations: [
5158
5270
  AutofocusDirective,
5159
5271
  NgVarDirective,
5160
- DragAndDropDirective
5272
+ DragAndDropDirective,
5273
+ AutoTitleDirective
5161
5274
  ],
5162
5275
  exports: [
5163
5276
  AutofocusDirective,
5164
5277
  NgVarDirective,
5165
- DragAndDropDirective
5278
+ DragAndDropDirective,
5279
+ AutoTitleDirective
5166
5280
  ]
5167
5281
  },] }
5168
5282
  ];
@@ -18241,6 +18355,8 @@
18241
18355
  };
18242
18356
  return FilesUtils;
18243
18357
  }());
18358
+ FilesUtils.UTF8_BOM_CHAR = new Uint8Array([0xEF, 0xBB, 0xBF]); // UTF-8 BOM
18359
+
18244
18360
  var UriUtils = /** @class */ (function () {
18245
18361
  function UriUtils() {
18246
18362
  }
@@ -20755,6 +20871,94 @@
20755
20871
  return JobUtils;
20756
20872
  }());
20757
20873
 
20874
+ //@dynamic
20875
+ var CsvUtils = /** @class */ (function () {
20876
+ function CsvUtils() {
20877
+ }
20878
+ CsvUtils.exportToFile = function (rows, opts) {
20879
+ if (!rows || !rows.length)
20880
+ return; // Skip if empty
20881
+ var filename = (opts === null || opts === void 0 ? void 0 : opts.filename) || 'export.csv';
20882
+ var charset = ((opts === null || opts === void 0 ? void 0 : opts.encoding) || 'utf-8').toLowerCase();
20883
+ var separator = (opts === null || opts === void 0 ? void 0 : opts.separator) || ',';
20884
+ var protectCellRegexp = new RegExp("/(\"|" + separator + "|\n)/g");
20885
+ var keys = Object.keys(rows[0]);
20886
+ var headers = (opts === null || opts === void 0 ? void 0 : opts.headers) || keys;
20887
+ var csvContent =
20888
+ // Header row
20889
+ headers.join(separator) + '\n' +
20890
+ // Data rows
20891
+ rows.map(function (row) {
20892
+ return keys.map(function (k) {
20893
+ var cell = row[k] === null || row[k] === undefined ? '' : row[k];
20894
+ var cellStr = cell instanceof Date
20895
+ ? cell.toLocaleString()
20896
+ : cell.toString().replace(/"/g, '""');
20897
+ if (protectCellRegexp.test(cellStr)) {
20898
+ cellStr = "\"" + cellStr + "\"";
20899
+ }
20900
+ return cellStr;
20901
+ }).join(separator);
20902
+ }).join('\n');
20903
+ var blob = new Blob((charset === 'utf-8')
20904
+ // Add UTF-8 BOM character
20905
+ ? [FilesUtils.UTF8_BOM_CHAR, csvContent]
20906
+ // Non UTF-8 charset
20907
+ : [csvContent], { type: "text/csv;charset=" + charset + ";" });
20908
+ if (navigator.msSaveBlob) { // IE 10+
20909
+ navigator.msSaveBlob(blob, filename);
20910
+ }
20911
+ else {
20912
+ var link = document.createElement('a');
20913
+ if (link.download !== undefined) {
20914
+ // Browsers that support HTML5 download attribute
20915
+ var url = URL.createObjectURL(blob);
20916
+ link.setAttribute('href', url);
20917
+ link.setAttribute('download', filename);
20918
+ link.style.visibility = 'hidden';
20919
+ document.body.appendChild(link);
20920
+ link.click();
20921
+ document.body.removeChild(link);
20922
+ }
20923
+ }
20924
+ };
20925
+ CsvUtils.parseFile = function (file, opts) {
20926
+ return FilesUtils.readAsText(file, opts === null || opts === void 0 ? void 0 : opts.encoding)
20927
+ .pipe(operators.map(function (e) {
20928
+ if (e.type === i2$1.HttpEventType.UploadProgress) {
20929
+ var loaded = Math.round(e.loaded * 0.8);
20930
+ return Object.assign(Object.assign({}, e), { loaded: loaded });
20931
+ }
20932
+ else if (e instanceof FileResponse) {
20933
+ var body = e.body;
20934
+ var data = CsvUtils.parseCSV(body, opts);
20935
+ return new FileResponse({ body: data });
20936
+ }
20937
+ }), operators.filter(isNotNil));
20938
+ };
20939
+ CsvUtils.parseCSV = function (body, opts) {
20940
+ var separator = (opts === null || opts === void 0 ? void 0 : opts.separator) || ',';
20941
+ var skipEmptyLine = !opts || opts.skipEmptyLine !== false;
20942
+ // Protect special characters (quote and /n)
20943
+ body = body.replace('""', '<quote>') // Protect double quote
20944
+ .replace(/("[^\n"]+)\n\r?/gm, '"$1<br>') // Protect \n inside a quoted expression
20945
+ .replace(/\n\r/gm, '\n'); // Windows CR
20946
+ var headerAndRows = body.split('\n', 2);
20947
+ var headers = headerAndRows[0].split(separator);
20948
+ return body.split('\n') // split into rows
20949
+ .filter(function (line) { return !skipEmptyLine || line.trim().length > 0; }) // Skip empty line
20950
+ .map(function (line) {
20951
+ var cells = line.split(separator, headers.length) // split into cells
20952
+ .map(function (cell) { return cell.replace(/^"([^"]*)"$/, '$1'); }) // Clean trailing quotes
20953
+ .map(function (cell) { return cell.replace('<quote>', '"'); }) // restore protected quote
20954
+ .map(function (cell) { return cell.replace('<br>', '\n'); }) // restore protected br
20955
+ ;
20956
+ return cells;
20957
+ });
20958
+ };
20959
+ return CsvUtils;
20960
+ }());
20961
+
20758
20962
  /**
20759
20963
  * Define here theme colors
20760
20964
  */
@@ -32204,6 +32408,7 @@
32204
32408
  exports.AuthForm = AuthForm;
32205
32409
  exports.AuthGuardService = AuthGuardService;
32206
32410
  exports.AuthModal = AuthModal;
32411
+ exports.AutoTitleDirective = AutoTitleDirective;
32207
32412
  exports.AutocompleteTestPage = AutocompleteTestPage;
32208
32413
  exports.AutofocusDirective = AutofocusDirective;
32209
32414
  exports.Base58 = Base58;
@@ -32223,6 +32428,7 @@
32223
32428
  exports.CoreModule = CoreModule;
32224
32429
  exports.CoreTestingModule = CoreTestingModule;
32225
32430
  exports.CryptoService = CryptoService;
32431
+ exports.CsvUtils = CsvUtils;
32226
32432
  exports.DATE_ISO_PATTERN = DATE_ISO_PATTERN;
32227
32433
  exports.DATE_UNIX_MS_TIMESTAMP = DATE_UNIX_MS_TIMESTAMP;
32228
32434
  exports.DATE_UNIX_TIMESTAMP = DATE_UNIX_TIMESTAMP;
@@ -32343,6 +32549,7 @@
32343
32549
  exports.PlatformService = PlatformService;
32344
32550
  exports.ProgressBarService = ProgressBarService;
32345
32551
  exports.ProgressInterceptor = ProgressInterceptor;
32552
+ exports.PropertyFormatPipe = PropertyFormatPipe;
32346
32553
  exports.PropertyGetPipe = PropertyGetPipe;
32347
32554
  exports.RESERVED_END_COLUMNS = RESERVED_END_COLUMNS;
32348
32555
  exports.RESERVED_START_COLUMNS = RESERVED_START_COLUMNS;