aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/src/app/shared
diff options
context:
space:
mode:
Diffstat (limited to 'client/src/app/shared')
-rw-r--r--client/src/app/shared/search/index.ts1
-rw-r--r--client/src/app/shared/search/search.component.ts21
-rw-r--r--client/src/app/shared/search/search.service.ts15
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 @@
1export * from './search-field.type'; 1export * from './search-field.type';
2export * from './search.component'; 2export * from './search.component';
3export * from './search.model'; 3export * from './search.model';
4export * 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 @@
1import { Component, EventEmitter, Output } from '@angular/core'; 1import { Component, EventEmitter, Output, OnInit } from '@angular/core';
2 2
3import { DROPDOWN_DIRECTIVES} from 'ng2-bootstrap/components/dropdown'; 3import { DROPDOWN_DIRECTIVES} from 'ng2-bootstrap/components/dropdown';
4 4
5import { Search } from './search.model'; 5import { Search } from './search.model';
6import { SearchField } from './search-field.type'; 6import { SearchField } from './search-field.type';
7import { 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
14export class SearchComponent { 15export 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 @@
1import { Injectable } from '@angular/core';
2import { Subject } from 'rxjs/Subject';
3
4import { 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()
9export class SearchService {
10 searchChanged: Subject<Search>;
11
12 constructor() {
13 this.searchChanged = new Subject<Search>();
14 }
15}