2016-05-23 09:30:18 +02:00
|
|
|
import { Component, EventEmitter, Output } from '@angular/core';
|
|
|
|
|
|
|
|
import { DROPDOWN_DIRECTIVES} from 'ng2-bootstrap/components/dropdown';
|
|
|
|
|
2016-05-27 16:23:10 +02:00
|
|
|
import { Search } from './search.model';
|
|
|
|
import { SearchField } from './search-field.type';
|
2016-05-23 09:30:18 +02:00
|
|
|
|
|
|
|
@Component({
|
|
|
|
selector: 'my-search',
|
2016-05-27 16:23:10 +02:00
|
|
|
templateUrl: 'client/app/shared/search.component.html',
|
2016-05-23 09:30:18 +02:00
|
|
|
directives: [ DROPDOWN_DIRECTIVES ]
|
|
|
|
})
|
|
|
|
|
|
|
|
export class SearchComponent {
|
2016-05-27 17:25:52 +02:00
|
|
|
@Output() search = new EventEmitter<Search>();
|
2016-05-23 09:30:18 +02:00
|
|
|
|
|
|
|
searchCriterias: Search = {
|
2016-05-23 12:15:03 +02:00
|
|
|
field: 'name',
|
|
|
|
value: ''
|
|
|
|
};
|
2016-05-27 17:25:52 +02:00
|
|
|
|
2016-05-23 09:30:18 +02:00
|
|
|
fieldChoices = {
|
2016-05-23 12:15:03 +02:00
|
|
|
name: 'Name',
|
|
|
|
author: 'Author',
|
|
|
|
podUrl: 'Pod Url',
|
|
|
|
magnetUri: 'Magnet Uri'
|
|
|
|
};
|
2016-05-23 09:30:18 +02:00
|
|
|
|
|
|
|
get choiceKeys() {
|
|
|
|
return Object.keys(this.fieldChoices);
|
|
|
|
}
|
|
|
|
|
2016-05-27 17:25:52 +02:00
|
|
|
getStringChoice(choiceKey: SearchField) {
|
2016-05-23 09:30:18 +02:00
|
|
|
return this.fieldChoices[choiceKey];
|
|
|
|
}
|
|
|
|
|
2016-05-27 17:25:52 +02:00
|
|
|
choose($event: MouseEvent, choice: SearchField) {
|
2016-05-23 09:30:18 +02:00
|
|
|
$event.preventDefault();
|
|
|
|
$event.stopPropagation();
|
|
|
|
|
|
|
|
this.searchCriterias.field = choice;
|
|
|
|
}
|
|
|
|
|
2016-05-27 17:25:52 +02:00
|
|
|
doSearch() {
|
2016-05-23 09:30:18 +02:00
|
|
|
this.search.emit(this.searchCriterias);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|