@masterteam/components 0.0.189 → 0.0.191

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.
@@ -6,13 +6,13 @@ import * as i1 from '@angular/forms';
6
6
  import { ControlContainer, Validators, NgControl, FormsModule } from '@angular/forms';
7
7
  import * as i2 from '@jsverse/transloco';
8
8
  import { TranslocoService, TranslocoPipe, TranslocoModule } from '@jsverse/transloco';
9
- import { startWith, finalize, catchError, of, take } from 'rxjs';
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';
13
13
  import { MultiSelectField } from '@masterteam/components/multi-select-field';
14
14
  import { FieldValidation } from '@masterteam/components/field-validation';
15
- import { HttpClient } from '@angular/common/http';
15
+ 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';
@@ -1008,9 +1008,184 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.8", ngImpor
1008
1008
  ], changeDetection: ChangeDetectionStrategy.OnPush, host: { class: 'grid gap-1' }, template: "<div class=\"flex flex-col gap-2\">\r\n @if (label()) {\r\n <label class=\"font-medium text-color\">\r\n {{ label() }}\r\n @if (required()) {\r\n <span class=\"text-red-500\">*</span>\r\n }\r\n </label>\r\n }\r\n\r\n @if (errorMessage(); as err) {\r\n <p-message severity=\"error\" [text]=\"err\" styleClass=\"w-full\" />\r\n } @else if (canWrite()) {\r\n <div class=\"flex justify-end\">\r\n <mt-button\r\n [label]=\"'components.entityListField.add' | transloco\"\r\n icon=\"general.plus\"\r\n size=\"small\"\r\n [disabled]=\"disabled()\"\r\n (onClick)=\"openAddDialog()\"\r\n />\r\n </div>\r\n <mt-table\r\n [noCard]=\"true\"\r\n [data]=\"displayRows()\"\r\n [columns]=\"columns()\"\r\n [rowActions]=\"writeRowActions()\"\r\n dataKey=\"Id\"\r\n [loading]=\"loading()\"\r\n />\r\n } @else if (!canRead()) {\r\n <div\r\n class=\"rounded border border-dashed border-surface-300 bg-surface-50 p-3 text-sm text-muted-color\"\r\n >\r\n {{ \"components.entityListField.readingNotAllowed\" | transloco }}\r\n </div>\r\n } @else if (!hasRequiredContext()) {\r\n <div\r\n class=\"rounded border border-dashed border-surface-300 bg-surface-50 p-3 text-sm text-muted-color\"\r\n >\r\n {{ \"components.entityListField.saveFormFirst\" | transloco }}\r\n </div>\r\n } @else if (loading() && !hasRows()) {\r\n <div class=\"flex flex-col gap-2\">\r\n <p-skeleton width=\"100%\" height=\"3rem\" />\r\n <p-skeleton width=\"100%\" height=\"3rem\" />\r\n </div>\r\n } @else if (!hasRows()) {\r\n <div\r\n class=\"rounded border border-dashed border-surface-300 bg-surface-50 p-3 text-sm text-muted-color\"\r\n >\r\n {{ \"components.entityListField.noRelatedItems\" | transloco }}\r\n </div>\r\n } @else {\r\n <mt-table\r\n [noCard]=\"true\"\r\n [data]=\"rows()\"\r\n [columns]=\"columns()\"\r\n dataKey=\"Id\"\r\n [loading]=\"loading()\"\r\n />\r\n }\r\n\r\n @if (ngControl?.control) {\r\n <mt-field-validation\r\n [control]=\"ngControl?.control!\"\r\n [touched]=\"ngControl?.touched ?? false\"\r\n />\r\n }\r\n</div>\r\n", styles: [":host{display:block}\n"] }]
1009
1009
  }], 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 }] }], context: [{ type: i0.Input, args: [{ isSignal: true, alias: "context", required: false }] }] } });
1010
1010
 
