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