@@ -2,21 +2,27 @@ import {
22 Component ,
33 Inject ,
44 OnInit ,
5+ OnDestroy ,
56 Input ,
67 NgZone ,
78 ViewChild ,
89 ElementRef ,
9- Query ,
1010} from "@angular/core" ;
1111import { SelectItem } from "primeng/api" ;
1212import { DropdownModule } from "primeng/dropdown" ;
1313import { TaxonomyListService } from "../shared/taxonomy-list/index" ;
1414import { SearchfieldsListService } from "../shared/searchfields-list/index" ;
15- import { SearchService , SEARCH_SERVICE } from "../shared/search-service" ;
15+ import {
16+ SearchService ,
17+ SEARCH_SERVICE ,
18+ ProductTypeState ,
19+ ProductTypeKey ,
20+ DEFAULT_PRODUCT_TYPES ,
21+ } from "../shared/search-service" ;
1622import { Router , NavigationExtras } from "@angular/router" ;
1723import * as _ from "lodash-es" ;
1824import { AppConfig , Config } from "../shared/config-service/config.service" ;
19- import { timer } from "rxjs" ;
25+ import { Observable , Subscription , timer } from "rxjs" ;
2026import {
2127 trigger ,
2228 state ,
@@ -28,17 +34,24 @@ import { OverlayPanel } from "primeng/overlaypanel";
2834// MARK: 08/21/2024: Disabled for now until rework
2935// import { AdvSearchComponent } from "../adv-search/adv-search.component";
3036import { SearchQueryService } from "../shared/search-query/search-query.service" ;
31- import { Observable } from "rxjs" ;
3237import {
3338 SDPQuery ,
3439 QueryRow ,
3540 CurrentQueryInfo ,
3641} from "../shared/search-query/query" ;
37- import { ReadVarExpr } from "@angular/compiler" ;
3842import { find } from "./autocomplete" ;
3943// import fetch from "cross-fetch";
4044import { MessageService } from "primeng/api" ;
4145
46+ type ProductTypeOption = {
47+ key : ProductTypeKey ;
48+ label : string ;
49+ icon : string ;
50+ external ?: boolean ;
51+ comingSoon ?: boolean ;
52+ description ?: string ;
53+ } ;
54+
4255@Component ( {
4356 selector : "app-search-panel" ,
4457 templateUrl : "./search-panel.component.html" ,
@@ -67,7 +80,7 @@ import { MessageService } from "primeng/api";
6780 ] ) ,
6881 ] ,
6982} )
70- export class SearchPanelComponent implements OnInit {
83+ export class SearchPanelComponent implements OnInit , OnDestroy {
7184 @Input ( ) title : string ;
7285 @Input ( ) subtitle : boolean ;
7386 @Input ( ) helpicon : boolean = false ;
@@ -107,6 +120,27 @@ export class SearchPanelComponent implements OnInit {
107120 searchBottonWith : string = "10%" ;
108121 breadcrumb_top : string = "6em" ;
109122 includeExternalProducts : boolean = false ;
123+ productTypes : ProductTypeState = { ...DEFAULT_PRODUCT_TYPES } ;
124+ productTypeOptions : ProductTypeOption [ ] = [
125+ { key : "data" , label : "Data" , icon : "pi pi-database" } ,
126+ { key : "code" , label : "Code" , icon : "pi pi-code" , external : true } ,
127+ {
128+ key : "papers" ,
129+ label : "Papers" ,
130+ icon : "pi pi-book" ,
131+ external : true ,
132+ comingSoon : true ,
133+ } ,
134+ {
135+ key : "patents" ,
136+ label : "Patents" ,
137+ icon : "pi pi-briefcase" ,
138+ external : true ,
139+ comingSoon : true ,
140+ } ,
141+ ] ;
142+ private productTypesSub ?: Subscription ;
143+ private externalToggleSub ?: Subscription ;
110144 externalHelperText : string =
111145 "Toggle to include external products like open-source code (patents & papers coming soon). Results and filters will blend with NIST data." ;
112146 externalInfoVisible : boolean = false ;
@@ -263,9 +297,17 @@ export class SearchPanelComponent implements OnInit {
263297 this . imageURL = this . SDPAPI + "assets/images/ngi-background.png" ;
264298 } ) ;
265299
266- this . searchService . watchExternalProducts ( ) . subscribe ( ( enabled ) => {
267- this . includeExternalProducts = enabled ;
268- } ) ;
300+ this . productTypesSub = this . searchService
301+ . watchProductTypes ( )
302+ . subscribe ( ( state ) => {
303+ this . productTypes = state ;
304+ } ) ;
305+
306+ this . externalToggleSub = this . searchService
307+ . watchExternalProducts ( )
308+ . subscribe ( ( enabled ) => {
309+ this . includeExternalProducts = enabled ;
310+ } ) ;
269311
270312 this . getTaxonomySuggestions ( ) ;
271313 }
@@ -313,6 +355,23 @@ export class SearchPanelComponent implements OnInit {
313355 this . externalInfoVisible = false ;
314356 }
315357
358+ get visibleProductTypes ( ) : ProductTypeOption [ ] {
359+ return this . productTypeOptions . filter (
360+ ( option ) => this . includeExternalProducts || ! option . external
361+ ) ;
362+ }
363+
364+ isProductTypeActive ( key : ProductTypeKey ) : boolean {
365+ return ! ! this . productTypes && ! ! this . productTypes [ key ] ;
366+ }
367+
368+ onProductTypeToggle ( option : ProductTypeOption ) {
369+ if ( option . comingSoon ) return ;
370+ if ( option . external && ! this . includeExternalProducts ) return ;
371+ const nextState = ! this . isProductTypeActive ( option . key ) ;
372+ this . searchService . setProductTypeEnabled ( option . key , nextState ) ;
373+ }
374+
316375 /**
317376 * Hide syntax rules and field lookup help
318377 */
@@ -710,4 +769,9 @@ export class SearchPanelComponent implements OnInit {
710769 showDialog ( ) {
711770 this . visible = true ;
712771 }
772+
773+ ngOnDestroy ( ) : void {
774+ this . productTypesSub ?. unsubscribe ( ) ;
775+ this . externalToggleSub ?. unsubscribe ( ) ;
776+ }
713777}
0 commit comments