diff options
Diffstat (limited to 'client/src/app/shared/search')
-rw-r--r-- | client/src/app/shared/search/index.ts | 8 | ||||
-rw-r--r-- | client/src/app/shared/search/search-field.type.ts | 2 | ||||
-rw-r--r-- | client/src/app/shared/search/search.component.ts | 48 | ||||
-rw-r--r-- | client/src/app/shared/search/search.model.ts | 6 | ||||
-rw-r--r-- | client/src/app/shared/search/search.service.ts | 18 |
5 files changed, 41 insertions, 41 deletions
diff --git a/client/src/app/shared/search/index.ts b/client/src/app/shared/search/index.ts index a897ed099..d4016cf89 100644 --- a/client/src/app/shared/search/index.ts +++ b/client/src/app/shared/search/index.ts | |||
@@ -1,4 +1,4 @@ | |||
1 | export * from './search-field.type'; | 1 | export * from './search-field.type' |
2 | export * from './search.component'; | 2 | export * from './search.component' |
3 | export * from './search.model'; | 3 | export * from './search.model' |
4 | export * from './search.service'; | 4 | export * from './search.service' |
diff --git a/client/src/app/shared/search/search-field.type.ts b/client/src/app/shared/search/search-field.type.ts index 6be584ed1..63557898a 100644 --- a/client/src/app/shared/search/search-field.type.ts +++ b/client/src/app/shared/search/search-field.type.ts | |||
@@ -1 +1 @@ | |||
export type SearchField = "name" | "author" | "host" | "magnetUri" | "tags"; | export type SearchField = 'name' | 'author' | 'host' | 'magnetUri' | 'tags' | ||
diff --git a/client/src/app/shared/search/search.component.ts b/client/src/app/shared/search/search.component.ts index 48413b4f2..ecce20666 100644 --- a/client/src/app/shared/search/search.component.ts +++ b/client/src/app/shared/search/search.component.ts | |||
@@ -1,9 +1,9 @@ | |||
1 | import { Component, OnInit } from '@angular/core'; | 1 | import { Component, OnInit } from '@angular/core' |
2 | import { Router } from '@angular/router'; | 2 | import { Router } from '@angular/router' |
3 | 3 | ||
4 | import { Search } from './search.model'; | 4 | import { Search } from './search.model' |
5 | import { SearchField } from './search-field.type'; | 5 | import { SearchField } from './search-field.type' |
6 | import { SearchService } from './search.service'; | 6 | import { SearchService } from './search.service' |
7 | 7 | ||
8 | @Component({ | 8 | @Component({ |
9 | selector: 'my-search', | 9 | selector: 'my-search', |
@@ -18,53 +18,53 @@ export class SearchComponent implements OnInit { | |||
18 | host: 'Pod Host', | 18 | host: 'Pod Host', |
19 | magnetUri: 'Magnet URI', | 19 | magnetUri: 'Magnet URI', |
20 | tags: 'Tags' | 20 | tags: 'Tags' |
21 | }; | 21 | } |
22 | searchCriterias: Search = { | 22 | searchCriterias: Search = { |
23 | field: 'name', | 23 | field: 'name', |
24 | value: '' | 24 | value: '' |
25 | }; | 25 | } |
26 | 26 | ||
27 | constructor(private searchService: SearchService, private router: Router) {} | 27 | constructor (private searchService: SearchService, private router: Router) {} |
28 | 28 | ||
29 | ngOnInit() { | 29 | ngOnInit () { |
30 | // Subscribe if the search changed | 30 | // Subscribe if the search changed |
31 | // Usually changed by videos list component | 31 | // Usually changed by videos list component |
32 | this.searchService.updateSearch.subscribe( | 32 | this.searchService.updateSearch.subscribe( |
33 | newSearchCriterias => { | 33 | newSearchCriterias => { |
34 | // Put a field by default | 34 | // Put a field by default |
35 | if (!newSearchCriterias.field) { | 35 | if (!newSearchCriterias.field) { |
36 | newSearchCriterias.field = 'name'; | 36 | newSearchCriterias.field = 'name' |
37 | } | 37 | } |
38 | 38 | ||
39 | this.searchCriterias = newSearchCriterias; | 39 | this.searchCriterias = newSearchCriterias |
40 | } | 40 | } |
41 | ); | 41 | ) |
42 | } | 42 | } |
43 | 43 | ||
44 | get choiceKeys() { | 44 | get choiceKeys () { |
45 | return Object.keys(this.fieldChoices); | 45 | return Object.keys(this.fieldChoices) |
46 | } | 46 | } |
47 | 47 | ||
48 | choose($event: MouseEvent, choice: SearchField) { | 48 | choose ($event: MouseEvent, choice: SearchField) { |
49 | $event.preventDefault(); | 49 | $event.preventDefault() |
50 | $event.stopPropagation(); | 50 | $event.stopPropagation() |
51 | 51 | ||
52 | this.searchCriterias.field = choice; | 52 | this.searchCriterias.field = choice |
53 | 53 | ||
54 | if (this.searchCriterias.value) { | 54 | if (this.searchCriterias.value) { |
55 | this.doSearch(); | 55 | this.doSearch() |
56 | } | 56 | } |
57 | } | 57 | } |
58 | 58 | ||
59 | doSearch() { | 59 | doSearch () { |
60 | if (this.router.url.indexOf('/videos/list') === -1) { | 60 | if (this.router.url.indexOf('/videos/list') === -1) { |
61 | this.router.navigate([ '/videos/list' ]); | 61 | this.router.navigate([ '/videos/list' ]) |
62 | } | 62 | } |
63 | 63 | ||
64 | this.searchService.searchUpdated.next(this.searchCriterias); | 64 | this.searchService.searchUpdated.next(this.searchCriterias) |
65 | } | 65 | } |
66 | 66 | ||
67 | getStringChoice(choiceKey: SearchField) { | 67 | getStringChoice (choiceKey: SearchField) { |
68 | return this.fieldChoices[choiceKey]; | 68 | return this.fieldChoices[choiceKey] |
69 | } | 69 | } |
70 | } | 70 | } |
diff --git a/client/src/app/shared/search/search.model.ts b/client/src/app/shared/search/search.model.ts index 932a6566c..174adf2c6 100644 --- a/client/src/app/shared/search/search.model.ts +++ b/client/src/app/shared/search/search.model.ts | |||
@@ -1,6 +1,6 @@ | |||
1 | import { SearchField } from './search-field.type'; | 1 | import { SearchField } from './search-field.type' |
2 | 2 | ||
3 | export interface Search { | 3 | export interface Search { |
4 | field: SearchField; | 4 | field: SearchField |
5 | value: string; | 5 | value: string |
6 | } | 6 | } |
diff --git a/client/src/app/shared/search/search.service.ts b/client/src/app/shared/search/search.service.ts index 717a7fa50..0480b46bd 100644 --- a/client/src/app/shared/search/search.service.ts +++ b/client/src/app/shared/search/search.service.ts | |||
@@ -1,18 +1,18 @@ | |||
1 | import { Injectable } from '@angular/core'; | 1 | import { Injectable } from '@angular/core' |
2 | import { Subject } from 'rxjs/Subject'; | 2 | import { Subject } from 'rxjs/Subject' |
3 | import { ReplaySubject } from 'rxjs/ReplaySubject'; | 3 | import { ReplaySubject } from 'rxjs/ReplaySubject' |
4 | 4 | ||
5 | import { Search } from './search.model'; | 5 | import { Search } from './search.model' |
6 | 6 | ||
7 | // This class is needed to communicate between videos/ and search component | 7 | // This class is needed to communicate between videos/ and search component |
8 | // Remove it when we'll be able to subscribe to router changes | 8 | // Remove it when we'll be able to subscribe to router changes |
9 | @Injectable() | 9 | @Injectable() |
10 | export class SearchService { | 10 | export class SearchService { |
11 | searchUpdated: Subject<Search>; | 11 | searchUpdated: Subject<Search> |
12 | updateSearch: Subject<Search>; | 12 | updateSearch: Subject<Search> |
13 | 13 | ||
14 | constructor() { | 14 | constructor () { |
15 | this.updateSearch = new Subject<Search>(); | 15 | this.updateSearch = new Subject<Search>() |
16 | this.searchUpdated = new ReplaySubject<Search>(1); | 16 | this.searchUpdated = new ReplaySubject<Search>(1) |
17 | } | 17 | } |
18 | } | 18 | } |