From 38c37f6a091e81088cf4de9b356bf71966c11339 Mon Sep 17 00:00:00 2001 From: Bill Erickson Date: Mon, 12 Aug 2019 16:15:12 -0400 Subject: [PATCH] LP1839881 FM Editor fieldOrder option Adds a new fieldOrder @Input() for FM Record Editor, which is a comma-separated list of field names specifying the order in which they should be rendered in the editor form. Fields not explicitly named are sorted alphabetically by label after the named fields. Includes sandbox example. Signed-off-by: Bill Erickson --- .../src/app/share/fm-editor/fm-editor.component.ts | 35 +++++++++++++++++++--- .../src/app/staff/sandbox/sandbox.component.html | 7 +++-- 2 files changed, 35 insertions(+), 7 deletions(-) diff --git a/Open-ILS/src/eg2/src/app/share/fm-editor/fm-editor.component.ts b/Open-ILS/src/eg2/src/app/share/fm-editor/fm-editor.component.ts index a574e5491d..9753ce5ccb 100644 --- a/Open-ILS/src/eg2/src/app/share/fm-editor/fm-editor.component.ts +++ b/Open-ILS/src/eg2/src/app/share/fm-editor/fm-editor.component.ts @@ -160,6 +160,11 @@ export class FmRecordEditorComponent if (id) { this.recId = id; } } + // Comma-separated list of field names defining the order in which + // fields should be rendered in the form. Any fields not represented + // will be rendered alphabetically by label after the named fields. + @Input() fieldOrder: string; + constructor( private modal: NgbModal, // required for passing to parent private idl: IdlService, @@ -318,13 +323,35 @@ export class FmRecordEditorComponent private getFieldList(): Promise { - this.fields = this.idlDef.fields.filter(f => - !f.virtual && !this.hiddenFieldsList.includes(f.name) - ); + const fields = this.idlDef.fields.filter(f => + !f.virtual && !this.hiddenFieldsList.includes(f.name)); // Wait for all network calls to complete return Promise.all( - this.fields.map(field => this.constructOneField(field))); + fields.map(field => this.constructOneField(field)) + + ).then(() => { + + if (!this.fieldOrder) { + this.fields = fields.sort((a, b) => a.label < b.label ? -1 : 1); + return; + } + + let newList = []; + const ordered = this.fieldOrder.split(/,/); + + ordered.forEach(name => { + const f1 = fields.filter(f2 => f2.name === name)[0]; + if (f1) { newList.push(f1); } + }); + + // Sort remaining fields by label + const remainder = fields.filter(f => !ordered.includes(f.name)); + remainder.sort((a, b) => a.label < b.label ? -1 : 1); + newList = newList.concat(remainder); + + this.fields = newList; + }); } private constructOneField(field: any): Promise { diff --git a/Open-ILS/src/eg2/src/app/staff/sandbox/sandbox.component.html b/Open-ILS/src/eg2/src/app/staff/sandbox/sandbox.component.html index 2febd8eb3b..f9a8bd3587 100644 --- a/Open-ILS/src/eg2/src/app/staff/sandbox/sandbox.component.html +++ b/Open-ILS/src/eg2/src/app/staff/sandbox/sandbox.component.html @@ -33,9 +33,10 @@ + idlClass="cmrcfld" mode="create" hiddenFields="id" + fieldOrder="owner,name,description,marc_format,marc_record_type,tag" + [fieldOptions]="{marc_record_type:{customValues:[{id:'biblio'},{id:'serial'},{id:'authority'}]},description:{customTemplate:{template:descriptionTemplate,context:{'hello':'goodbye'}}}}" + recordId="1" orgDefaultAllowed="owner">