Skip to content

Commit 49f5c37

Browse files
authored
Merge pull request #238 from usnistgov/fix/ODD890-advanced-search
Fix/odd890 advanced search
2 parents 347d8e0 + d3af6d2 commit 49f5c37

5 files changed

Lines changed: 84 additions & 8 deletions

File tree

angular/src/app/adv-search/adv-search.component.ts

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import { SearchEntity } from '../shared/search-query/search.entity';
1111
import { FormCanDeactivate } from '../form-can-deactivate/form-can-deactivate';
1212
import { timer } from 'rxjs/observable/timer';
1313
import { GoogleAnalyticsService } from '../shared/ga-service/google-analytics.service';
14+
import { AdvSearchService } from './adv-search.service';
1415

1516
import * 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
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { TestBed, inject } from '@angular/core/testing';
2+
3+
import { AdvSearchService } from './adv-search.service';
4+
5+
describe('AdvSearchService', () => {
6+
beforeEach(() => {
7+
TestBed.configureTestingModule({
8+
providers: [AdvSearchService]
9+
});
10+
});
11+
12+
it('should be created', inject([AdvSearchService], (service: AdvSearchService) => {
13+
expect(service).toBeTruthy();
14+
}));
15+
});
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import { Injectable, OnInit } from '@angular/core';
2+
import { BehaviorSubject } from 'rxjs/BehaviorSubject';
3+
4+
@Injectable({
5+
providedIn: 'root'
6+
})
7+
export class AdvSearchService implements OnInit {
8+
9+
constructor() { }
10+
11+
ngOnInit() {
12+
}
13+
14+
/**
15+
* Behavior subject to remotely start the search function. This is used when user clicks on a query
16+
* at top right query list.
17+
*/
18+
private _remoteSearch : BehaviorSubject<string> = new BehaviorSubject<string>('');
19+
_watchRemoteSearch() {
20+
return this._remoteSearch;
21+
}
22+
23+
/**
24+
* Trigger the search function
25+
*/
26+
public remoteStartSearch(queryValue) : void {
27+
this._remoteSearch.next(queryValue);
28+
}
29+
}

angular/src/app/app.module.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import { RealModule } from '../app/real.module';
2828
import {enableProdMode} from '@angular/core';
2929
import {GoogleAnalyticsService} from "./shared/ga-service/google-analytics.service";
3030
import {GoogleAnalyticsServiceMock} from "./shared/ga-service/google-analytics.service.mock";
31+
import { AdvSearchService } from './adv-search/adv-search.service';
3132

3233
/**
3334
* Initialize the configs for backend services
@@ -75,6 +76,7 @@ enableProdMode();
7576
],
7677
providers: [
7778
HttpClientModule,
79+
AdvSearchService,
7880
GoogleAnalyticsService,
7981
GoogleAnalyticsServiceMock,
8082
{

angular/src/app/app.searchtopbar.component.ts

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { SearchQueryService } from './shared/search-query/search-query.service';
44
import { SearchEntity } from './shared/search-query/search.entity';
55
import * as _ from 'lodash';
66
import { AppConfig, Config } from './shared/config-service/config-service.service';
7-
7+
import { AdvSearchService } from './adv-search/adv-search.service';
88

99
@Component({
1010
selector: 'app-searchtopbar',
@@ -29,8 +29,9 @@ import { AppConfig, Config } from './shared/config-service/config-service.servic
2929
<p-overlayPanel #op [dismissable]="true" [showCloseIcon]="true">
3030
<ul class="line-separated" style="list-style-type: none;margin-right:20px">
3131
<li *ngFor="let entities of searchEntities| slice:0:5;let i = index">
32-
<div>
33-
<a href="/#/search?q={{entities.data.queryValue}}&key=&queryAdvSearch=" (click) = "op.hide($event)" target="_parent">{{entities.data.id}}</a>
32+
<div (click)="op.hide($event); startSearch(entities.data.queryValue)" style="cursor: pointer">
33+
<!-- <a href="/#/search?q={{entities.data.queryValue}}&key=&queryAdvSearch=" (click) = "op.hide($event)" target="_parent">{{entities.data.id}}</a> -->
34+
{{entities.data.id}}
3435
</div>
3536
</li>
3637
</ul>
@@ -51,6 +52,7 @@ export class SearchTopBarComponent {
5152
constructor(
5253
public app: AppComponent,
5354
public searchQueryService: SearchQueryService,
55+
public advSearchService: AdvSearchService,
5456
private appConfig: AppConfig) {
5557

5658
this.searchQueryService.watchStorage().subscribe(value => {
@@ -77,4 +79,11 @@ export class SearchTopBarComponent {
7779
this.app.getSearchQueryList();
7880
}
7981

82+
/**
83+
* Remote start the search function in advance search page
84+
* @param queryValue
85+
*/
86+
startSearch(queryValue: string) {
87+
this.advSearchService.remoteStartSearch(queryValue);
88+
}
8089
}

0 commit comments

Comments
 (0)