@masterteam/components 0.0.300 → 0.0.302
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/common.css +1 -1
- package/assets/i18n/ar.json +392 -391
- package/assets/i18n/en.json +392 -391
- package/fesm2022/masterteam-components-business-fields.mjs +696 -51
- package/fesm2022/masterteam-components-business-fields.mjs.map +1 -1
- package/fesm2022/masterteam-components-checkbox-field.mjs +2 -2
- package/fesm2022/masterteam-components-checkbox-field.mjs.map +1 -1
- package/fesm2022/masterteam-components-entities.mjs +363 -293
- package/fesm2022/masterteam-components-entities.mjs.map +1 -1
- package/fesm2022/masterteam-components-radio-button-field.mjs +2 -2
- package/fesm2022/masterteam-components-radio-button-field.mjs.map +1 -1
- package/fesm2022/masterteam-components-select-field.mjs +23 -2
- package/fesm2022/masterteam-components-select-field.mjs.map +1 -1
- package/fesm2022/masterteam-components-table.mjs +1 -1
- package/fesm2022/masterteam-components-table.mjs.map +1 -1
- package/fesm2022/masterteam-components-toggle-field.mjs +2 -2
- package/fesm2022/masterteam-components-toggle-field.mjs.map +1 -1
- package/fesm2022/masterteam-components.mjs +43 -2
- package/fesm2022/masterteam-components.mjs.map +1 -1
- package/package.json +1 -1
- package/types/masterteam-components-business-fields.d.ts +259 -29
- package/types/masterteam-components-entities.d.ts +252 -111
- package/types/masterteam-components-select-field.d.ts +14 -0
- package/types/masterteam-components.d.ts +27 -2
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { CommonModule, NgComponentOutlet } from '@angular/common';
|
|
2
2
|
import * as i0 from '@angular/core';
|
|
3
|
-
import { input, inject, DestroyRef, signal, computed, ChangeDetectionStrategy, Component, effect, untracked, viewChild, linkedSignal, InjectionToken } from '@angular/core';
|
|
3
|
+
import { input, inject, DestroyRef, signal, computed, ChangeDetectionStrategy, Component, ChangeDetectorRef, effect, untracked, viewChild, linkedSignal, InjectionToken } from '@angular/core';
|
|
4
4
|
import { takeUntilDestroyed, toSignal } from '@angular/core/rxjs-interop';
|
|
5
5
|
import * as i1 from '@angular/forms';
|
|
6
6
|
import { ControlContainer, NgControl, FormsModule, Validators } from '@angular/forms';
|
|
@@ -16,11 +16,11 @@ import { HttpClient, HttpParams } from '@angular/common/http';
|
|
|
16
16
|
import { Button } from '@masterteam/components/button';
|
|
17
17
|
import { NumberField } from '@masterteam/components/number-field';
|
|
18
18
|
import { Table } from '@masterteam/components/table';
|
|
19
|
-
import { newFieldId } from '@masterteam/components';
|
|
19
|
+
import { newFieldId, coerceCheckboxValue } from '@masterteam/components';
|
|
20
20
|
import { Skeleton } from 'primeng/skeleton';
|
|
21
21
|
import { Message } from 'primeng/message';
|
|
22
22
|
import { ModalService } from '@masterteam/components/modal';
|
|
23
|
-
import {
|
|
23
|
+
import { sortLocalRows, visibleLocalSchemaFields, resolveLocalFieldViewType, resolveLocalFieldLabel, localCellsByFieldId, resolveLocalFieldConfiguration, isEntityListLocalDocument, serializeEntityRawValue, readEntityValueColor, EntityRuntimeContextStore, ENTITY_LIST_TABLE_COMPONENT } from '@masterteam/components/entities';
|
|
24
24
|
import * as i2$1 from 'primeng/inputtext';
|
|
25
25
|
import { InputTextModule } from 'primeng/inputtext';
|
|
26
26
|
|
|
@@ -191,6 +191,11 @@ class SchemaConnectionField {
|
|
|
191
191
|
label = input('', ...(ngDevMode ? [{ debugName: "label" }] : /* istanbul ignore next */ []));
|
|
192
192
|
placeholder = input('', ...(ngDevMode ? [{ debugName: "placeholder" }] : /* istanbul ignore next */ []));
|
|
193
193
|
readonly = input(false, ...(ngDevMode ? [{ debugName: "readonly" }] : /* istanbul ignore next */ []));
|
|
194
|
+
/**
|
|
195
|
+
* Kept for direct-host API compatibility. Dynamic/client forms do not bind
|
|
196
|
+
* it; runtime requiredness is defined per source by
|
|
197
|
+
* `configuration.sourceLevels[].isOptional`.
|
|
198
|
+
*/
|
|
194
199
|
required = input(false, ...(ngDevMode ? [{ debugName: "required" }] : /* istanbul ignore next */ []));
|
|
195
200
|
filter = input(true, ...(ngDevMode ? [{ debugName: "filter" }] : /* istanbul ignore next */ []));
|
|
196
201
|
/**
|
|
@@ -223,21 +228,26 @@ class SchemaConnectionField {
|
|
|
223
228
|
onTouched = () => { };
|
|
224
229
|
onModelChange = () => { };
|
|
225
230
|
/**
|
|
226
|
-
*
|
|
227
|
-
*
|
|
228
|
-
*
|
|
229
|
-
* stock `Validators.required` accepts — so a plain required check would let an
|
|
230
|
-
* empty connection pass and the form submit. Mirrors {@link syncValue}, which
|
|
231
|
-
* collapses a source-less selection to `null`.
|
|
231
|
+
* Every source whose `isOptional` is false must have at least one selected
|
|
232
|
+
* record. The field-level `isRequired` flag is intentionally ignored because
|
|
233
|
+
* one Connection property can mix optional and required source levels.
|
|
232
234
|
*/
|
|
233
|
-
|
|
235
|
+
requiredSourcesValidator = (control) => {
|
|
234
236
|
const value = parseConnectionPayload(control.value);
|
|
235
|
-
const
|
|
236
|
-
|
|
237
|
+
const selectedSources = Array.isArray(value?.sources) ? value.sources : [];
|
|
238
|
+
const allRequiredSourcesSelected = this.sourceLevels()
|
|
239
|
+
.filter((source) => source.isOptional !== true)
|
|
240
|
+
.every((source) => {
|
|
241
|
+
const sourceId = this.getSourceId(source);
|
|
242
|
+
return selectedSources.some((selected) => (selected.sourceLevelId ?? selected.sourceModuleId) === sourceId &&
|
|
243
|
+
(selected.sourceLevelDataId ?? selected.sourceModuleDataId) != null);
|
|
244
|
+
});
|
|
245
|
+
return allRequiredSourcesSelected ? null : { required: true };
|
|
237
246
|
};
|
|
238
247
|
ngControl = null;
|
|
239
248
|
http = inject(HttpClient);
|
|
240
249
|
destroyRef = inject(DestroyRef);
|
|
250
|
+
cdr = inject(ChangeDetectorRef);
|
|
241
251
|
transloco = inject(TranslocoService);
|
|
242
252
|
/** Active UI language, kept reactive so source labels re-resolve on switch. */
|
|
243
253
|
activeLang = toSignal(this.transloco.langChanges$, {
|
|
@@ -300,13 +310,13 @@ class SchemaConnectionField {
|
|
|
300
310
|
const control = this.ngControl?.control;
|
|
301
311
|
if (!control)
|
|
302
312
|
return;
|
|
303
|
-
const
|
|
313
|
+
const hasRequiredSources = this.sourceLevels().some((source) => source.isOptional !== true);
|
|
304
314
|
untracked(() => {
|
|
305
|
-
if (
|
|
306
|
-
control.addValidators(this.
|
|
315
|
+
if (hasRequiredSources) {
|
|
316
|
+
control.addValidators(this.requiredSourcesValidator);
|
|
307
317
|
}
|
|
308
318
|
else {
|
|
309
|
-
control.removeValidators(this.
|
|
319
|
+
control.removeValidators(this.requiredSourcesValidator);
|
|
310
320
|
}
|
|
311
321
|
control.updateValueAndValidity({ emitEvent: false });
|
|
312
322
|
});
|
|
@@ -340,6 +350,23 @@ class SchemaConnectionField {
|
|
|
340
350
|
});
|
|
341
351
|
});
|
|
342
352
|
}
|
|
353
|
+
/**
|
|
354
|
+
* Repaint when the control's own state changes.
|
|
355
|
+
*
|
|
356
|
+
* `touched` and validity are plain `AbstractControl` state, not signals, and
|
|
357
|
+
* this component is `OnPush` — so a host that calls `markAllAsTouched()` on a
|
|
358
|
+
* failed submit marked the connection invalid and nothing re-rendered. The
|
|
359
|
+
* required message only appeared once the user happened to touch a dropdown,
|
|
360
|
+
* which is the one moment they no longer need telling.
|
|
361
|
+
*
|
|
362
|
+
* `ngOnInit` rather than the constructor: `formControl` / `formControlName`
|
|
363
|
+
* only expose `.control` after their first `ngOnChanges`.
|
|
364
|
+
*/
|
|
365
|
+
ngOnInit() {
|
|
366
|
+
this.ngControl?.control?.events
|
|
367
|
+
.pipe(takeUntilDestroyed(this.destroyRef))
|
|
368
|
+
.subscribe(() => this.cdr.markForCheck());
|
|
369
|
+
}
|
|
343
370
|
// ============================================================================
|
|
344
371
|
// Source Level Helpers
|
|
345
372
|
// ============================================================================
|
|
@@ -351,6 +378,49 @@ class SchemaConnectionField {
|
|
|
351
378
|
getSourceId(source) {
|
|
352
379
|
return (source.levelId ?? source.moduleId);
|
|
353
380
|
}
|
|
381
|
+
/**
|
|
382
|
+
* A source that must be selected and is not. Mirrors
|
|
383
|
+
* {@link requiredSourcesValidator}, which decides the same thing from the
|
|
384
|
+
* control value.
|
|
385
|
+
*
|
|
386
|
+
* A method, not a computed: `selections` is a plain object that `ngModel`
|
|
387
|
+
* mutates in place and carries no signal, so only re-reading it every change
|
|
388
|
+
* detection cycle stays truthful.
|
|
389
|
+
*/
|
|
390
|
+
isSourceMissing(source) {
|
|
391
|
+
if (source.isOptional === true)
|
|
392
|
+
return false;
|
|
393
|
+
const selected = this.selections[this.getSourceId(source)];
|
|
394
|
+
return Array.isArray(selected) ? selected.length === 0 : selected == null;
|
|
395
|
+
}
|
|
396
|
+
/**
|
|
397
|
+
* The control, but only for the source the message belongs under — every
|
|
398
|
+
* other source gets `null` and renders nothing. `mt-field-validation` still
|
|
399
|
+
* decides whether to paint: it waits for `touched`.
|
|
400
|
+
*
|
|
401
|
+
* Field height stays stable because the reserved line moves rather than
|
|
402
|
+
* appears. A null control reserves nothing, so exactly one slot is live at a
|
|
403
|
+
* time — the missing source's, or {@link unattributedErrorControl}'s below
|
|
404
|
+
* the row.
|
|
405
|
+
*/
|
|
406
|
+
sourceErrorControl(source) {
|
|
407
|
+
return this.isSourceMissing(source)
|
|
408
|
+
? (this.ngControl?.control ?? null)
|
|
409
|
+
: null;
|
|
410
|
+
}
|
|
411
|
+
/**
|
|
412
|
+
* The control, but only while no source owns the failure — a server error on
|
|
413
|
+
* a fully selected connection has nowhere else to render. Null as soon as a
|
|
414
|
+
* source is missing, so one failure never prints twice.
|
|
415
|
+
*/
|
|
416
|
+
unattributedErrorControl() {
|
|
417
|
+
const control = this.ngControl?.control ?? null;
|
|
418
|
+
if (!control)
|
|
419
|
+
return null;
|
|
420
|
+
return this.sourceLevels().some((source) => this.isSourceMissing(source))
|
|
421
|
+
? null
|
|
422
|
+
: control;
|
|
423
|
+
}
|
|
354
424
|
/**
|
|
355
425
|
* Builds the `contextKey` for the `fetch/query` request based on source type.
|
|
356
426
|
*/
|
|
@@ -473,7 +543,7 @@ class SchemaConnectionField {
|
|
|
473
543
|
this.disabled.set(disabled);
|
|
474
544
|
}
|
|
475
545
|
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.8", ngImport: i0, type: SchemaConnectionField, deps: [], target: i0.ɵɵFactoryTarget.Component });
|
|
476
|
-
static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "21.2.8", type: SchemaConnectionField, isStandalone: true, selector: "mt-schema-connection-field", inputs: { label: { classPropertyName: "label", publicName: "label", isSignal: true, isRequired: false, transformFunction: null }, placeholder: { classPropertyName: "placeholder", publicName: "placeholder", 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 }, filter: { classPropertyName: "filter", publicName: "filter", isSignal: true, isRequired: false, transformFunction: null }, configuration: { classPropertyName: "configuration", publicName: "configuration", isSignal: true, isRequired: true, transformFunction: null }, runtimeContext: { classPropertyName: "runtimeContext", publicName: "runtimeContext", 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 gap-4 w-full\">\
|
|
546
|
+
static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "21.2.8", type: SchemaConnectionField, isStandalone: true, selector: "mt-schema-connection-field", inputs: { label: { classPropertyName: "label", publicName: "label", isSignal: true, isRequired: false, transformFunction: null }, placeholder: { classPropertyName: "placeholder", publicName: "placeholder", 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 }, filter: { classPropertyName: "filter", publicName: "filter", isSignal: true, isRequired: false, transformFunction: null }, configuration: { classPropertyName: "configuration", publicName: "configuration", isSignal: true, isRequired: true, transformFunction: null }, runtimeContext: { classPropertyName: "runtimeContext", publicName: "runtimeContext", 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 gap-4 w-full\">\n @for (state of sourceLevelStates(); track getSourceId(state.source)) {\n <!--\n `grid gap-1 grid-cols-[minmax(0,1fr)]` matches the label\u2192control spacing\n every other mt-* field gets from its host class; the explicit column\n keeps the implicit max-content track from letting long values overflow.\n -->\n <div\n [style.width]=\"dropdownWidth()\"\n class=\"grid gap-1 grid-cols-[minmax(0,1fr)] min-w-0\"\n >\n <div class=\"flex items-center gap-1\">\n <label\n class=\"truncate\"\n [class.required]=\"state.source.isOptional !== true\"\n >\n {{ resolveSourceName(state.source) }}\n </label>\n <span\n class=\"inline-flex shrink-0 text-surface-400\"\n [mtTooltip]=\"connectionHint()\"\n tooltipPosition=\"top\"\n >\n <mt-icon icon=\"general.link-01\" />\n </span>\n </div>\n\n @if (state.source.allowManyToMany) {\n <mt-multi-select-field\n [field]=\"false\"\n [(ngModel)]=\"selections[getSourceId(state.source)]\"\n (ngModelChange)=\"syncValue()\"\n [options]=\"state.options\"\n optionLabel=\"name\"\n optionValue=\"id\"\n [placeholder]=\"sourcePlaceholder(state.source)\"\n [readonly]=\"disabled() || readonly()\"\n [filter]=\"filter()\"\n [showClear]=\"state.source.isOptional === true\"\n display=\"chip\"\n />\n } @else {\n <mt-select-field\n [field]=\"false\"\n [(ngModel)]=\"selections[getSourceId(state.source)]\"\n (ngModelChange)=\"syncValue()\"\n [options]=\"state.options\"\n optionLabel=\"name\"\n optionValue=\"id\"\n [placeholder]=\"sourcePlaceholder(state.source)\"\n [readonly]=\"disabled() || readonly()\"\n [filter]=\"filter()\"\n [loading]=\"state.loading\"\n [showClear]=\"state.source.isOptional === true\"\n />\n }\n\n <!--\n The error belongs to the dropdown that is empty, not to the field. One\n message below the whole row always rendered under the first source, so\n a missing `Program` read as an error on `Portfolio`.\n -->\n <mt-field-validation\n [control]=\"sourceErrorControl(state.source)\"\n ></mt-field-validation>\n </div>\n }\n</div>\n\n<!--\n Whatever the control reports that no single source owns \u2014 a server error, say.\n Null while a source is missing, so the message is never shown twice.\n-->\n<mt-field-validation\n [control]=\"unattributedErrorControl()\"\n></mt-field-validation>\n", styles: [""], dependencies: [{ kind: "ngmodule", type: FormsModule }, { kind: "directive", type: i1.NgControlStatus, selector: "[formControlName],[ngModel],[formControl]" }, { kind: "directive", type: i1.NgModel, selector: "[ngModel]:not([formControlName]):not([formControl])", inputs: ["name", "disabled", "ngModel", "ngModelOptions"], outputs: ["ngModelChange"], exportAs: ["ngModel"] }, { kind: "component", type: SelectField, selector: "mt-select-field", inputs: ["field", "hint", "label", "placeholder", "hasPlaceholderPrefix", "class", "readonly", "pInputs", "options", "optionValue", "optionLabel", "filter", "filterBy", "dataKey", "showClear", "clearAfterSelect", "required", "group", "size", "optionGroupLabel", "optionGroupChildren", "loading", "optionIcon", "optionIconColor", "optionIconShape", "optionAvatarShape", "optionGroupIcon", "optionGroupIconColor", "optionGroupIconShape", "optionGroupAvatarShape", "markCurrentUser"], outputs: ["onChange"] }, { kind: "component", type: MultiSelectField, selector: "mt-multi-select-field", inputs: ["field", "label", "placeholder", "class", "readonly", "pInputs", "options", "optionValue", "optionLabel", "filter", "filterBy", "dataKey", "showClear", "display", "required", "maxSelectedLabels", "group", "virtualScroll", "virtualScrollItemSize", "optionGroupLabel", "optionGroupChildren", "optionIcon", "optionIconColor", "optionIconShape", "optionAvatarShape", "optionGroupIcon", "optionGroupIconColor", "optionGroupIconShape", "optionGroupAvatarShape"], outputs: ["onChange"] }, { kind: "component", type: FieldValidation, selector: "mt-field-validation", inputs: ["control", "touched", "messageId"] }, { kind: "directive", type: Tooltip, selector: "[mtTooltip]" }, { kind: "component", type: Icon, selector: "mt-icon", inputs: ["icon"] }], changeDetection: i0.ChangeDetectionStrategy.OnPush });
|
|
477
547
|
}
|
|
478
548
|
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.8", ngImport: i0, type: SchemaConnectionField, decorators: [{
|
|
479
549
|
type: Component,
|
|
@@ -486,7 +556,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.8", ngImpor
|
|
|
486
556
|
Icon,
|
|
487
557
|
], changeDetection: ChangeDetectionStrategy.OnPush, host: {
|
|
488
558
|
class: 'grid gap-1',
|
|
489
|
-
}, template: "<div class=\"flex gap-4 w-full\">\
|
|
559
|
+
}, template: "<div class=\"flex gap-4 w-full\">\n @for (state of sourceLevelStates(); track getSourceId(state.source)) {\n <!--\n `grid gap-1 grid-cols-[minmax(0,1fr)]` matches the label\u2192control spacing\n every other mt-* field gets from its host class; the explicit column\n keeps the implicit max-content track from letting long values overflow.\n -->\n <div\n [style.width]=\"dropdownWidth()\"\n class=\"grid gap-1 grid-cols-[minmax(0,1fr)] min-w-0\"\n >\n <div class=\"flex items-center gap-1\">\n <label\n class=\"truncate\"\n [class.required]=\"state.source.isOptional !== true\"\n >\n {{ resolveSourceName(state.source) }}\n </label>\n <span\n class=\"inline-flex shrink-0 text-surface-400\"\n [mtTooltip]=\"connectionHint()\"\n tooltipPosition=\"top\"\n >\n <mt-icon icon=\"general.link-01\" />\n </span>\n </div>\n\n @if (state.source.allowManyToMany) {\n <mt-multi-select-field\n [field]=\"false\"\n [(ngModel)]=\"selections[getSourceId(state.source)]\"\n (ngModelChange)=\"syncValue()\"\n [options]=\"state.options\"\n optionLabel=\"name\"\n optionValue=\"id\"\n [placeholder]=\"sourcePlaceholder(state.source)\"\n [readonly]=\"disabled() || readonly()\"\n [filter]=\"filter()\"\n [showClear]=\"state.source.isOptional === true\"\n display=\"chip\"\n />\n } @else {\n <mt-select-field\n [field]=\"false\"\n [(ngModel)]=\"selections[getSourceId(state.source)]\"\n (ngModelChange)=\"syncValue()\"\n [options]=\"state.options\"\n optionLabel=\"name\"\n optionValue=\"id\"\n [placeholder]=\"sourcePlaceholder(state.source)\"\n [readonly]=\"disabled() || readonly()\"\n [filter]=\"filter()\"\n [loading]=\"state.loading\"\n [showClear]=\"state.source.isOptional === true\"\n />\n }\n\n <!--\n The error belongs to the dropdown that is empty, not to the field. One\n message below the whole row always rendered under the first source, so\n a missing `Program` read as an error on `Portfolio`.\n -->\n <mt-field-validation\n [control]=\"sourceErrorControl(state.source)\"\n ></mt-field-validation>\n </div>\n }\n</div>\n\n<!--\n Whatever the control reports that no single source owns \u2014 a server error, say.\n Null while a source is missing, so the message is never shown twice.\n-->\n<mt-field-validation\n [control]=\"unattributedErrorControl()\"\n></mt-field-validation>\n" }]
|
|
490
560
|
}], ctorParameters: () => [], propDecorators: { label: [{ type: i0.Input, args: [{ isSignal: true, alias: "label", required: false }] }], placeholder: [{ type: i0.Input, args: [{ isSignal: true, alias: "placeholder", required: false }] }], readonly: [{ type: i0.Input, args: [{ isSignal: true, alias: "readonly", required: false }] }], required: [{ type: i0.Input, args: [{ isSignal: true, alias: "required", required: false }] }], filter: [{ type: i0.Input, args: [{ isSignal: true, alias: "filter", required: false }] }], configuration: [{ type: i0.Input, args: [{ isSignal: true, alias: "configuration", required: true }] }], runtimeContext: [{ type: i0.Input, args: [{ isSignal: true, alias: "runtimeContext", required: false }] }], context: [{ type: i0.Input, args: [{ isSignal: true, alias: "context", required: false }] }] } });
|
|
491
561
|
|
|
492
562
|
const PREDECESSOR_TYPE_BY_TOKEN = {
|
|
@@ -754,6 +824,130 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.8", ngImpor
|
|
|
754
824
|
* token is not registered, the field falls back to a minimal text-only popup.
|
|
755
825
|
*/
|
|
756
826
|
const ENTITY_LIST_ADD_DIALOG_COMPONENT = new InjectionToken('ENTITY_LIST_ADD_DIALOG_COMPONENT');
|
|
827
|
+
/**
|
|
828
|
+
* Local counterpart of `ENTITY_LIST_ADD_DIALOG_COMPONENT`, registered by the
|
|
829
|
+
* same `provideEntityListAddForm()`. Without it a Local list is read-only.
|
|
830
|
+
*/
|
|
831
|
+
const ENTITY_LIST_LOCAL_ROW_DIALOG_COMPONENT = new InjectionToken('ENTITY_LIST_LOCAL_ROW_DIALOG_COMPONENT');
|
|
832
|
+
|
|
833
|
+
function createLocalEditorState(base) {
|
|
834
|
+
return {
|
|
835
|
+
base,
|
|
836
|
+
created: [],
|
|
837
|
+
edited: {},
|
|
838
|
+
deleted: [],
|
|
839
|
+
order: null,
|
|
840
|
+
mutationId: null,
|
|
841
|
+
mutationKey: null,
|
|
842
|
+
};
|
|
843
|
+
}
|
|
844
|
+
/**
|
|
845
|
+
* Rows in display order. Until the user reorders, loaded rows keep their
|
|
846
|
+
* stored `order` and new rows go after the last one. After a reorder every row
|
|
847
|
+
* takes its position — the backend requires a non-negative order and nothing
|
|
848
|
+
* more, so positions are the simplest valid numbering.
|
|
849
|
+
*/
|
|
850
|
+
function orderLocalRows(state) {
|
|
851
|
+
const deleted = new Set(state.deleted);
|
|
852
|
+
const loaded = sortLocalRows(state.base?.localRows).filter((row) => !deleted.has(row.rowId));
|
|
853
|
+
const maxOrder = loaded.reduce((max, row) => Math.max(max, row.order ?? 0), -1);
|
|
854
|
+
const rows = [
|
|
855
|
+
...loaded.map((row) => ({
|
|
856
|
+
rowId: row.rowId,
|
|
857
|
+
order: row.order ?? 0,
|
|
858
|
+
existing: row,
|
|
859
|
+
})),
|
|
860
|
+
...state.created.map((row, index) => ({
|
|
861
|
+
rowId: row.rowId,
|
|
862
|
+
order: maxOrder + 1 + index,
|
|
863
|
+
created: row,
|
|
864
|
+
})),
|
|
865
|
+
];
|
|
866
|
+
if (!state.order)
|
|
867
|
+
return rows;
|
|
868
|
+
const position = new Map(state.order.map((rowId, index) => [rowId, index]));
|
|
869
|
+
return rows
|
|
870
|
+
.map((row, index) => ({ row, index }))
|
|
871
|
+
.sort((a, b) => (position.get(a.row.rowId) ?? state.order.length + a.index) -
|
|
872
|
+
(position.get(b.row.rowId) ?? state.order.length + b.index))
|
|
873
|
+
.map(({ row }, index) => ({ ...row, order: index }));
|
|
874
|
+
}
|
|
875
|
+
/**
|
|
876
|
+
* What changed, or null when nothing did.
|
|
877
|
+
*
|
|
878
|
+
* - A loaded row is sent only when a cell or its order changed, with its
|
|
879
|
+
* loaded version and only those cells: omission retains a cell or a row, it
|
|
880
|
+
* never deletes one. A reorder alone sends no cells.
|
|
881
|
+
* - A new row is sent with version 0 and every cell the user filled in.
|
|
882
|
+
* - A removed row is listed in `deletedRowIds` and never also submitted.
|
|
883
|
+
*/
|
|
884
|
+
function buildLocalMutationContent(state) {
|
|
885
|
+
const localRows = [];
|
|
886
|
+
for (const row of orderLocalRows(state)) {
|
|
887
|
+
if (row.existing) {
|
|
888
|
+
const cells = toCells(state.edited[row.rowId]?.cells ?? {});
|
|
889
|
+
if (!cells.length && row.order === (row.existing.order ?? 0))
|
|
890
|
+
continue;
|
|
891
|
+
localRows.push({
|
|
892
|
+
rowId: row.rowId,
|
|
893
|
+
order: row.order,
|
|
894
|
+
version: row.existing.version ?? 0,
|
|
895
|
+
cells,
|
|
896
|
+
});
|
|
897
|
+
continue;
|
|
898
|
+
}
|
|
899
|
+
localRows.push({
|
|
900
|
+
rowId: row.rowId,
|
|
901
|
+
order: row.order,
|
|
902
|
+
version: 0,
|
|
903
|
+
cells: toCells(row.created?.draft.cells ?? {}).filter((cell) => cell.rawValue !== null),
|
|
904
|
+
});
|
|
905
|
+
}
|
|
906
|
+
if (!localRows.length && !state.deleted.length)
|
|
907
|
+
return null;
|
|
908
|
+
return { localRows, deletedRowIds: [...state.deleted] };
|
|
909
|
+
}
|
|
910
|
+
function toCells(cells) {
|
|
911
|
+
return Object.entries(cells).map(([fieldId, rawValue]) => ({
|
|
912
|
+
fieldId,
|
|
913
|
+
rawValue,
|
|
914
|
+
}));
|
|
915
|
+
}
|
|
916
|
+
/**
|
|
917
|
+
* The cells of an edited loaded row that differ from what was loaded.
|
|
918
|
+
* Setting a cell back to its loaded value drops it, so an edit that is undone
|
|
919
|
+
* by hand stops being an edit.
|
|
920
|
+
*/
|
|
921
|
+
function diffLocalCells(loaded, next) {
|
|
922
|
+
const before = new Map((loaded.cells ?? []).map((cell) => [cell.fieldId, cell.rawValue ?? null]));
|
|
923
|
+
const changed = {};
|
|
924
|
+
for (const [fieldId, rawValue] of Object.entries(next)) {
|
|
925
|
+
if ((before.get(fieldId) ?? null) === rawValue)
|
|
926
|
+
continue;
|
|
927
|
+
changed[fieldId] = rawValue;
|
|
928
|
+
}
|
|
929
|
+
return changed;
|
|
930
|
+
}
|
|
931
|
+
/**
|
|
932
|
+
* A v4 UUID. Row ids and mutation ids are parsed as GUIDs by the backend.
|
|
933
|
+
* `crypto.randomUUID` exists only in secure contexts, and these apps are also
|
|
934
|
+
* served over plain HTTP, where `getRandomValues` is still available.
|
|
935
|
+
*/
|
|
936
|
+
function newLocalUuid() {
|
|
937
|
+
if (typeof crypto.randomUUID === 'function')
|
|
938
|
+
return crypto.randomUUID();
|
|
939
|
+
const bytes = crypto.getRandomValues(new Uint8Array(16));
|
|
940
|
+
bytes[6] = (bytes[6] & 0x0f) | 0x40;
|
|
941
|
+
bytes[8] = (bytes[8] & 0x3f) | 0x80;
|
|
942
|
+
const hex = Array.from(bytes, (byte) => byte.toString(16).padStart(2, '0'));
|
|
943
|
+
return [
|
|
944
|
+
hex.slice(0, 4).join(''),
|
|
945
|
+
hex.slice(4, 6).join(''),
|
|
946
|
+
hex.slice(6, 8).join(''),
|
|
947
|
+
hex.slice(8, 10).join(''),
|
|
948
|
+
hex.slice(10, 16).join(''),
|
|
949
|
+
].join('-');
|
|
950
|
+
}
|
|
757
951
|
|
|
758
952
|
function resolveMetadataFailure(status) {
|
|
759
953
|
if (status === 403)
|
|
@@ -797,6 +991,20 @@ const OBJECT_VALUED_VIEW_TYPES = new Set(['User', 'MultiUser']);
|
|
|
797
991
|
const ROW_CHANGE_KEY = '__change';
|
|
798
992
|
/** Column key of the synthetic flag column — never a target property key. */
|
|
799
993
|
const ROW_CHANGE_COLUMN_KEY = '__changeState';
|
|
994
|
+
/** Internal row key marking a Local row added in this session. */
|
|
995
|
+
const ROW_LOCAL_CREATED_KEY = '__localCreated';
|
|
996
|
+
/**
|
|
997
|
+
* The editing state behind each Local value this field emitted, keyed by that
|
|
998
|
+
* value.
|
|
999
|
+
*
|
|
1000
|
+
* A mutation carries only what changed, so it cannot rebuild the table on its
|
|
1001
|
+
* own — and the field is not always the one that emitted it: `mt-dynamic-form`
|
|
1002
|
+
* destroys the sections outside the current wizard step, and the field that
|
|
1003
|
+
* comes back is a new instance handed the form's current value. Keeping the
|
|
1004
|
+
* state out of the payload leaves the submitted JSON exactly the contract,
|
|
1005
|
+
* and a `WeakMap` lets it go with the value.
|
|
1006
|
+
*/
|
|
1007
|
+
const LOCAL_EDITOR_STATES = new WeakMap();
|
|
800
1008
|
/**
|
|
801
1009
|
* Badge colour per staged operation, as a hex: `mt-entity-status` derives its
|
|
802
1010
|
* own 12%-alpha background by slicing the value's `color`, so a Tailwind class
|
|
@@ -846,14 +1054,17 @@ class EntityListField {
|
|
|
846
1054
|
/** Optional HttpContext (kept for back-compat). */
|
|
847
1055
|
context = input(undefined, ...(ngDevMode ? [{ debugName: "context" }] : /* istanbul ignore next */ []));
|
|
848
1056
|
/**
|
|
849
|
-
*
|
|
850
|
-
*
|
|
851
|
-
* `
|
|
1057
|
+
* The stored value, for hosts that render this field **outside a form** —
|
|
1058
|
+
* the read-only `mt-entity-list-preview` creates it through
|
|
1059
|
+
* `NgComponentOutlet`, which can set inputs but cannot drive a
|
|
1060
|
+
* `ControlValueAccessor`.
|
|
852
1061
|
*
|
|
853
|
-
* Ignored
|
|
854
|
-
*
|
|
1062
|
+
* Ignored once a form control is attached, so it can never race
|
|
1063
|
+
* `writeValue`. It matters for a `Write`-access list: that field may not read
|
|
1064
|
+
* the target module, so its stored `rows[]` are the only thing it has to
|
|
1065
|
+
* show.
|
|
855
1066
|
*/
|
|
856
|
-
|
|
1067
|
+
initialValue = input(null, ...(ngDevMode ? [{ debugName: "initialValue" }] : /* istanbul ignore next */ []));
|
|
857
1068
|
// CVA state — pass-through value (EntityList stored JSON shape).
|
|
858
1069
|
storedValue = signal(null, ...(ngDevMode ? [{ debugName: "storedValue" }] : /* istanbul ignore next */ []));
|
|
859
1070
|
/** Runtime-scoped metadata; null until the endpoint answers. */
|
|
@@ -1174,6 +1385,146 @@ class EntityListField {
|
|
|
1174
1385
|
},
|
|
1175
1386
|
];
|
|
1176
1387
|
}, ...(ngDevMode ? [{ debugName: "tableColumns" }] : /* istanbul ignore next */ []));
|
|
1388
|
+
// ============================================================================
|
|
1389
|
+
// Local storage (`storageMode: "Local"`) — rows owned by the parent record
|
|
1390
|
+
// ============================================================================
|
|
1391
|
+
/** Loaded document plus this session's edits; see `LocalEditorState`. */
|
|
1392
|
+
localState = signal(createLocalEditorState(null), ...(ngDevMode ? [{ debugName: "localState" }] : /* istanbul ignore next */ []));
|
|
1393
|
+
/** The bound value was a Local document, whatever the metadata says yet. */
|
|
1394
|
+
localValueSeen = signal(false, ...(ngDevMode ? [{ debugName: "localValueSeen" }] : /* istanbul ignore next */ []));
|
|
1395
|
+
/** The last Local value emitted, so its echo does not reset the edits. */
|
|
1396
|
+
lastLocalEmit = null;
|
|
1397
|
+
/**
|
|
1398
|
+
* Rows live inside the parent record: no target records, no `fetch/query`,
|
|
1399
|
+
* and the value is a document of its own rather than operation markers.
|
|
1400
|
+
* Known from the metadata, or earlier from the value itself.
|
|
1401
|
+
*/
|
|
1402
|
+
localMode = computed(() => this.metadata()?.storageMode === 'Local' || this.localValueSeen(), ...(ngDevMode ? [{ debugName: "localMode" }] : /* istanbul ignore next */ []));
|
|
1403
|
+
/**
|
|
1404
|
+
* The schema the table is built from. A loaded value's own schema wins: it
|
|
1405
|
+
* is the one its rows were projected against, and pending or approved
|
|
1406
|
+
* evidence stays pinned to the schema it was submitted with. The metadata's
|
|
1407
|
+
* active schema is the fallback for a list that has never been saved.
|
|
1408
|
+
*/
|
|
1409
|
+
localSchema = computed(() => this.localState().base?.schema ?? this.metadata()?.localSchema ?? null, ...(ngDevMode ? [{ debugName: "localSchema" }] : /* istanbul ignore next */ []));
|
|
1410
|
+
localFields = computed(() => visibleLocalSchemaFields(this.localSchema()), ...(ngDevMode ? [{ debugName: "localFields" }] : /* istanbul ignore next */ []));
|
|
1411
|
+
/**
|
|
1412
|
+
* Render the Local table once the metadata answered: it is the access
|
|
1413
|
+
* boundary, and it carries the operation switches the table obeys.
|
|
1414
|
+
*/
|
|
1415
|
+
localReady = computed(() => this.localMode() && !!this.metadata(), ...(ngDevMode ? [{ debugName: "localReady" }] : /* istanbul ignore next */ []));
|
|
1416
|
+
/**
|
|
1417
|
+
* Writes are staged into the parent's submission, never sent on their own.
|
|
1418
|
+
*
|
|
1419
|
+
* Whether the host lets this field be edited is the form's call —
|
|
1420
|
+
* `readonly` — as it is for a linked list; `pendingSubmission` is not one.
|
|
1421
|
+
* A loaded request is not always a review: a returned request is loaded to
|
|
1422
|
+
* be corrected and resubmitted, and the backend projects the active schema
|
|
1423
|
+
* for exactly that.
|
|
1424
|
+
*/
|
|
1425
|
+
localWritable = computed(() => !!this.localDialogComponent &&
|
|
1426
|
+
!!this.metadata() &&
|
|
1427
|
+
this.writeAllowed() &&
|
|
1428
|
+
!this.readonly() &&
|
|
1429
|
+
!this.disabled() &&
|
|
1430
|
+
this.localFields().length > 0, ...(ngDevMode ? [{ debugName: "localWritable" }] : /* istanbul ignore next */ []));
|
|
1431
|
+
localCanCreate = computed(() => this.localWritable() && this.metadata()?.allowCreate !== false, ...(ngDevMode ? [{ debugName: "localCanCreate" }] : /* istanbul ignore next */ []));
|
|
1432
|
+
localCanEdit = computed(() => this.localWritable() && this.metadata()?.allowEdit !== false, ...(ngDevMode ? [{ debugName: "localCanEdit" }] : /* istanbul ignore next */ []));
|
|
1433
|
+
localCanDelete = computed(() => this.localWritable() && this.metadata()?.allowDelete !== false, ...(ngDevMode ? [{ debugName: "localCanDelete" }] : /* istanbul ignore next */ []));
|
|
1434
|
+
/** Reordering rewrites loaded rows, so it is an edit. */
|
|
1435
|
+
localCanReorder = computed(() => this.localCanEdit() && this.localTableRows().length > 1, ...(ngDevMode ? [{ debugName: "localCanReorder" }] : /* istanbul ignore next */ []));
|
|
1436
|
+
/**
|
|
1437
|
+
* One column per visible schema field, keyed by the field's local id — the
|
|
1438
|
+
* id cells are keyed by. Sorting is off while rows can be dragged: a sorted
|
|
1439
|
+
* table would show an order that is not the one being saved.
|
|
1440
|
+
*/
|
|
1441
|
+
localColumns = computed(() => {
|
|
1442
|
+
const lang = this.lang();
|
|
1443
|
+
const sortable = !this.localCanEdit();
|
|
1444
|
+
return this.localFields().map((field, index) => {
|
|
1445
|
+
const viewType = resolveLocalFieldViewType(field);
|
|
1446
|
+
return {
|
|
1447
|
+
key: field.id,
|
|
1448
|
+
label: resolveLocalFieldLabel(field, lang),
|
|
1449
|
+
type: 'entity',
|
|
1450
|
+
sortable: sortable &&
|
|
1451
|
+
!UNSORTABLE_ENTITY_VIEW_TYPES.has(viewType),
|
|
1452
|
+
viewType,
|
|
1453
|
+
order: index,
|
|
1454
|
+
visible: true,
|
|
1455
|
+
configuration: null,
|
|
1456
|
+
};
|
|
1457
|
+
});
|
|
1458
|
+
}, ...(ngDevMode ? [{ debugName: "localColumns" }] : /* istanbul ignore next */ []));
|
|
1459
|
+
/**
|
|
1460
|
+
* Rows as rendered: loaded rows with this session's edits over them, then
|
|
1461
|
+
* new rows, in the order they would be saved. A loaded cell renders from the
|
|
1462
|
+
* backend's resolved `value`; a cell the user set renders from the dialog's
|
|
1463
|
+
* control value and option label, like a locally added linked row.
|
|
1464
|
+
*/
|
|
1465
|
+
localTableRows = computed(() => {
|
|
1466
|
+
const state = this.localState();
|
|
1467
|
+
const fields = this.localFields();
|
|
1468
|
+
const columns = new Map(this.localColumns().map((column) => [column.key, column]));
|
|
1469
|
+
return orderLocalRows(state).map((entry) => {
|
|
1470
|
+
const cells = entry.existing
|
|
1471
|
+
? localCellsByFieldId(entry.existing)
|
|
1472
|
+
: new Map();
|
|
1473
|
+
const draft = entry.created?.draft ?? state.edited[entry.rowId];
|
|
1474
|
+
const row = {
|
|
1475
|
+
Id: entry.rowId,
|
|
1476
|
+
[ROW_ID_KEY]: entry.rowId,
|
|
1477
|
+
[ROW_LOCAL_CREATED_KEY]: !!entry.created,
|
|
1478
|
+
};
|
|
1479
|
+
for (const field of fields) {
|
|
1480
|
+
const fieldId = field.id;
|
|
1481
|
+
const column = columns.get(fieldId);
|
|
1482
|
+
if (!column)
|
|
1483
|
+
continue;
|
|
1484
|
+
const configuration = resolveLocalFieldConfiguration(field);
|
|
1485
|
+
row[fieldId] =
|
|
1486
|
+
draft && (entry.created || fieldId in draft.cells)
|
|
1487
|
+
? this.buildLocalDraftCell(column, draft, configuration)
|
|
1488
|
+
: this.buildLocalLoadedCell(column, cells.get(fieldId), configuration);
|
|
1489
|
+
}
|
|
1490
|
+
return row;
|
|
1491
|
+
});
|
|
1492
|
+
}, ...(ngDevMode ? [{ debugName: "localTableRows" }] : /* istanbul ignore next */ []));
|
|
1493
|
+
/**
|
|
1494
|
+
* Edit and delete per row. A row added in this session is still part of the
|
|
1495
|
+
* create — changing or dropping it undoes nothing stored — so it follows
|
|
1496
|
+
* `allowCreate`; a loaded row follows `allowEdit` / `allowDelete`.
|
|
1497
|
+
*/
|
|
1498
|
+
localRowActions = computed(() => {
|
|
1499
|
+
this.lang();
|
|
1500
|
+
const canCreate = this.localCanCreate();
|
|
1501
|
+
const canEdit = this.localCanEdit();
|
|
1502
|
+
const canDelete = this.localCanDelete();
|
|
1503
|
+
const isCreated = (row) => row[ROW_LOCAL_CREATED_KEY] === true;
|
|
1504
|
+
const actions = [];
|
|
1505
|
+
if (canCreate || canEdit) {
|
|
1506
|
+
actions.push({
|
|
1507
|
+
icon: 'custom.pencil',
|
|
1508
|
+
tooltip: this.transloco.translate('components.entityListField.edit'),
|
|
1509
|
+
hidden: (row) => isCreated(row) ? !canCreate : !canEdit,
|
|
1510
|
+
action: (row) => this.openLocalRowDialog(row),
|
|
1511
|
+
});
|
|
1512
|
+
}
|
|
1513
|
+
if (canCreate || canDelete) {
|
|
1514
|
+
actions.push({
|
|
1515
|
+
icon: 'general.trash-01',
|
|
1516
|
+
tooltip: this.transloco.translate('components.entityListField.delete'),
|
|
1517
|
+
color: 'danger',
|
|
1518
|
+
confirmation: {
|
|
1519
|
+
type: 'popup',
|
|
1520
|
+
confirmationType: 'delete',
|
|
1521
|
+
},
|
|
1522
|
+
hidden: (row) => isCreated(row) ? !canCreate : !canDelete,
|
|
1523
|
+
action: (row) => this.deleteLocalRow(row),
|
|
1524
|
+
});
|
|
1525
|
+
}
|
|
1526
|
+
return actions;
|
|
1527
|
+
}, ...(ngDevMode ? [{ debugName: "localRowActions" }] : /* istanbul ignore next */ []));
|
|
1177
1528
|
/** Enough context to ask the backend what this field should render. */
|
|
1178
1529
|
hasRequiredContext = computed(() => this.propertyKeyId() > 0 && Number(this.levelId()) > 0, ...(ngDevMode ? [{ debugName: "hasRequiredContext" }] : /* istanbul ignore next */ []));
|
|
1179
1530
|
/**
|
|
@@ -1195,6 +1546,13 @@ class EntityListField {
|
|
|
1195
1546
|
}
|
|
1196
1547
|
if (!this.metadata())
|
|
1197
1548
|
return null;
|
|
1549
|
+
// A Local list reads nothing from the source module; it needs only a
|
|
1550
|
+
// schema to render its own rows with.
|
|
1551
|
+
if (this.localMode()) {
|
|
1552
|
+
return this.localFields().length
|
|
1553
|
+
? null
|
|
1554
|
+
: 'components.entityListField.missingConfiguration';
|
|
1555
|
+
}
|
|
1198
1556
|
if (!this.moduleBacked()) {
|
|
1199
1557
|
return 'components.entityListField.missingConfiguration';
|
|
1200
1558
|
}
|
|
@@ -1221,6 +1579,12 @@ class EntityListField {
|
|
|
1221
1579
|
* `writeFields`.
|
|
1222
1580
|
*/
|
|
1223
1581
|
addDialogComponent = inject(ENTITY_LIST_ADD_DIALOG_COMPONENT, { optional: true });
|
|
1582
|
+
/**
|
|
1583
|
+
* Row dialog of a Local list, built from the schema's captured definitions
|
|
1584
|
+
* (`provideEntityListAddForm()` registers it beside the linked one). Without
|
|
1585
|
+
* it a Local list renders read-only.
|
|
1586
|
+
*/
|
|
1587
|
+
localDialogComponent = inject(ENTITY_LIST_LOCAL_ROW_DIALOG_COMPONENT, { optional: true });
|
|
1224
1588
|
constructor() {
|
|
1225
1589
|
this.ngControl = inject(NgControl, { self: true, optional: true });
|
|
1226
1590
|
if (this.ngControl) {
|
|
@@ -1236,15 +1600,15 @@ class EntityListField {
|
|
|
1236
1600
|
const levelDataId = this.levelDataId();
|
|
1237
1601
|
untracked(() => this.loadTable(propertyId, levelId, levelDataId));
|
|
1238
1602
|
});
|
|
1239
|
-
//
|
|
1240
|
-
// the
|
|
1241
|
-
// is
|
|
1603
|
+
// Form-less hosts hand the value over as an input instead. `writeValue` is
|
|
1604
|
+
// the one entry point that resets the pending rows and deletions with it,
|
|
1605
|
+
// so it is reused rather than re-implemented.
|
|
1242
1606
|
//
|
|
1243
|
-
//
|
|
1244
|
-
//
|
|
1245
|
-
// `writeValue`
|
|
1607
|
+
// Purely additive: an absent input never clears a value, so a host that
|
|
1608
|
+
// does not bind it — or binds it late — cannot wipe what a form or a direct
|
|
1609
|
+
// `writeValue` already put there.
|
|
1246
1610
|
effect(() => {
|
|
1247
|
-
const value = this.
|
|
1611
|
+
const value = this.initialValue();
|
|
1248
1612
|
if (this.ngControl || value == null)
|
|
1249
1613
|
return;
|
|
1250
1614
|
untracked(() => this.writeValue(value));
|
|
@@ -1254,6 +1618,8 @@ class EntityListField {
|
|
|
1254
1618
|
// CVA
|
|
1255
1619
|
// ============================================================================
|
|
1256
1620
|
writeValue(value) {
|
|
1621
|
+
if (this.writeLocalValue(value))
|
|
1622
|
+
return;
|
|
1257
1623
|
const incoming = this.coerceStoredValue(value);
|
|
1258
1624
|
// Ignore the echo of our own emission (DynamicForm re-writes the model on
|
|
1259
1625
|
// every value change) so pending edits/deletions are not reset.
|
|
@@ -1273,6 +1639,46 @@ class EntityListField {
|
|
|
1273
1639
|
this.stagedDeletedIds.set([]);
|
|
1274
1640
|
this.rowDrafts.set({});
|
|
1275
1641
|
}
|
|
1642
|
+
/**
|
|
1643
|
+
* Take a Local document, and say whether it was one.
|
|
1644
|
+
*
|
|
1645
|
+
* - Our own emission echoed back (`mt-dynamic-form` re-writes the model on
|
|
1646
|
+
* every change) keeps the session's edits.
|
|
1647
|
+
* - A value some instance of this field emitted restores that instance's
|
|
1648
|
+
* state — see `LOCAL_EDITOR_STATES`.
|
|
1649
|
+
* - A document the backend sent starts a fresh session on it: the projection
|
|
1650
|
+
* `process-form-load` returns (its `schema` set, cells rendered), or the
|
|
1651
|
+
* stored document the fetch endpoints return for a preview (`schema:
|
|
1652
|
+
* null`, cells unrendered) — the schema then comes from the metadata.
|
|
1653
|
+
* Every backend document carries the `schema` member, null or not; a
|
|
1654
|
+
* mutation never does. So a mutation nobody here emitted has no rows to
|
|
1655
|
+
* rebuild the table from and is left as the control's value, untouched
|
|
1656
|
+
* until the user edits.
|
|
1657
|
+
*
|
|
1658
|
+
* An empty value resets the Local session too — a form reset — and still
|
|
1659
|
+
* falls through, since which storage the list uses may not be known yet.
|
|
1660
|
+
*/
|
|
1661
|
+
writeLocalValue(value) {
|
|
1662
|
+
const incoming = this.coerceStoredValue(value);
|
|
1663
|
+
if (!isEntityListLocalDocument(incoming)) {
|
|
1664
|
+
if (incoming == null) {
|
|
1665
|
+
this.lastLocalEmit = null;
|
|
1666
|
+
this.localState.set(createLocalEditorState(null));
|
|
1667
|
+
}
|
|
1668
|
+
return false;
|
|
1669
|
+
}
|
|
1670
|
+
this.localValueSeen.set(true);
|
|
1671
|
+
if (incoming === this.lastLocalEmit)
|
|
1672
|
+
return true;
|
|
1673
|
+
this.lastLocalEmit = null;
|
|
1674
|
+
const restored = LOCAL_EDITOR_STATES.get(incoming);
|
|
1675
|
+
if (restored) {
|
|
1676
|
+
this.localState.set(restored);
|
|
1677
|
+
return true;
|
|
1678
|
+
}
|
|
1679
|
+
this.localState.set(createLocalEditorState('schema' in incoming ? incoming : null));
|
|
1680
|
+
return true;
|
|
1681
|
+
}
|
|
1276
1682
|
/**
|
|
1277
1683
|
* True when the written value still carries exactly the rows and deletions
|
|
1278
1684
|
* we last emitted — i.e. the form is echoing our own value back rather than
|
|
@@ -1477,6 +1883,226 @@ class EntityListField {
|
|
|
1477
1883
|
this.clearRowDraft(rowId);
|
|
1478
1884
|
this.emitValue();
|
|
1479
1885
|
}
|
|
1886
|
+
// ============================================================================
|
|
1887
|
+
// Local write mode — staged into the parent's own submission
|
|
1888
|
+
// ============================================================================
|
|
1889
|
+
/**
|
|
1890
|
+
* Add a Local row (no `row`) or edit one. The dialog is built from the
|
|
1891
|
+
* schema; its `submit` map is serialized here into cell `rawValue`s.
|
|
1892
|
+
*
|
|
1893
|
+
* A loaded row keeps only the cells that differ from what was loaded, so an
|
|
1894
|
+
* untouched cell is omitted and retained. Emptying a cell that had a value
|
|
1895
|
+
* is a clear, sent as `null` — the dialog is filled from every schema field,
|
|
1896
|
+
* so an empty control here really was emptied.
|
|
1897
|
+
*/
|
|
1898
|
+
openLocalRowDialog(row) {
|
|
1899
|
+
const component = this.localDialogComponent;
|
|
1900
|
+
if (!component || this.disabled())
|
|
1901
|
+
return;
|
|
1902
|
+
const state = this.localState();
|
|
1903
|
+
const rowId = row ? String(row[ROW_ID_KEY] ?? '') : null;
|
|
1904
|
+
const created = rowId
|
|
1905
|
+
? state.created.find((entry) => entry.rowId === rowId)
|
|
1906
|
+
: undefined;
|
|
1907
|
+
const existing = rowId && !created
|
|
1908
|
+
? state.base?.localRows?.find((entry) => entry.rowId === rowId)
|
|
1909
|
+
: undefined;
|
|
1910
|
+
const ref = this.modal.openModal(component, 'dialog', {
|
|
1911
|
+
header: this.transloco.translate(row
|
|
1912
|
+
? 'components.entityListField.edit'
|
|
1913
|
+
: 'components.entityListField.add'),
|
|
1914
|
+
styleClass: '!w-[48rem] max-w-[96vw]',
|
|
1915
|
+
dismissableMask: true,
|
|
1916
|
+
inputValues: {
|
|
1917
|
+
fields: this.localFields(),
|
|
1918
|
+
lookups: this.lookups(),
|
|
1919
|
+
initialCells: existing
|
|
1920
|
+
? Object.fromEntries(localCellsByFieldId(existing))
|
|
1921
|
+
: undefined,
|
|
1922
|
+
initialValues: created?.draft.values ??
|
|
1923
|
+
(rowId ? state.edited[rowId]?.values : undefined),
|
|
1924
|
+
isEdit: !!row,
|
|
1925
|
+
},
|
|
1926
|
+
});
|
|
1927
|
+
ref.onClose.pipe(take(1)).subscribe((result) => {
|
|
1928
|
+
const parsed = this.parseDialogResult(result);
|
|
1929
|
+
if (!parsed)
|
|
1930
|
+
return;
|
|
1931
|
+
const draft = {
|
|
1932
|
+
cells: this.toLocalCells(parsed.values, parsed.submit),
|
|
1933
|
+
values: parsed.values,
|
|
1934
|
+
display: parsed.display,
|
|
1935
|
+
};
|
|
1936
|
+
const current = this.localState();
|
|
1937
|
+
if (!rowId) {
|
|
1938
|
+
this.emitLocal({
|
|
1939
|
+
...current,
|
|
1940
|
+
created: [...current.created, { rowId: newLocalUuid(), draft }],
|
|
1941
|
+
});
|
|
1942
|
+
return;
|
|
1943
|
+
}
|
|
1944
|
+
if (created) {
|
|
1945
|
+
this.emitLocal({
|
|
1946
|
+
...current,
|
|
1947
|
+
created: current.created.map((entry) => entry.rowId === rowId ? { ...entry, draft } : entry),
|
|
1948
|
+
});
|
|
1949
|
+
return;
|
|
1950
|
+
}
|
|
1951
|
+
if (!existing)
|
|
1952
|
+
return;
|
|
1953
|
+
const edited = { ...current.edited };
|
|
1954
|
+
const changed = diffLocalCells(existing, draft.cells);
|
|
1955
|
+
if (Object.keys(changed).length > 0) {
|
|
1956
|
+
edited[rowId] = { ...draft, cells: changed };
|
|
1957
|
+
}
|
|
1958
|
+
else {
|
|
1959
|
+
delete edited[rowId];
|
|
1960
|
+
}
|
|
1961
|
+
this.emitLocal({ ...current, edited });
|
|
1962
|
+
});
|
|
1963
|
+
}
|
|
1964
|
+
/**
|
|
1965
|
+
* Remove a Local row. A loaded row is listed in `deletedRowIds` and its
|
|
1966
|
+
* pending edit dropped — a row is never both deleted and submitted. A row
|
|
1967
|
+
* added in this session just disappears.
|
|
1968
|
+
*/
|
|
1969
|
+
deleteLocalRow(row) {
|
|
1970
|
+
if (this.disabled())
|
|
1971
|
+
return;
|
|
1972
|
+
const rowId = String(row[ROW_ID_KEY] ?? '');
|
|
1973
|
+
const current = this.localState();
|
|
1974
|
+
if (current.created.some((entry) => entry.rowId === rowId)) {
|
|
1975
|
+
this.emitLocal({
|
|
1976
|
+
...current,
|
|
1977
|
+
created: current.created.filter((entry) => entry.rowId !== rowId),
|
|
1978
|
+
});
|
|
1979
|
+
return;
|
|
1980
|
+
}
|
|
1981
|
+
const edited = { ...current.edited };
|
|
1982
|
+
delete edited[rowId];
|
|
1983
|
+
this.emitLocal({
|
|
1984
|
+
...current,
|
|
1985
|
+
edited,
|
|
1986
|
+
deleted: current.deleted.includes(rowId)
|
|
1987
|
+
? current.deleted
|
|
1988
|
+
: [...current.deleted, rowId],
|
|
1989
|
+
});
|
|
1990
|
+
}
|
|
1991
|
+
/**
|
|
1992
|
+
* Apply a drag within the table. Replays PrimeNG's own move on the rows as
|
|
1993
|
+
* rendered: `p-table` is bound to a derived array, so the event's `value`
|
|
1994
|
+
* is not reliably the reordered one.
|
|
1995
|
+
*/
|
|
1996
|
+
onLocalReorder(event) {
|
|
1997
|
+
const from = Number(event?.dragIndex);
|
|
1998
|
+
const to = Number(event?.dropIndex);
|
|
1999
|
+
const ids = this.localTableRows().map((row) => String(row[ROW_ID_KEY]));
|
|
2000
|
+
if (!Number.isInteger(from) ||
|
|
2001
|
+
!Number.isInteger(to) ||
|
|
2002
|
+
from === to ||
|
|
2003
|
+
from < 0 ||
|
|
2004
|
+
to < 0 ||
|
|
2005
|
+
from >= ids.length ||
|
|
2006
|
+
to >= ids.length) {
|
|
2007
|
+
return;
|
|
2008
|
+
}
|
|
2009
|
+
const [moved] = ids.splice(from, 1);
|
|
2010
|
+
ids.splice(to, 0, moved);
|
|
2011
|
+
this.emitLocal({ ...this.localState(), order: ids });
|
|
2012
|
+
}
|
|
2013
|
+
/**
|
|
2014
|
+
* Serialize one dialog result into cells, by field id, for every visible
|
|
2015
|
+
* field. `submit` is the dialog's reduction to stored scalars and wins over
|
|
2016
|
+
* the raw control value, as for linked rows.
|
|
2017
|
+
*/
|
|
2018
|
+
toLocalCells(values, submit) {
|
|
2019
|
+
const cells = {};
|
|
2020
|
+
for (const field of this.localFields()) {
|
|
2021
|
+
const fieldId = field.id;
|
|
2022
|
+
cells[fieldId] = this.toRawValue(fieldId in submit ? submit[fieldId] : values[fieldId]);
|
|
2023
|
+
}
|
|
2024
|
+
return cells;
|
|
2025
|
+
}
|
|
2026
|
+
/**
|
|
2027
|
+
* Publish the Local state as the control's value.
|
|
2028
|
+
*
|
|
2029
|
+
* With changes, the value is a mutation: the loaded list and schema
|
|
2030
|
+
* versions, only the changed rows and cells, explicit deletions, and a
|
|
2031
|
+
* `mutationId` that stays the same while the content does (a retry of the
|
|
2032
|
+
* same save) and changes with it (a new save). Without changes it is the
|
|
2033
|
+
* loaded document again, which `mapFormValueToSubmitFields` leaves out of the
|
|
2034
|
+
* submission — an unchanged Local list is omitted, never re-sent.
|
|
2035
|
+
*/
|
|
2036
|
+
emitLocal(next) {
|
|
2037
|
+
const content = buildLocalMutationContent(next);
|
|
2038
|
+
let state = next;
|
|
2039
|
+
let value = next.base;
|
|
2040
|
+
if (content) {
|
|
2041
|
+
const mutation = {
|
|
2042
|
+
storageMode: 'Local',
|
|
2043
|
+
formatVersion: 1,
|
|
2044
|
+
schemaVersion: next.base?.schemaVersion ??
|
|
2045
|
+
this.metadata()?.localSchema?.version ??
|
|
2046
|
+
'',
|
|
2047
|
+
version: next.base?.version ?? 0,
|
|
2048
|
+
...content,
|
|
2049
|
+
};
|
|
2050
|
+
const mutationKey = JSON.stringify(mutation);
|
|
2051
|
+
const mutationId = next.mutationKey === mutationKey && next.mutationId
|
|
2052
|
+
? next.mutationId
|
|
2053
|
+
: newLocalUuid();
|
|
2054
|
+
state = { ...next, mutationId, mutationKey };
|
|
2055
|
+
value = { ...mutation, mutationId };
|
|
2056
|
+
}
|
|
2057
|
+
else {
|
|
2058
|
+
state = { ...next, mutationId: null, mutationKey: null };
|
|
2059
|
+
}
|
|
2060
|
+
this.localState.set(state);
|
|
2061
|
+
if (value)
|
|
2062
|
+
LOCAL_EDITOR_STATES.set(value, state);
|
|
2063
|
+
this.lastLocalEmit = value;
|
|
2064
|
+
this.onModelChange(value);
|
|
2065
|
+
this.onTouched();
|
|
2066
|
+
}
|
|
2067
|
+
/** A cell the user set in this session, shaped like a backend one. */
|
|
2068
|
+
buildLocalDraftCell(column, draft, configuration) {
|
|
2069
|
+
const fieldId = column.key;
|
|
2070
|
+
const raw = draft.values[fieldId];
|
|
2071
|
+
const label = draft.display[fieldId];
|
|
2072
|
+
// A multi-select holds ids and resolves to labels; print the labels.
|
|
2073
|
+
const value = Array.isArray(raw) && Array.isArray(label)
|
|
2074
|
+
? label.join(', ')
|
|
2075
|
+
: this.toLocalEntityValue(column.viewType, raw, label);
|
|
2076
|
+
return {
|
|
2077
|
+
key: fieldId,
|
|
2078
|
+
name: column.label,
|
|
2079
|
+
viewType: (column.viewType ?? 'Text'),
|
|
2080
|
+
value: (value !== null && typeof value === 'object'
|
|
2081
|
+
? value
|
|
2082
|
+
: (this.toRawValue(value) ?? '')),
|
|
2083
|
+
rawValue: draft.cells[fieldId] ?? undefined,
|
|
2084
|
+
propertyConfiguration: configuration ?? undefined,
|
|
2085
|
+
};
|
|
2086
|
+
}
|
|
2087
|
+
/**
|
|
2088
|
+
* A loaded cell: the backend's rendered `value` beside its `rawValue`. A
|
|
2089
|
+
* stored document from the fetch endpoints has no rendered values, so the
|
|
2090
|
+
* raw one is shaped the way a locally set cell would be — a user id still
|
|
2091
|
+
* renders as a user, though only as its id until the backend renders it.
|
|
2092
|
+
*/
|
|
2093
|
+
buildLocalLoadedCell(column, cell, configuration) {
|
|
2094
|
+
const value = cell?.value != null
|
|
2095
|
+
? cell.value
|
|
2096
|
+
: this.toLocalEntityValue(column.viewType, cell?.rawValue, undefined);
|
|
2097
|
+
return {
|
|
2098
|
+
key: column.key,
|
|
2099
|
+
name: column.label,
|
|
2100
|
+
viewType: (column.viewType ?? 'Text'),
|
|
2101
|
+
value: (value ?? ''),
|
|
2102
|
+
rawValue: serializeEntityRawValue(cell?.rawValue),
|
|
2103
|
+
propertyConfiguration: configuration ?? undefined,
|
|
2104
|
+
};
|
|
2105
|
+
}
|
|
1480
2106
|
/**
|
|
1481
2107
|
* Normalize the add/edit dialog close payload. The rich dialog returns
|
|
1482
2108
|
* `{ values, display }`; a custom add-dialog may still return the raw values
|
|
@@ -1820,6 +2446,11 @@ class EntityListField {
|
|
|
1820
2446
|
*/
|
|
1821
2447
|
applyMetadata(metadata, levelDataId) {
|
|
1822
2448
|
this.metadata.set(metadata);
|
|
2449
|
+
// A Local list's rows are the value; the source module is not read.
|
|
2450
|
+
if (this.localMode()) {
|
|
2451
|
+
this.loading.set(false);
|
|
2452
|
+
return;
|
|
2453
|
+
}
|
|
1823
2454
|
this.columns.set(this.buildColumns(metadata));
|
|
1824
2455
|
if (!this.moduleBacked() ||
|
|
1825
2456
|
!this.canRead() ||
|
|
@@ -1949,14 +2580,24 @@ class EntityListField {
|
|
|
1949
2580
|
}
|
|
1950
2581
|
for (const key of valueKeys) {
|
|
1951
2582
|
const cell = record.values?.[key];
|
|
2583
|
+
const viewType = viewTypeByKey.get(key) ?? properties.get(key)?.viewType ?? '';
|
|
1952
2584
|
// Keep the machine-readable value as the baseline a partial update is
|
|
1953
2585
|
// diffed against — it is the shape the row submits.
|
|
1954
2586
|
values[key] = cell?.raw ?? cell?.value ?? null;
|
|
1955
2587
|
// What the edit dialog patches into its form, which is not always the
|
|
1956
2588
|
// same thing: see OBJECT_VALUED_VIEW_TYPES.
|
|
1957
|
-
|
|
1958
|
-
|
|
1959
|
-
|
|
2589
|
+
if (OBJECT_VALUED_VIEW_TYPES.has(viewType)) {
|
|
2590
|
+
prefill[key] = cell?.value ?? cell?.raw ?? null;
|
|
2591
|
+
}
|
|
2592
|
+
else if (viewType === 'Checkbox') {
|
|
2593
|
+
// Stored as text (`'True'`/`'False'`), while `mt-toggle-field`
|
|
2594
|
+
// only shows a switch on as a strict `true` — see
|
|
2595
|
+
// `coerceCheckboxValue`.
|
|
2596
|
+
prefill[key] = coerceCheckboxValue(values[key]);
|
|
2597
|
+
}
|
|
2598
|
+
else {
|
|
2599
|
+
prefill[key] = values[key];
|
|
2600
|
+
}
|
|
1960
2601
|
}
|
|
1961
2602
|
row[ROW_VALUES_KEY] = values;
|
|
1962
2603
|
row[ROW_PREFILL_KEY] = prefill;
|
|
@@ -1982,7 +2623,7 @@ class EntityListField {
|
|
|
1982
2623
|
};
|
|
1983
2624
|
}
|
|
1984
2625
|
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.8", ngImport: i0, type: EntityListField, deps: [], target: i0.ɵɵFactoryTarget.Component });
|
|
1985
|
-
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 },
|
|
2626
|
+
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 }, initialValue: { classPropertyName: "initialValue", publicName: "initialValue", isSignal: true, isRequired: false, transformFunction: null } }, host: { classAttribute: "grid gap-1" }, providers: [EntityRuntimeContextStore], 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 (localReady()) {\n <!--\n A Local list: rows owned by this record, staged into its own submission.\n Add / edit / delete / drag follow the Local operation switches.\n -->\n @if (localCanCreate()) {\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)=\"openLocalRowDialog()\"\n />\n </div>\n }\n @if (localTableRows().length || localCanCreate()) {\n <mt-table\n [noCard]=\"true\"\n [data]=\"localTableRows()\"\n [columns]=\"localColumns()\"\n [rowActions]=\"localRowActions()\"\n [reorderableRows]=\"localCanReorder()\"\n (rowReorder)=\"onLocalReorder($event)\"\n dataKey=\"Id\"\n />\n } @else {\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.noLocalRows\" | transloco }}\n </div>\n }\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]=\"tableColumns()\"\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]=\"tableColumns()\"\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 });
|
|
1986
2627
|
}
|
|
1987
2628
|
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.8", ngImport: i0, type: EntityListField, decorators: [{
|
|
1988
2629
|
type: Component,
|
|
@@ -1994,26 +2635,30 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.8", ngImpor
|
|
|
1994
2635
|
Table,
|
|
1995
2636
|
Button,
|
|
1996
2637
|
TranslocoPipe,
|
|
1997
|
-
], 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]=\"tableColumns()\"\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]=\"tableColumns()\"\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"] }]
|
|
1998
|
-
}], 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 }] }],
|
|
2638
|
+
], changeDetection: ChangeDetectionStrategy.OnPush, host: { class: 'grid gap-1' }, providers: [EntityRuntimeContextStore], 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 (localReady()) {\n <!--\n A Local list: rows owned by this record, staged into its own submission.\n Add / edit / delete / drag follow the Local operation switches.\n -->\n @if (localCanCreate()) {\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)=\"openLocalRowDialog()\"\n />\n </div>\n }\n @if (localTableRows().length || localCanCreate()) {\n <mt-table\n [noCard]=\"true\"\n [data]=\"localTableRows()\"\n [columns]=\"localColumns()\"\n [rowActions]=\"localRowActions()\"\n [reorderableRows]=\"localCanReorder()\"\n (rowReorder)=\"onLocalReorder($event)\"\n dataKey=\"Id\"\n />\n } @else {\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.noLocalRows\" | transloco }}\n </div>\n }\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]=\"tableColumns()\"\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]=\"tableColumns()\"\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"] }]
|
|
2639
|
+
}], 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 }] }], initialValue: [{ type: i0.Input, args: [{ isSignal: true, alias: "initialValue", required: false }] }] } });
|
|
1999
2640
|
|
|
2000
2641
|
/**
|
|
2001
|
-
* Lets
|
|
2002
|
-
*
|
|
2642
|
+
* Lets `mt-entity-list-preview` render a module-backed `EntityList` as the
|
|
2643
|
+
* real, fetched table instead of its count-and-drawer trigger.
|
|
2003
2644
|
*
|
|
2004
|
-
*
|
|
2005
|
-
*
|
|
2006
|
-
*
|
|
2007
|
-
*
|
|
2645
|
+
* Pair it with an `EntityRuntimeContextStore` carrying the owning level and
|
|
2646
|
+
* level-data ids — the preview needs both, and without the context this
|
|
2647
|
+
* provider changes nothing. `mt-client-instance-preview` sets both up, so a
|
|
2648
|
+
* host rendering preview cards through it needs neither.
|
|
2008
2649
|
*
|
|
2009
|
-
* The
|
|
2010
|
-
*
|
|
2650
|
+
* The indirection exists because `entities` cannot import `table`: `table`
|
|
2651
|
+
* already imports `entities`, and they are separate entry points of
|
|
2652
|
+
* `@masterteam/components`. See `ENTITY_LIST_TABLE_COMPONENT`.
|
|
2653
|
+
*
|
|
2654
|
+
* ```ts
|
|
2655
|
+
* @Component({
|
|
2656
|
+
* providers: [EntityRuntimeContextStore, provideEntityListTablePreview()],
|
|
2657
|
+
* })
|
|
2658
|
+
* ```
|
|
2011
2659
|
*/
|
|
2012
|
-
function
|
|
2013
|
-
return {
|
|
2014
|
-
provide: ENTITY_LIST_TABLE_COMPONENT,
|
|
2015
|
-
useValue: EntityListField,
|
|
2016
|
-
};
|
|
2660
|
+
function provideEntityListTablePreview() {
|
|
2661
|
+
return { provide: ENTITY_LIST_TABLE_COMPONENT, useValue: EntityListField };
|
|
2017
2662
|
}
|
|
2018
2663
|
|
|
2019
2664
|
/** Page size when loading the full deliverable list, and a hard safety cap. */
|
|
@@ -2443,5 +3088,5 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.8", ngImpor
|
|
|
2443
3088
|
* Generated bundle index. Do not edit.
|
|
2444
3089
|
*/
|
|
2445
3090
|
|
|
2446
|
-
export { ENTITY_LIST_ADD_DIALOG_COMPONENT, EntityListField, LOOKUP_CHECK_LIST_FORM_COMPONENT, LookupMatrixField, LookupModuleCheckListField, ScheduleItemSelectorField, SchedulePredecessorField, SchemaConnectionField,
|
|
3091
|
+
export { ENTITY_LIST_ADD_DIALOG_COMPONENT, ENTITY_LIST_LOCAL_ROW_DIALOG_COMPONENT, EntityListField, LOOKUP_CHECK_LIST_FORM_COMPONENT, LookupMatrixField, LookupModuleCheckListField, ScheduleItemSelectorField, SchedulePredecessorField, SchemaConnectionField, provideEntityListTablePreview };
|
|
2447
3092
|
//# sourceMappingURL=masterteam-components-business-fields.mjs.map
|