-import { Component, EventEmitter, Output, OnInit } from '@angular/core';
-
-import { DROPDOWN_DIRECTIVES} from 'ng2-bootstrap/components/dropdown';
+import { Component, OnInit } from '@angular/core';
+import { Router } from '@angular/router';
import { Search } from './search.model';
import { SearchField } from './search-field.type';
-import { SearchService } from './search.service'; // Temporary
+import { SearchService } from './search.service';
@Component({
- selector: 'my-search',
- template: require('./search.component.html'),
- directives: [ DROPDOWN_DIRECTIVES ]
+ selector: 'my-search',
+ templateUrl: './search.component.html'
})
export class SearchComponent implements OnInit {
- @Output() search = new EventEmitter<Search>();
-
fieldChoices = {
name: 'Name',
author: 'Author',
- podUrl: 'Pod Url',
- magnetUri: 'Magnet Uri',
+ host: 'Pod Host',
+ magnetUri: 'Magnet URI',
tags: 'Tags'
};
searchCriterias: Search = {
value: ''
};
- constructor(private searchService: SearchService) {}
+ constructor(private searchService: SearchService, private router: Router) {}
ngOnInit() {
- this.searchService.searchChanged.subscribe(
+ // Subscribe if the search changed
+ // Usually changed by videos list component
+ this.searchService.updateSearch.subscribe(
newSearchCriterias => {
// Put a field by default
if (!newSearchCriterias.field) {
$event.stopPropagation();
this.searchCriterias.field = choice;
- this.doSearch();
+
+ if (this.searchCriterias.value) {
+ this.doSearch();
+ }
}
doSearch() {
- this.search.emit(this.searchCriterias);
+ if (this.router.url.indexOf('/videos/list') === -1) {
+ this.router.navigate([ '/videos/list' ]);
+ }
+
+ this.searchService.searchUpdated.next(this.searchCriterias);
}
getStringChoice(choiceKey: SearchField) {