LP#626157 Ang2 experiments
authorBill Erickson <berickxx@gmail.com>
Mon, 4 Dec 2017 21:49:46 +0000 (16:49 -0500)
committerBill Erickson <berickxx@gmail.com>
Mon, 11 Dec 2017 17:39:51 +0000 (12:39 -0500)
Signed-off-by: Bill Erickson <berickxx@gmail.com>
Open-ILS/webby-src/src/app/share/catalog/search-context.ts
Open-ILS/webby-src/src/app/staff/catalog/catalog.component.html
Open-ILS/webby-src/src/app/staff/catalog/catalog.component.ts
Open-ILS/webby-src/src/app/staff/catalog/result/results.component.ts
Open-ILS/webby-src/src/app/staff/catalog/search-form.component.ts

index 1599ff7..1ac63a3 100644 (file)
@@ -155,8 +155,8 @@ export class CatalogSearchContext {
      * router.navigate(..., {queryParams:...}).  
      * No navigation is performed within.
      */
-    toUrl(): any {
-        let query = {};
+    toUrlParams(): any {
+        let query = {query : ['piano']}; // TODO
 
         return query;
     }
@@ -165,8 +165,8 @@ export class CatalogSearchContext {
      * Absorbs URL values from the active route and applies them to 
      * this search context instance.
      */
-    fromUrl(params: Params): void {
-        //queryParamMap
+    fromUrlParams(params: Params): void {
+        console.log('checking params with query ' + params.query);
     }
 }
 
index 2d4c9b1..1596454 100644 (file)
@@ -1,5 +1,6 @@
 <!-- search form sits atop every catalog page -->
 <eg-catalog-search-form></eg-catalog-search-form>
 
+<!-- search results, record details, etc. -->
 <router-outlet></router-outlet>
 
index e75fc89..67aa072 100644 (file)
@@ -1,15 +1,30 @@
 import {Component, OnInit} from '@angular/core';
 import {Observable} from 'rxjs/Rx';
 import {ActivatedRoute} from '@angular/router';
+import {EgCatalogService} from '@eg/share/catalog/catalog.service';
+import {CatalogSearchContext} from '@eg/share/catalog/search-context';
 
 @Component({
   templateUrl: 'catalog.component.html'
 })
 export class EgCatalogComponent implements OnInit {
 
-    constructor(private route: ActivatedRoute) {}
+    searchContext: CatalogSearchContext;
+
+    constructor(
+        private route: ActivatedRoute,
+        private cat: EgCatalogService
+    ) {}
 
     ngOnInit() {
+
+        // TODO: MOVE THIS OUT OF THE CAT SERVICE
+        // and pass it down to each child component that needs
+        // it via @Input.
+        this.searchContext = this.cat.searchContext;
+
+        // Sync the context with the load-time URL params.
+        this.searchContext.fromUrlParams(this.route.snapshot.queryParams);
     }
 
 }
index 045c050..2c5db57 100644 (file)
@@ -1,7 +1,10 @@
 import {Component, OnInit, Input} from '@angular/core';
+import {ActivatedRoute} from '@angular/router';
 import {EgCatalogService} from '@eg/share/catalog/catalog.service';
 import {CatalogSearchContext} from '@eg/share/catalog/search-context';
 
+import {EgOrgService} from '@eg/core/org';
+
 @Component({
   selector: 'eg-catalog-results',
   styleUrls: ['results.component.css'],
@@ -12,11 +15,26 @@ export class ResultsComponent implements OnInit {
     searchContext: CatalogSearchContext;
 
     constructor(
+        private org: EgOrgService,
         private cat: EgCatalogService
     ) {}
 
     ngOnInit() { 
         this.searchContext = this.cat.searchContext;
+        this.searchByUrl();
+    }
+
+    searchByUrl(): void {
+        // skip searching when there's no query, etc.
+
+        this.searchContext.searchOrg = this.org.get(4); // TODO: testing
+
+        if (!this.searchContext.query[0]) return;
+
+        this.cat.search(this.searchContext).then(ok => {
+            console.debug('search complete');
+        });
+
     }
 
 }
index 9148e25..53b2c96 100644 (file)
@@ -1,5 +1,5 @@
 import {Component, OnInit} from '@angular/core';
-import {ActivatedRoute} from '@angular/router';
+import {Router, ActivatedRoute} from '@angular/router';
 import {EgIdlObject} from '@eg/core/idl';
 import {EgOrgService} from '@eg/core/org';
 import {EgCatalogService} from '@eg/share/catalog/catalog.service';
@@ -18,6 +18,7 @@ export class SearchFormComponent implements OnInit {
     showAdvancedSearch: boolean = false;
 
     constructor(
+        private router: Router,
         private route: ActivatedRoute,
         private org: EgOrgService,
         private cat: EgCatalogService
@@ -27,11 +28,6 @@ export class SearchFormComponent implements OnInit {
         this.ccvmMap = this.cat.ccvmMap;
         this.cmfMap = this.cat.cmfMap;
         this.searchContext = this.cat.searchContext;
-
-        // Sync the context with the load-time URL params and launch
-        // a new search if necessary.
-        this.searchContext.fromUrl(this.route.snapshot.queryParams);
-        this.searchByUrl();
     }
 
     addSearchRow(index: number): void {
@@ -60,14 +56,17 @@ export class SearchFormComponent implements OnInit {
        return index;
     }
 
+    /**
+     * Redirect to the search results page while propagating the current
+     * search paramters into the URL.  Let the search results component
+     * execute the actual search.
+     */
     searchByForm(): void {
         this.searchContext.searchOrg = this.org.get(4); // TODO: TEST BR1
-        this.cat.search(this.searchContext).then(ok => {
-            console.debug('search complete');
-        });
-    }
-
-    searchByUrl(): void {
+        this.router.navigate(
+            ['/staff/catalog/search'],
+            {queryParams: this.searchContext.toUrlParams()}
+        )
     }
 
 }