1011
+ /** Page size when loading the full deliverable list, and a hard safety cap. */
1012
+ const PAGE_SIZE = 100;
1013
+ const MAX_ITEMS = 5000;
1014
+ /**
1015
+ * Runtime picker for `ScheduleItemSelector` properties.
1016
+ *
1017
+ * Backend-filtered: the full option list comes from
1018
+ * `GET forms/options/{propertyKey}` (which applies the configured rule, e.g.
1019
+ * `DeliverableAcceptance.AvailableDeliverables`). All available items are
1020
+ * loaded up front and rendered with the standard `mt-select-field` /
1021
+ * `mt-multi-select-field`; the field shows only the item name.
1022
+ *
1023
+ * The control value is always a numeric id array (`valueMode = "IdArray"`).
1024
+ * In `Single` mode only one id may be selected.
1025
+ */
1026
+ class ScheduleItemSelectorField {
1027
+ label = input('', ...(ngDevMode ? [{ debugName: "label" }] : /* istanbul ignore next */ []));
1028
+ placeholder = input('', ...(ngDevMode ? [{ debugName: "placeholder" }] : /* istanbul ignore next */ []));
1029
+ readonly = input(false, ...(ngDevMode ? [{ debugName: "readonly" }] : /* istanbul ignore next */ []));
1030
+ required = input(false, ...(ngDevMode ? [{ debugName: "required" }] : /* istanbul ignore next */ []));
1031
+ propertyKey = input('', ...(ngDevMode ? [{ debugName: "propertyKey" }] : /* istanbul ignore next */ []));
1032
+ selectionMode = input('Multi', ...(ngDevMode ? [{ debugName: "selectionMode" }] : /* istanbul ignore next */ []));
1033
+ runtimeContext = input(null, ...(ngDevMode ? [{ debugName: "runtimeContext" }] : /* istanbul ignore next */ []));
1034
+ context = input(undefined, ...(ngDevMode ? [{ debugName: "context" }] : /* istanbul ignore next */ []));
1035
+ /** Full list of available deliverables (loaded once). */
1036
+ options = signal([], ...(ngDevMode ? [{ debugName: "options" }] : /* istanbul ignore next */ []));
1037
+ loading = signal(false, ...(ngDevMode ? [{ debugName: "loading" }] : /* istanbul ignore next */ []));
1038
+ disabled = signal(false, ...(ngDevMode ? [{ debugName: "disabled" }] : /* istanbul ignore next */ []));
1039
+ /** Selected ids — the control value (`number[]`). */
1040
+ value = signal([], ...(ngDevMode ? [{ debugName: "value" }] : /* istanbul ignore next */ []));
1041
+ isMultiple = computed(() => this.selectionMode() !== 'Single', ...(ngDevMode ? [{ debugName: "isMultiple" }] : /* istanbul ignore next */ []));
1042
+ /** Single-mode ngModel value (a scalar id, not an array). */
1043
+ singleValue = computed(() => this.value()[0] ?? null, ...(ngDevMode ? [{ debugName: "singleValue" }] : /* istanbul ignore next */ []));
1044
+ ngControl = null;
1045
+ onTouched = () => { };
1046
+ onModelChange = () => { };
1047
+ http = inject(HttpClient);
1048
+ destroyRef = inject(DestroyRef);
1049
+ /** Query signature already loaded — prevents duplicate full loads. */
1050
+ loadedKey = null;
1051
+ constructor() {
1052
+ this.ngControl = inject(NgControl, { self: true, optional: true });
1053
+ if (this.ngControl) {
1054
+ this.ngControl.valueAccessor = this;
1055
+ }
1056
+ effect(() => {
1057
+ if (this.ngControl?.control && this.required()) {
1058
+ this.ngControl.control.addValidators(Validators.required);
1059
+ this.ngControl.control.updateValueAndValidity();
1060
+ }
1061
+ });
1062
+ // Load the full option list as soon as the query context is available.
1063
+ effect(() => {
1064
+ const key = this.queryKey();
1065
+ if (!key || this.loadedKey === key)
1066
+ return;
1067
+ untracked(() => this.loadAllOptions(key));
1068
+ });
1069
+ }
1070
+ // ── Selection ──────────────────────────────────────────────────────────
1071
+ onMultiChange(ids) {
1072
+ this.value.set(ids ?? []);
1073
+ this.emit();
1074
+ }
1075
+ onSingleChange(id) {
1076
+ this.value.set(id == null ? [] : [id]);
1077
+ this.emit();
1078
+ }
1079
+ // ── ControlValueAccessor ────────────────────────────────────────────────
1080
+ writeValue(value) {
1081
+ this.value.set(this.normalizeIds(value));
1082
+ }
1083
+ registerOnChange(fn) {
1084
+ this.onModelChange = fn;
1085
+ }
1086
+ registerOnTouched(fn) {
1087
+ this.onTouched = fn;
1088
+ }
1089
+ setDisabledState(disabled) {
1090
+ this.disabled.set(disabled);
1091
+ }
1092
+ // ── Option loading ──────────────────────────────────────────────────────
1093
+ loadAllOptions(key) {
1094
+ this.loadedKey = key;
1095
+ this.loading.set(true);
1096
+ this.fetchPage(0)
1097
+ .pipe(expand((page) => page.hasMore && page.nextSkip < MAX_ITEMS
1098
+ ? this.fetchPage(page.nextSkip)
1099
+ : EMPTY), reduce((acc, page) => acc.concat(page.options), []), takeUntilDestroyed(this.destroyRef), finalize(() => this.loading.set(false)), catchError(() => of([])))
1100
+ .subscribe((options) => this.options.set(options));
1101
+ }
1102
+ fetchPage(skip) {
1103
+ const params = this.buildParams(skip);
1104
+ if (!params) {
1105
+ return of({ options: [], hasMore: false, nextSkip: skip });
1106
+ }
1107
+ return this.http
1108
+ .get(`forms/options/${encodeURIComponent(this.propertyKey())}`, { params, context: this.context() })
1109
+ .pipe(map((response) => ({
1110
+ options: this.mapOptions(response),
1111
+ hasMore: !!response?.data?.hasMore,
1112
+ nextSkip: skip + PAGE_SIZE,
1113
+ })));
1114
+ }
1115
+ buildParams(skip) {
1116
+ const contextKey = this.buildContextKey();
1117
+ const levelDataId = this.runtimeContext()?.levelDataId;
1118
+ if (!contextKey || levelDataId == null)
1119
+ return null;
1120
+ let params = new HttpParams()
1121
+ .set('contextKey', contextKey)
1122
+ .set('levelDataId', String(levelDataId))
1123
+ .set('skip', String(skip))
1124
+ .set('take', String(PAGE_SIZE));
1125
+ const ownerRecordId = this.runtimeContext()?.ownerRecordId;
1126
+ if (ownerRecordId != null) {
1127
+ params = params.set('ownerRecordId', String(ownerRecordId));
1128
+ }
1129
+ return params;
1130
+ }
1131
+ mapOptions(response) {
1132
+ const items = response?.data?.items ?? [];
1133
+ return items
1134
+ .map((item) => {
1135
+ const id = Number(item.key);
1136
+ if (!Number.isFinite(id))
1137
+ return null;
1138
+ return { label: item.name || String(id), value: id };
1139
+ })
1140
+ .filter((option) => option != null);
1141
+ }
1142
+ // ── Context helpers ─────────────────────────────────────────────────────
1143
+ buildContextKey() {
1144
+ const levelId = this.runtimeContext()?.levelId;
1145
+ const moduleId = this.runtimeContext()?.moduleId;
1146
+ if (levelId == null || moduleId == null)
1147
+ return null;
1148
+ return `Level:${levelId}/Module:${moduleId}`;
1149
+ }
1150
+ queryKey() {
1151
+ const contextKey = this.buildContextKey();
1152
+ const levelDataId = this.runtimeContext()?.levelDataId;
1153
+ const propertyKey = this.propertyKey();
1154
+ if (!contextKey || levelDataId == null || !propertyKey)
1155
+ return null;
1156
+ const ownerRecordId = this.runtimeContext()?.ownerRecordId ?? '';
1157
+ return `${contextKey}|${levelDataId}|${ownerRecordId}|${propertyKey}`;
1158
+ }
1159
+ emit() {
1160
+ this.onModelChange(this.value());
1161
+ this.onTouched();
1162
+ }
1163
+ normalizeIds(value) {
1164
+ const raw = Array.isArray(value) ? value : value == null ? [] : [value];
1165
+ const ids = [];
1166
+ for (const entry of raw) {
1167
+ const id = entry && typeof entry === 'object'
1168
+ ? Number(entry.id)
1169
+ : Number(entry);
1170
+ if (Number.isFinite(id) && id > 0 && !ids.includes(id)) {
1171
+ ids.push(id);
1172
+ }
1173
+ }
1174
+ return ids;
1175
+ }
1176
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.8", ngImport: i0, type: ScheduleItemSelectorField, deps: [], target: i0.ɵɵFactoryTarget.Component });
1177
+ static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "21.2.8", type: ScheduleItemSelectorField, isStandalone: true, selector: "mt-schedule-item-selector-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 }, propertyKey: { classPropertyName: "propertyKey", publicName: "propertyKey", isSignal: true, isRequired: false, transformFunction: null }, selectionMode: { classPropertyName: "selectionMode", publicName: "selectionMode", isSignal: true, isRequired: false, 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: "block" }, ngImport: i0, template: "@if (isMultiple()) {\r\n <mt-multi-select-field\r\n [label]=\"label()\"\r\n [placeholder]=\"placeholder()\"\r\n [options]=\"options()\"\r\n [optionLabel]=\"'label'\"\r\n [optionValue]=\"'value'\"\r\n [filter]=\"options().length > 10\"\r\n [showClear]=\"!required()\"\r\n [required]=\"required()\"\r\n [readonly]=\"readonly() || disabled()\"\r\n [ngModel]=\"value()\"\r\n [ngModelOptions]=\"{ standalone: true }\"\r\n (ngModelChange)=\"onMultiChange($event)\"\r\n />\r\n} @else {\r\n <mt-select-field\r\n [label]=\"label()\"\r\n [placeholder]=\"placeholder()\"\r\n [options]=\"options()\"\r\n [optionLabel]=\"'label'\"\r\n [optionValue]=\"'value'\"\r\n [filter]=\"options().length > 10\"\r\n [showClear]=\"!required()\"\r\n [loading]=\"loading()\"\r\n [required]=\"required()\"\r\n [readonly]=\"readonly() || disabled()\"\r\n [ngModel]=\"singleValue()\"\r\n [ngModelOptions]=\"{ standalone: true }\"\r\n (ngModelChange)=\"onSingleChange($event)\"\r\n />\r\n}\r\n", dependencies: [{ kind: "ngmodule", type: FormsModule }, { kind: "directive", type: i1.NgControlStatus, selector: "[formControlName],[ngModel],[formControl]" }, { kind: "directive", type: i1.RequiredValidator, selector: ":not([type=checkbox])[required][formControlName],:not([type=checkbox])[required][formControl],:not([type=checkbox])[required][ngModel]", inputs: ["required"] }, { kind: "directive", type: i1.NgModel, selector: "[ngModel]:not([formControlName]):not([formControl])", inputs: ["name", "disabled", "ngModel", "ngModelOptions"], outputs: ["ngModelChange"], exportAs: ["ngModel"] }, { 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", "optionGroupLabel", "optionGroupChildren", "optionIcon", "optionIconColor", "optionIconShape", "optionAvatarShape", "optionGroupIcon", "optionGroupIconColor", "optionGroupIconShape", "optionGroupAvatarShape"], outputs: ["onChange"] }, { 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"] }], changeDetection: i0.ChangeDetectionStrategy.OnPush });
1178
+ }
1179
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.8", ngImport: i0, type: ScheduleItemSelectorField, decorators: [{
1180
+ type: Component,
1181
+ args: [{ selector: 'mt-schedule-item-selector-field', standalone: true, imports: [FormsModule, MultiSelectField, SelectField], changeDetection: ChangeDetectionStrategy.OnPush, host: {
1182
+ class: 'block',
1183
+ }, template: "@if (isMultiple()) {\r\n <mt-multi-select-field\r\n [label]=\"label()\"\r\n [placeholder]=\"placeholder()\"\r\n [options]=\"options()\"\r\n [optionLabel]=\"'label'\"\r\n [optionValue]=\"'value'\"\r\n [filter]=\"options().length > 10\"\r\n [showClear]=\"!required()\"\r\n [required]=\"required()\"\r\n [readonly]=\"readonly() || disabled()\"\r\n [ngModel]=\"value()\"\r\n [ngModelOptions]=\"{ standalone: true }\"\r\n (ngModelChange)=\"onMultiChange($event)\"\r\n />\r\n} @else {\r\n <mt-select-field\r\n [label]=\"label()\"\r\n [placeholder]=\"placeholder()\"\r\n [options]=\"options()\"\r\n [optionLabel]=\"'label'\"\r\n [optionValue]=\"'value'\"\r\n [filter]=\"options().length > 10\"\r\n [showClear]=\"!required()\"\r\n [loading]=\"loading()\"\r\n [required]=\"required()\"\r\n [readonly]=\"readonly() || disabled()\"\r\n [ngModel]=\"singleValue()\"\r\n [ngModelOptions]=\"{ standalone: true }\"\r\n (ngModelChange)=\"onSingleChange($event)\"\r\n />\r\n}\r\n" }]
1184
+ }], 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 }] }], propertyKey: [{ type: i0.Input, args: [{ isSignal: true, alias: "propertyKey", required: false }] }], selectionMode: [{ type: i0.Input, args: [{ isSignal: true, alias: "selectionMode", required: false }] }], runtimeContext: [{ type: i0.Input, args: [{ isSignal: true, alias: "runtimeContext", required: false }] }], context: [{ type: i0.Input, args: [{ isSignal: true, alias: "context", required: false }] }] } });
1185
+
1011
1186
  /**
1012
1187
  * Generated bundle index. Do not edit.
1013
1188
  */
1014
1189
 
1015
- export { ENTITY_LIST_ADD_DIALOG_COMPONENT, EntityListField, LookupMatrixField, SchedulePredecessorField, SchemaConnectionField };
1190
+ export { ENTITY_LIST_ADD_DIALOG_COMPONENT, EntityListField, LookupMatrixField, ScheduleItemSelectorField, SchedulePredecessorField, SchemaConnectionField };
1016
1191
  //# sourceMappingURL=masterteam-components-business-fields.mjs.map