@masterteam/forms 0.0.35 → 0.0.36
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/forms.css +2 -2
- package/fesm2022/masterteam-forms-client-form.mjs +598 -0
- package/fesm2022/masterteam-forms-client-form.mjs.map +1 -0
- package/fesm2022/masterteam-forms-dynamic-field.mjs +1 -1
- package/fesm2022/masterteam-forms-dynamic-field.mjs.map +1 -1
- package/package.json +6 -2
- package/types/masterteam-forms-client-form.d.ts +337 -0
|
@@ -0,0 +1,337 @@
|
|
|
1
|
+
import * as _angular_core from '@angular/core';
|
|
2
|
+
import { OnDestroy } from '@angular/core';
|
|
3
|
+
import { FormControl } from '@angular/forms';
|
|
4
|
+
import { DynamicFormConfig } from '@masterteam/components';
|
|
5
|
+
import * as _masterteam_forms_client_form from '@masterteam/forms/client-form';
|
|
6
|
+
import { Observable } from 'rxjs';
|
|
7
|
+
|
|
8
|
+
interface Response<T> {
|
|
9
|
+
endpoint: string;
|
|
10
|
+
status: number;
|
|
11
|
+
code: number;
|
|
12
|
+
locale: string;
|
|
13
|
+
message?: string | null;
|
|
14
|
+
errors?: any | null;
|
|
15
|
+
data: T;
|
|
16
|
+
cacheSession?: string;
|
|
17
|
+
}
|
|
18
|
+
type ProcessFormMode = 'Approval' | 'Direct';
|
|
19
|
+
type ProcessFormSubmitStatus = 'PendingApproval' | 'Executed';
|
|
20
|
+
type OperationType = 'FormOperation' | 'ActionOperation';
|
|
21
|
+
type ProcessFormSource = 'Step' | 'ModuleFallback' | 'LevelFallback' | 'None';
|
|
22
|
+
interface ProcessFormLoadRequest {
|
|
23
|
+
moduleKey: string;
|
|
24
|
+
operationKey: string;
|
|
25
|
+
moduleId?: number;
|
|
26
|
+
levelId?: number;
|
|
27
|
+
levelDataId?: number;
|
|
28
|
+
moduleDataId?: number;
|
|
29
|
+
requestSchemaId?: number;
|
|
30
|
+
draftProcessId?: number;
|
|
31
|
+
preview?: boolean;
|
|
32
|
+
}
|
|
33
|
+
interface ProcessFormLoadResponse {
|
|
34
|
+
mode: ProcessFormMode;
|
|
35
|
+
formSource: ProcessFormSource;
|
|
36
|
+
requiresForm: boolean;
|
|
37
|
+
requestSchemaId: number | null;
|
|
38
|
+
requestId: number | null;
|
|
39
|
+
stepId: number | null;
|
|
40
|
+
stepSchemaId: number | null;
|
|
41
|
+
stepName: string | null;
|
|
42
|
+
formConfiguration: ClientFormConfiguration | null;
|
|
43
|
+
values: ProcessFormValue[];
|
|
44
|
+
context: ProcessFormContext;
|
|
45
|
+
}
|
|
46
|
+
interface ProcessFormSubmitRequest {
|
|
47
|
+
moduleKey: string;
|
|
48
|
+
operationKey: string;
|
|
49
|
+
moduleId?: number;
|
|
50
|
+
levelId?: number;
|
|
51
|
+
levelDataId?: number;
|
|
52
|
+
moduleDataId?: number;
|
|
53
|
+
requestSchemaId?: number;
|
|
54
|
+
draftProcessId?: number;
|
|
55
|
+
returnUrl?: string;
|
|
56
|
+
values: ProcessFormSubmitValue[];
|
|
57
|
+
}
|
|
58
|
+
interface ProcessFormSubmitValue {
|
|
59
|
+
requestPropertyId?: number;
|
|
60
|
+
propertyKey: string;
|
|
61
|
+
value: any;
|
|
62
|
+
}
|
|
63
|
+
interface ProcessFormSubmitResponse {
|
|
64
|
+
status: ProcessFormSubmitStatus;
|
|
65
|
+
requestSchemaId: number | null;
|
|
66
|
+
requestId: number | null;
|
|
67
|
+
createdEntityId: number | null;
|
|
68
|
+
message: string | null;
|
|
69
|
+
}
|
|
70
|
+
interface ProcessFormValue {
|
|
71
|
+
propertyKey: string;
|
|
72
|
+
value: any;
|
|
73
|
+
metadata?: ProcessFormValueMetadata;
|
|
74
|
+
}
|
|
75
|
+
interface ProcessFormValueMetadata {
|
|
76
|
+
propertyId: number;
|
|
77
|
+
key: string;
|
|
78
|
+
viewType: string;
|
|
79
|
+
source: string;
|
|
80
|
+
}
|
|
81
|
+
interface ProcessFormContext {
|
|
82
|
+
moduleKey: string;
|
|
83
|
+
operationKey: string;
|
|
84
|
+
moduleId: number | null;
|
|
85
|
+
levelId: number | null;
|
|
86
|
+
levelDataId: number | null;
|
|
87
|
+
moduleDataId: number | null;
|
|
88
|
+
requestSchemaId: number | null;
|
|
89
|
+
requestId: number | null;
|
|
90
|
+
stepId: number | null;
|
|
91
|
+
stepSchemaId: number | null;
|
|
92
|
+
preview: boolean;
|
|
93
|
+
}
|
|
94
|
+
type ClientFieldWidth = '25' | '50' | '100';
|
|
95
|
+
interface ClientFormConfiguration {
|
|
96
|
+
isActive: boolean;
|
|
97
|
+
sections: ClientFormSection[];
|
|
98
|
+
validations?: ClientValidationRule[];
|
|
99
|
+
}
|
|
100
|
+
interface ClientFormSection {
|
|
101
|
+
id: string;
|
|
102
|
+
name: {
|
|
103
|
+
en: string;
|
|
104
|
+
ar: string;
|
|
105
|
+
};
|
|
106
|
+
order: number;
|
|
107
|
+
fields: ClientFormField[];
|
|
108
|
+
}
|
|
109
|
+
interface ClientFormField {
|
|
110
|
+
id: string;
|
|
111
|
+
sectionId: string;
|
|
112
|
+
propertyKey: string;
|
|
113
|
+
property?: ClientPropertyItem;
|
|
114
|
+
width: ClientFieldWidth;
|
|
115
|
+
order: number;
|
|
116
|
+
hiddenInCreation?: boolean;
|
|
117
|
+
hiddenInEditForm?: boolean;
|
|
118
|
+
isRequired?: boolean;
|
|
119
|
+
isRead?: boolean;
|
|
120
|
+
isWrite?: boolean;
|
|
121
|
+
showConditionalDisplayFormula?: boolean;
|
|
122
|
+
conditionalDisplayFormula?: string;
|
|
123
|
+
}
|
|
124
|
+
interface ClientPropertyItem {
|
|
125
|
+
key: string;
|
|
126
|
+
propertyId?: number;
|
|
127
|
+
name: string | Record<string, string>;
|
|
128
|
+
viewType?: string;
|
|
129
|
+
configuration?: Record<string, unknown>;
|
|
130
|
+
[key: string]: any;
|
|
131
|
+
}
|
|
132
|
+
interface ClientValidationRule {
|
|
133
|
+
id: string | number;
|
|
134
|
+
formulaTokens: string;
|
|
135
|
+
formulaText: string;
|
|
136
|
+
message: {
|
|
137
|
+
en: string;
|
|
138
|
+
ar: string;
|
|
139
|
+
};
|
|
140
|
+
severity: 'error' | 'warning';
|
|
141
|
+
enabled: boolean;
|
|
142
|
+
}
|
|
143
|
+
interface FormRequiredInterception {
|
|
144
|
+
requestSchemaId: number;
|
|
145
|
+
operationType: OperationType;
|
|
146
|
+
status: 'FormRequired';
|
|
147
|
+
message: string;
|
|
148
|
+
levelId: number;
|
|
149
|
+
levelDataId: number;
|
|
150
|
+
moduleDataId: number;
|
|
151
|
+
}
|
|
152
|
+
/**
|
|
153
|
+
* Type guard to detect a FormRequired interception response from legacy commands.
|
|
154
|
+
* Use in HTTP interceptors to redirect to process-forms flow.
|
|
155
|
+
*/
|
|
156
|
+
declare function isFormRequiredInterception(response: any): response is FormRequiredInterception;
|
|
157
|
+
|
|
158
|
+
/**
|
|
159
|
+
* Per-instance signal-based state for ClientForm.
|
|
160
|
+
*
|
|
161
|
+
* NOT providedIn root — each ClientForm component provides its own instance
|
|
162
|
+
* via `providers: [ClientFormStateService]`, enabling multiple independent
|
|
163
|
+
* forms on the same page.
|
|
164
|
+
*/
|
|
165
|
+
declare class ClientFormStateService {
|
|
166
|
+
readonly loading: _angular_core.WritableSignal<boolean>;
|
|
167
|
+
readonly submitting: _angular_core.WritableSignal<boolean>;
|
|
168
|
+
readonly error: _angular_core.WritableSignal<string | null>;
|
|
169
|
+
readonly submitError: _angular_core.WritableSignal<string | null>;
|
|
170
|
+
readonly loadResponse: _angular_core.WritableSignal<ProcessFormLoadResponse | null>;
|
|
171
|
+
readonly submitResponse: _angular_core.WritableSignal<ProcessFormSubmitResponse | null>;
|
|
172
|
+
readonly isLoaded: _angular_core.Signal<boolean>;
|
|
173
|
+
readonly mode: _angular_core.Signal<ProcessFormMode | null>;
|
|
174
|
+
readonly isApproval: _angular_core.Signal<boolean>;
|
|
175
|
+
readonly isDirect: _angular_core.Signal<boolean>;
|
|
176
|
+
readonly formSource: _angular_core.Signal<ProcessFormSource | null>;
|
|
177
|
+
readonly isFallbackForm: _angular_core.Signal<boolean>;
|
|
178
|
+
readonly requiresForm: _angular_core.Signal<boolean>;
|
|
179
|
+
readonly formConfiguration: _angular_core.Signal<ClientFormConfiguration | null>;
|
|
180
|
+
readonly values: _angular_core.Signal<ProcessFormValue[]>;
|
|
181
|
+
readonly context: _angular_core.Signal<ProcessFormContext | null>;
|
|
182
|
+
readonly stepName: _angular_core.Signal<string | null>;
|
|
183
|
+
readonly requestSchemaId: _angular_core.Signal<number | null>;
|
|
184
|
+
readonly requestId: _angular_core.Signal<number | null>;
|
|
185
|
+
readonly stepId: _angular_core.Signal<number | null>;
|
|
186
|
+
readonly stepSchemaId: _angular_core.Signal<number | null>;
|
|
187
|
+
/** Process virtual fields (Request_Date, Step_Name, etc.) — read-only display */
|
|
188
|
+
readonly virtualFields: _angular_core.Signal<ProcessFormValue[]>;
|
|
189
|
+
/** Editable form values (non-virtual) */
|
|
190
|
+
readonly formValues: _angular_core.Signal<ProcessFormValue[]>;
|
|
191
|
+
readonly isSubmitted: _angular_core.Signal<boolean>;
|
|
192
|
+
readonly submitStatus: _angular_core.Signal<_masterteam_forms_client_form.ProcessFormSubmitStatus | null>;
|
|
193
|
+
readonly isPendingApproval: _angular_core.Signal<boolean>;
|
|
194
|
+
readonly isExecuted: _angular_core.Signal<boolean>;
|
|
195
|
+
readonly createdEntityId: _angular_core.Signal<number | null>;
|
|
196
|
+
setLoadResponse(response: ProcessFormLoadResponse): void;
|
|
197
|
+
setSubmitResponse(response: ProcessFormSubmitResponse): void;
|
|
198
|
+
setError(message: string): void;
|
|
199
|
+
setSubmitError(message: string): void;
|
|
200
|
+
reset(): void;
|
|
201
|
+
static ɵfac: _angular_core.ɵɵFactoryDeclaration<ClientFormStateService, never>;
|
|
202
|
+
static ɵprov: _angular_core.ɵɵInjectableDeclaration<ClientFormStateService>;
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
/**
|
|
206
|
+
* Client Form — Runtime process form component.
|
|
207
|
+
*
|
|
208
|
+
* Self-contained, signal-based (no NGXS). Each instance manages its own state
|
|
209
|
+
* via a component-scoped `ClientFormStateService`.
|
|
210
|
+
*
|
|
211
|
+
* **No action buttons in template.** Parent controls all actions via `viewChild()`:
|
|
212
|
+
*
|
|
213
|
+
* ```html
|
|
214
|
+
* <mt-client-form #processForm [moduleKey]="'Risk'" [operationKey]="'CloseRisk'" />
|
|
215
|
+
* <button (click)="processForm.load()">Load</button>
|
|
216
|
+
* <button (click)="processForm.submit()">Submit</button>
|
|
217
|
+
* ```
|
|
218
|
+
*
|
|
219
|
+
* Or programmatically:
|
|
220
|
+
* ```typescript
|
|
221
|
+
* readonly processForm = viewChild.required(ClientForm);
|
|
222
|
+
* this.processForm().load();
|
|
223
|
+
* this.processForm().submit();
|
|
224
|
+
* ```
|
|
225
|
+
*/
|
|
226
|
+
declare class ClientForm implements OnDestroy {
|
|
227
|
+
private readonly api;
|
|
228
|
+
protected readonly state: ClientFormStateService;
|
|
229
|
+
private loadSub?;
|
|
230
|
+
private submitSub?;
|
|
231
|
+
readonly moduleKey: _angular_core.InputSignal<string>;
|
|
232
|
+
readonly operationKey: _angular_core.InputSignal<string>;
|
|
233
|
+
readonly moduleId: _angular_core.InputSignal<number | undefined>;
|
|
234
|
+
readonly levelId: _angular_core.InputSignal<number | undefined>;
|
|
235
|
+
readonly levelDataId: _angular_core.InputSignal<number | undefined>;
|
|
236
|
+
readonly moduleDataId: _angular_core.InputSignal<number | undefined>;
|
|
237
|
+
readonly requestSchemaId: _angular_core.InputSignal<number | undefined>;
|
|
238
|
+
readonly draftProcessId: _angular_core.InputSignal<number | undefined>;
|
|
239
|
+
readonly preview: _angular_core.InputSignal<boolean>;
|
|
240
|
+
readonly returnUrl: _angular_core.InputSignal<string | undefined>;
|
|
241
|
+
readonly readonly: _angular_core.InputSignal<boolean>;
|
|
242
|
+
readonly autoLoad: _angular_core.InputSignal<boolean>;
|
|
243
|
+
readonly formMode: _angular_core.InputSignal<"create" | "edit">;
|
|
244
|
+
readonly lang: _angular_core.InputSignal<"en" | "ar">;
|
|
245
|
+
readonly loaded: _angular_core.OutputEmitterRef<ProcessFormLoadResponse>;
|
|
246
|
+
readonly submitted: _angular_core.OutputEmitterRef<ProcessFormSubmitResponse>;
|
|
247
|
+
readonly errored: _angular_core.OutputEmitterRef<string>;
|
|
248
|
+
readonly modeDetected: _angular_core.OutputEmitterRef<ProcessFormMode>;
|
|
249
|
+
readonly formSourceDetected: _angular_core.OutputEmitterRef<ProcessFormSource>;
|
|
250
|
+
readonly formControl: FormControl<Record<string, any> | null>;
|
|
251
|
+
readonly formConfig: _angular_core.Signal<DynamicFormConfig | null>;
|
|
252
|
+
readonly initialValues: _angular_core.Signal<Record<string, any>>;
|
|
253
|
+
readonly virtualFields: _angular_core.Signal<ProcessFormValue[]>;
|
|
254
|
+
readonly hasVirtualFields: _angular_core.Signal<boolean>;
|
|
255
|
+
private readonly autoLoadEffect;
|
|
256
|
+
private readonly patchValuesEffect;
|
|
257
|
+
/**
|
|
258
|
+
* Load form configuration from the API.
|
|
259
|
+
* Builds request from current input values.
|
|
260
|
+
*/
|
|
261
|
+
load(): void;
|
|
262
|
+
/**
|
|
263
|
+
* Submit the current form values.
|
|
264
|
+
* Builds submit request from form value + load context.
|
|
265
|
+
*/
|
|
266
|
+
submit(): void;
|
|
267
|
+
/**
|
|
268
|
+
* Get the current form value as a flat key-value object.
|
|
269
|
+
*/
|
|
270
|
+
getFormValue(): Record<string, any>;
|
|
271
|
+
/**
|
|
272
|
+
* Get the current form value mapped to submit payload format.
|
|
273
|
+
*/
|
|
274
|
+
getSubmitValues(): ProcessFormSubmitValue[];
|
|
275
|
+
/**
|
|
276
|
+
* Check whether the current form state is valid.
|
|
277
|
+
*/
|
|
278
|
+
isValid(): boolean;
|
|
279
|
+
/**
|
|
280
|
+
* Reset the component to its initial state.
|
|
281
|
+
*/
|
|
282
|
+
reset(): void;
|
|
283
|
+
ngOnDestroy(): void;
|
|
284
|
+
private buildLoadRequest;
|
|
285
|
+
private buildSubmitRequest;
|
|
286
|
+
static ɵfac: _angular_core.ɵɵFactoryDeclaration<ClientForm, never>;
|
|
287
|
+
static ɵcmp: _angular_core.ɵɵComponentDeclaration<ClientForm, "mt-client-form", never, { "moduleKey": { "alias": "moduleKey"; "required": true; "isSignal": true; }; "operationKey": { "alias": "operationKey"; "required": true; "isSignal": true; }; "moduleId": { "alias": "moduleId"; "required": false; "isSignal": true; }; "levelId": { "alias": "levelId"; "required": false; "isSignal": true; }; "levelDataId": { "alias": "levelDataId"; "required": false; "isSignal": true; }; "moduleDataId": { "alias": "moduleDataId"; "required": false; "isSignal": true; }; "requestSchemaId": { "alias": "requestSchemaId"; "required": false; "isSignal": true; }; "draftProcessId": { "alias": "draftProcessId"; "required": false; "isSignal": true; }; "preview": { "alias": "preview"; "required": false; "isSignal": true; }; "returnUrl": { "alias": "returnUrl"; "required": false; "isSignal": true; }; "readonly": { "alias": "readonly"; "required": false; "isSignal": true; }; "autoLoad": { "alias": "autoLoad"; "required": false; "isSignal": true; }; "formMode": { "alias": "formMode"; "required": false; "isSignal": true; }; "lang": { "alias": "lang"; "required": false; "isSignal": true; }; }, { "loaded": "loaded"; "submitted": "submitted"; "errored": "errored"; "modeDetected": "modeDetected"; "formSourceDetected": "formSourceDetected"; }, never, never, true, never>;
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
/**
|
|
291
|
+
* Stateless HTTP service for process-forms runtime APIs.
|
|
292
|
+
* Root-provided — safe to share across multiple ClientForm instances.
|
|
293
|
+
*/
|
|
294
|
+
declare class ClientFormApiService {
|
|
295
|
+
private readonly http;
|
|
296
|
+
private readonly baseUrl;
|
|
297
|
+
/**
|
|
298
|
+
* Load form configuration and values for a given operation context.
|
|
299
|
+
* Backend determines mode (Approval vs Direct) based on published schema.
|
|
300
|
+
*/
|
|
301
|
+
load(request: ProcessFormLoadRequest): Observable<Response<ProcessFormLoadResponse>>;
|
|
302
|
+
/**
|
|
303
|
+
* Submit form values. Result depends on mode:
|
|
304
|
+
* - Approval → status: 'PendingApproval'
|
|
305
|
+
* - Direct → status: 'Executed'
|
|
306
|
+
*/
|
|
307
|
+
submit(request: ProcessFormSubmitRequest): Observable<Response<ProcessFormSubmitResponse>>;
|
|
308
|
+
static ɵfac: _angular_core.ɵɵFactoryDeclaration<ClientFormApiService, never>;
|
|
309
|
+
static ɵprov: _angular_core.ɵɵInjectableDeclaration<ClientFormApiService>;
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
/**
|
|
313
|
+
* Convert a runtime FormConfiguration into a DynamicFormConfig
|
|
314
|
+
* that can be passed directly to `<mt-dynamic-form>`.
|
|
315
|
+
*
|
|
316
|
+
* @param config The form configuration from the load API
|
|
317
|
+
* @param lang Current UI language ('en' | 'ar')
|
|
318
|
+
* @param mode 'create' or 'edit' — filters hidden fields accordingly
|
|
319
|
+
*/
|
|
320
|
+
declare function mapToDynamicFormConfig(config: ClientFormConfiguration, lang?: 'en' | 'ar', mode?: 'create' | 'edit'): DynamicFormConfig;
|
|
321
|
+
/**
|
|
322
|
+
* Convert API property values into a flat key-value object
|
|
323
|
+
* suitable for `formControl.patchValue()`.
|
|
324
|
+
*
|
|
325
|
+
* Only includes non-virtual (editable) values.
|
|
326
|
+
*/
|
|
327
|
+
declare function mapValuesToFormValue(values: ProcessFormValue[]): Record<string, any>;
|
|
328
|
+
/**
|
|
329
|
+
* Convert the current form value back into the submit payload format.
|
|
330
|
+
*
|
|
331
|
+
* Maps `requestPropertyId` from the load response metadata where available,
|
|
332
|
+
* so backend can match to schema request properties.
|
|
333
|
+
*/
|
|
334
|
+
declare function mapFormValueToSubmitValues(formValue: Record<string, any>, loadResponse: ProcessFormLoadResponse): ProcessFormSubmitValue[];
|
|
335
|
+
|
|
336
|
+
export { ClientForm, ClientFormApiService, ClientFormStateService, isFormRequiredInterception, mapFormValueToSubmitValues, mapToDynamicFormConfig, mapValuesToFormValue };
|
|
337
|
+
export type { ClientFieldWidth, ClientFormConfiguration, ClientFormField, ClientFormSection, ClientPropertyItem, ClientValidationRule, FormRequiredInterception, OperationType, ProcessFormContext, ProcessFormLoadRequest, ProcessFormLoadResponse, ProcessFormMode, ProcessFormSource, ProcessFormSubmitRequest, ProcessFormSubmitResponse, ProcessFormSubmitStatus, ProcessFormSubmitValue, ProcessFormValue, ProcessFormValueMetadata, Response };
|