1 import { Component, EventEmitter, Output, OnInit } from '@angular/core';
3 import { DROPDOWN_DIRECTIVES} from 'ng2-bootstrap/components/dropdown';
5 import { Search } from './search.model';
6 import { SearchField } from './search-field.type';
7 import { SearchService } from './search.service'; // Temporary
10 selector: 'my-search',
11 template: require('./search.component.html'),
12 directives: [ DROPDOWN_DIRECTIVES ]
15 export class SearchComponent implements OnInit {
16 @Output() search = new EventEmitter<Search>();
22 magnetUri: 'Magnet Uri',
25 searchCriterias: Search = {
30 constructor(private searchService: SearchService) {}
33 this.searchService.searchChanged.subscribe(
34 newSearchCriterias => {
35 // Put a field by default
36 if (!newSearchCriterias.field) {
37 newSearchCriterias.field = 'name';
40 this.searchCriterias = newSearchCriterias;
46 return Object.keys(this.fieldChoices);
49 choose($event: MouseEvent, choice: SearchField) {
50 $event.preventDefault();
51 $event.stopPropagation();
53 this.searchCriterias.field = choice;
55 if (this.searchCriterias.value !== '') {
61 this.search.emit(this.searchCriterias);
64 getStringChoice(choiceKey: SearchField) {
65 return this.fieldChoices[choiceKey];