aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/angular/app/search.component.ts
blob: 3e8db70c0eb2ca010c28bbf69397ae72f3a88bff (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import { Component, EventEmitter, Output } from '@angular/core';
import { RouteConfig, ROUTER_DIRECTIVES, ROUTER_PROVIDERS, Router } from '@angular/router-deprecated';
import { HTTP_PROVIDERS } from '@angular/http';

import { DROPDOWN_DIRECTIVES} from  'ng2-bootstrap/components/dropdown';

import { Search, SearchField } from './search';

@Component({
    selector: 'my-search',
    templateUrl: 'app/angular/app/search.component.html',
    directives: [ DROPDOWN_DIRECTIVES ]
})

export class SearchComponent {
  @Output() search: EventEmitter<Search> = new EventEmitter<Search>();

  searchCriterias: Search = {
    field: "name",
    value: ""
  }
  fieldChoices = {
    name: "Name",
    author: "Author",
    podUrl: "Pod Url",
    magnetUri: "Magnet Uri"
  }

  get choiceKeys() {
    return Object.keys(this.fieldChoices);
  }

  getStringChoice(choiceKey: SearchField): string {
    return this.fieldChoices[choiceKey];
  }

  choose($event:MouseEvent, choice: SearchField){
    $event.preventDefault();
    $event.stopPropagation();

    this.searchCriterias.field = choice;
  }

  doSearch(): void {
    this.search.emit(this.searchCriterias);
  }

}