LP1809288: Make some brt fields read-only
authorJane Sandberg <sandbej@linnbenton.edu>
Sun, 30 Dec 2018 00:40:10 +0000 (16:40 -0800)
committerBill Erickson <berickxx@gmail.com>
Fri, 25 Jan 2019 17:08:16 +0000 (12:08 -0500)
Signed-off-by: Jane Sandberg <sandbej@linnbenton.edu>
Signed-off-by: Bill Erickson <berickxx@gmail.com>
Open-ILS/src/eg2/src/app/share/fm-editor/fm-editor.component.ts
Open-ILS/src/eg2/src/app/staff/admin/basic-admin-page.component.ts
Open-ILS/src/eg2/src/app/staff/admin/booking/routing.module.ts
Open-ILS/src/eg2/src/app/staff/share/admin-page/admin-page.component.html
Open-ILS/src/eg2/src/app/staff/share/admin-page/admin-page.component.ts

index 3ad4892..7b90a02 100644 (file)
@@ -256,7 +256,18 @@ export class FmRecordEditorComponent
                 };
             }
 
-            if (field.datatype === 'link') {
+            if (field.datatype === 'link' && field.readOnly) { // no need to fetch all possible values for read-only fields
+                let id_to_fetch = this.record[field.name]();
+                if (id_to_fetch) {
+                    promises.push(
+                        this.pcrud.retrieve(field.class, this.record[field.name]())
+                        .toPromise().then(list => {
+                            field.linkedValues =
+                                this.flattenLinkedValues(field.class, Array(list));
+                        })
+                    );
+                }
+            } else if (field.datatype === 'link') {
                 promises.push(
                     this.pcrud.retrieveAll(field.class, {}, {atomic : true})
                     .toPromise().then(list => {
index 0d6be84..0427646 100644 (file)
@@ -10,7 +10,7 @@ import {IdlService} from '@eg/core/idl.service';
     template: `
       <eg-staff-banner bannerText="{{classLabel}} Configuration" i18n-bannerText>
       </eg-staff-banner>
-      <eg-admin-page persistKeyPfx="{{persistKeyPfx}}" idlClass="{{idlClass}}"></eg-admin-page>
+      <eg-admin-page persistKeyPfx="{{persistKeyPfx}}" idlClass="{{idlClass}}" readonlyFields="{{readonlyFields}}"></eg-admin-page>
     `
 })
 
@@ -19,6 +19,7 @@ export class BasicAdminPageComponent implements OnInit {
     idlClass: string;
     classLabel: string;
     persistKeyPfx: string;
+    readonlyFields: string = '';
 
     constructor(
         private route: ActivatedRoute,
@@ -33,7 +34,13 @@ export class BasicAdminPageComponent implements OnInit {
             const data = this.route.snapshot.data[0];
             if (data) { schema = data.schema; }
         }
-        const table = schema + '.' + this.route.snapshot.paramMap.get('table');
+        let table = this.route.snapshot.paramMap.get('table');
+        if (!table) {
+            const data = this.route.snapshot.data[0];
+            if (data) { table = data.table; }
+        }
+        const full_table = schema + '.' + table;
+
 
         // Set the prefix to "server", "local", "workstation",
         // extracted from the URL path.
@@ -44,16 +51,22 @@ export class BasicAdminPageComponent implements OnInit {
             this.persistKeyPfx = '';
         }
 
+        // Pass the readonlyFields param if available
+        if (this.route.snapshot.data[0].readonlyFields) {
+            this.readonlyFields = this.route.snapshot.data[0].readonlyFields;
+        }
+
+
         Object.keys(this.idl.classes).forEach(class_ => {
             const classDef = this.idl.classes[class_];
-            if (classDef.table === table) {
+            if (classDef.table === full_table) {
                 this.idlClass = class_;
                 this.classLabel = classDef.label;
             }
         });
 
         if (!this.idlClass) {
-            throw new Error('Unable to find IDL class for table ' + table);
+            throw new Error('Unable to find IDL class for table ' + full_table);
         }
     }
 }
index 1cbf480..cb5ef9e 100644 (file)
@@ -7,6 +7,10 @@ const routes: Routes = [{
     path: 'splash',
     component: AdminBookingSplashComponent
 }, {
+    path: 'resource_type',
+    component: BasicAdminPageComponent,
+    data: [{schema: 'booking', table: 'resource_type', readonlyFields: 'catalog_item,record'}]
+}, {
     path: ':table',
     component: BasicAdminPageComponent,
     // All booking admin pages cover data in the booking.* schema.  No need to
index 194f06b..0fc5c44 100644 (file)
@@ -53,7 +53,7 @@
   </eg-grid-toolbar-action>
 </eg-grid>
 
-<eg-fm-record-editor #editDialog idlClass="{{idlClass}}">
+<eg-fm-record-editor #editDialog idlClass="{{idlClass}}" readonlyFields="{{readonlyFields}}">
 </eg-fm-record-editor>
 
 
index be4452b..80fd2fd 100644 (file)
@@ -62,6 +62,9 @@ export class AdminPageComponent implements OnInit {
     // 'eg.grid.admin.${persistKeyPfx}.config.billing_type'
     @Input() persistKeyPfx: string;
 
+    // Optional comma-separated list of read-only fields
+    @Input() readonlyFields: string;
+
     @ViewChild('grid') grid: GridComponent;
     @ViewChild('editDialog') editDialog: FmRecordEditorComponent;
     @ViewChild('successString') successString: StringComponent;