Revert "LP#1945385: use eg-admin-page for circ limit sets admin UI"
authorJason Stephenson <jason@sigio.com>
Tue, 19 Jul 2022 18:18:29 +0000 (14:18 -0400)
committerJason Stephenson <jason@sigio.com>
Tue, 19 Jul 2022 18:20:53 +0000 (14:20 -0400)
This reverts commit 5380bfb11a3a38bac521ce8ef92216c13d46f3b9.

The reverted code raises the following error in 3.7:

ERROR in
src/app/staff/admin/local/circ_limit_set/circ_limit_set.component.html:4:32
- error NG8002: Can't bind to 'templateFields' since it isn't a known
property of 'eg-admin-page'.

Signed-off-by: Jason Stephenson <jason@sigio.com>
Open-ILS/src/eg2/src/app/staff/admin/local/circ_limit_set/circ_limit_set.component.html
Open-ILS/src/eg2/src/app/staff/admin/local/circ_limit_set/circ_limit_set.component.ts
Open-ILS/src/eg2/src/app/staff/admin/local/circ_limit_set/circ_limit_set.module.ts
Open-ILS/src/eg2/src/app/staff/admin/local/circ_limit_set/circ_limit_set_edit.component.ts

index 44fc39b..58340e7 100644 (file)
@@ -1,14 +1,26 @@
 <eg-staff-banner bannerText="Circulation Limit Set Administration" i18n-bannerText>
   </eg-staff-banner>
 
-<eg-admin-page idlClass="ccls" [templateFields]="[{name: 'Linked Entities', template: cclsLinkedEntitiesTmpl}]"></eg-admin-page>
+<eg-string #createFailedString i18n-text text="Created Circulation Limit 
+  Set"></eg-string>
+<eg-string #createSuccessString i18n-text text="Failed to Create Circulation 
+  Limit Set"></eg-string>
+<eg-string #deleteFailedString i18n-text text="Delete of Circulation Limit Set 
+  failed or was not allowed"></eg-string>
+<eg-string #deleteSuccessString i18n-text text="Delete of Circulation Limit Set
+  succeeded"></eg-string>
+<eg-string #updateSuccessString i18n-text text="Circulation Limit Set Update 
+  Succeeded"></eg-string>
+<eg-string #updateFailedString i18n-text text="Circulation Limit Set 
+  Update Failed"></eg-string>
 
-<ng-template #cclsLinkedEntitiesTmpl let-row="row">
-  <div>
-    <a routerLink="/staff/admin/local/config/circ_limit_set/{{row.id()}}">
-      Manage
-    </a>
-  </div>
-</ng-template>
+<eg-grid #grid idlClass="ccls" [dataSource]="gridDataSource" hideFields="id">
+  <eg-grid-toolbar-button label="New Circulation Limit Set" i18n-label 
+    (onClick)="createNew()"></eg-grid-toolbar-button>
+  <eg-grid-toolbar-action label="Edit Selected" i18n-label 
+    (onClick)="editSelected($event)"></eg-grid-toolbar-action>
+  <eg-grid-toolbar-action label="Delete Selected" i18n-label 
+    (onClick)="deleteSelected($event)"></eg-grid-toolbar-action>
+</eg-grid>
 
 <eg-fm-record-editor #editDialog hiddenFields="id" idlClass="ccls"></eg-fm-record-editor>
index ce28023..f38a9df 100644 (file)
@@ -1,7 +1,123 @@
-import {Component} from '@angular/core';
+import {Pager} from '@eg/share/util/pager';
+import {Component, OnInit, Input, ViewChild} from '@angular/core';
+import {GridComponent} from '@eg/share/grid/grid.component';
+import {GridDataSource} from '@eg/share/grid/grid';
+import {Router} from '@angular/router';
+import {IdlObject} from '@eg/core/idl.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 {ToastService} from '@eg/share/toast/toast.service';
 
 @Component({
     templateUrl: './circ_limit_set.component.html'
 })
 
