1 import { Component, OnInit } from '@angular/core';
2 import { Router } from '@angular/router';
4 import { Search } from './search.model';
5 import { SearchField } from './search-field.type';
6 import { SearchService } from './search.service';
10 templateUrl: './search.component.html'
13 export class SearchComponent implements OnInit {
18 magnetUri: 'Magnet Uri',
21 searchCriterias: Search = {
26 constructor(private searchService: SearchService, private router: Router) {}
29 // Subscribe if the search changed
30 // Usually changed by videos list component
31 this.searchService.updateSearch.subscribe(
32 newSearchCriterias => {
33 // Put a field by default
34 if (!newSearchCriterias.field) {
35 newSearchCriterias.field = 'name';
38 this.searchCriterias = newSearchCriterias;
44 return Object.keys(this.fieldChoices);
47 choose($event: MouseEvent, choice: SearchField) {
48 $event.preventDefault();
49 $event.stopPropagation();
51 this.searchCriterias.field = choice;
53 if (this.searchCriterias.value) {
59 if (this.router.url.indexOf('/videos/list') === -1) {
60 this.router.navigate([ '/videos/list' ]);
63 this.searchService.searchUpdated.next(this.searchCriterias);
66 getStringChoice(choiceKey: SearchField) {
67 return this.fieldChoices[choiceKey];