Attributes tab
authorMike Rylander <mrylander@gmail.com>
Fri, 27 Mar 2020 18:52:37 +0000 (14:52 -0400)
committerGalen Charlton <gmc@equinoxinitiative.org>
Fri, 27 Mar 2020 21:34:15 +0000 (17:34 -0400)
Signed-off-by: Mike Rylander <mrylander@gmail.com>
Signed-off-by: Galen Charlton <gmc@equinoxinitiative.org>
Open-ILS/src/eg2/src/app/staff/acq/provider/acq-provider.component.html
Open-ILS/src/eg2/src/app/staff/acq/provider/acq-provider.module.ts
Open-ILS/src/eg2/src/app/staff/acq/provider/provider-attributes.component.html [new file with mode: 0644]
Open-ILS/src/eg2/src/app/staff/acq/provider/provider-attributes.component.ts [new file with mode: 0644]
Open-ILS/src/eg2/src/app/staff/acq/provider/provider-record.service.ts

index 5187113..a140237 100644 (file)
@@ -49,7 +49,9 @@
         </ng-template>
       </ngb-tab>
       <ngb-tab title="Attribute Definitions" i18n-title id="attributes" [disabled]="!id">
-        <ng-template ngbTabContent>PROVIDER ATTRIBUTES TAB</ng-template>
+        <ng-template ngbTabContent>
+          <eg-provider-attributes></eg-provider-attributes>
+        </ng-template>
       </ngb-tab>
       <ngb-tab title="Holdings Definitions" i18n-title id="holdings" [disabled]="!id">
         <ng-template ngbTabContent>
index 368dc93..01fca1d 100644 (file)
@@ -9,6 +9,7 @@ import {ProviderDetailsComponent} from './provider-details.component';
 import {ProviderAddressesComponent} from './provider-addresses.component';
 import {ProviderContactsComponent} from './provider-contacts.component';
 import {ProviderHoldingsComponent} from './provider-holdings.component';
+import {ProviderAttributesComponent} from './provider-attributes.component';
 import {ProviderInvoicesComponent} from './provider-invoices.component';
 import {ProviderPurchaseOrdersComponent} from './provider-purchase-orders.component';
 import {OrgFamilySelectModule} from '@eg/share/org-family-select/org-family-select.module';
@@ -25,6 +26,7 @@ import {ProviderRecordService} from './provider-record.service';
     ProviderAddressesComponent,
     ProviderContactsComponent,
     ProviderHoldingsComponent,
+    ProviderAttributesComponent,
     ProviderInvoicesComponent,
     ProviderPurchaseOrdersComponent,
     AcqProviderSummaryPaneComponent