-export class CircLimitSetComponent { }
+export class CircLimitSetComponent implements OnInit {
+
+    recId: number;
+    gridDataSource: GridDataSource;
+    initDone = false;
+    cspSource: GridDataSource = new GridDataSource();
+
+    @ViewChild('editDialog', {static: true}) editDialog: FmRecordEditorComponent;
+    @ViewChild('grid', {static: true}) grid: GridComponent;
+    @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('createSuccessString', {static: true}) createSuccessString: StringComponent;
+    @ViewChild('createErrString', {static: true}) createErrString: StringComponent;
+
+    @Input() dialogSize: 'sm' | 'lg' = 'lg';
+
+    constructor(
+        private pcrud: PcrudService,
+        private toast: ToastService,
+        private router: Router
+    ) {
+        this.gridDataSource = new GridDataSource();
+    }
+
+    ngOnInit() {
+        this.gridDataSource.getRows = (pager: Pager, sort: any[]) => {
+            const orderBy: any = {};
+            const searchOps = {
+                offset: pager.offset,
+                limit: pager.limit,
+                order_by: orderBy
+            };
+            return this.pcrud.retrieveAll('ccls', searchOps, {fleshSelectors: true});
+        };
+
+        this.grid.onRowActivate.subscribe(
+            (set: IdlObject) => {
+                const idToEdit = set.id();
+                this.navigateToEditPage(idToEdit);
+            }
+        );
+    }
+
+    deleteSelected = (idlThings: IdlObject[]) => {
+        idlThings.forEach(idlThing => idlThing.isdeleted(true));
+        this.pcrud.autoApply(idlThings).subscribe(
+            val => {
+                this.deleteSuccessString.current()
+                    .then(str => this.toast.success(str));
+            },
+            err => {
+                this.deleteFailedString.current()
+                    .then(str => this.toast.danger(str));
+            },
+            ()  => this.grid.reload()
+        );
+    }
+
+    editSelected(sets: IdlObject[]) {
+        const idToEdit = sets[0].id();
+        this.navigateToEditPage(idToEdit);
+    }
+
+    navigateToEditPage(id: any) {
+        this.router.navigate(['/staff/admin/local/config/circ_limit_set/' + id]);
+    }
+
+    createNew() {
+        this.editDialog.mode = 'create';
+        this.editDialog.recordId = null;
+        this.editDialog.record = null;
+        this.editDialog.open({size: this.dialogSize}).subscribe(
+            ok => {
+                this.createSuccessString.current()
+                    .then(str => this.toast.success(str));
+                this.grid.reload();
+            },
+            rejection => {
+                if (!rejection.dismissed) {
+                    this.createErrString.current()
+                        .then(str => this.toast.danger(str));
+                }
+            }
+        );
+    }
+
+    showEditDialog(standingPenalty: IdlObject): Promise<any> {
+        this.editDialog.mode = 'update';
+        this.editDialog.recordId = standingPenalty['id']();
+        return new Promise((resolve, reject) => {
+            this.editDialog.open({size: this.dialogSize}).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);
+                }
+            );
+        });
+    }
+}
index 8149691..e7cf75a 100644 (file)
@@ -4,7 +4,6 @@ import {CircLimitSetComponent} from './circ_limit_set.component';
 import {CircLimitSetEditComponent} from './circ_limit_set_edit.component';
 import {CircLimitSetRoutingModule} from './circ_limit_set_routing.module';
 import {ItemLocationSelectModule} from '@eg/share/item-location-select/item-location-select.module';
-import {AdminPageModule} from '@eg/staff/share/admin-page/admin-page.module';
 
 @NgModule({
   declarations: [
@@ -13,7 +12,6 @@ import {AdminPageModule} from '@eg/staff/share/admin-page/admin-page.module';
   ],
   imports: [
     AdminCommonModule,
-    AdminPageModule,
     CircLimitSetRoutingModule,
     ItemLocationSelectModule,
   ],
index be81a1c..a8dd48e 100644 (file)
@@ -25,7 +25,7 @@ export class CircLimitSetEditComponent  implements OnInit {
     selectedLimitGroup: any;
     locId = 0;
 
-    circTab: 'limitSet' | 'linked' = 'linked';
+    circTab: 'limitSet' | 'linked' = 'limitSet';
 
     @ViewChild('addingSuccess', {static: true}) addingSuccess: StringComponent;
     @ViewChild('removingSuccess', {static: true}) removingSuccess: StringComponent;