mirror of https://github.com/Chocobozzz/PeerTube
68 lines
1.5 KiB
TypeScript
68 lines
1.5 KiB
TypeScript
import { Component, OnInit } from '@angular/core';
|
|
|
|
import { DROPDOWN_DIRECTIVES} from 'ng2-bootstrap/components/dropdown';
|
|
|
|
import { Search } from './search.model';
|
|
import { SearchField } from './search-field.type';
|
|
import { SearchService } from './search.service';
|
|
|
|
@Component({
|
|
selector: 'my-search',
|
|
template: require('./search.component.html'),
|
|
directives: [ DROPDOWN_DIRECTIVES ]
|
|
})
|
|
|
|
export class SearchComponent implements OnInit {
|
|
fieldChoices = {
|
|
name: 'Name',
|
|
author: 'Author',
|
|
podUrl: 'Pod Url',
|
|
magnetUri: 'Magnet Uri',
|
|
tags: 'Tags'
|
|
};
|
|
searchCriterias: Search = {
|
|
field: 'name',
|
|
value: ''
|
|
};
|
|
|
|
constructor(private searchService: SearchService) {}
|
|
|
|
ngOnInit() {
|
|
// Subscribe is the search changed
|
|
// Usually changed by videos list component
|
|
this.searchService.updateSearch.subscribe(
|
|
newSearchCriterias => {
|
|
// Put a field by default
|
|
if (!newSearchCriterias.field) {
|
|
newSearchCriterias.field = 'name';
|
|
}
|
|
|
|
this.searchCriterias = newSearchCriterias;
|
|
}
|
|
);
|
|
}
|
|
|
|
get choiceKeys() {
|
|
return Object.keys(this.fieldChoices);
|
|
}
|
|
|
|
choose($event: MouseEvent, choice: SearchField) {
|
|
$event.preventDefault();
|
|
$event.stopPropagation();
|
|
|
|
this.searchCriterias.field = choice;
|
|
|
|
if (this.searchCriterias.value) {
|
|
this.doSearch();
|
|
}
|
|
}
|
|
|
|
doSearch() {
|
|
this.searchService.searchUpdated.next(this.searchCriterias);
|
|
}
|
|
|
|
getStringChoice(choiceKey: SearchField) {
|
|
return this.fieldChoices[choiceKey];
|
|
}
|
|
}
|