diff options
Diffstat (limited to 'client/src/app/shared')
-rw-r--r-- | client/src/app/shared/search/index.ts | 1 | ||||
-rw-r--r-- | client/src/app/shared/search/search.component.ts | 21 | ||||
-rw-r--r-- | client/src/app/shared/search/search.service.ts | 15 |
3 files changed, 35 insertions, 2 deletions
diff --git a/client/src/app/shared/search/index.ts b/client/src/app/shared/search/index.ts index a49a4f1a9..a897ed099 100644 --- a/client/src/app/shared/search/index.ts +++ b/client/src/app/shared/search/index.ts | |||
@@ -1,3 +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'; | ||
diff --git a/client/src/app/shared/search/search.component.ts b/client/src/app/shared/search/search.component.ts index c14c2d99c..ed1ce807a 100644 --- a/client/src/app/shared/search/search.component.ts +++ b/client/src/app/shared/search/search.component.ts | |||
@@ -1,9 +1,10 @@ | |||
1 | import { Component, EventEmitter, Output } from '@angular/core'; | 1 | import { Component, EventEmitter, Output, OnInit } from '@angular/core'; |
2 | 2 | ||
3 | import { DROPDOWN_DIRECTIVES} from 'ng2-bootstrap/components/dropdown'; | 3 | import { DROPDOWN_DIRECTIVES} from 'ng2-bootstrap/components/dropdown'; |
4 | 4 | ||
5 | import { Search } from './search.model'; | 5 | import { Search } from './search.model'; |
6 | import { SearchField } from './search-field.type'; | 6 | import { SearchField } from './search-field.type'; |
7 | import { SearchService } from './search.service'; // Temporary | ||
7 | 8 | ||
8 | @Component({ | 9 | @Component({ |
9 | selector: 'my-search', | 10 | selector: 'my-search', |
@@ -11,7 +12,7 @@ import { SearchField } from './search-field.type'; | |||
11 | directives: [ DROPDOWN_DIRECTIVES ] | 12 | directives: [ DROPDOWN_DIRECTIVES ] |
12 | }) | 13 | }) |
13 | 14 | ||
14 | export class SearchComponent { | 15 | export class SearchComponent implements OnInit { |
15 | @Output() search = new EventEmitter<Search>(); | 16 | @Output() search = new EventEmitter<Search>(); |
16 | 17 | ||
17 | fieldChoices = { | 18 | fieldChoices = { |
@@ -26,6 +27,21 @@ export class SearchComponent { | |||
26 | value: '' | 27 | value: '' |
27 | }; | 28 | }; |
28 | 29 | ||
30 | constructor(private searchService: SearchService) {} | ||
31 | |||
32 | ngOnInit() { | ||
33 | this.searchService.searchChanged.subscribe( | ||
34 | newSearchCriterias => { | ||
35 | // Put a field by default | ||
36 | if (!newSearchCriterias.field) { | ||
37 | newSearchCriterias.field = 'name'; | ||
38 | } | ||
39 | |||
40 | this.searchCriterias = newSearchCriterias; | ||
41 | } | ||
42 | ); | ||
43 | } | ||
44 | |||
29 | get choiceKeys() { | 45 | get choiceKeys() { |
30 | return Object.keys(this.fieldChoices); | 46 | return Object.keys(this.fieldChoices); |
31 | } | 47 | } |
@@ -35,6 +51,7 @@ export class SearchComponent { | |||
35 | $event.stopPropagation(); | 51 | $event.stopPropagation(); |
36 | 52 | ||
37 | this.searchCriterias.field = choice; | 53 | this.searchCriterias.field = choice; |
54 | this.doSearch(); | ||
38 | } | 55 | } |
39 | 56 | ||
40 | doSearch() { | 57 | doSearch() { |
diff --git a/client/src/app/shared/search/search.service.ts b/client/src/app/shared/search/search.service.ts new file mode 100644 index 000000000..787c02d2b --- /dev/null +++ b/client/src/app/shared/search/search.service.ts | |||
@@ -0,0 +1,15 @@ | |||
1 | import { Injectable } from '@angular/core'; | ||
2 | import { Subject } from 'rxjs/Subject'; | ||
3 | |||
4 | import { Search } from './search.model'; | ||
5 | |||
6 | // This class is needed to communicate between videos/list and search component | ||
7 | // Remove it when we'll be able to subscribe to router changes | ||
8 | @Injectable() | ||
9 | export class SearchService { | ||
10 | searchChanged: Subject<Search>; | ||
11 | |||
12 | constructor() { | ||
13 | this.searchChanged = new Subject<Search>(); | ||
14 | } | ||
15 | } | ||