LP1843970: Refactor Coded Value Map grid to use eg-admin-page
authorJane Sandberg <sandbergja@gmail.com>
Fri, 19 Nov 2021 04:19:40 +0000 (20:19 -0800)
committerBill Erickson <berickxx@gmail.com>
Wed, 16 Mar 2022 19:12:33 +0000 (15:12 -0400)
Also adds a new @Input to eg-admin-page that accepts arbitrary
columns based on <ng-template>s

Signed-off-by: Jane Sandberg <sandbergja@gmail.com>
Signed-off-by: Bill Erickson <berickxx@gmail.com>
Open-ILS/src/eg2/src/app/staff/admin/server/coded-value-maps/coded-value-maps.component.html
Open-ILS/src/eg2/src/app/staff/admin/server/coded-value-maps/coded-value-maps.component.ts
Open-ILS/src/eg2/src/app/staff/admin/server/coded-value-maps/coded-value-maps.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 228e514..1c86d6b 100644 (file)
@@ -1,46 +1,14 @@
 <eg-staff-banner bannerText="SVF Record Attribute Coded Value Map Configuration" i18n-bannerText>
 </eg-staff-banner>
 
-<eg-grid #grid idlClass="ccvm" [dataSource]="gridDataSource" [sortable]="true">
-  <eg-grid-toolbar-button
-    label="New SVF Record Attribute Coded Value Map" i18n-label (onClick)="createNew()">
-  </eg-grid-toolbar-button>
-  <eg-grid-toolbar-action label="Edit Selected" i18n-label [action]="editSelected">
-  </eg-grid-toolbar-action>
-  <eg-grid-toolbar-action label="Delete Selected" i18n-label
-    [action]="deleteSelected"></eg-grid-toolbar-action>
-  
-  <eg-grid-column path='id' i18n-label label="ID"></eg-grid-column> 
-  <eg-grid-column path='ctype' i18n-label label="SVF Attribute"></eg-grid-column>
-  <eg-grid-column path='code' i18n-label label="Code"></eg-grid-column>
-  <eg-grid-column path='value' i18n-label label='value'></eg-grid-column>
-  <eg-grid-column path='description' i18n-label label='description'></eg-grid-column>
-  <eg-grid-column path='opac_visible' i18n-label label='OPAC Visible'></eg-grid-column>
-  <eg-grid-column path='search_label' i18n-label label='Search Label'></eg-grid-column>
-  <eg-grid-column path='is_simple' i18n-label label='Is Simple Selector'></eg-grid-column>
-  <eg-grid-column path='concept_uri' i18n-label label='Concept URI'></eg-grid-column>
-  <ng-template #compDefTmpl let-row="row">
-    <div *ngIf="row.ctype().composite() == 't'">
-      <a href="staff/admin/server/config/coded_value_map/composite_def/{{row.id()}}">
-        Manage
-      </a>
-    </div>
-  </ng-template>
-  <eg-grid-column i18n-label label="Composite Definition"
-      [cellTemplate]="compDefTmpl"></eg-grid-column>
-</eg-grid>
+<eg-admin-page idlClass="ccvm" [templateFields]="[{name: 'Composite Definition', template: compDefTmpl}]">
+</eg-admin-page>
 
-<eg-fm-record-editor #editDialog idlClass="ccvm">
-</eg-fm-record-editor>
 
-<eg-string #createString i18n-text text="New Map Added"></eg-string>
-<eg-string #createErrString i18n-text text="Failed to Create New Map">
-</eg-string>
-<eg-string #deleteFailedString i18n-text 
-  text="Delete of Map failed or was not allowed"></eg-string>
-<eg-string #deleteSuccessString i18n-text 
-  text="Delete of Map succeeded"></eg-string>
-<eg-string #updateFailedString i18n-text 
-  text="Update of Map failed"></eg-string>
-<eg-string #updateSuccessString i18n-text 
-  text="Update of Map succeeded"></eg-string>
\ No newline at end of file
+<ng-template #compDefTmpl let-row="row">
+  <div *ngIf="row.ctype().composite() == 't'">
+    <a routerLink="/staff/admin/server/config/coded_value_map/composite_def/{{row.id()}}">
+      Manage
+    </a>
+  </div>
+</ng-template>
index f89a79e..c3f7866 100644 (file)
@@ -1,106 +1,7 @@
-import {Pager} from '@eg/share/util/pager';
-import {Component, ViewChild, OnInit} from '@angular/core';
-import {IdlObject} from '@eg/core/idl.service';
-import {GridDataSource} from '@eg/share/grid/grid';
-import {GridComponent} from '@eg/share/grid/grid.component';
-import {ToastService} from '@eg/share/toast/toast.service';
-import {PcrudService} from '@eg/core/pcrud.service';
-import {FmRecordEditorComponent} from '@eg/share/fm-editor/fm-editor.component';
-import {StringComponent} from '@eg/share/string/string.component';
+import {Component} from '@angular/core';
 
 @Component({
     templateUrl: './coded-value-maps.component.html'
 })
 
