]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - client/src/app/shared/search/search.component.ts
Server: Add NSFW in user profile
[github/Chocobozzz/PeerTube.git] / client / src / app / shared / search / search.component.ts
index 31f8b1535d21f5f5301649f442dcd41d288ef2a2..9f7e156ecaeea7d77300cc293578e4d58686553e 100644 (file)
@@ -1,30 +1,45 @@
-import { Component, EventEmitter, Output } from '@angular/core';
-
-import { DROPDOWN_DIRECTIVES} from  'ng2-bootstrap/components/dropdown';
+import { Component, OnInit } from '@angular/core';
+import { Router } from '@angular/router';
 
 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 ]
+  selector: 'my-search',
+  templateUrl: './search.component.html'
 })
 
-export class SearchComponent {
-  @Output() search = new EventEmitter<Search>();
-
+export class SearchComponent implements OnInit {
   fieldChoices = {
     name: 'Name',
     author: 'Author',
-    podUrl: 'Pod Url',
-    magnetUri: 'Magnet Uri'
+    host: 'Pod Host',
+    magnetUri: 'Magnet URI',
+    tags: 'Tags'
   };
   searchCriterias: Search = {
     field: 'name',
     value: ''
   };
 
+  constructor(private searchService: SearchService, private router: Router) {}
+
+  ngOnInit() {
+    // Subscribe if 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);
   }
@@ -34,10 +49,18 @@ export class SearchComponent {
     $event.stopPropagation();
 
     this.searchCriterias.field = choice;
+
+    if (this.searchCriterias.value) {
+      this.doSearch();
+    }
   }
 
   doSearch() {
-    this.search.emit(this.searchCriterias);
+    if (this.router.url.indexOf('/videos/list') === -1) {
+      this.router.navigate([ '/videos/list' ]);
+    }
+
+    this.searchService.searchUpdated.next(this.searchCriterias);
   }
 
   getStringChoice(choiceKey: SearchField) {