Basket view uses search results page
authorBill Erickson <berickxx@gmail.com>
Thu, 15 Nov 2018 21:31:47 +0000 (16:31 -0500)
committerBill Erickson <berickxx@gmail.com>
Fri, 30 Nov 2018 16:34:20 +0000 (11:34 -0500)
Signed-off-by: Bill Erickson <berickxx@gmail.com>
Open-ILS/src/eg2/src/app/share/catalog/catalog-url.service.ts
Open-ILS/src/eg2/src/app/share/catalog/catalog.service.ts
Open-ILS/src/eg2/src/app/share/catalog/search-context.ts
Open-ILS/src/eg2/src/app/staff/catalog/basket-actions.component.html
Open-ILS/src/eg2/src/app/staff/catalog/basket-actions.component.ts
Open-ILS/src/eg2/src/app/staff/catalog/basket/basket.component.html [deleted file]
Open-ILS/src/eg2/src/app/staff/catalog/basket/basket.component.ts [deleted file]
Open-ILS/src/eg2/src/app/staff/catalog/catalog.module.ts
Open-ILS/src/eg2/src/app/staff/catalog/routing.module.ts

index 253e3aa..5b39750 100644 (file)
@@ -40,7 +40,8 @@ export class CatalogUrlService {
         }
 
         // These fields can be copied directly into place