diff --git a/Open-ILS/src/eg2/src/app/staff/acq/provider/provider-attributes.component.html b/Open-ILS/src/eg2/src/app/staff/acq/provider/provider-attributes.component.html
new file mode 100644 (file)
index 0000000..9280f65
--- /dev/null
@@ -0,0 +1,26 @@
+<eg-string #createString i18n-text text="New Provider Attributes Added"></eg-string>
+<eg-string #createErrString i18n-text text="Failed to Create New Provider Attributes"></eg-string>
+<eg-string #successString i18n-text text="Provider Attributes Update Succeeded"></eg-string>
+<eg-string #updateFailedString i18n-text text="Provider Attributes Update Failed"></eg-string>
+<eg-string #deleteFailedString i18n-text text="Delete of Provider Attributes failed or was not allowed"></eg-string>
+<eg-string #deleteSuccessString i18n-text text="Delete of Provider Attributes succeeded"></eg-string>
+
+<eg-grid #acqProviderAttributesGrid
+  persistKey="acq.provider.attributes.grid"
+  idlClass="acqlipad" [dataSource]="gridSource"
+  [sortable]="true"
+  hideFields="provider"
+  [cellTextGenerator]="cellTextGenerator">
+
+  <eg-grid-toolbar-button label="New Attributes" 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
+  idlClass="acqlipad"
+  readonlyFields="id,provider"
+  fieldOrder="id,provider,code,description,xpath,remove,ident">
+</eg-fm-record-editor>
+
diff --git a/Open-ILS/src/eg2/src/app/staff/acq/provider/provider-attributes.component.ts b/Open-ILS/src/eg2/src/app/staff/acq/provider/provider-attributes.component.ts
new file mode 100644 (file)
index 0000000..a9a90b0
--- /dev/null
@@ -0,0 +1,178 @@
+import {Component, OnInit, AfterViewInit, Input, ViewChild} from '@angular/core';
+import {empty, throwError, Observable, from} from 'rxjs';
+import {map} from 'rxjs/operators';
+import {Router, ActivatedRoute, ParamMap} from '@angular/router';
+import {Pager} from '@eg/share/util/pager';
+import {IdlService, IdlObject} from '@eg/core/idl.service';
+import {NetService} from '@eg/core/net.service';
+import {AuthService} from '@eg/core/auth.service';
+import {GridComponent} from '@eg/share/grid/grid.component';
+import {GridDataSource, GridCellTextGenerator} from '@eg/share/grid/grid';
+import {ProviderRecordService} from './provider-record.service';
+import {AcqProviderSearchFormComponent} from './acq-provider-search-form.component';
+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({
+  selector: 'eg-provider-attributes',
+  templateUrl: 'provider-attributes.component.html',
+})
+export class ProviderAttributesComponent implements OnInit, AfterViewInit {
+
+    @Input() providerId: any;
+    attributes: any[] = [];
+
+    gridSource: GridDataSource;
+    @ViewChild('editDialog', { static: true }) editDialog: FmRecordEditorComponent;
+    @ViewChild('acqProviderAttributesGrid', { static: true }) providerAttributesGrid: GridComponent;
+    @ViewChild('successString', { static: true }) successString: StringComponent;
+    @ViewChild('createString', { static: false }) createString: StringComponent;
+    @ViewChild('createErrString', { static: false }) createErrString: StringComponent;
+    @ViewChild('updateFailedString', { static: false }) updateFailedString: StringComponent;
+    @ViewChild('deleteFailedString', { static: true }) deleteFailedString: StringComponent;
+    @ViewChild('deleteSuccessString', { static: true }) deleteSuccessString: StringComponent;
+
+    cellTextGenerator: GridCellTextGenerator;
+    provider: IdlObject;
+
+    canCreate: boolean;
+    canDelete: boolean;
+    deleteSelected: (rows: IdlObject[]) => void;
+
+    permissions: {[name: string]: boolean};
+
+    // Size of create/edito dialog.  Uses large by default.
+    @Input() dialogSize: 'sm' | 'lg' = 'lg';
+
+    constructor(
+        private router: Router,
+        private route: ActivatedRoute,
+        private net: NetService,
+        private auth: AuthService,
+        private idl: IdlService,
+        private providerRecord: ProviderRecordService,
+        private toast: ToastService) {
+
+    }
+
+    ngOnInit() {
+        this.gridSource = this.getDataSource()
+        this.cellTextGenerator = {};
+        this.deleteSelected = (idlThings: IdlObject[]) => {
+            idlThings.forEach(idlThing => idlThing.isdeleted(true));
+            this.providerRecord.batchUpdate(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.providerRecord.refreshCurrent().then(
+                        () => this.providerAttributesGrid.reload()
+                    );
+                }
+            );
+        };
+        this.providerAttributesGrid.onRowActivate.subscribe(
+            (idlThing: IdlObject) => this.showEditDialog(idlThing)
+        );
+    }
+
+    ngAfterViewInit() {
+        console.log('this.providerRecord',this.providerRecord);
+    }
+
+    getDataSource(): GridDataSource {
+        const gridSource = new GridDataSource();
+
+        gridSource.getRows = (pager: Pager, sort: any[]) => {
+            this.provider = this.providerRecord.current();
+            if (!this.provider) {
+                return empty();
+            }
+            let attributes = this.provider.attributes()
+
+            if (sort.length > 0) {
+                attributes = attributes.sort((a, b) => {
+                    for (let i = 0; i < sort.length; i++) {
+                        let lt = -1;
+                        let sfield = sort[i].name;
+                        if (sort[i].dir.substring(0,1).toLowerCase() === 'd') {
+                            lt *= -1;
+                        }
+                        if (a[sfield]() < b[sfield]()) { return lt }
+                        if (a[sfield]() > b[sfield]()) { return lt * -1 }
+                    }
+                    return 0;
+                });
+
+            }
+
+            return from(attributes.slice(pager.offset, pager.offset + pager.limit - 1));
+        };
+        return gridSource;
+    }
+
+    showEditDialog(providerAttribute: IdlObject): Promise<any> {
+        this.editDialog.mode = 'update';
+        this.editDialog.recordId = providerAttribute['id']();
+        return new Promise((resolve, reject) => {
+            this.editDialog.open({size: this.dialogSize}).subscribe(
+                result => {
+                    this.successString.current()
+                        .then(str => this.toast.success(str));
+                    this.providerRecord.refreshCurrent().then(
+                        () => this.providerAttributesGrid.reload()
+                    );
+                    resolve(result);
+                },
+                error => {
+                    this.updateFailedString.current()
+                        .then(str => this.toast.danger(str));
+                    reject(error);
+                }
+            );
+        });
+    }
+
+    editSelected(providerAttributesFields: IdlObject[]) {
+        // Edit each IDL thing one at a time
+        const editOneThing = (providerAttributes: IdlObject) => {
+            if (!providerAttributes) { return; }
+
+            this.showEditDialog(providerAttributes).then(
+                () => editOneThing(providerAttributesFields.shift()));
+        };
+
+        editOneThing(providerAttributesFields.shift());
+    }
+
+    createNew() {
+        this.editDialog.mode = 'create';
+        const attributes = this.idl.create('acqlipad');
+        attributes.provider(this.provider.id());
+        this.editDialog.record = attributes;
+        this.editDialog.recordId = null;
+        this.editDialog.open({size: this.dialogSize}).subscribe(
+            ok => {
+                this.createString.current()
+                    .then(str => this.toast.success(str));
+                this.providerRecord.refreshCurrent().then(
+                    () => this.providerAttributesGrid.reload()
+                );
+            },
+            rejection => {
+                if (!rejection.dismissed) {
+                    this.createErrString.current()
+                        .then(str => this.toast.danger(str));
+                }
+            }
+        );
+    }
+}
index 4ab5c89..a0886cb 100644 (file)
@@ -39,10 +39,11 @@ export class ProviderRecordService {
         return this.pcrud.search('acqpro', { id: id },
             {
                 flesh: 3,
-                flesh_fields: { acqpro: ['holdings_subfields', 'contacts', 'addresses', 'provider_notes'],
-                                acqpa:  ['provider'],
-                                acqpc:  ['provider'],
-                                acqphsm:['provider'],
+                flesh_fields: { acqpro:  ['attributes','holdings_subfields', 'contacts', 'addresses', 'provider_notes'],
+                                acqpa:   ['provider'],
+                                acqpc:   ['provider'],
+                                acqphsm: ['provider'],
+                                acqlipad:['provider'],
                               }
             },
             {}