pict-section-recordset 1.21.1 → 1.22.0

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pict-section-recordset",
3
- "version": "1.21.1",
3
+ "version": "1.22.0",
4
4
  "description": "Pict dynamic record set management views",
5
5
  "main": "source/Pict-Section-RecordSet.js",
6
6
  "files": [
@@ -186,6 +186,43 @@ class RecordSetMetacontroller extends libFableServiceProviderBase
186
186
  return this.recordSetProviderConfigurations[pRecordSet];
187
187
  }
188
188
 
189
+ /**
190
+ * Resolve a column name to the record-set it references, so a form can mount an entity Picker and the
191
+ * read view can resolve the name. Two sources, in order:
192
+ *
193
+ * 1. The record-set config's explicit `ForeignKeyEntities` map ({ ColumnName: EntityName }). This is
194
+ * how non-conventional references are declared — prefixed/suffixed columns (ParentIDSample,
195
+ * ItemIDTestSpecificationSet, LinkedIDUser, IDMaterialParent, …) and any override. Mapping a
196
+ * column to a falsy value explicitly opts it OUT (keeps it a plain input).
197
+ * 2. The plain `ID<Entity>` convention — a column named exactly `ID` + an entity that is a
198
+ * registered record-set (IDOrganization → Organization). No prefix heuristics; anything that
199
+ * isn't a clean `ID<Entity>` must be declared in the map above.
200
+ *
201
+ * Returns false for the row's own id, IDCustomer, non-references, and references this app doesn't
202
+ * manage as a record-set (which then stay plain inputs).
203
+ *
204
+ * @param {string} pFieldName - the schema column name.
205
+ * @param {Record<string, any>} [pRecordSetConfiguration] - the owning record-set's configuration.
206
+ * @param {string} [pOwnIDField] - the row's own id field, excluded (e.g. 'IDTestSpecification').
207
+ * @return {string|false} the referenced record-set name, or false.
208
+ */
209
+ resolveForeignEntity(pFieldName, pRecordSetConfiguration, pOwnIDField)
210
+ {
211
+ if (!pFieldName || (typeof pFieldName !== 'string')) { return false; }
212
+ // 1. Explicit per-record-set mapping wins (declares exceptions; a falsy value opts a column out).
213
+ const tmpMap = pRecordSetConfiguration && pRecordSetConfiguration.ForeignKeyEntities;
214
+ if (tmpMap && Object.prototype.hasOwnProperty.call(tmpMap, pFieldName))
215
+ {
216
+ return tmpMap[pFieldName] || false;
217
+ }
218
+ // 2. Plain ID<Entity> convention, validated against the registered record-sets.
219
+ if ((pFieldName === pOwnIDField) || (pFieldName === 'IDCustomer')) { return false; }
220
+ if (!pFieldName.startsWith('ID')) { return false; }
221
+ const tmpRemote = pFieldName.slice(2);
222
+ if (!tmpRemote) { return false; }
223
+ return this.recordSetProviderConfigurations[tmpRemote] ? tmpRemote : false;
224
+ }
225
+
189
226
  /**
190
227
  * @param {Record<string, any>} pRecordSetConfiguration - The RecordSet configuration to load.
191
228
  */
@@ -210,14 +210,14 @@ class viewRecordSetCreate extends libPictRecordSetRecordView
210
210
  let rowCounter = 1;
211
211
  for (const p of Object.keys(tmpRecordCreateData.RecordSchema.properties))
