import { Component , ElementRef , EventEmitter , Input , Output , ViewChild , ViewEncapsulation , } from '@angular/core' ; import { FormsModule , ReactiveFormsModule , FormGroup , FormBuilder , Validators } from '@angular/forms' ; import { Router } from '@angular/router' ; import { content } from '../../../../config/code-gov-config.json' ; import { ClientService } from '../../services/client' ; /**
 * Class representing a search component for repositories.
 */ @ Component ( { selector : 'repos-search' , template : require ( './repos-search.template.html' ) , styles : [ require ( './repos-search.style.scss' ) ] , encapsulation : ViewEncapsulation . None , } ) export class ReposSearchComponent { @ Input ( ) queryValue = '' ; @ Input ( ) autofocus = false ; @ Input ( ) buttonClasses = '' ; @ Input ( ) placeholder : string ; @ ViewChild ( 'repoSearch' ) searchFormElement : ElementRef ; private browse_by_text : string = content . home . banner . browse_by_text ; private entities : any [ ] ; constructor param { Router } router constructor ( private router , private clientService ) { this . clientService . getAgencies ( ) . subscribe ( entities => { this . entities = entities . filter ( entity => Number ( entity . numRepos ) > 0 ) . filter ( entity => entity . acronym !== 'NRC' ) ; } ) ; } param { any } form return { void } onSubmit ( ) { if ( this . queryValue && this . queryValue . length > 0 ) { this . search ( ) ; } else { console . log ( 'No search terms were entered, so do nothing' ) ; } } return { void } search ( ) { this . router . navigateByUrl ( '/search?q=' + this . queryValue ) ; } onBrowseByEntityChange ( newValue ) { let url = '/browse-projects' ; if ( typeof newValue === 'string' && newValue !== 'All' ) { url += '?agencies=' + newValue ; } this . router . navigateByUrl ( url ) ; } }