@@ -11,6 +11,7 @@ import { SearchEntity } from '../shared/search-query/search.entity';
1111import { FormCanDeactivate } from '../form-can-deactivate/form-can-deactivate' ;
1212import { timer } from 'rxjs/observable/timer' ;
1313import { GoogleAnalyticsService } from '../shared/ga-service/google-analytics.service' ;
14+ import { AdvSearchService } from './adv-search.service' ;
1415
1516import * as _ from 'lodash' ;
1617
@@ -67,6 +68,7 @@ export class AdvSearchComponent extends FormCanDeactivate implements OnInit {
6768 queryString : string ;
6869 caretDown = 'faa faa-angle-down' ;
6970 placeholder : string ;
71+ startup : boolean = true ;
7072 placeHolderText : string [ ] = [ 'Kinetics database' , 'Gallium' , '"SRD 101"' , 'XPDB' , 'Interatomic Potentials' ] ;
7173
7274 @ViewChild ( 'input1' ) inputEl : ElementRef ;
@@ -79,13 +81,14 @@ export class AdvSearchComponent extends FormCanDeactivate implements OnInit {
7981 * Constructor
8082 */
8183 constructor ( @Inject ( SEARCH_SERVICE ) private searchService : SearchService ,
82- ngZone : NgZone ,
84+ public ngZone : NgZone ,
8385 public taxonomyListService : TaxonomyListService ,
8486 public searchFieldsListService : SearchfieldsListService ,
8587 public gaService : GoogleAnalyticsService ,
8688 // public searchService: SearchService,
8789 private router : Router ,
8890 public searchQueryService : SearchQueryService ,
91+ public advSearchService : AdvSearchService ,
8992 private confirmationService : ConfirmationService ,
9093 private renderer : Renderer2 ) {
9194
@@ -107,6 +110,16 @@ export class AdvSearchComponent extends FormCanDeactivate implements OnInit {
107110 this . mobHeight = window . innerHeight ;
108111 } ) ;
109112 } ;
113+
114+ // Watch search request from other module
115+ this . advSearchService . _watchRemoteSearch ( ) . subscribe ( ( queryValue ) => {
116+ // we don't want to execute the query at startup. So always skip the first check
117+ if ( ! this . startup && queryValue ) {
118+ this . executeQuery ( queryValue ) ;
119+ }
120+
121+ this . startup = false ;
122+ } ) ;
110123 }
111124
112125
@@ -267,8 +280,17 @@ export class AdvSearchComponent extends FormCanDeactivate implements OnInit {
267280 * Advanced Search builder string
268281 */
269282 saveSearch ( ) {
283+ this . constructSearchString ( ) ;
284+ this . dataChanged = true ;
285+ }
286+
287+ /**
288+ * Construct the search string
289+ */
290+ constructSearchString ( ) {
270291 this . searchValue = '' ;
271292 this . queryAdvSearch = 'yes' ;
293+
272294 for ( let i = 0 ; i < this . rows . length ; i ++ ) {
273295 if ( typeof this . rows [ i ] . column1 === 'undefined' ) {
274296 this . rows [ i ] . column1 = 'AND' ;
@@ -292,7 +314,6 @@ export class AdvSearchComponent extends FormCanDeactivate implements OnInit {
292314 }
293315 }
294316 }
295- this . dataChanged = true ;
296317 }
297318
298319 /**
@@ -407,7 +428,7 @@ export class AdvSearchComponent extends FormCanDeactivate implements OnInit {
407428 this . searchTaxonomyKey = searchTaxonomyKey ;
408429 let params : NavigationExtras = {
409430 queryParams : {
410- 'q' : this . searchValue , 'key' : this . searchTaxonomyKey ? this . searchTaxonomyKey : '' ,
431+ 'q' : searchValue , 'key' : this . searchTaxonomyKey ? this . searchTaxonomyKey : '' ,
411432 'queryAdvSearch' : this . queryAdvSearch
412433 }
413434 } ;
@@ -647,7 +668,7 @@ export class AdvSearchComponent extends FormCanDeactivate implements OnInit {
647668 * Execute query
648669 */
649670 executeQuery ( queryValue : string ) {
650- this . queryString = "/#/search?q=" + queryValue + "&key=&queryAdvSearch=" ;
651- window . open ( this . queryString , '_self ' ) ;
671+ this . searchValue = queryValue ;
672+ this . search ( queryValue , this . searchTaxonomyKey , 'yes ' ) ;
652673 }
653674}
0 commit comments