From 8ec7e9616e1f944b99de1d0b3ceba3a82c899994 Mon Sep 17 00:00:00 2001 From: Bill Erickson Date: Mon, 16 Apr 2018 20:52:31 +0000 Subject: [PATCH] LP#1626157 fm editor xport Signed-off-by: Bill Erickson --- .../app/share/fm-editor/fm-editor.component.html | 62 ++++++++++++++++++++++ .../src/app/share/fm-editor/fm-editor.component.ts | 59 ++++++++++++++------ .../workstations/workstations.component.html | 4 +- 3 files changed, 108 insertions(+), 17 deletions(-) diff --git a/Open-ILS/src/eg2/src/app/share/fm-editor/fm-editor.component.html b/Open-ILS/src/eg2/src/app/share/fm-editor/fm-editor.component.html index c49da97493..69e7b73007 100644 --- a/Open-ILS/src/eg2/src/app/share/fm-editor/fm-editor.component.html +++ b/Open-ILS/src/eg2/src/app/share/fm-editor/fm-editor.component.html @@ -20,6 +20,7 @@ + + + + + + + + + + + + + + + + + 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 b2fbe6d80d..ac45e3d51f 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 @@ -4,7 +4,7 @@ import {EgOrgService} from '@eg/core/org.service'; import {EgIdlService, EgIdlObject} from '@eg/core/idl.service'; import {EgPcrudService} from '@eg/core/pcrud.service'; import {EgDialogComponent} from '@eg/share/dialog/dialog.component'; -import {NgbModal} from '@ng-bootstrap/ng-bootstrap'; +import {NgbModal, NgbModalOptions} from '@ng-bootstrap/ng-bootstrap'; @Component({ selector: 'fm-record-editor', @@ -18,6 +18,7 @@ export class FmRecordEditorComponent // mode: 'create' for creating a new record, // 'update' for editing an existing record + // 'view' for viewing an existing record without editing @Input() mode: string; // record ID to update. Not all IDs are numbers. @@ -83,28 +84,43 @@ export class FmRecordEditorComponent super(modal) } + // Avoid fetching data on init since that may lead to unnecessary + // data retrieval. ngOnInit() { this.idlDef = this.idl.classes[this.idlClass]; this.recordLabel = this.idlDef.label; - this.initRecord(); + } + + // Opening dialog, fetch data. + open(options?: NgbModalOptions): Promise { + return this.initRecord().then( + ok => super.open(options), + err => console.warn(`Error fetching FM data: ${err}`) + ); } private initRecord(): Promise { - if (this.mode == 'update') { + if (this.mode == 'update' || this.mode == 'view') { return this.pcrud.retrieve(this.idlClass, this.recordId) .toPromise().then(rec => { + + if (!rec) { + return Promise.reject( + `No record found with id ${this.recordId}`); + } + this.record = rec; this.convertDatatypesToJs(); - this.fields = this.getFieldList(); + return this.getFieldList().then( + fields => this.fields = fields); }); } // create a new record from scratch this.pkeyIsEditable = !('pkey_sequence' in this.idlDef); this.record = this.idl.create(this.idlClass); - this.fields = this.getFieldList(); - return Promise.resolve(); + return this.getFieldList().then(fields => this.fields = fields); } // Modifies the FM record in place, replacing IDL-compatible values @@ -122,25 +138,26 @@ export class FmRecordEditorComponent } private flattenLinkedValues(cls: string, list: EgIdlObject[]): any[] { - let results: any[] = []; - let idField: string = this.idlDef.pkey; - let selector: string = - this.idlDef.field_map[idField].selector || idField; - + 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(): any[] { + private getFieldList(): Promise { let fields = this.idlDef.fields.filter(f => f.virtual != 'true' && !this.hiddenFields.includes(f.name) ); + let promises = []; + fields.forEach(field => { - field.readOnly = this.readonlyFields.includes(field.name); + field.readOnly = this.mode == 'view' + || this.readonlyFields.includes(field.name); if (this.isRequiredOverride && field.name in this.isRequiredOverride) { @@ -154,11 +171,21 @@ export class FmRecordEditorComponent } } - // TODO + if (field.datatype == 'link') { + promises.push( + this.pcrud.retrieveAll(field.class, {}, {atomic : true}) + .toPromise().then(list => { + field.linkedValues = + this.flattenLinkedValues(field.class, list); + }) + ); + } + + // TODO org unit + // TODO custom field templates }); - console.debug(fields); - return fields; + return Promise.all(promises).then(ok => fields); } save() { diff --git a/Open-ILS/src/eg2/src/app/staff/admin/workstation/workstations/workstations.component.html b/Open-ILS/src/eg2/src/app/staff/admin/workstation/workstations/workstations.component.html index 32a14491ab..d79bed53cb 100644 --- a/Open-ILS/src/eg2/src/app/staff/admin/workstation/workstations/workstations.component.html +++ b/Open-ILS/src/eg2/src/app/staff/admin/workstation/workstations/workstations.component.html @@ -10,7 +10,9 @@ - + -- 2.11.0