]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - client/src/app/shared/search/search.component.ts
Add info when server is processing a video at upload
[github/Chocobozzz/PeerTube.git] / client / src / app / shared / search / search.component.ts
1 import { Component, OnInit } from '@angular/core'
2 import { Router } from '@angular/router'
3
4 import { Search } from './search.model'
5 import { SearchField } from './search-field.type'
6 import { SearchService } from './search.service'
7
8 @Component({
9 selector: 'my-search',
10 templateUrl: './search.component.html',
11 styleUrls: [ './search.component.scss' ]
12 })
13
14 export class SearchComponent implements OnInit {
15 fieldChoices = {
16 name: 'Name',
17 author: 'Author',
18 host: 'Pod Host',
19 magnetUri: 'Magnet URI',
20 tags: 'Tags'
21 }
22 searchCriterias: Search = {
23 field: 'name',
24 value: ''
25 }
26
27 constructor (private searchService: SearchService, private router: Router) {}
28
29 ngOnInit () {
30 // Subscribe if the search changed
31 // Usually changed by videos list component
32 this.searchService.updateSearch.subscribe(
33 newSearchCriterias => {
34 // Put a field by default
35 if (!newSearchCriterias.field) {
36 newSearchCriterias.field = 'name'
37 }
38
39 this.searchCriterias = newSearchCriterias
40 }
41 )
42 }
43
44 get choiceKeys () {
45 return Object.keys(this.fieldChoices)
46 }
47
48 choose ($event: MouseEvent, choice: SearchField) {
49 $event.preventDefault()
50 $event.stopPropagation()
51
52 this.searchCriterias.field = choice
53
54 if (this.searchCriterias.value) {
55 this.doSearch()
56 }
57 }
58
59 doSearch () {
60 if (this.router.url.indexOf('/videos/list') === -1) {
61 this.router.navigate([ '/videos/list' ])
62 }
63
64 this.searchService.searchUpdated.next(this.searchCriterias)
65 }
66
67 getStringChoice (choiceKey: SearchField) {
68 return this.fieldChoices[choiceKey]
69 }
70 }