@masterteam/components 0.0.293 → 0.0.294
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/assets/i18n/ar.json +387 -386
- package/assets/i18n/en.json +387 -386
- package/fesm2022/masterteam-components-business-fields.mjs +259 -195
- package/fesm2022/masterteam-components-business-fields.mjs.map +1 -1
- package/fesm2022/masterteam-components-entities.mjs.map +1 -1
- package/package.json +1 -1
- package/types/masterteam-components-business-fields.d.ts +118 -12
- package/types/masterteam-components-entities.d.ts +1 -1
|
@@ -6,7 +6,7 @@ import * as i1 from '@angular/forms';
|
|
|
6
6
|
import { ControlContainer, NgControl, FormsModule, Validators } from '@angular/forms';
|
|
7
7
|
import * as i2 from '@jsverse/transloco';
|
|
8
8
|
import { TranslocoService, TranslocoModule, TranslocoPipe } from '@jsverse/transloco';
|
|
9
|
-
import { startWith, finalize, catchError, of, take,
|
|
9
|
+
import { startWith, finalize, catchError, of, take, expand, EMPTY, reduce, map } from 'rxjs';
|
|
10
10
|
import { Tooltip } from '@masterteam/components/tooltip';
|
|
11
11
|
import { Icon } from '@masterteam/icons';
|
|
12
12
|
import { SelectField } from '@masterteam/components/select-field';
|
|
@@ -755,6 +755,11 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.8", ngImpor
|
|
|
755
755
|
*/
|
|
756
756
|
const ENTITY_LIST_ADD_DIALOG_COMPONENT = new InjectionToken('ENTITY_LIST_ADD_DIALOG_COMPONENT');
|
|
757
757
|
|
|
758
|
+
function resolveMetadataFailure(status) {
|
|
759
|
+
if (status === 403)
|
|
760
|
+
return 'forbidden';
|
|
761
|
+
return status === 400 || status === 404 ? 'unavailable' : 'failed';
|
|
762
|
+
}
|
|
758
763
|
const UNSORTABLE_ENTITY_VIEW_TYPES = new Set([
|
|
759
764
|
'Attachment',
|
|
760
765
|
'Checkbox',
|
|
@@ -788,27 +793,25 @@ const ROW_PREFILL_KEY = '__prefill';
|
|
|
788
793
|
* object and would otherwise display a bare id.
|
|
789
794
|
*/
|
|
790
795
|
const OBJECT_VALUED_VIEW_TYPES = new Set(['User', 'MultiUser']);
|
|
791
|
-
/**
|
|
792
|
-
* Stable sort by the payload's `order`, falling back to array position when it
|
|
793
|
-
* is absent. Used to flatten a process form into reading order: `order` on a
|
|
794
|
-
* form field is *section-relative*, so every section restarts at 0 and the
|
|
795
|
-
* numbers only mean anything within their own section.
|
|
796
|
-
*/
|
|
797
|
-
function sortByOrder(items) {
|
|
798
|
-
return items
|
|
799
|
-
.map((item, index) => ({ item, index }))
|
|
800
|
-
.sort((a, b) => (a.item.order ?? a.index) - (b.item.order ?? b.index) ||
|
|
801
|
-
a.index - b.index)
|
|
802
|
-
.map(({ item }) => item);
|
|
803
|
-
}
|
|
804
796
|
class EntityListField {
|
|
805
797
|
// Inputs
|
|
806
798
|
label = input('', ...(ngDevMode ? [{ debugName: "label" }] : /* istanbul ignore next */ []));
|
|
807
799
|
readonly = input(false, ...(ngDevMode ? [{ debugName: "readonly" }] : /* istanbul ignore next */ []));
|
|
808
800
|
required = input(false, ...(ngDevMode ? [{ debugName: "required" }] : /* istanbul ignore next */ []));
|
|
809
|
-
/**
|
|
801
|
+
/**
|
|
802
|
+
* EntityList property id. **Required** — with the owning level it addresses
|
|
803
|
+
* the table-metadata endpoint, which is the only source of this field's
|
|
804
|
+
* effective configuration.
|
|
805
|
+
*/
|
|
810
806
|
propertyId = input(null, ...(ngDevMode ? [{ debugName: "propertyId" }] : /* istanbul ignore next */ []));
|
|
811
|
-
/**
|
|
807
|
+
/**
|
|
808
|
+
* Stored property configuration (sourceType, moduleId, access, readFields …).
|
|
809
|
+
*
|
|
810
|
+
* Kept for hosts that still bind it, but **not read**: the stored value is
|
|
811
|
+
* the un-overridden one, and the backend resolves the level-module override
|
|
812
|
+
* before answering the metadata request. Everything this field gates on comes
|
|
813
|
+
* from that response.
|
|
814
|
+
*/
|
|
812
815
|
configuration = input(null, ...(ngDevMode ? [{ debugName: "configuration" }] : /* istanbul ignore next */ []));
|
|
813
816
|
/** Runtime ids needed to call the read endpoint. */
|
|
814
817
|
runtimeContext = input(null, ...(ngDevMode ? [{ debugName: "runtimeContext" }] : /* istanbul ignore next */ []));
|
|
@@ -830,6 +833,9 @@ class EntityListField {
|
|
|
830
833
|
context = input(undefined, ...(ngDevMode ? [{ debugName: "context" }] : /* istanbul ignore next */ []));
|
|
831
834
|
// CVA state — pass-through value (EntityList stored JSON shape).
|
|
832
835
|
storedValue = signal(null, ...(ngDevMode ? [{ debugName: "storedValue" }] : /* istanbul ignore next */ []));
|
|
836
|
+
/** Runtime-scoped metadata; null until the endpoint answers. */
|
|
837
|
+
metadata = signal(null, ...(ngDevMode ? [{ debugName: "metadata" }] : /* istanbul ignore next */ []));
|
|
838
|
+
metadataFailure = signal(null, ...(ngDevMode ? [{ debugName: "metadataFailure" }] : /* istanbul ignore next */ []));
|
|
833
839
|
// Loaded table state.
|
|
834
840
|
columns = signal([], ...(ngDevMode ? [{ debugName: "columns" }] : /* istanbul ignore next */ []));
|
|
835
841
|
/** Rows loaded from the backend (existing target records). */
|
|
@@ -847,25 +853,41 @@ class EntityListField {
|
|
|
847
853
|
const raw = this.runtimeContext()?.levelDataId ?? null;
|
|
848
854
|
return raw == null || raw === '' ? null : raw;
|
|
849
855
|
}, ...(ngDevMode ? [{ debugName: "levelDataId" }] : /* istanbul ignore next */ []));
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
readFields = computed(() => {
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
856
|
+
/** EntityList property id as a number; `0` when the host bound none. */
|
|
857
|
+
propertyKeyId = computed(() => Number(this.propertyId() ?? 0), ...(ngDevMode ? [{ debugName: "propertyKeyId" }] : /* istanbul ignore next */ []));
|
|
858
|
+
/** Target module id, as resolved for this level. */
|
|
859
|
+
moduleId = computed(() => this.metadata()?.moduleId ?? null, ...(ngDevMode ? [{ debugName: "moduleId" }] : /* istanbul ignore next */ []));
|
|
860
|
+
/** Canonical readable target keys — the columns this field renders. */
|
|
861
|
+
readFields = computed(() => this.metadata()?.readFields ?? [], ...(ngDevMode ? [{ debugName: "readFields" }] : /* istanbul ignore next */ []));
|
|
862
|
+
/**
|
|
863
|
+
* Keys the row projection asks for: readable **and** writable.
|
|
864
|
+
*
|
|
865
|
+
* A writable key that is not readable has no column, but the edit dialog
|
|
866
|
+
* still renders it — and several are `isRequired` on the target module (the
|
|
867
|
+
* schedule module's `task_planned_finish` is). Projecting only `readFields`
|
|
868
|
+
* left those controls empty, so the form was invalid until the user retyped a
|
|
869
|
+
* value that already existed, and a different value silently overwrote the
|
|
870
|
+
* stored one. Read order first, so the request body stays stable.
|
|
871
|
+
*/
|
|
872
|
+
projectedKeys = computed(() => [
|
|
873
|
+
...new Set([...this.readFields(), ...this.writeFields()]),
|
|
874
|
+
], ...(ngDevMode ? [{ debugName: "projectedKeys" }] : /* istanbul ignore next */ []));
|
|
875
|
+
/** Effective `access` for this level, as resolved by the backend. */
|
|
863
876
|
accessMode = computed(() => {
|
|
864
|
-
const raw = this.
|
|
877
|
+
const raw = this.metadata()?.access;
|
|
865
878
|
if (raw == null || raw === '')
|
|
866
|
-
return '
|
|
867
|
-
return ACCESS_ALIASES[String(raw).trim().toLowerCase()] ?? '
|
|
879
|
+
return 'None';
|
|
880
|
+
return ACCESS_ALIASES[String(raw).trim().toLowerCase()] ?? 'None';
|
|
868
881
|
}, ...(ngDevMode ? [{ debugName: "accessMode" }] : /* istanbul ignore next */ []));
|
|
882
|
+
/**
|
|
883
|
+
* The table is backed by target module records. Inline lists resolve their
|
|
884
|
+
* rows from the stored value and have no module form to write through, so
|
|
885
|
+
* this field does not render them.
|
|
886
|
+
*/
|
|
887
|
+
moduleBacked = computed(() => {
|
|
888
|
+
const metadata = this.metadata();
|
|
889
|
+
return metadata?.sourceType === 'Module' && Number(metadata.moduleId) > 0;
|
|
890
|
+
}, ...(ngDevMode ? [{ debugName: "moduleBacked" }] : /* istanbul ignore next */ []));
|
|
869
891
|
canRead = computed(() => {
|
|
870
892
|
const access = this.accessMode();
|
|
871
893
|
return access === 'Auto' || access === 'Read' || access === 'ReadWrite';
|
|
@@ -882,14 +904,14 @@ class EntityListField {
|
|
|
882
904
|
return access === 'Auto' || access === 'Write' || access === 'ReadWrite';
|
|
883
905
|
}, ...(ngDevMode ? [{ debugName: "writeAllowed" }] : /* istanbul ignore next */ []));
|
|
884
906
|
/** Write UI is rendered only when access allows it and the field is editable. */
|
|
885
|
-
canWrite = computed(() => this.writeAllowed() && !this.readonly(), ...(ngDevMode ? [{ debugName: "canWrite" }] : /* istanbul ignore next */ []));
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
907
|
+
canWrite = computed(() => this.writeAllowed() && this.moduleBacked() && !this.readonly(), ...(ngDevMode ? [{ debugName: "canWrite" }] : /* istanbul ignore next */ []));
|
|
908
|
+
/**
|
|
909
|
+
* Canonical writable target keys. They are what the add/edit dialog renders
|
|
910
|
+
* and what a submitted row is restricted to — canonical, so a configuration
|
|
911
|
+
* that listed `normalizedKey` aliases still matches the target module's form
|
|
912
|
+
* value keys.
|
|
913
|
+
*/
|
|
914
|
+
writeFields = computed(() => this.metadata()?.writeFields ?? [], ...(ngDevMode ? [{ debugName: "writeFields" }] : /* istanbul ignore next */ []));
|
|
893
915
|
/**
|
|
894
916
|
* Pending create/update rows, in the exact shape persisted by the backend
|
|
895
917
|
* (`rows[]` of the stored EntityList JSON). Rows with `entityId > 0` are
|
|
@@ -1004,12 +1026,38 @@ class EntityListField {
|
|
|
1004
1026
|
return [...existing, ...this.createdRows()];
|
|
1005
1027
|
}, ...(ngDevMode ? [{ debugName: "displayRows" }] : /* istanbul ignore next */ []));
|
|
1006
1028
|
hasRows = computed(() => this.displayRows().length > 0, ...(ngDevMode ? [{ debugName: "hasRows" }] : /* istanbul ignore next */ []));
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1029
|
+
/** Enough context to ask the backend what this field should render. */
|
|
1030
|
+
hasRequiredContext = computed(() => this.propertyKeyId() > 0 && Number(this.levelId()) > 0, ...(ngDevMode ? [{ debugName: "hasRequiredContext" }] : /* istanbul ignore next */ []));
|
|
1031
|
+
/**
|
|
1032
|
+
* The non-error state the field renders instead of a table, as a translation
|
|
1033
|
+
* key. Null while the metadata request is still in flight, so the template
|
|
1034
|
+
* falls through to the skeleton.
|
|
1035
|
+
*/
|
|
1036
|
+
noticeKey = computed(() => {
|
|
1037
|
+
if (!this.hasRequiredContext()) {
|
|
1038
|
+
return 'components.entityListField.missingConfiguration';
|
|
1039
|
+
}
|
|
1040
|
+
switch (this.metadataFailure()) {
|
|
1041
|
+
case 'forbidden':
|
|
1042
|
+
return 'components.entityListField.accessDenied';
|
|
1043
|
+
case 'unavailable':
|
|
1044
|
+
return 'components.entityListField.missingConfiguration';
|
|
1045
|
+
case 'failed':
|
|
1046
|
+
return null;
|
|
1047
|
+
}
|
|
1048
|
+
if (!this.metadata())
|
|
1049
|
+
return null;
|
|
1050
|
+
if (!this.moduleBacked()) {
|
|
1051
|
+
return 'components.entityListField.missingConfiguration';
|
|
1052
|
+
}
|
|
1053
|
+
return this.canDisplayRows()
|
|
1054
|
+
? null
|
|
1055
|
+
: 'components.entityListField.readingNotAllowed';
|
|
1056
|
+
}, ...(ngDevMode ? [{ debugName: "noticeKey" }] : /* istanbul ignore next */ []));
|
|
1010
1057
|
onTouched = () => { };
|
|
1011
1058
|
onModelChange = () => { };
|
|
1012
1059
|
http = inject(HttpClient);
|
|
1060
|
+
metadataSubscription;
|
|
1013
1061
|
fetchSubscription;
|
|
1014
1062
|
destroyRef = inject(DestroyRef);
|
|
1015
1063
|
modal = inject(ModalService);
|
|
@@ -1026,34 +1074,15 @@ class EntityListField {
|
|
|
1026
1074
|
if (this.ngControl) {
|
|
1027
1075
|
this.ngControl.valueAccessor = this;
|
|
1028
1076
|
}
|
|
1029
|
-
//
|
|
1030
|
-
//
|
|
1077
|
+
// The property and its level address the metadata endpoint; the answer
|
|
1078
|
+
// decides everything else, including whether rows are fetched at all.
|
|
1079
|
+
// Only these scalars retrigger a load — a host that rebuilds its field
|
|
1080
|
+
// config object (language, readonly) must not cost a round trip.
|
|
1031
1081
|
effect(() => {
|
|
1032
|
-
const
|
|
1033
|
-
const allowedWrite = this.writeAllowed();
|
|
1034
|
-
const ready = this.hasRequiredContext();
|
|
1082
|
+
const propertyId = this.propertyKeyId();
|
|
1035
1083
|
const levelId = this.levelId();
|
|
1036
1084
|
const levelDataId = this.levelDataId();
|
|
1037
|
-
|
|
1038
|
-
const readFields = this.readFields();
|
|
1039
|
-
untracked(() => {
|
|
1040
|
-
this.fetchSubscription?.unsubscribe();
|
|
1041
|
-
this.columns.set([]);
|
|
1042
|
-
this.rows.set([]);
|
|
1043
|
-
this.errorMessage.set(null);
|
|
1044
|
-
if ((!allowedRead && !allowedWrite) ||
|
|
1045
|
-
!ready ||
|
|
1046
|
-
levelId == null ||
|
|
1047
|
-
moduleId == null) {
|
|
1048
|
-
return;
|
|
1049
|
-
}
|
|
1050
|
-
if (levelDataId == null || Number(levelDataId) <= 0 || !allowedRead) {
|
|
1051
|
-
this.fetchDraftColumns(levelId, moduleId, readFields);
|
|
1052
|
-
}
|
|
1053
|
-
else {
|
|
1054
|
-
this.fetchRows(levelId, levelDataId, moduleId, readFields);
|
|
1055
|
-
}
|
|
1056
|
-
});
|
|
1085
|
+
untracked(() => this.loadTable(propertyId, levelId, levelDataId));
|
|
1057
1086
|
});
|
|
1058
1087
|
}
|
|
1059
1088
|
// ============================================================================
|
|
@@ -1340,14 +1369,36 @@ class EntityListField {
|
|
|
1340
1369
|
}
|
|
1341
1370
|
return row;
|
|
1342
1371
|
}
|
|
1343
|
-
/**
|
|
1372
|
+
/**
|
|
1373
|
+
* Render one table cell from a raw form value and its resolved label.
|
|
1374
|
+
*
|
|
1375
|
+
* The cell has to arrive in the shape the backend would have sent, because
|
|
1376
|
+
* that is what the entity renderers bind. Two things a control value is not:
|
|
1377
|
+
*
|
|
1378
|
+
* - **A scalar `value` is a string.** `mt-entity-percentage` reads `d.value`
|
|
1379
|
+
* only when `typeof` it is `'string'` and prints its placeholder otherwise,
|
|
1380
|
+
* so a numeric control value rendered as a filled bar with no number beside
|
|
1381
|
+
* it. Objects and arrays are the resolved shapes the rich renderers want,
|
|
1382
|
+
* and pass through untouched.
|
|
1383
|
+
* - **The column configuration has to travel with it.** Colour rules live
|
|
1384
|
+
* there, and `mt-entity-percentage` falls back to evaluating them itself
|
|
1385
|
+
* exactly when no per-value colour was resolved — which is every locally
|
|
1386
|
+
* added row. Without it a new 45% row rendered in the default colour while
|
|
1387
|
+
* the same value loaded from the backend rendered in its band colour.
|
|
1388
|
+
*/
|
|
1344
1389
|
buildCell(column, raw, label) {
|
|
1390
|
+
const value = this.toLocalEntityValue(column.viewType, raw, label);
|
|
1391
|
+
const propertyKey = column.propertyKey ?? column.key;
|
|
1345
1392
|
return {
|
|
1346
1393
|
name: column.label ?? column.key,
|
|
1347
1394
|
key: column.key,
|
|
1348
1395
|
viewType: column.viewType ?? 'Text',
|
|
1349
|
-
value:
|
|
1350
|
-
|
|
1396
|
+
value: value !== null && typeof value === 'object'
|
|
1397
|
+
? value
|
|
1398
|
+
: (this.toRawValue(value) ?? ''),
|
|
1399
|
+
rawValue: this.toRawValue(raw) ?? undefined,
|
|
1400
|
+
configuration: column.configuration,
|
|
1401
|
+
propertyConfiguration: this.propertyByKey().get(propertyKey)?.configuration,
|
|
1351
1402
|
};
|
|
1352
1403
|
}
|
|
1353
1404
|
/**
|
|
@@ -1549,97 +1600,123 @@ class EntityListField {
|
|
|
1549
1600
|
return this.toRawValue(a) === this.toRawValue(b);
|
|
1550
1601
|
}
|
|
1551
1602
|
// ============================================================================
|
|
1552
|
-
// Read
|
|
1603
|
+
// Read endpoints — GET Properties/{id}/entitylist/table-metadata (columns,
|
|
1604
|
+
// effective access, canonical keys) + POST fetch/query (rows)
|
|
1553
1605
|
// ============================================================================
|
|
1554
|
-
|
|
1606
|
+
/**
|
|
1607
|
+
* Load the runtime-scoped table description, then its rows.
|
|
1608
|
+
*
|
|
1609
|
+
* The metadata endpoint is the authorization boundary for this field: it
|
|
1610
|
+
* answers `403` when the user may not read the target module in this level,
|
|
1611
|
+
* so the columns are never built from a source that skipped that check.
|
|
1612
|
+
*/
|
|
1613
|
+
loadTable(propertyId, levelId, levelDataId) {
|
|
1614
|
+
this.metadataSubscription?.unsubscribe();
|
|
1615
|
+
this.fetchSubscription?.unsubscribe();
|
|
1616
|
+
this.metadata.set(null);
|
|
1617
|
+
this.metadataFailure.set(null);
|
|
1618
|
+
this.columns.set([]);
|
|
1619
|
+
this.rows.set([]);
|
|
1620
|
+
this.errorMessage.set(null);
|
|
1621
|
+
this.loading.set(false);
|
|
1622
|
+
if (!(propertyId > 0) || levelId == null || !(Number(levelId) > 0))
|
|
1623
|
+
return;
|
|
1555
1624
|
this.loading.set(true);
|
|
1556
1625
|
const ctx = this.context();
|
|
1557
|
-
|
|
1558
|
-
.get(
|
|
1559
|
-
params: {
|
|
1560
|
-
//
|
|
1561
|
-
//
|
|
1562
|
-
//
|
|
1563
|
-
// only honours `noMessage`, and `fetch/catalog` is not a silent
|
|
1564
|
-
// endpoint the way `fetch/query` is.
|
|
1626
|
+
this.metadataSubscription = this.http
|
|
1627
|
+
.get(`Properties/${propertyId}/entitylist/table-metadata`, {
|
|
1628
|
+
params: { levelId: String(levelId) },
|
|
1629
|
+
// `403` (no module read access) and `404` (not configured for this
|
|
1630
|
+
// level) are states this field renders inline, not failures worth a
|
|
1631
|
+
// toast from the host's message interceptor.
|
|
1565
1632
|
headers: { noMessage: 'true' },
|
|
1566
1633
|
...(ctx ? { context: ctx } : {}),
|
|
1567
1634
|
})
|
|
1568
|
-
.pipe(
|
|
1569
|
-
if (this.accessMode() !== 'Write' || error.status !== 404) {
|
|
1570
|
-
return throwError(() => error);
|
|
1571
|
-
}
|
|
1572
|
-
// Write-only EntityLists may intentionally use a target module that
|
|
1573
|
-
// is not mapped to the owning level. Fetch catalog represents a
|
|
1574
|
-
// browsable level/module context and rejects that pair; the runtime
|
|
1575
|
-
// Create form remains the authorized source for its field metadata.
|
|
1576
|
-
return this.http
|
|
1577
|
-
.post('process-form-load', {
|
|
1578
|
-
moduleKey: 'ModuleData',
|
|
1579
|
-
operationKey: 'Create',
|
|
1580
|
-
moduleId,
|
|
1581
|
-
levelId,
|
|
1582
|
-
}, {
|
|
1583
|
-
headers: { noMessage: 'true' },
|
|
1584
|
-
...(ctx ? { context: ctx } : {}),
|
|
1585
|
-
})
|
|
1586
|
-
.pipe(map((response) => this.mapProcessFormProperties(response)));
|
|
1587
|
-
}));
|
|
1588
|
-
this.fetchSubscription = properties$
|
|
1589
|
-
.pipe(takeUntilDestroyed(this.destroyRef), finalize(() => this.loading.set(false)))
|
|
1635
|
+
.pipe(takeUntilDestroyed(this.destroyRef))
|
|
1590
1636
|
.subscribe({
|
|
1591
|
-
next: (
|
|
1592
|
-
|
|
1593
|
-
|
|
1594
|
-
|
|
1595
|
-
|
|
1596
|
-
|
|
1597
|
-
|
|
1598
|
-
|
|
1599
|
-
|
|
1600
|
-
|
|
1601
|
-
viewType: property.viewType,
|
|
1602
|
-
order: property.order,
|
|
1603
|
-
visible: true,
|
|
1604
|
-
configuration: property.configuration ?? null,
|
|
1605
|
-
})),
|
|
1606
|
-
},
|
|
1607
|
-
});
|
|
1637
|
+
next: (response) => this.applyMetadata(response.data, levelDataId),
|
|
1638
|
+
error: (error) => {
|
|
1639
|
+
this.loading.set(false);
|
|
1640
|
+
const failure = resolveMetadataFailure(error.status);
|
|
1641
|
+
this.metadataFailure.set(failure);
|
|
1642
|
+
// `forbidden` and `unavailable` are rendered as their own notice; only
|
|
1643
|
+
// a real request failure is an error.
|
|
1644
|
+
if (failure === 'failed') {
|
|
1645
|
+
this.errorMessage.set(this.transloco.translate('components.entityListField.loadFailed'));
|
|
1646
|
+
}
|
|
1608
1647
|
},
|
|
1609
|
-
error: () => this.errorMessage.set(this.transloco.translate('components.entityListField.loadFailed')),
|
|
1610
1648
|
});
|
|
1611
1649
|
}
|
|
1612
1650
|
/**
|
|
1613
|
-
*
|
|
1614
|
-
*
|
|
1615
|
-
*
|
|
1616
|
-
*
|
|
1651
|
+
* Apply the metadata, then fetch rows when there is a persisted parent to
|
|
1652
|
+
* scope them to. A draft parent (no `levelDataId`) and a write-only field
|
|
1653
|
+
* both stop at the columns — the first has no records yet, the second may
|
|
1654
|
+
* not read them.
|
|
1617
1655
|
*/
|
|
1618
|
-
|
|
1619
|
-
|
|
1620
|
-
|
|
1621
|
-
|
|
1622
|
-
.
|
|
1623
|
-
|
|
1624
|
-
|
|
1625
|
-
|
|
1626
|
-
|
|
1627
|
-
|
|
1628
|
-
|
|
1629
|
-
? name
|
|
1630
|
-
: name?.display || name?.en || name?.ar || key;
|
|
1631
|
-
return {
|
|
1632
|
-
id: metadata.propertyId ?? 0,
|
|
1633
|
-
key,
|
|
1634
|
-
normalizedKey: metadata.normalizedKey || key,
|
|
1635
|
-
label,
|
|
1636
|
-
viewType: metadata.viewType,
|
|
1637
|
-
configuration: metadata.configuration ?? null,
|
|
1638
|
-
order: index,
|
|
1639
|
-
};
|
|
1640
|
-
})
|
|
1641
|
-
.filter((property) => property !== null);
|
|
1656
|
+
applyMetadata(metadata, levelDataId) {
|
|
1657
|
+
this.metadata.set(metadata);
|
|
1658
|
+
this.columns.set(this.buildColumns(metadata));
|
|
1659
|
+
if (!this.moduleBacked() ||
|
|
1660
|
+
!this.canRead() ||
|
|
1661
|
+
levelDataId == null ||
|
|
1662
|
+
Number(levelDataId) <= 0) {
|
|
1663
|
+
this.loading.set(false);
|
|
1664
|
+
return;
|
|
1665
|
+
}
|
|
1666
|
+
this.fetchRows(metadata.levelId, levelDataId, metadata.moduleId, this.projectedKeys());
|
|
1642
1667
|
}
|
|
1668
|
+
/**
|
|
1669
|
+
* Table columns, in the order the backend returned them.
|
|
1670
|
+
*
|
|
1671
|
+
* `projectionMeta.columns[].key` is the catalog property key here — the same
|
|
1672
|
+
* key `fetch/query` keys its record values by — so a column maps onto a row
|
|
1673
|
+
* value directly. The lookup still falls back to `normalizedKey` so a column
|
|
1674
|
+
* fed from any other projection keeps resolving.
|
|
1675
|
+
*
|
|
1676
|
+
* The columns are the *union* of readable and writable fields, so a
|
|
1677
|
+
* write-only key arrives as a column too — a `Planned Finish` the user may
|
|
1678
|
+
* set in the dialog but may not read. It is not projected into the rows and
|
|
1679
|
+
* would render as an empty column, so only readable keys become columns.
|
|
1680
|
+
* Write-only access is the exception: its readable set is empty by
|
|
1681
|
+
* definition, and its stored rows have nothing else to render through.
|
|
1682
|
+
*/
|
|
1683
|
+
buildColumns(metadata) {
|
|
1684
|
+
const propertyByKey = new Map();
|
|
1685
|
+
const propertyByNormalizedKey = new Map();
|
|
1686
|
+
for (const property of metadata.catalog?.properties ?? []) {
|
|
1687
|
+
propertyByKey.set(property.key, property);
|
|
1688
|
+
propertyByNormalizedKey.set(property.normalizedKey, property);
|
|
1689
|
+
}
|
|
1690
|
+
const readable = new Set(metadata.readFields);
|
|
1691
|
+
return (metadata.projectionMeta?.columns ?? [])
|
|
1692
|
+
.filter((column) => column.visible)
|
|
1693
|
+
.filter((column) => readable.size === 0 || readable.has(column.key))
|
|
1694
|
+
.sort((a, b) => a.order - b.order)
|
|
1695
|
+
.map((column) => ({
|
|
1696
|
+
key: column.key,
|
|
1697
|
+
label: column.label,
|
|
1698
|
+
type: 'entity',
|
|
1699
|
+
sortable: !UNSORTABLE_ENTITY_VIEW_TYPES.has(column.viewType),
|
|
1700
|
+
viewType: column.viewType,
|
|
1701
|
+
order: column.order,
|
|
1702
|
+
visible: column.visible,
|
|
1703
|
+
configuration: column.configuration ?? null,
|
|
1704
|
+
propertyKey: (propertyByKey.has(column.key)
|
|
1705
|
+
? column.key
|
|
1706
|
+
: propertyByNormalizedKey.get(column.key)?.key) ?? column.key,
|
|
1707
|
+
}));
|
|
1708
|
+
}
|
|
1709
|
+
/** Catalog properties of the loaded metadata, keyed by property key. */
|
|
1710
|
+
propertyByKey = computed(() => {
|
|
1711
|
+
const map = new Map();
|
|
1712
|
+
for (const property of this.metadata()?.catalog?.properties ?? []) {
|
|
1713
|
+
map.set(property.key, property);
|
|
1714
|
+
if (!map.has(property.normalizedKey)) {
|
|
1715
|
+
map.set(property.normalizedKey, property);
|
|
1716
|
+
}
|
|
1717
|
+
}
|
|
1718
|
+
return map;
|
|
1719
|
+
}, ...(ngDevMode ? [{ debugName: "propertyByKey" }] : /* istanbul ignore next */ []));
|
|
1643
1720
|
fetchRows(levelId, levelDataId, moduleId, propertyKeys) {
|
|
1644
1721
|
this.loading.set(true);
|
|
1645
1722
|
this.errorMessage.set(null);
|
|
@@ -1670,42 +1747,30 @@ class EntityListField {
|
|
|
1670
1747
|
const payload = response && typeof response === 'object' && 'data' in response
|
|
1671
1748
|
? (response.data ?? response)
|
|
1672
1749
|
: response;
|
|
1673
|
-
this.
|
|
1750
|
+
this.applyRecords(payload.records ?? []);
|
|
1674
1751
|
});
|
|
1675
1752
|
}
|
|
1676
|
-
|
|
1677
|
-
|
|
1678
|
-
|
|
1679
|
-
|
|
1680
|
-
|
|
1681
|
-
|
|
1682
|
-
|
|
1683
|
-
|
|
1684
|
-
|
|
1685
|
-
const columns =
|
|
1686
|
-
|
|
1687
|
-
|
|
1688
|
-
|
|
1689
|
-
|
|
1690
|
-
|
|
1691
|
-
|
|
1692
|
-
|
|
1693
|
-
|
|
1694
|
-
|
|
1695
|
-
|
|
1696
|
-
|
|
1697
|
-
// Store the catalog property key so buildRow can look up form values
|
|
1698
|
-
// keyed by property key (e.g. "task_name") rather than the
|
|
1699
|
-
// normalizedKey used as the column display key (e.g. "Name").
|
|
1700
|
-
propertyKey: propertyByNormalizedKey.get(column.key)?.key ?? column.key,
|
|
1701
|
-
}));
|
|
1702
|
-
this.columns.set(columns);
|
|
1703
|
-
// Reading blocked (access = Write / None): keep the columns, drop records.
|
|
1704
|
-
if (!this.canRead()) {
|
|
1705
|
-
this.rows.set([]);
|
|
1706
|
-
return;
|
|
1707
|
-
}
|
|
1708
|
-
const rows = (response.records ?? []).map((record) => {
|
|
1753
|
+
/**
|
|
1754
|
+
* Project fetched records onto the metadata columns.
|
|
1755
|
+
*
|
|
1756
|
+
* Cells are built per rendered column, but the row's value maps cover every
|
|
1757
|
+
* **projected** key — a writable key without a column has no cell to render
|
|
1758
|
+
* and still has to reach the edit dialog and the update diff.
|
|
1759
|
+
*/
|
|
1760
|
+
applyRecords(records) {
|
|
1761
|
+
const properties = this.propertyByKey();
|
|
1762
|
+
const columns = this.columns();
|
|
1763
|
+
const valueKeys = [
|
|
1764
|
+
...new Set([
|
|
1765
|
+
...this.projectedKeys(),
|
|
1766
|
+
...columns.map((column) => column.propertyKey ?? column.key),
|
|
1767
|
+
]),
|
|
1768
|
+
];
|
|
1769
|
+
const viewTypeByKey = new Map(columns.map((column) => [
|
|
1770
|
+
column.propertyKey ?? column.key,
|
|
1771
|
+
column.viewType,
|
|
1772
|
+
]));
|
|
1773
|
+
this.rows.set(records.map((record) => {
|
|
1709
1774
|
const values = {};
|
|
1710
1775
|
const prefill = {};
|
|
1711
1776
|
const row = {
|
|
@@ -1714,25 +1779,24 @@ class EntityListField {
|
|
|
1714
1779
|
[ROW_ENTITY_ID_KEY]: record.id,
|
|
1715
1780
|
};
|
|
1716
1781
|
for (const column of columns) {
|
|
1717
|
-
const
|
|
1718
|
-
|
|
1719
|
-
|
|
1720
|
-
|
|
1721
|
-
|
|
1782
|
+
const propertyKey = column.propertyKey ?? column.key;
|
|
1783
|
+
row[column.key] = this.toEntityData(column, record.values?.[propertyKey], properties.get(propertyKey), record.id);
|
|
1784
|
+
}
|
|
1785
|
+
for (const key of valueKeys) {
|
|
1786
|
+
const cell = record.values?.[key];
|
|
1722
1787
|
// Keep the machine-readable value as the baseline a partial update is
|
|
1723
1788
|
// diffed against — it is the shape the row submits.
|
|
1724
|
-
values[
|
|
1789
|
+
values[key] = cell?.raw ?? cell?.value ?? null;
|
|
1725
1790
|
// What the edit dialog patches into its form, which is not always the
|
|
1726
1791
|
// same thing: see OBJECT_VALUED_VIEW_TYPES.
|
|
1727
|
-
prefill[
|
|
1792
|
+
prefill[key] = OBJECT_VALUED_VIEW_TYPES.has(viewTypeByKey.get(key) ?? properties.get(key)?.viewType ?? '')
|
|
1728
1793
|
? (cell?.value ?? cell?.raw ?? null)
|
|
1729
|
-
: values[
|
|
1794
|
+
: values[key];
|
|
1730
1795
|
}
|
|
1731
1796
|
row[ROW_VALUES_KEY] = values;
|
|
1732
1797
|
row[ROW_PREFILL_KEY] = prefill;
|
|
1733
1798
|
return row;
|
|
1734
|
-
});
|
|
1735
|
-
this.rows.set(rows);
|
|
1799
|
+
}));
|
|
1736
1800
|
}
|
|
1737
1801
|
toEntityData(column, cell, property, recordId) {
|
|
1738
1802
|
return {
|
|
@@ -1753,7 +1817,7 @@ class EntityListField {
|
|
|
1753
1817
|
};
|
|
1754
1818
|
}
|
|
1755
1819
|
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.8", ngImport: i0, type: EntityListField, deps: [], target: i0.ɵɵFactoryTarget.Component });
|
|
1756
|
-
static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "21.2.8", type: EntityListField, isStandalone: true, selector: "mt-entity-list-field", inputs: { label: { classPropertyName: "label", publicName: "label", isSignal: true, isRequired: false, transformFunction: null }, readonly: { classPropertyName: "readonly", publicName: "readonly", isSignal: true, isRequired: false, transformFunction: null }, required: { classPropertyName: "required", publicName: "required", isSignal: true, isRequired: false, transformFunction: null }, propertyId: { classPropertyName: "propertyId", publicName: "propertyId", isSignal: true, isRequired: false, transformFunction: null }, configuration: { classPropertyName: "configuration", publicName: "configuration", isSignal: true, isRequired: false, transformFunction: null }, runtimeContext: { classPropertyName: "runtimeContext", publicName: "runtimeContext", isSignal: true, isRequired: false, transformFunction: null }, pendingSubmission: { classPropertyName: "pendingSubmission", publicName: "pendingSubmission", isSignal: true, isRequired: false, transformFunction: null }, lookups: { classPropertyName: "lookups", publicName: "lookups", isSignal: true, isRequired: false, transformFunction: null }, context: { classPropertyName: "context", publicName: "context", isSignal: true, isRequired: false, transformFunction: null } }, host: { classAttribute: "grid gap-1" }, ngImport: i0, template: "<div class=\"flex flex-col gap-2\">\
|
|
1820
|
+
static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "21.2.8", type: EntityListField, isStandalone: true, selector: "mt-entity-list-field", inputs: { label: { classPropertyName: "label", publicName: "label", isSignal: true, isRequired: false, transformFunction: null }, readonly: { classPropertyName: "readonly", publicName: "readonly", isSignal: true, isRequired: false, transformFunction: null }, required: { classPropertyName: "required", publicName: "required", isSignal: true, isRequired: false, transformFunction: null }, propertyId: { classPropertyName: "propertyId", publicName: "propertyId", isSignal: true, isRequired: false, transformFunction: null }, configuration: { classPropertyName: "configuration", publicName: "configuration", isSignal: true, isRequired: false, transformFunction: null }, runtimeContext: { classPropertyName: "runtimeContext", publicName: "runtimeContext", isSignal: true, isRequired: false, transformFunction: null }, pendingSubmission: { classPropertyName: "pendingSubmission", publicName: "pendingSubmission", isSignal: true, isRequired: false, transformFunction: null }, lookups: { classPropertyName: "lookups", publicName: "lookups", isSignal: true, isRequired: false, transformFunction: null }, context: { classPropertyName: "context", publicName: "context", isSignal: true, isRequired: false, transformFunction: null } }, host: { classAttribute: "grid gap-1" }, ngImport: i0, template: "<div class=\"flex flex-col gap-2\">\n @if (label()) {\n <label class=\"font-medium text-color\">\n {{ label() }}\n @if (required()) {\n <span class=\"text-red-500\">*</span>\n }\n </label>\n }\n\n @if (errorMessage(); as err) {\n <p-message severity=\"error\" [text]=\"err\" styleClass=\"w-full\" />\n } @else if (noticeKey(); as notice) {\n <div\n class=\"rounded-md border border-dashed border-surface-300 bg-surface-50 p-3 text-sm text-muted-color\"\n >\n {{ notice | transloco }}\n </div>\n } @else if (canWrite()) {\n <div class=\"flex justify-end\">\n <mt-button\n [label]=\"'components.entityListField.add' | transloco\"\n icon=\"general.plus\"\n size=\"small\"\n [disabled]=\"disabled()\"\n (onClick)=\"openAddDialog()\"\n />\n </div>\n <mt-table\n [noCard]=\"true\"\n [data]=\"displayRows()\"\n [columns]=\"columns()\"\n [rowActions]=\"writeRowActions()\"\n dataKey=\"Id\"\n [loading]=\"loading()\"\n />\n } @else if (loading() && !hasRows()) {\n <div class=\"flex flex-col gap-2\">\n <p-skeleton width=\"100%\" height=\"3rem\" borderRadius=\"0.375rem\" />\n <p-skeleton width=\"100%\" height=\"3rem\" borderRadius=\"0.375rem\" />\n </div>\n } @else if (!hasRows()) {\n <div\n class=\"rounded-md border border-dashed border-surface-300 bg-surface-50 p-3 text-sm text-muted-color\"\n >\n {{ \"components.entityListField.noRelatedItems\" | transloco }}\n </div>\n } @else {\n <mt-table\n [noCard]=\"true\"\n [data]=\"displayRows()\"\n [columns]=\"columns()\"\n dataKey=\"Id\"\n [loading]=\"loading()\"\n />\n }\n\n @if (ngControl?.control) {\n <mt-field-validation\n [control]=\"ngControl?.control!\"\n [touched]=\"ngControl?.touched ?? false\"\n />\n }\n</div>\n", styles: [":host{display:block}\n"], dependencies: [{ kind: "ngmodule", type: CommonModule }, { kind: "component", type: FieldValidation, selector: "mt-field-validation", inputs: ["control", "touched", "messageId"] }, { kind: "component", type: Skeleton, selector: "p-skeleton", inputs: ["styleClass", "shape", "animation", "borderRadius", "size", "width", "height"] }, { kind: "component", type: Message, selector: "p-message", inputs: ["severity", "text", "escape", "style", "styleClass", "closable", "icon", "closeIcon", "life", "showTransitionOptions", "hideTransitionOptions", "size", "variant", "motionOptions"], outputs: ["onClose"] }, { kind: "component", type: Table, selector: "mt-table", inputs: ["filters", "data", "columns", "rowActions", "size", "showGridlines", "stripedRows", "selectableRows", "clickableRows", "generalSearch", "lazyLocalSearch", "showFilters", "filterMode", "loading", "updating", "lazy", "lazyLocalSort", "lazyTotalRecords", "reorderableColumns", "reorderableRows", "dataKey", "storageKey", "storageMode", "persistStateExclude", "exportable", "printable", "groupable", "groupCountMap", "cellClickFilter", "freezeActions", "virtualScroll", "virtualScrollItemSize", "scrollHeight", "printTitle", "exportFilename", "actionShape", "rowActionsLoadingFn", "tableLayout", "noCard", "tabs", "tabsOptionLabel", "tabsOptionValue", "activeTab", "actions", "captionStartTemplate", "captionEndTemplate", "emptyTitle", "emptyDescription", "emptyActionLabel", "emptyActionIcon", "paginatorPosition", "alwaysShowPaginator", "rowsPerPageOptions", "pageSize", "currentPage", "first", "filterTerm", "groupBy", "sortField", "sortDirection"], outputs: ["selectionChange", "cellChange", "lazyLoad", "columnReorder", "rowReorder", "rowClick", "emptyAction", "rowActionsRequested", "filtersChange", "activeTabChange", "onTabChange", "pageSizeChange", "currentPageChange", "firstChange", "filterTermChange", "groupByChange", "sortFieldChange", "sortDirectionChange"] }, { kind: "component", type: Button, selector: "mt-button", inputs: ["icon", "label", "tooltip", "class", "type", "styleClass", "severity", "badge", "variant", "badgeSeverity", "size", "iconPos", "autofocus", "fluid", "raised", "rounded", "text", "plain", "outlined", "link", "disabled", "loading", "pInputs", "ariaLabel"], outputs: ["onClick", "onFocus", "onBlur"] }, { kind: "pipe", type: TranslocoPipe, name: "transloco" }], changeDetection: i0.ChangeDetectionStrategy.OnPush });
|
|
1757
1821
|
}
|
|
1758
1822
|
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.8", ngImport: i0, type: EntityListField, decorators: [{
|
|
1759
1823
|
type: Component,
|
|
@@ -1765,7 +1829,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.8", ngImpor
|
|
|
1765
1829
|
Table,
|
|
1766
1830
|
Button,
|
|
1767
1831
|
TranslocoPipe,
|
|
1768
|
-
], changeDetection: ChangeDetectionStrategy.OnPush, host: { class: 'grid gap-1' }, template: "<div class=\"flex flex-col gap-2\">\
|
|
1832
|
+
], changeDetection: ChangeDetectionStrategy.OnPush, host: { class: 'grid gap-1' }, template: "<div class=\"flex flex-col gap-2\">\n @if (label()) {\n <label class=\"font-medium text-color\">\n {{ label() }}\n @if (required()) {\n <span class=\"text-red-500\">*</span>\n }\n </label>\n }\n\n @if (errorMessage(); as err) {\n <p-message severity=\"error\" [text]=\"err\" styleClass=\"w-full\" />\n } @else if (noticeKey(); as notice) {\n <div\n class=\"rounded-md border border-dashed border-surface-300 bg-surface-50 p-3 text-sm text-muted-color\"\n >\n {{ notice | transloco }}\n </div>\n } @else if (canWrite()) {\n <div class=\"flex justify-end\">\n <mt-button\n [label]=\"'components.entityListField.add' | transloco\"\n icon=\"general.plus\"\n size=\"small\"\n [disabled]=\"disabled()\"\n (onClick)=\"openAddDialog()\"\n />\n </div>\n <mt-table\n [noCard]=\"true\"\n [data]=\"displayRows()\"\n [columns]=\"columns()\"\n [rowActions]=\"writeRowActions()\"\n dataKey=\"Id\"\n [loading]=\"loading()\"\n />\n } @else if (loading() && !hasRows()) {\n <div class=\"flex flex-col gap-2\">\n <p-skeleton width=\"100%\" height=\"3rem\" borderRadius=\"0.375rem\" />\n <p-skeleton width=\"100%\" height=\"3rem\" borderRadius=\"0.375rem\" />\n </div>\n } @else if (!hasRows()) {\n <div\n class=\"rounded-md border border-dashed border-surface-300 bg-surface-50 p-3 text-sm text-muted-color\"\n >\n {{ \"components.entityListField.noRelatedItems\" | transloco }}\n </div>\n } @else {\n <mt-table\n [noCard]=\"true\"\n [data]=\"displayRows()\"\n [columns]=\"columns()\"\n dataKey=\"Id\"\n [loading]=\"loading()\"\n />\n }\n\n @if (ngControl?.control) {\n <mt-field-validation\n [control]=\"ngControl?.control!\"\n [touched]=\"ngControl?.touched ?? false\"\n />\n }\n</div>\n", styles: [":host{display:block}\n"] }]
|
|
1769
1833
|
}], ctorParameters: () => [], propDecorators: { label: [{ type: i0.Input, args: [{ isSignal: true, alias: "label", required: false }] }], readonly: [{ type: i0.Input, args: [{ isSignal: true, alias: "readonly", required: false }] }], required: [{ type: i0.Input, args: [{ isSignal: true, alias: "required", required: false }] }], propertyId: [{ type: i0.Input, args: [{ isSignal: true, alias: "propertyId", required: false }] }], configuration: [{ type: i0.Input, args: [{ isSignal: true, alias: "configuration", required: false }] }], runtimeContext: [{ type: i0.Input, args: [{ isSignal: true, alias: "runtimeContext", required: false }] }], pendingSubmission: [{ type: i0.Input, args: [{ isSignal: true, alias: "pendingSubmission", required: false }] }], lookups: [{ type: i0.Input, args: [{ isSignal: true, alias: "lookups", required: false }] }], context: [{ type: i0.Input, args: [{ isSignal: true, alias: "context", required: false }] }] } });
|
|
1770
1834
|
|
|
1771
1835
|
/** Page size when loading the full deliverable list, and a hard safety cap. */
|