From ab722be1767ad603f554314bf03375d85177224b Mon Sep 17 00:00:00 2001 From: Bill Erickson Date: Mon, 4 Dec 2017 16:49:46 -0500 Subject: [PATCH] LP#626157 Ang2 experiments Signed-off-by: Bill Erickson --- .../src/app/share/catalog/search-context.ts | 8 ++++---- .../src/app/staff/catalog/catalog.component.html | 1 + .../src/app/staff/catalog/catalog.component.ts | 17 +++++++++++++++- .../app/staff/catalog/result/results.component.ts | 18 +++++++++++++++++ .../src/app/staff/catalog/search-form.component.ts | 23 +++++++++++----------- 5 files changed, 50 insertions(+), 17 deletions(-) diff --git a/Open-ILS/webby-src/src/app/share/catalog/search-context.ts b/Open-ILS/webby-src/src/app/share/catalog/search-context.ts index 1599ff7058..1ac63a39d0 100644 --- a/Open-ILS/webby-src/src/app/share/catalog/search-context.ts +++ b/Open-ILS/webby-src/src/app/share/catalog/search-context.ts @@ -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); } } diff --git a/Open-ILS/webby-src/src/app/staff/catalog/catalog.component.html b/Open-ILS/webby-src/src/app/staff/catalog/catalog.component.html index 2d4c9b1fd5..1596454ac1 100644 --- a/Open-ILS/webby-src/src/app/staff/catalog/catalog.component.html +++ b/Open-ILS/webby-src/src/app/staff/catalog/catalog.component.html @@ -1,5 +1,6 @@ + diff --git a/Open-ILS/webby-src/src/app/staff/catalog/catalog.component.ts b/Open-ILS/webby-src/src/app/staff/catalog/catalog.component.ts index e75fc89ec8..67aa0723bd 100644 --- a/Open-ILS/webby-src/src/app/staff/catalog/catalog.component.ts +++ b/Open-ILS/webby-src/src/app/staff/catalog/catalog.component.ts @@ -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); } } diff --git a/Open-ILS/webby-src/src/app/staff/catalog/result/results.component.ts b/Open-ILS/webby-src/src/app/staff/catalog/result/results.component.ts index 045c050467..2c5db57a1f 100644 --- a/Open-ILS/webby-src/src/app/staff/catalog/result/results.component.ts +++ b/Open-ILS/webby-src/src/app/staff/catalog/result/results.component.ts @@ -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'); + }); + } } diff --git a/Open-ILS/webby-src/src/app/staff/catalog/search-form.component.ts b/Open-ILS/webby-src/src/app/staff/catalog/search-form.component.ts index 9148e25741..53b2c96baa 100644 --- a/Open-ILS/webby-src/src/app/staff/catalog/search-form.component.ts +++ b/Open-ILS/webby-src/src/app/staff/catalog/search-form.component.ts @@ -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()} + ) } } -- 2.11.0