212
212
  {
213
- const exclusionSet = [this.pict.providers[this.providerHash].getIDField(), this.pict.providers[this.providerHash].getGUIDField(), 'CreatingIDUser', 'UpdatingIDUser', 'DeletingIDUser', 'Deleted', 'CreateDate', 'UpdateDate', 'DeleteDate', 'Deleted'];
213
+ const exclusionSet = [this.pict.providers[this.providerHash].getIDField(), this.pict.providers[this.providerHash].getGUIDField(), 'CreatingIDUser', 'UpdatingIDUser', 'DeletingIDUser', 'Deleted', 'CreateDate', 'UpdateDate', 'DeleteDate', 'Deleted', 'IDCustomer', 'ExternalSyncDate', 'ExternalSyncGUID']; // IDCustomer: meadow-endpoints/retold tenancy discriminator — server-managed, never settable via the API
214
214
  if (exclusionSet.includes(p))
215
215
  {
216
216
  continue;
217
217
  }
218
218
  const tmpDescriptor =
219
219
  {
220
- "Name": `${ this.pict.providers[pProviderHash].getHumanReadableFieldName?.() || p }`,
220
+ "Name": `${ this.pict.providers[pProviderHash].getHumanReadableFieldName?.(p) || p }`,
221
221
  "Hash": `${ tmpRecordCreateData.RecordSet }-${ p }`,
222
222
  "DataType": "String",
223
223
  "PictForm":
@@ -256,6 +256,17 @@ class viewRecordSetCreate extends libPictRecordSetRecordView
256
256
  tmpDescriptor.DataType = 'String';
257
257
  }
258
258
 
259
+ const tmpForeignEntity = this.pict.PictSectionRecordSet.resolveForeignEntity(p, pRecordConfiguration, this.pict.providers[this.providerHash].getIDField());
260
+ if (tmpForeignEntity && this.pict.providers['Pict-Section-Picker'])
261
+ {
262
+ // Foreign-key column → searchable entity Picker (edit) + resolved name (read).
263
+ tmpDescriptor.PictForm.InputType = 'Picker';
264
+ tmpDescriptor.PictForm.Entity = tmpForeignEntity;
265
+ const tmpForeignConfig = this.pict.PictSectionRecordSet.recordSetProviderConfigurations[tmpForeignEntity];
266
+ if (tmpForeignConfig && tmpForeignConfig.SearchFields) { tmpDescriptor.PictForm.SearchFields = tmpForeignConfig.SearchFields; }
267
+ }
268
+ // Per-record-set label override (e.g. Contract/Project IDOrganization → "Prime Contractor").
269
+ if (pRecordConfiguration.FieldLabels && pRecordConfiguration.FieldLabels[p]) { tmpDescriptor.Name = pRecordConfiguration.FieldLabels[p]; }
259
270
  this.defaultManifest.Descriptors[`${ tmpRecordCreateData.RecordSet }Details.${ p }`] = tmpDescriptor;
260
271
  }
261
272
  this.pict.TemplateProvider.addTemplate(`PRSP-Create-RecordCreate-Template`, /*html*/`
@@ -218,6 +218,8 @@ class viewRecordSetDashboard extends libPictRecordSetRecordView
218
218
  'DeletingIDUser',
219
219
  'UpdateDate',
220
220
  'UpdatingIDUser',
221
+ 'IDCustomer', // meadow-endpoints/retold tenancy discriminator — server-managed, hidden from every record view
222
+ 'ExternalSyncDate', 'ExternalSyncGUID', // external-sync auditing stamps (Headlight integration sync)
221
223
  ];
222
224
 
223
225
  const tmpSchema = pRecordListData.RecordSchema;
@@ -34,8 +34,16 @@ const _DEFAULT_CONFIGURATION_List_Title =
34
34
  <header id="PRSP_Title_Container">
35
35
  <h1 id="PRSP_Title">{~D:Record.Title~}</h1>
36
36
  <h2 id="PRSP_Subtitle">{~D:Record.Subtitle~}</h2>
37
+ {~TIfAbs:PRSP-List-Title-CreateButton-Template:Record:Record.RecordSetConfiguration.RecordSetListShowCreateButton^TRUE^~}
37
38
  </header>
38
39
  <!-- DefaultPackage end view template: [PRSP-List-Title-Template] -->
40
+ `
41
+ },
42
+ {
43
+ Hash: 'PRSP-List-Title-CreateButton-Template',
44
+ Template: /*html*/`
45
+ <!-- Optional list "New" action; opt in per record set via RecordSetConfiguration.RecordSetListShowCreateButton. -->
46
+ <button type="button" class="prsp-list-title-create" title="Create a new record" onclick="_Pict.views['RSP-RecordSet-List'].createNew('{~D:Record.RecordSet~}')">{~I:Plus~} New</button>
39
47
  `
40
48
  },
41
49
  ],
@@ -189,6 +189,26 @@ class viewRecordSetList extends libPictRecordSetRecordView
189
189
  return true;
190
190
  }
191
191
 
192
+ /**
193
+ * Navigate to the Create form for a record set. Backs the optional list title-bar "New" button
194
+ * (opt in per record set via RecordSetConfiguration.RecordSetListShowCreateButton). Routes through
195
+ * the section router so it works in both hash and memory router modes; falls back to the active
196
+ * route's record set when called without an argument.
197
+ * @param {string} [pRecordSet] - The record set to create a new record in.
198
+ * @return {boolean} True when navigation was issued.
199
+ */
200
+ createNew(pRecordSet)
201
+ {
202
+ const tmpRecordSet = pRecordSet || this.fable?.providers?.RecordSetRouter?.pictRouter?.router?.current?.[0]?.data?.RecordSet;
203
+ if (!tmpRecordSet)
204
+ {
205
+ this.log.warn(`RecordSetList: createNew called but no record set could be resolved.`);
206
+ return false;
207
+ }
208
+ this.fable.providers.RecordSetRouter.pictRouter.navigate(`/PSRS/${ tmpRecordSet }/Create`);
209
+ return true;
210
+ }
211
+
192
212
  onBeforeRenderList(pRecordListData)
