]>
Commit | Line | Data |
---|---|---|
471bc22f | 1 | import { Component, EventEmitter, Output } from '@angular/core'; |
471bc22f C |
2 | |
3 | import { DROPDOWN_DIRECTIVES} from 'ng2-bootstrap/components/dropdown'; | |
4 | ||
41a2aee3 C |
5 | import { Search } from './search.model'; |
6 | import { SearchField } from './search-field.type'; | |
471bc22f C |
7 | |
8 | @Component({ | |
9 | selector: 'my-search', | |
41a2aee3 | 10 | templateUrl: 'client/app/shared/search.component.html', |
471bc22f C |
11 | directives: [ DROPDOWN_DIRECTIVES ] |
12 | }) | |
13 | ||
14 | export class SearchComponent { | |
ccf6ed16 | 15 | @Output() search = new EventEmitter<Search>(); |
471bc22f | 16 | |
471bc22f | 17 | fieldChoices = { |
aff038cd C |
18 | name: 'Name', |
19 | author: 'Author', | |
20 | podUrl: 'Pod Url', | |
21 | magnetUri: 'Magnet Uri' | |
22 | }; | |
4fd8aa32 C |
23 | searchCriterias: Search = { |
24 | field: 'name', | |
25 | value: '' | |
26 | }; | |
471bc22f C |
27 | |
28 | get choiceKeys() { | |
29 | return Object.keys(this.fieldChoices); | |
30 | } | |
31 | ||
ccf6ed16 | 32 | choose($event: MouseEvent, choice: SearchField) { |
471bc22f C |
33 | $event.preventDefault(); |
34 | $event.stopPropagation(); | |
35 | ||
36 | this.searchCriterias.field = choice; | |
37 | } | |
38 | ||
ccf6ed16 | 39 | doSearch() { |
471bc22f C |
40 | this.search.emit(this.searchCriterias); |
41 | } | |
42 | ||
4fd8aa32 C |
43 | getStringChoice(choiceKey: SearchField) { |
44 | return this.fieldChoices[choiceKey]; | |
45 | } | |
471bc22f | 46 | } |