]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - client/app/shared/search.component.ts
Follow the angular styleguide for the directories structure
[github/Chocobozzz/PeerTube.git] / client / app / shared / search.component.ts
CommitLineData
471bc22f 1import { Component, EventEmitter, Output } from '@angular/core';
471bc22f
C
2
3import { DROPDOWN_DIRECTIVES} from 'ng2-bootstrap/components/dropdown';
4
41a2aee3
C
5import { Search } from './search.model';
6import { 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
14export class SearchComponent {
15 @Output() search: EventEmitter<Search> = new EventEmitter<Search>();
16
17 searchCriterias: Search = {
aff038cd
C
18 field: 'name',
19 value: ''
20 };
471bc22f 21 fieldChoices = {
aff038cd
C
22 name: 'Name',
23 author: 'Author',
24 podUrl: 'Pod Url',
25 magnetUri: 'Magnet Uri'
26 };
471bc22f
C
27
28 get choiceKeys() {
29 return Object.keys(this.fieldChoices);
30 }
31
32 getStringChoice(choiceKey: SearchField): string {
33 return this.fieldChoices[choiceKey];
34 }
35
aff038cd 36 choose($event:MouseEvent, choice: SearchField) {
471bc22f
C
37 $event.preventDefault();
38 $event.stopPropagation();
39
40 this.searchCriterias.field = choice;
41 }
42
43 doSearch(): void {
44 this.search.emit(this.searchCriterias);
45 }
46
47}