From: Bill Erickson Date: Mon, 16 Apr 2018 21:24:52 +0000 (+0000) Subject: LP#1626157 fm editor xport X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=bd683a094a57d8851769da12b382e4f13eb7e349;p=working%2FEvergreen.git LP#1626157 fm editor xport Signed-off-by: Bill Erickson --- 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 ac45e3d51f..e08d2e14e4 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 @@ -21,8 +21,11 @@ export class FmRecordEditorComponent // 'view' for viewing an existing record without editing @Input() mode: string; - // record ID to update. Not all IDs are numbers. - @Input() recordId: string; + // Record ID to view/update. Value is dynamic. + recId: any; + @Input() set recordId(id: any) { + if (id) this.recId = id; + } // TODO // customFieldTemplates @@ -65,6 +68,7 @@ export class FmRecordEditorComponent idlDef: any; // IDL record we are editing + // TODO: allow this to be provided by the caller? record: EgIdlObject; // Can we edit the primary key? @@ -102,25 +106,24 @@ export class FmRecordEditorComponent private initRecord(): Promise { if (this.mode == 'update' || this.mode == 'view') { - return this.pcrud.retrieve(this.idlClass, this.recordId) + return this.pcrud.retrieve(this.idlClass, this.recId) .toPromise().then(rec => { if (!rec) { - return Promise.reject( - `No record found with id ${this.recordId}`); + return Promise.reject(`No '${this.idlClass}' + record found with id ${this.recId}`); } this.record = rec; this.convertDatatypesToJs(); - return this.getFieldList().then( - fields => this.fields = fields); + return this.applyFields(); }); } // create a new record from scratch this.pkeyIsEditable = !('pkey_sequence' in this.idlDef); this.record = this.idl.create(this.idlClass); - return this.getFieldList().then(fields => this.fields = fields); + return this.applyFields(); } // Modifies the FM record in place, replacing IDL-compatible values @@ -141,21 +144,22 @@ export class FmRecordEditorComponent let idField = this.idl.classes[cls].pkey; let selector = this.idl.classes[cls].field_map[idField].selector || idField; + return list.map(item => { return {id: item[idField](), name: item[selector]()} }); } - private getFieldList(): Promise { + private applyFields(): Promise { - let fields = this.idlDef.fields.filter(f => + this.fields = this.idlDef.fields.filter(f => f.virtual != 'true' && !this.hiddenFields.includes(f.name) ); let promises = []; - fields.forEach(field => { + this.fields.forEach(field => { field.readOnly = this.mode == 'view' || this.readonlyFields.includes(field.name); @@ -185,7 +189,8 @@ export class FmRecordEditorComponent // TODO custom field templates }); - return Promise.all(promises).then(ok => fields); + // Wait for all network calls to complete + return Promise.all(promises); } save() {