LP#1942220: implement Export Single Attribute List from LI Search
authorGalen Charlton <gmc@equinoxOLI.org>
Tue, 14 Dec 2021 15:43:09 +0000 (10:43 -0500)
committerGalen Charlton <gmc@equinoxOLI.org>
Tue, 14 Dec 2021 15:43:09 +0000 (10:43 -0500)
Also do a bit of refactoring; LineitemService will include more
of the meat of each action, leaving it to the caller to stage
parameters.

Signed-off-by: Galen Charlton <gmc@equinoxOLI.org>
Open-ILS/src/eg2/src/app/staff/acq/lineitem/lineitem-list.component.ts
Open-ILS/src/eg2/src/app/staff/acq/lineitem/lineitem.service.ts
Open-ILS/src/eg2/src/app/staff/acq/search/acq-search.module.ts
Open-ILS/src/eg2/src/app/staff/acq/search/lineitem-results.component.html
Open-ILS/src/eg2/src/app/staff/acq/search/lineitem-results.component.ts

index 83ee4ba..54ea3aa 100644 (file)
@@ -18,7 +18,6 @@ import {AddCopiesDialogComponent} from './add-copies-dialog.component';
 import {LinkInvoiceDialogComponent} from './link-invoice-dialog.component';
 import {ExportAttributesDialogComponent} from './export-attributes-dialog.component';
 import {ClaimPolicyDialogComponent} from './claim-policy-dialog.component';
-import {saveAs} from 'file-saver';
 
 const DELETABLE_STATES = [
     'new', 'selector-ready', 'order-ready', 'approved', 'pending-order'
@@ -716,21 +715,7 @@ export class LineitemListComponent implements OnInit {
         this.exportAttributesDialog.open().subscribe(attr => {
             if (!attr) { return; }
 
-            const values: string[] = [];
-            this.liService.getFleshedLineitems(ids, { fromCache: true }).subscribe(
-                li => values.push(this.displayAttr(li.lineitem, attr)),
-                err => {},
-                () => {
-                    const filtered = values.filter(x => x !== '');
-                    saveAs(
-                        new Blob(
-                            [ filtered.join('\n') + '\n' ],
-                            { type: 'text/plain;charset=utf-8' }
-                        ),
-                        'export_attr_list.txt'
-                    );
-                }
-            );
+            this.liService.doExportSingleAttributeList(ids, attr);
         });
     }
 
index 928ee9b..faaf3be 100644 (file)
@@ -7,6 +7,7 @@ import {AuthService} from '@eg/core/auth.service';
 import {PcrudService} from '@eg/core/pcrud.service';
 import {ComboboxEntry} from '@eg/share/combobox/combobox.component';
 import {ItemLocationService} from '@eg/share/item-location-select/item-location-select.service';
+import {saveAs} from 'file-saver';
 
 const COPY_ORDER_DISPOSITIONS:
     'canceled' | 'delayed' | 'received' | 'on-order' | 'pre-order' = null;
@@ -437,5 +438,24 @@ export class LineitemService {
                 return li.id();
         }
     }
+
+    doExportSingleAttributeList(ids: number[], attr: string) {
+        if (!attr) { return; }
+        const values: string[] = [];
+        this.getFleshedLineitems(ids, { fromCache: true }).subscribe(
+            li => values.push(this.getFirstAttributeValue(li.lineitem, attr, 'lineitem_marc_attr_definition')),
+            err => {},
+            () => {
+                const filtered = values.filter(x => x !== '');
+                saveAs(
+                    new Blob(
+                        [ filtered.join('\n') + '\n' ],
+                        { type: 'text/plain;charset=utf-8' }
+                    ),
+                    'export_attr_list.txt'
+                );
+            }
+        );
+    }
 }
 
index 1fea224..05226d5 100644 (file)
@@ -12,6 +12,7 @@ import {PicklistCloneDialogComponent} from './picklist-clone-dialog.component';
 import {PicklistDeleteDialogComponent} from './picklist-delete-dialog.component';
 import {PicklistMergeDialogComponent} from './picklist-merge-dialog.component';
 import {AcqSearchService} from './acq-search.service';
+import {LineitemModule} from '@eg/staff/acq/lineitem/lineitem.module';
 
 @NgModule({
   declarations: [
@@ -28,7 +29,8 @@ import {AcqSearchService} from './acq-search.service';
   ],
   imports: [
     StaffCommonModule,
-    AcqSearchRoutingModule
+    AcqSearchRoutingModule,
+    LineitemModule
   ],
   providers: [AcqSearchService]
 })
index f980421..93d4b33 100644 (file)
@@ -2,6 +2,8 @@
   i18n-searchTypeLabel searchTypeLabel="Line Item" runImmediatelySetting="eg.acq.search.lineitems.run_immediately"
   defaultSearchSetting="eg.acq.search.default.lineitems"></eg-acq-search-form>
 
+<eg-acq-export-attributes-dialog #exportAttributesDialog></eg-acq-export-attributes-dialog>
+
 <ng-template #idTmpl let-lineitem="row">
 
   <ng-container>
index bf5f983..9fcb40d 100644 (file)
@@ -9,6 +9,8 @@ import {AuthService} from '@eg/core/auth.service';
 import {GridComponent} from '@eg/share/grid/grid.component';
 import {GridDataSource, GridCellTextGenerator} from '@eg/share/grid/grid';
 import {AcqSearchService, AcqSearchTerm, AcqSearch} from './acq-search.service';
+import {LineitemService} from '../lineitem/lineitem.service';
+import {ExportAttributesDialogComponent} from '../lineitem/export-attributes-dialog.component';
 import {AcqSearchFormComponent} from './acq-search-form.component';
 
 @Component({
@@ -22,6 +24,7 @@ export class LineitemResultsComponent implements OnInit {
     gridSource: GridDataSource;
     @ViewChild('acqSearchForm', { static: true}) acqSearchForm: AcqSearchFormComponent;
     @ViewChild('acqSearchLineitemsGrid', { static: true }) lineitemResultsGrid: GridComponent;
+    @ViewChild('exportAttributesDialog') exportAttributesDialog: ExportAttributesDialogComponent;
 
     noSelectedRows: (rows: IdlObject[]) => boolean;
 
@@ -32,6 +35,7 @@ export class LineitemResultsComponent implements OnInit {
         private route: ActivatedRoute,
         private net: NetService,
         private auth: AuthService,
+        private liService: LineitemService,
         private acqSearch: AcqSearchService) {
     }
 
@@ -74,4 +78,14 @@ export class LineitemResultsComponent implements OnInit {
         window.open('/eg2/staff/acq/po/' + row.purchase_order().id() +
                     '/lineitem/' + row.id() + '/worksheet', '_blank');
     }
+
+    exportSingleAttributeList(rows: IdlObject[]) {
+        const ids = rows.map(x => Number(x.id()));
+        this.exportAttributesDialog.ids = ids;
+        this.exportAttributesDialog.open().subscribe(attr => {
+            if (!attr) { return; }
+
+            this.liService.doExportSingleAttributeList(ids, attr);
+        });
+    }
 }