-        ['format', 'sort', 'available', 'global', 'identQuery', 'identQueryType']
+        ['format', 'sort', 'available', 'global', 'identQuery', 
+            'identQueryType', 'basket']
         .forEach(field => {
             if (context[field]) {
                 // Only propagate applied values to the URL.
@@ -99,7 +100,8 @@ export class CatalogUrlService {
         context.reset();
 
         // These fields can be copied directly into place
-        ['format', 'sort', 'available', 'global', 'identQuery', 'identQueryType']
+        ['format', 'sort', 'available', 'global', 'identQuery', 
+            'identQueryType', 'basket']
         .forEach(field => {
             const val = params.get(field);
             if (val !== null) {
index 2dc07c5..c513407 100644 (file)
@@ -9,6 +9,7 @@ import {NetService} from '@eg/core/net.service';
 import {PcrudService} from '@eg/core/pcrud.service';
 import {CatalogSearchContext, CatalogSearchState} from './search-context';
 import {BibRecordService, BibRecordSummary} from './bib-record.service';
+import {BasketService} from './basket.service';
 
 // CCVM's we care about in a catalog context
 // Don't fetch them all because there are a lot.
@@ -46,7 +47,8 @@ export class CatalogService {
         private org: OrgService,
         private unapi: UnapiService,
         private pcrud: PcrudService,
-        private bibService: BibRecordService
+        private bibService: BibRecordService,
+        private basket: BasketService
     ) {
         this.onSearchComplete = new EventEmitter<CatalogSearchContext>();
         
@@ -55,6 +57,33 @@ export class CatalogService {
     search(ctx: CatalogSearchContext): Promise<void> {
         ctx.searchState = CatalogSearchState.SEARCHING;
 
+        if (ctx.basket) {
+            return this.basketSearch(ctx);
+        } else {
+            return this.querySearch(ctx);
+        }
+    }
+
+    // "Search" the basket by loading the IDs and treating
+    // them like a standard query search results set.
+    basketSearch(ctx: CatalogSearchContext): Promise<void> {
+
+        return this.basket.getRecordIds().then(ids => {
+
+            // Map our list of IDs into a search results object
+            // the search context can understand.
+            const result = {
+                count: ids.length,
+                ids: ids.map(id => [id])
+            };
+
+            this.applyResultData(ctx, result);
+            ctx.searchState = CatalogSearchState.COMPLETE;
+            this.onSearchComplete.emit(ctx);
+        });
+    }
+
+    querySearch(ctx: CatalogSearchContext): Promise<void> {
         const fullQuery = ctx.compileSearch();
 
         console.debug(`search query: ${fullQuery}`);
@@ -77,6 +106,7 @@ export class CatalogService {
                 resolve();
             });
         });
+
     }
 
     applyResultData(ctx: CatalogSearchContext, result: any): void {
index e4e64b2..52ad4bc 100644 (file)
@@ -48,6 +48,7 @@ export class CatalogSearchContext {
     ccvmFilters: {[ccvmCode: string]: string[]};
     facetFilters: FacetFilter[];
     isStaff: boolean;
+    basket = false;
 
     // Result from most recent search.
     result: any = {};
@@ -118,10 +119,15 @@ export class CatalogSearchContext {
         this.result = {};
         this.resultIds = [];
         this.searchState = CatalogSearchState.PENDING;
+        this.basket = false;
     }
 
     isSearchable(): boolean {
 
+        if (this.basket) {
+            return true;
+        }
+
         if (this.identQuery && this.identQueryType) {
             return true;
         }
index 2485a39..aa69477 100644 (file)
@@ -2,7 +2,9 @@
 <div class="row">
   <div class="col-lg-4 pr-1">
     <div class="float-right">
-      <a routerLink="/staff/catalog/basket" class="label-with-material-icon">
+      <!-- note basket view link does not propagate search params -->
+      <a routerLink="/staff/catalog/search" [queryParams]="{basket: true}" 
+        class="label-with-material-icon">
         <span class="material-icons">shopping_basket</span>
         <span i18n>({{basketCount()}})</span>
       </a>
index d79d309..fd225f1 100644 (file)
@@ -30,7 +30,9 @@ export class BasketActionsComponent implements OnInit {
 
         switch(this.basketAction) {
             case 'view':
-                this.router.navigate(['/staff/catalog/basket']);
+                // This does not propagate search params -- unclear if needed.
+                this.router.navigate(['/staff/catalog/search'], 
+                    {queryParams: {basket: true}});
                 break;
 
             case 'clear':
diff --git a/Open-ILS/src/eg2/src/app/staff/catalog/basket/basket.component.html b/Open-ILS/src/eg2/src/app/staff/catalog/basket/basket.component.html
deleted file mode 100644 (file)
index 7a64033..0000000
+++ /dev/null
@@ -1,20 +0,0 @@
-<div class="row">
-  <div class="col-lg-4">
-    <h3 i18n>Basket View</h3>
-  </div>
-  <div class="col-lg-8">
-    <div class="float-right">
-      <eg-catalog-result-pagination></eg-catalog-result-pagination>
-    </div>
-  </div>
-</div>
-<div class="row" 
-    *ngFor="let summary of searchContext.result.records; let idx = index">
-  <div class="col-lg-12">
-    <ng-container *ngIf="summary">
-      <eg-catalog-result-record [summary]="summary" [index]="idx">
-      </eg-catalog-result-record>
-    </ng-container>
-  </div>
-</div>
-
diff --git a/Open-ILS/src/eg2/src/app/staff/catalog/basket/basket.component.ts b/Open-ILS/src/eg2/src/app/staff/catalog/basket/basket.component.ts
deleted file mode 100644 (file)
index 50affa8..0000000
+++ /dev/null
@@ -1,60 +0,0 @@
-import {Component, OnInit, OnDestroy, Input} from '@angular/core';
-import {Router} from '@angular/router';
-import {Observable} from 'rxjs/Observable';
-import {Subscription} from 'rxjs/Subscription';
-import {BibRecordService} from '@eg/share/catalog/bib-record.service';
-import {CatalogService} from '@eg/share/catalog/catalog.service';
-import {StaffCatalogService} from '../catalog.service';
-import {CatalogSearchContext, CatalogSearchState} from '@eg/share/catalog/search-context';
-import {BasketService} from '@eg/share/catalog/basket.service';
-
-@Component({
-  selector: 'eg-catalog-basket',
-  templateUrl: 'basket.component.html'
-})
-export class BasketComponent implements OnInit, OnDestroy {
-
-    searchContext: CatalogSearchContext;
-
-    constructor(
-        private router: Router,
-        private bib: BibRecordService,
-        private cat: CatalogService,
-        private staffCat: StaffCatalogService,
-        private basket: BasketService
-    ) {}
-
-    ngOnInit() {
-        this.searchContext = this.staffCat.searchContext;
-
-        this.basket.getRecordIds().then(ids => {
-
-            // Bypass the standard catalog search by providing a 
-            // search result object of our own.
-            // Map our list of IDs into a search results object
-            // the search context can understand.
-            const result = {
-                count: ids.length,
-                ids: ids.map(id => [id])
-            };
-
-            this.searchContext.reset();
-            this.cat.applyResultData(this.searchContext, result);
-            this.cat.fetchBibSummaries(this.searchContext)
-                .then(ok => this.fleshSearchResults());
-
-        });
-    }
-
-    ngOnDestroy() {
-    }
-
-    fleshSearchResults(): void {
-        const records = this.searchContext.result.records;
-        if (!records || records.length === 0) { return; }
-        // Flesh the creator / editor fields with the user object.
-        this.bib.fleshBibUsers(records.map(r => r.record));
-    }
-}
-
-
index 172a829..e490da2 100644 (file)
@@ -15,7 +15,6 @@ import {RecordPaginationComponent} from './record/pagination.component';
 import {RecordActionsComponent} from './record/actions.component';
 import {HoldingsService} from '@eg/staff/share/holdings.service';
 import {BasketActionsComponent} from './basket-actions.component';
-import {BasketComponent} from './basket/basket.component';
 
 @NgModule({
   declarations: [
@@ -29,8 +28,7 @@ import {BasketComponent} from './basket/basket.component';
     ResultPaginationComponent,
     RecordPaginationComponent,
     RecordActionsComponent,
-    BasketActionsComponent,
-    BasketComponent
+    BasketActionsComponent
   ],
   imports: [
     StaffCommonModule,
index d92bcf6..0e3c96f 100644 (file)
@@ -4,7 +4,6 @@ import {CatalogComponent} from './catalog.component';
 import {ResultsComponent} from './result/results.component';
 import {RecordComponent} from './record/record.component';
 import {CatalogResolver} from './resolver.service';
-import {BasketComponent} from './basket/basket.component';
 
 const routes: Routes = [{
   path: '',
@@ -14,9 +13,6 @@ const routes: Routes = [{
     path: 'search',
     component: ResultsComponent
   }, {
-    path: 'basket',
-    component: BasketComponent
-  }, {
     path: 'record/:id',
     component: RecordComponent
   }, {