193
213
  {
194
214
  return pRecordListData;
@@ -269,6 +289,8 @@ class viewRecordSetList extends libPictRecordSetRecordView
269
289
  'DeletingIDUser',
270
290
  'UpdateDate',
271
291
  'UpdatingIDUser',
292
+ 'IDCustomer', // meadow-endpoints/retold tenancy discriminator — server-managed, hidden from every record view
293
+ 'ExternalSyncDate', 'ExternalSyncGUID', // external-sync auditing stamps (Headlight integration sync)
272
294
  ];
273
295
  }
274
296
 
@@ -5,7 +5,9 @@ const libViewAssociationEditor = require('../associate/RecordSet-AssociationEdit
5
5
  // surfaced through the record audit header (the first-class activity line + the Details
6
6
  // modal), not inline in the record body. The entity's own ID/GUID field names are added
7
7
  // at suppression time via the provider's getIDField()/getGUIDField().
8
- const _AUDIT_FIELD_NAMES = ['CreatingIDUser', 'UpdatingIDUser', 'DeletingIDUser', 'Deleted', 'CreateDate', 'UpdateDate', 'DeleteDate'];
8
+ // Audit / sync-bookkeeping fields suppressed from the record body and surfaced in the Details modal.
9
+ // ExternalSyncDate / ExternalSyncGUID are the external-sync auditing stamps (Headlight integration sync).
10
+ const _AUDIT_FIELD_NAMES = ['CreatingIDUser', 'UpdatingIDUser', 'DeletingIDUser', 'Deleted', 'CreateDate', 'UpdateDate', 'DeleteDate', 'ExternalSyncDate', 'ExternalSyncGUID'];
9
11
 
10
12
  /** @type {Record<string, any>} */
11
13
  const _DEFAULT_CONFIGURATION__Read = (
@@ -43,9 +45,10 @@ const _DEFAULT_CONFIGURATION__Read = (
43
45
  .prsp-audit-button:hover { border-color: var(--theme-color-brand-primary, #156dd1); color: var(--theme-color-brand-primary, #156dd1); }
44
46
  .prsp-record-related:empty { display: none; }
45
47
  .prsp-audit-anchor { position: relative; }
46
- .prsp-audit-popover { position: absolute; top: calc(100% + 8px); right: 0; min-width: 320px; max-width: 90vw; background: var(--theme-color-background-panel, #fff); border: 1px solid var(--theme-color-border-default, #d7dce3); border-radius: 10px; box-shadow: 0 14px 36px rgba(15, 23, 42, 0.18); padding: 1rem 1.1rem; z-index: 40; display: none; }
48
+ .prsp-audit-popover { position: absolute; top: calc(100% + 8px); right: 0; min-width: 380px; width: max-content; max-width: 90vw; background: var(--theme-color-background-panel, #fff); border: 1px solid var(--theme-color-border-default, #d7dce3); border-radius: 10px; box-shadow: 0 14px 36px rgba(15, 23, 42, 0.18); padding: 1rem 1.1rem; z-index: 40; display: none; }
47
49
  .prsp-audit-popover.is-open { display: block; }
48
- .prsp-audit-dl { display: grid; grid-template-columns: auto 1fr; gap: 0.6rem 1rem; align-items: baseline; margin: 0; }
50
+ .prsp-audit-dl { display: grid; grid-template-columns: auto auto; gap: 0.6rem 1rem; align-items: baseline; margin: 0; }
51
+ .prsp-audit-dl dd { white-space: nowrap; }
49
52
  .prsp-audit-dl dt { color: var(--theme-color-text-muted, #6b7686); font-size: 0.74rem; text-transform: uppercase; letter-spacing: 0.03em; white-space: nowrap; }
50
53
  .prsp-audit-dl dd { margin: 0; color: var(--theme-color-text-primary, #1f2733); font-size: 0.9rem; }
51
54
  .prsp-audit-dl dd small { color: var(--theme-color-text-muted, #6b7686); }
@@ -242,6 +245,7 @@ const _DEFAULT_CONFIGURATION__Read = (
242
245
  {~TS:PRSP-Read-RecordAudit-Created-Template:AppData.PRSP_RecordAudit.CreatedSlot~}
243
246
  {~TS:PRSP-Read-RecordAudit-Updated-Template:AppData.PRSP_RecordAudit.UpdatedSlot~}
244
247
  {~TS:PRSP-Read-RecordAudit-Deleted-Template:AppData.PRSP_RecordAudit.DeletedSlot~}
248
+ {~TS:PRSP-Read-RecordAudit-ExternalSync-Template:AppData.PRSP_RecordAudit.ExternalSyncSlot~}
245
249
  </dl>
246
250
  </div>
247
251
  </div>
@@ -268,6 +272,14 @@ const _DEFAULT_CONFIGURATION__Read = (
268
272
  Hash: 'PRSP-Read-RecordAudit-Deleted-Template',
269
273
  Template: /*html*/`<dt>Deleted</dt><dd class="is-deleted">{~DateFormat:Record.Date^MMM D, YYYY - h:mm A~} <small>by {~E:User^Record.UserID^PRSP-Read-RecordAudit-UserName-Template~}</small></dd>`
270
274
  },
275
+ {
276
+ Hash: 'PRSP-Read-RecordAudit-ExternalSync-Template',
277
+ Template: /*html*/`<dt>External sync</dt><dd>{~TIfAbs:PRSP-Read-RecordAudit-ExternalSyncDate-Template:Record:Record.HasDate^TRUE^~}{~NE:Record.NeverSynced^Never synced~}</dd>`
278
+ },
279
+ {
280
+ Hash: 'PRSP-Read-RecordAudit-ExternalSyncDate-Template',
281
+ Template: /*html*/`{~DateFormat:Record.Date^MMM D, YYYY - h:mm A~}`
282
+ },
271
283
  {
272
284
  // Soft-deleted record banner (the ViewDeleted route, or a record deleted out from
273
285
  // under a normal View). The one-or-zero-element DeletedBannerSlot drives it.
@@ -518,7 +530,9 @@ class viewRecordSetRead extends libPictRecordSetRecordView
518
530
  DeletedSlot: tmpDeleted ? [{ Date: pRecord.DeleteDate, UserID: pRecord.DeletingIDUser }] : [],
519
531
  // The ViewDeleted route's banner: present whenever the record is soft-deleted (whether the
520
532
  // user arrived via ViewDeleted or the record was deleted out from under a normal View).
521
- DeletedBannerSlot: (!!pRecord.Deleted) ? [{ Date: pRecord.DeleteDate, UserID: pRecord.DeletingIDUser, HasDate: this._validAuditDate(pRecord.DeleteDate) }] : []
533
+ DeletedBannerSlot: (!!pRecord.Deleted) ? [{ Date: pRecord.DeleteDate, UserID: pRecord.DeletingIDUser, HasDate: this._validAuditDate(pRecord.DeleteDate) }] : [],
534
+ // External-sync auditing stamp — surfaced in the Details modal for entities that carry the field.
535
+ ExternalSyncSlot: ('ExternalSyncDate' in pRecord) ? [{ Date: pRecord.ExternalSyncDate, HasDate: this._validAuditDate(pRecord.ExternalSyncDate), NeverSynced: !this._validAuditDate(pRecord.ExternalSyncDate) }] : []
522
536
  };
523
537
  }
524
538
 
@@ -657,7 +671,7 @@ class viewRecordSetRead extends libPictRecordSetRecordView
657
671
  return;
658
672
  }
659
673
  const tmpProvider = this.pict.providers[this.providerHash];
660
- const tmpSuppress = _AUDIT_FIELD_NAMES.slice();
674
+ const tmpSuppress = _AUDIT_FIELD_NAMES.concat('IDCustomer'); // IDCustomer: meadow-endpoints/retold tenancy discriminator — server-managed
661
675
  if (tmpProvider)
662
676
  {
663
677
  tmpSuppress.push(tmpProvider.getIDField());
@@ -963,14 +977,14 @@ class viewRecordSetRead extends libPictRecordSetRecordView
963
977
  const schema = await this.pict.providers[providerHash].getRecordSchema();
964
978
  for (const p of Object.keys(schema.properties))
965
979
  {
966
- const exclusionSet = [this.pict.providers[this.providerHash].getIDField(), this.pict.providers[this.providerHash].getGUIDField()].concat(_AUDIT_FIELD_NAMES);
980
+ const exclusionSet = [this.pict.providers[this.providerHash].getIDField(), this.pict.providers[this.providerHash].getGUIDField()].concat(_AUDIT_FIELD_NAMES, 'IDCustomer');
967
981
  if (exclusionSet.includes(p))
968
982
  {
969
983
  continue;
970
984
  }
971
985
  const tmpDescriptor =
972
986
  {
973
- "Name": `${ this.pict.providers[providerHash].getHumanReadableFieldName?.() || p }`,
987
+ "Name": `${ this.pict.providers[providerHash].getHumanReadableFieldName?.(p) || p }`,
974
988
  "Hash": `${ this.pict.providers[this.providerHash].options.Entity }-${ p }`,
975
989
  "DataType": "String",
976
990
  "PictForm":
@@ -1009,6 +1023,28 @@ class viewRecordSetRead extends libPictRecordSetRecordView
1009
1023
  tmpDescriptor.DataType = 'String';
1010
1024
  }
1011
1025
 
1026
+ const tmpForeignEntity = this.pict.PictSectionRecordSet.resolveForeignEntity(p, this.pict.PictSectionRecordSet.recordSetProviderConfigurations[recordSet], this.pict.providers[this.providerHash].getIDField());
1027
+ if (tmpForeignEntity && this.pict.providers['Pict-Section-Picker'])
1028
+ {
1029
+ // Foreign-key column → searchable entity Picker (edit) + resolved name (read, see the view-mode override).
1030
+ tmpDescriptor.PictForm.InputType = 'Picker';
1031
+ tmpDescriptor.PictForm.Entity = tmpForeignEntity;
1032
+ const tmpForeignConfig = this.pict.PictSectionRecordSet.recordSetProviderConfigurations[tmpForeignEntity];
1033
+ if (tmpForeignConfig && tmpForeignConfig.SearchFields) { tmpDescriptor.PictForm.SearchFields = tmpForeignConfig.SearchFields; }
1034
+ }
1035
+ // Per-record-set label override (e.g. Contract/Project IDOrganization → "Prime Contractor").
1036
+ const tmpReadRSConfig = this.pict.PictSectionRecordSet.recordSetProviderConfigurations[recordSet];
1037
+ if (tmpReadRSConfig && tmpReadRSConfig.FieldLabels && tmpReadRSConfig.FieldLabels[p]) { tmpDescriptor.Name = tmpReadRSConfig.FieldLabels[p]; }
1038
+ // JSON/object columns → embedded ObjectEditor (read-only tree in View, editable in Edit). Driven by the
1039
+ // schema column type, with a per-record-set ObjectEditorFields list to opt in string-typed JSON blobs.
1040
+ // Gated on the pict-section-form ObjectEditor input being registered (graceful on older form versions).
1041
+ const tmpObjectEditorFields = (tmpReadRSConfig && Array.isArray(tmpReadRSConfig.ObjectEditorFields)) ? tmpReadRSConfig.ObjectEditorFields : [];
1042
+ if (tmpDescriptor.PictForm.InputType !== 'Picker' && this.pict.providers['Pict-Input-ObjectEditor'] &&
1043
+ (schema.properties[p].type === 'object' || schema.properties[p].type === 'json' || tmpObjectEditorFields.includes(p)))
1044
+ {
1045
+ tmpDescriptor.DataType = 'Object';
1046
+ tmpDescriptor.PictForm.InputType = 'ObjectEditor';
1047
+ }
1012
1048
  defaultManifest.Descriptors[`${ recordSet }Details.${ p }`] = tmpDescriptor;
1013
1049
  }
1014
1050
  return defaultManifest;
@@ -1039,6 +1075,11 @@ class viewRecordSetRead extends libPictRecordSetRecordView
1039
1075
  {
1040
1076
  tmpManifest.Descriptors[x].PictForm = {};
1041
1077
  }
1078
+ // Entity-reference (Picker) fields stay a Picker but render read-only (the resolved entity
1079
+ // name as plain text, no dropdown); everything else becomes plain read-only text.
1080
+ if (tmpManifest.Descriptors[x].PictForm.InputType === 'Picker') { tmpManifest.Descriptors[x].PictForm.ReadOnly = true; continue; }
1081
+ // ObjectEditor stays an ObjectEditor but renders its read-only tree (not a plain text field).
1082
+ if (tmpManifest.Descriptors[x].PictForm.InputType === 'ObjectEditor') { tmpManifest.Descriptors[x].PictForm.ReadOnly = true; continue; }
1042
1083
  tmpManifest.Descriptors[x].PictForm.InputType = 'ReadOnly';
1043
1084
  }
1044
1085
  }