-export class CodedValueMapsComponent implements OnInit {
-
-    gridDataSource: GridDataSource = new GridDataSource();
-    @ViewChild('createString', { static: true }) createString: StringComponent;
-    @ViewChild('createErrString', { static: true }) createErrString: StringComponent;
-    @ViewChild('updateSuccessString', { static: true }) updateSuccessString: StringComponent;
-    @ViewChild('updateFailedString', { static: true }) updateFailedString: StringComponent;
-    @ViewChild('deleteFailedString', { static: true }) deleteFailedString: StringComponent;
-    @ViewChild('deleteSuccessString', { static: true }) deleteSuccessString: StringComponent;
-
-    @ViewChild('grid', {static: true}) grid: GridComponent;
-    @ViewChild('editDialog', { static: true }) editDialog: FmRecordEditorComponent;
-
-    constructor(
-        private pcrud: PcrudService,
-        private toast: ToastService,
-    ) {
-    }
-
-    ngOnInit() {
-        this.gridDataSource.getRows = (pager: Pager, sort: any[]) => {
-            return this.pcrud.retrieveAll('ccvm', {order_by: {ccvm: 'id'}}, {fleshSelectors: true});
-        };
-        this.grid.onRowActivate.subscribe(
-            (idlThing: IdlObject) => this.showEditDialog(idlThing)
-        );
-    }
-
-    showEditDialog(standingPenalty: IdlObject): Promise<any> {
-        this.editDialog.mode = 'update';
-        this.editDialog.recordId = standingPenalty['id']();
-        return new Promise((resolve, reject) => {
-            this.editDialog.open({size: 'lg'}).subscribe(
-                result => {
-                    this.updateSuccessString.current()
-                        .then(str => this.toast.success(str));
-                    this.grid.reload();
-                    resolve(result);
-                },
-                error => {
-                    this.updateFailedString.current()
-                        .then(str => this.toast.danger(str));
-                    reject(error);
-                }
-            );
-        });
-    }
-
-    editSelected = (maps: IdlObject[]) => {
-        const editOneThing = (map: IdlObject) => {
-            this.showEditDialog(map).then(
-                () => editOneThing(maps.shift()));
-        };
-        editOneThing(maps.shift());
-    }
-
-    deleteSelected = (idlThings: IdlObject[]) => {
-        idlThings.forEach(idlThing => idlThing.isdeleted(true));
-        this.pcrud.autoApply(idlThings).subscribe(
-            val => {
-                console.debug('deleted: ' + val);
-                this.deleteSuccessString.current()
-                    .then(str => this.toast.success(str));
-            },
-            err => {
-                this.deleteFailedString.current()
-                    .then(str => this.toast.danger(str));
-            },
-            ()  => this.grid.reload()
-        );
-    }
-
-    createNew = () => {
-        this.editDialog.mode = 'create';
-        this.editDialog.recordId = null;
-        this.editDialog.record = null;
-        this.editDialog.open({size: 'lg'}).subscribe(
-            ok => {
-                this.createString.current()
-                    .then(str => this.toast.success(str));
-                this.grid.reload();
-            },
-            rejection => {
-                if (!rejection.dismissed) {
-                    this.createErrString.current()
-                        .then(str => this.toast.danger(str));
-                }
-            }
-        );
-    }
-
- }
+export class CodedValueMapsComponent { }
index 36457f1..d42ea90 100644 (file)
@@ -6,6 +6,7 @@ import {CodedValueMapsComponent} from './coded-value-maps.component';
 import {CompositeDefComponent} from './composite-def.component';
 import {CompositeNewPointComponent} from './composite-new.component';
 import {CodedValueMapsRoutingModule} from './coded-value-maps-routing.module';
+import {AdminPageModule} from '@eg/staff/share/admin-page/admin-page.module';
 
 @NgModule({
   declarations: [
@@ -17,6 +18,7 @@ import {CodedValueMapsRoutingModule} from './coded-value-maps-routing.module';
     StaffCommonModule,
     FmRecordEditorModule,
     TreeModule,
+    AdminPageModule,
     CodedValueMapsRoutingModule
   ],
   exports: [
index d55a91d..58b940b 100644 (file)
     <eg-grid-column name="{{cf.name}}" [cellTemplate]="configFieldLink">
     </eg-grid-column>
   </ng-container>
+  <ng-container *ngFor="let tf of templateFields">
+    <eg-grid-column name="{{tf.name}}" [cellTemplate]="tf.template">
+    </eg-grid-column>
+  </ng-container>
 </eg-grid>
 
 <eg-fm-record-editor #editDialog idlClass="{{idlClass}}" 
index 9dda8f5..7098c70 100644 (file)
@@ -93,6 +93,11 @@ export class AdminPageComponent implements OnInit {
     // links to related tables via configField's.
     @Input() configLinkBasePath: string;
 
+    // Bonus fields to add to the grid by passing arbitrary templates,
+    // for example, a column created by callbacks based on data from
+    // other columns
+    @Input() templateFields: TemplateField[];
+
     @ViewChild('grid', { static: true }) grid: GridComponent;
     @ViewChild('editDialog', { static: true }) editDialog: FmRecordEditorComponent;
     @ViewChild('successString', { static: true }) successString: StringComponent;
@@ -497,4 +502,8 @@ export class AdminPageComponent implements OnInit {
     }
 }
 
+export interface TemplateField {
+    cellTemplate: TemplateRef<any>;
+    name: string;
+}