@sumaris-net/ngx-components 0.28.1 → 0.28.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.
- package/bundles/sumaris-net.ngx-components.umd.js +131 -57
- package/bundles/sumaris-net.ngx-components.umd.js.map +1 -1
- package/bundles/sumaris-net.ngx-components.umd.min.js +2 -2
- package/bundles/sumaris-net.ngx-components.umd.min.js.map +1 -1
- package/esm2015/src/app/core/account/account.js +4 -5
- package/esm2015/src/app/core/auth/form/form-auth.js +3 -4
- package/esm2015/src/app/core/form/editor.class.js +10 -2
- package/esm2015/src/app/core/form/entity-editor.class.js +15 -7
- package/esm2015/src/app/core/form/form.class.js +24 -10
- package/esm2015/src/app/core/form/list.form.js +2 -3
- package/esm2015/src/app/core/form/properties.form.js +2 -3
- package/esm2015/src/app/core/settings/settings.page.js +3 -4
- package/esm2015/src/app/shared/services/translate-context.service.js +38 -13
- package/fesm2015/sumaris-net.ngx-components.js +91 -40
- package/fesm2015/sumaris-net.ngx-components.js.map +1 -1
- package/package.json +1 -1
- package/src/app/core/account/account.d.ts +0 -1
- package/src/app/core/auth/form/form-auth.d.ts +0 -1
- package/src/app/core/form/editor.class.d.ts +2 -0
- package/src/app/core/form/form.class.d.ts +10 -2
- package/src/app/core/form/list.form.d.ts +0 -1
- package/src/app/core/form/properties.form.d.ts +0 -1
- package/src/app/core/settings/settings.page.d.ts +0 -1
- package/src/app/shared/services/translate-context.service.d.ts +10 -0
- package/sumaris-net.ngx-components.metadata.json +1 -1
|
@@ -36,7 +36,7 @@ import { MatAutocomplete, MatAutocompleteTrigger, MatAutocompleteModule, MAT_AUT
|
|
|
36
36
|
import { __awaiter, __decorate } from 'tslib';
|
|
37
37
|
import * as i1$6 from '@angular/forms';
|
|
38
38
|
import { NG_VALUE_ACCESSOR, FormGroupDirective, AbstractControl, FormGroup, FormArray, FormControl, ReactiveFormsModule, Validators, FormBuilder } from '@angular/forms';
|
|
39
|
-
import { timer, merge, fromEvent, Subscription, BehaviorSubject, Subject, isObservable,
|
|
39
|
+
import { timer, merge, fromEvent, Subscription, BehaviorSubject, Subject, isObservable, noop as noop$8, Observable, defer, of, from, combineLatest, EMPTY } from 'rxjs';
|
|
40
40
|
import { filter, first, map, takeUntil, startWith, debounceTime, takeWhile, switchMap, tap, distinctUntilChanged, mergeMap, catchError, throttleTime, skip } from 'rxjs/operators';
|
|
41
41
|
import * as i1$1 from '@ngx-translate/core';
|
|
42
42
|
import { TranslateService, TranslateModule } from '@ngx-translate/core';
|
|
@@ -2431,23 +2431,41 @@ class TranslateContextService {
|
|
|
2431
2431
|
}
|
|
2432
2432
|
get(key, context, interpolateParams) {
|
|
2433
2433
|
// No context: do a normal translate
|
|
2434
|
-
if (!isNil(context))
|
|
2434
|
+
if (!key || !isNil(context))
|
|
2435
2435
|
return this.translate.get(key, interpolateParams);
|
|
2436
2436
|
// Compute a contextual i18n key, using the context as suffix
|
|
2437
|
-
const
|
|
2437
|
+
const contextualKeys = this.contextualKeys(key, context);
|
|
2438
2438
|
// Return the contextual translation, or default of not exists
|
|
2439
|
-
return this.translate.get(
|
|
2440
|
-
.pipe(
|
|
2439
|
+
return this.translate.get(contextualKeys, interpolateParams)
|
|
2440
|
+
.pipe(map(translations => this.findFirstValid(contextualKeys, translations)));
|
|
2441
2441
|
}
|
|
2442
2442
|
instant(key, context, interpolateParams) {
|
|
2443
2443
|
// No context: do a normal translate
|
|
2444
|
-
if (isNilOrBlank(context))
|
|
2444
|
+
if (!key || isNilOrBlank(context))
|
|
2445
2445
|
return this.translate.instant(key, interpolateParams);
|
|
2446
2446
|
// Compute a contextual i18n key, using the context as suffix
|
|
2447
|
-
const
|
|
2448
|
-
|
|
2449
|
-
|
|
2450
|
-
|
|
2447
|
+
const contextualKeys = this.contextualKeys(key, context);
|
|
2448
|
+
const translations = this.translate.instant(contextualKeys, interpolateParams);
|
|
2449
|
+
return this.findFirstValid(contextualKeys, translations);
|
|
2450
|
+
}
|
|
2451
|
+
/**
|
|
2452
|
+
* Compute contextual i18n keys, using the context as suffix.<br>
|
|
2453
|
+
* Suffix can be simple name (like 'aaa' - will return ['<key>.aaa']) or complexe (like 'aaa.bbb' - will return ['<key>.aaa.bbb', '<key>.aaa']
|
|
2454
|
+
*
|
|
2455
|
+
* @param key
|
|
2456
|
+
* @param context
|
|
2457
|
+
* @private
|
|
2458
|
+
*/
|
|
2459
|
+
contextualKeys(key, context) {
|
|
2460
|
+
return context.split('.')
|
|
2461
|
+
.filter(isNotNilOrBlank)
|
|
2462
|
+
.reduce((res, item) => {
|
|
2463
|
+
const inheritedContext = res.length > 0 ? (res[res.length - 1] + '.') : '';
|
|
2464
|
+
return res.concat(inheritedContext + item);
|
|
2465
|
+
}, [])
|
|
2466
|
+
.reverse() // Start with children, ends with parent key
|
|
2467
|
+
.map(contextItem => this.contextualKey(key, contextItem))
|
|
2468
|
+
.concat(key);
|
|
2451
2469
|
}
|
|
2452
2470
|
/**
|
|
2453
2471
|
* Compute a contextual i18n key, using the context as suffix
|
|
@@ -2467,6 +2485,14 @@ class TranslateContextService {
|
|
|
2467
2485
|
? `${context}${key}`
|
|
2468
2486
|
: parts.slice(0, parts.length - 1).concat(context + parts[parts.length - 1]).join('.');
|
|
2469
2487
|
}
|
|
2488
|
+
findFirstValid(keys, translations) {
|
|
2489
|
+
// For eac contextual key: try to find translation, then use the first valid
|
|
2490
|
+
for (let key of keys) {
|
|
2491
|
+
if (translations[key] !== key)
|
|
2492
|
+
return translations[key];
|
|
2493
|
+
}
|
|
2494
|
+
return translations[keys[keys.length - 1]]; // Return the last keys translation
|
|
2495
|
+
}
|
|
2470
2496
|
}
|
|
2471
2497
|
TranslateContextService.ɵprov = i0.ɵɵdefineInjectable({ factory: function TranslateContextService_Factory() { return new TranslateContextService(i0.ɵɵinject(i1$1.TranslateService)); }, token: TranslateContextService, providedIn: "root" });
|
|
2472
2498
|
TranslateContextService.decorators = [
|
|
@@ -16657,7 +16683,7 @@ class AppForm {
|
|
|
16657
16683
|
this.error = null;
|
|
16658
16684
|
this._enable = false;
|
|
16659
16685
|
this._$ready = new BehaviorSubject(false);
|
|
16660
|
-
this.
|
|
16686
|
+
this._$loading = new BehaviorSubject(true);
|
|
16661
16687
|
this.i18nFieldPrefix = null;
|
|
16662
16688
|
this._subscription = new Subscription();
|
|
16663
16689
|
this.debug = false;
|
|
@@ -16673,8 +16699,20 @@ class AppForm {
|
|
|
16673
16699
|
});
|
|
16674
16700
|
this.autocompleteFields = this.autocompleteHelper.fields;
|
|
16675
16701
|
}
|
|
16676
|
-
|
|
16677
|
-
|
|
16702
|
+
/**
|
|
16703
|
+
* @deprecated
|
|
16704
|
+
*/
|
|
16705
|
+
set _loading(value) {
|
|
16706
|
+
this._$loading.next(value);
|
|
16707
|
+
}
|
|
16708
|
+
/**
|
|
16709
|
+
* @deprecated
|
|
16710
|
+
*/
|
|
16711
|
+
get _loading() {
|
|
16712
|
+
return this._$loading.value;
|
|
16713
|
+
}
|
|
16714
|
+
get loading() {
|
|
16715
|
+
return this._$loading.value;
|
|
16678
16716
|
}
|
|
16679
16717
|
get value() {
|
|
16680
16718
|
return this.form.value;
|
|
@@ -16768,9 +16806,11 @@ class AppForm {
|
|
|
16768
16806
|
if (this.debug)
|
|
16769
16807
|
console.debug('[form] Updating form (using entity)', data);
|
|
16770
16808
|
// Convert object to json, then apply it to form (e.g. convert 'undefined' into 'null')
|
|
16771
|
-
AppFormUtils.copyEntity2Form(data, this.form,
|
|
16772
|
-
if (!opts || opts.emitEvent !==
|
|
16809
|
+
AppFormUtils.copyEntity2Form(data, this.form, opts);
|
|
16810
|
+
if (!opts || opts.emitEvent !== false) {
|
|
16811
|
+
this.markAsLoaded({ emitEvent: false });
|
|
16773
16812
|
this.markForCheck();
|
|
16813
|
+
}
|
|
16774
16814
|
}
|
|
16775
16815
|
reset(data, opts) {
|
|
16776
16816
|
if (data) {
|
|
@@ -16819,15 +16859,15 @@ class AppForm {
|
|
|
16819
16859
|
this.markForCheck();
|
|
16820
16860
|
}
|
|
16821
16861
|
markAsLoading(opts) {
|
|
16822
|
-
if (
|
|
16823
|
-
this.
|
|
16862
|
+
if (this._$loading.value !== true) {
|
|
16863
|
+
this._$loading.next(true);
|
|
16824
16864
|
if (!opts || opts.emitEvent !== false)
|
|
16825
16865
|
this.markForCheck();
|
|
16826
16866
|
}
|
|
16827
16867
|
}
|
|
16828
16868
|
markAsLoaded(opts) {
|
|
16829
|
-
if (this.
|
|
16830
|
-
this.
|
|
16869
|
+
if (this._$loading.value !== false) {
|
|
16870
|
+
this._$loading.next(false);
|
|
16831
16871
|
if (!opts || opts.emitEvent !== false)
|
|
16832
16872
|
this.markForCheck();
|
|
16833
16873
|
}
|
|
@@ -16917,7 +16957,6 @@ class AuthForm extends AppForm {
|
|
|
16917
16957
|
this.network = network;
|
|
16918
16958
|
this.cd = cd;
|
|
16919
16959
|
this.environment = environment;
|
|
16920
|
-
this.loading = false;
|
|
16921
16960
|
this.canWorkOffline = false;
|
|
16922
16961
|
this.showPwd = false;
|
|
16923
16962
|
this.onCancel = new EventEmitter();
|
|
@@ -16965,13 +17004,13 @@ class AuthForm extends AppForm {
|
|
|
16965
17004
|
}
|
|
16966
17005
|
if (this.form.invalid || this.loading)
|
|
16967
17006
|
return;
|
|
16968
|
-
this.
|
|
17007
|
+
this.markAsLoading();
|
|
16969
17008
|
const data = this.form.value;
|
|
16970
17009
|
this.showPwd = false; // Hide password
|
|
16971
17010
|
this.error = null; // Reset error
|
|
16972
17011
|
this.registerSubscription(this.onSubmit
|
|
16973
17012
|
.pipe(debounceTime(500))
|
|
16974
|
-
.subscribe(res => this.
|
|
17013
|
+
.subscribe(res => this.markAsLoaded()));
|
|
16975
17014
|
setTimeout(() => this.onSubmit.emit({
|
|
16976
17015
|
username: data.username,
|
|
16977
17016
|
password: data.password,
|
|
@@ -17610,7 +17649,6 @@ class AccountPage extends AppForm {
|
|
|
17610
17649
|
this.translate = translate;
|
|
17611
17650
|
this.settings = settings;
|
|
17612
17651
|
this.cd = cd;
|
|
17613
|
-
this.loading = true;
|
|
17614
17652
|
this.email = {
|
|
17615
17653
|
confirmed: false,
|
|
17616
17654
|
notConfirmed: false,
|
|
@@ -17640,7 +17678,7 @@ class AccountPage extends AppForm {
|
|
|
17640
17678
|
this.onLogin(this.accountService.account);
|
|
17641
17679
|
}
|
|
17642
17680
|
else {
|
|
17643
|
-
this.
|
|
17681
|
+
this.markAsLoaded();
|
|
17644
17682
|
}
|
|
17645
17683
|
}));
|
|
17646
17684
|
}
|
|
@@ -17657,7 +17695,7 @@ class AccountPage extends AppForm {
|
|
|
17657
17695
|
this.enable();
|
|
17658
17696
|
this.markAsPristine();
|
|
17659
17697
|
this.startListenChanges();
|
|
17660
|
-
this.
|
|
17698
|
+
this.markAsLoaded();
|
|
17661
17699
|
}
|
|
17662
17700
|
onLogout() {
|
|
17663
17701
|
this.isLogin = false;
|
|
@@ -17674,7 +17712,7 @@ class AccountPage extends AppForm {
|
|
|
17674
17712
|
refresh(event) {
|
|
17675
17713
|
return __awaiter(this, void 0, void 0, function* () {
|
|
17676
17714
|
this.disable();
|
|
17677
|
-
this.
|
|
17715
|
+
this.markAsLoading();
|
|
17678
17716
|
return this.accountService.refresh();
|
|
17679
17717
|
});
|
|
17680
17718
|
}
|
|
@@ -18147,7 +18185,6 @@ class SettingsPage extends AppForm {
|
|
|
18147
18185
|
this.cd = cd;
|
|
18148
18186
|
this.network = network;
|
|
18149
18187
|
this.locales = locales;
|
|
18150
|
-
this.loading = true;
|
|
18151
18188
|
this.saving = false;
|
|
18152
18189
|
this.usageModes = ['FIELD', 'DESK'];
|
|
18153
18190
|
this.propertyDefinitionsByKey = {};
|
|
@@ -18207,7 +18244,7 @@ class SettingsPage extends AppForm {
|
|
|
18207
18244
|
}
|
|
18208
18245
|
load() {
|
|
18209
18246
|
return __awaiter(this, void 0, void 0, function* () {
|
|
18210
|
-
this.
|
|
18247
|
+
this.markAsLoading();
|
|
18211
18248
|
console.debug('[settings] Loading settings...');
|
|
18212
18249
|
const data = this.settings.settings;
|
|
18213
18250
|
// Set defaults
|
|
@@ -18238,7 +18275,7 @@ class SettingsPage extends AppForm {
|
|
|
18238
18275
|
this.enable({ emitEvent: false });
|
|
18239
18276
|
// Apply inheritance
|
|
18240
18277
|
this.setAccountInheritance(data.accountInheritance, { emitEvent: false });
|
|
18241
|
-
this.
|
|
18278
|
+
this.markAsLoaded();
|
|
18242
18279
|
this.error = null;
|
|
18243
18280
|
this.markForCheck();
|
|
18244
18281
|
}
|
|
@@ -18423,7 +18460,6 @@ class AppPropertiesForm extends AppForm {
|
|
|
18423
18460
|
this.settings = settings;
|
|
18424
18461
|
this.cd = cd;
|
|
18425
18462
|
this.formGroupDir = formGroupDir;
|
|
18426
|
-
this.loading = true;
|
|
18427
18463
|
this.definitionsMapByKey = {};
|
|
18428
18464
|
this.definitionsByIndex = {};
|
|
18429
18465
|
//this.debug = !environment.production;
|
|
@@ -18492,7 +18528,7 @@ class AppPropertiesForm extends AppForm {
|
|
|
18492
18528
|
this.helper.resize(values.length);
|
|
18493
18529
|
this.helper.formArray.patchValue(values, { emitEvent: false });
|
|
18494
18530
|
this.markAsPristine();
|
|
18495
|
-
this.
|
|
18531
|
+
this.markAsLoaded();
|
|
18496
18532
|
}
|
|
18497
18533
|
/* -- protected methods -- */
|
|
18498
18534
|
getPropertyFormGroup(data) {
|
|
@@ -18536,7 +18572,6 @@ class AppListForm extends AppForm {
|
|
|
18536
18572
|
this.settings = settings;
|
|
18537
18573
|
this.cd = cd;
|
|
18538
18574
|
this.formGroupDir = formGroupDir;
|
|
18539
|
-
this.loading = true;
|
|
18540
18575
|
this.selection = new SelectionModel(true, []);
|
|
18541
18576
|
this.displayWithFn = referentialToString;
|
|
18542
18577
|
this.onNewItem = new EventEmitter();
|
|
@@ -18620,7 +18655,7 @@ class AppListForm extends AppForm {
|
|
|
18620
18655
|
}
|
|
18621
18656
|
this.selection.clear();
|
|
18622
18657
|
this.markAsPristine();
|
|
18623
|
-
this.
|
|
18658
|
+
this.markAsLoaded();
|
|
18624
18659
|
}
|
|
18625
18660
|
/** Whether the number of selected elements matches the total number of rows. */
|
|
18626
18661
|
isAllSelected() {
|
|
@@ -22015,6 +22050,9 @@ class AppEditor {
|
|
|
22015
22050
|
get tables() {
|
|
22016
22051
|
return this._children && this._children.filter(c => c instanceof AppTable);
|
|
22017
22052
|
}
|
|
22053
|
+
get forms() {
|
|
22054
|
+
return this._children && this._children.filter(c => c instanceof AppForm);
|
|
22055
|
+
}
|
|
22018
22056
|
get dirty() {
|
|
22019
22057
|
var _a;
|
|
22020
22058
|
return this._dirty || (((_a = this._children) === null || _a === void 0 ? void 0 : _a.findIndex(c => c.enabled && c.dirty)) !== -1) || false;
|
|
@@ -22135,10 +22173,15 @@ class AppEditor {
|
|
|
22135
22173
|
}
|
|
22136
22174
|
}
|
|
22137
22175
|
markAsLoaded(opts) {
|
|
22176
|
+
var _a;
|
|
22138
22177
|
if (this._loading) {
|
|
22139
22178
|
this._loading = false;
|
|
22140
|
-
if (!opts || opts.emitEvent !== false)
|
|
22179
|
+
if (!opts || opts.emitEvent !== false) {
|
|
22180
|
+
// Emit to children forms
|
|
22181
|
+
// Tables should be changed by parent
|
|
22182
|
+
(_a = this.forms) === null || _a === void 0 ? void 0 : _a.forEach(c => c.markAsLoaded(opts));
|
|
22141
22183
|
this.markForCheck();
|
|
22184
|
+
}
|
|
22142
22185
|
}
|
|
22143
22186
|
}
|
|
22144
22187
|
markAsReady(opts) {
|
|
@@ -22656,12 +22699,20 @@ class AppEntityEditor extends AppTabEditor {
|
|
|
22656
22699
|
this.error = null;
|
|
22657
22700
|
// New data
|
|
22658
22701
|
if (isNil(id)) {
|
|
22659
|
-
|
|
22660
|
-
|
|
22661
|
-
|
|
22662
|
-
|
|
22663
|
-
|
|
22664
|
-
|
|
22702
|
+
try {
|
|
22703
|
+
// Create using default values
|
|
22704
|
+
const data = new this.dataType();
|
|
22705
|
+
this._usageMode = this.computeUsageMode(data);
|
|
22706
|
+
yield this.onNewEntity(data, opts);
|
|
22707
|
+
yield this.updateView(data, Object.assign({ openTabIndex: 0 }, opts));
|
|
22708
|
+
}
|
|
22709
|
+
catch (err) {
|
|
22710
|
+
this.setError(err);
|
|
22711
|
+
this.selectedTabIndex = 0;
|
|
22712
|
+
}
|
|
22713
|
+
finally {
|
|
22714
|
+
this.markAsLoaded();
|
|
22715
|
+
}
|
|
22665
22716
|
}
|
|
22666
22717
|
// Load existing data
|
|
22667
22718
|
else {
|