aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/src/app/header/search-typeahead.component.ts
diff options
context:
space:
mode:
Diffstat (limited to 'client/src/app/header/search-typeahead.component.ts')
-rw-r--r--client/src/app/header/search-typeahead.component.ts25
1 files changed, 18 insertions, 7 deletions
diff --git a/client/src/app/header/search-typeahead.component.ts b/client/src/app/header/search-typeahead.component.ts
index 514c04704..9b414bc56 100644
--- a/client/src/app/header/search-typeahead.component.ts
+++ b/client/src/app/header/search-typeahead.component.ts
@@ -8,14 +8,15 @@ import {
8 QueryList 8 QueryList
9} from '@angular/core' 9} from '@angular/core'
10import { Router, NavigationEnd, Params, ActivatedRoute } from '@angular/router' 10import { Router, NavigationEnd, Params, ActivatedRoute } from '@angular/router'
11import { AuthService } from '@app/core' 11import { AuthService, ServerService } from '@app/core'
12import { I18n } from '@ngx-translate/i18n-polyfill' 12import { I18n } from '@ngx-translate/i18n-polyfill'
13import { filter, first, tap, map } from 'rxjs/operators' 13import { filter, first, tap, map } from 'rxjs/operators'
14import { ListKeyManager } from '@angular/cdk/a11y' 14import { ListKeyManager } from '@angular/cdk/a11y'
15import { UP_ARROW, DOWN_ARROW, ENTER, TAB } from '@angular/cdk/keycodes' 15import { UP_ARROW, DOWN_ARROW, ENTER } from '@angular/cdk/keycodes'
16import { SuggestionComponent, Result } from './suggestion.component' 16import { SuggestionComponent, Result } from './suggestion.component'
17import { of } from 'rxjs' 17import { of } from 'rxjs'
18import { getParameterByName } from '@app/shared/misc/utils' 18import { getParameterByName } from '@app/shared/misc/utils'
19import { ServerConfig } from '@shared/models'
19 20
20@Component({ 21@Component({
21 selector: 'my-search-typeahead', 22 selector: 'my-search-typeahead',
@@ -30,7 +31,7 @@ export class SearchTypeaheadComponent implements OnInit, OnDestroy, AfterViewIni
30 newSearch = true 31 newSearch = true
31 32
32 searchInput: HTMLInputElement 33 searchInput: HTMLInputElement
33 URIPolicy: 'only-followed' | 'any' = 'any' 34 serverConfig: ServerConfig
34 35
35 URIPolicyText: string 36 URIPolicyText: string
36 inAllText: string 37 inAllText: string
@@ -44,6 +45,7 @@ export class SearchTypeaheadComponent implements OnInit, OnDestroy, AfterViewIni
44 private authService: AuthService, 45 private authService: AuthService,
45 private router: Router, 46 private router: Router,
46 private route: ActivatedRoute, 47 private route: ActivatedRoute,
48 private serverService: ServerService,
47 private i18n: I18n 49 private i18n: I18n
48 ) { 50 ) {
49 this.URIPolicyText = this.i18n('Determines whether you can resolve any distant content, or if your instance only allows doing so for instances it follows.') 51 this.URIPolicyText = this.i18n('Determines whether you can resolve any distant content, or if your instance only allows doing so for instances it follows.')
@@ -66,6 +68,9 @@ export class SearchTypeaheadComponent implements OnInit, OnDestroy, AfterViewIni
66 map(() => getParameterByName('search', window.location.href)) 68 map(() => getParameterByName('search', window.location.href))
67 ) 69 )
68 .subscribe(searchQuery => this.searchInput.value = searchQuery || '') 70 .subscribe(searchQuery => this.searchInput.value = searchQuery || '')
71
72 this.serverService.getConfig()
73 .subscribe(config => this.serverConfig = config)
69 } 74 }
70 75
71 ngOnDestroy () { 76 ngOnDestroy () {
@@ -90,6 +95,16 @@ export class SearchTypeaheadComponent implements OnInit, OnDestroy, AfterViewIni
90 return this.hasSearch && this.newSearch && this.activeResult && this.activeResult.type === 'search-global' || false 95 return this.hasSearch && this.newSearch && this.activeResult && this.activeResult.type === 'search-global' || false
91 } 96 }
92 97
98 get URIPolicy (): 'only-followed' | 'any' {
99 return (
100 this.authService.isLoggedIn()
101 ? this.serverConfig.search.remoteUri.users
102 : this.serverConfig.search.remoteUri.anonymous
103 )
104 ? 'any'
105 : 'only-followed'
106 }
107
93 computeResults () { 108 computeResults () {
94 this.newSearch = true 109 this.newSearch = true
95 let results: Result[] = [] 110 let results: Result[] = []
@@ -151,10 +166,6 @@ export class SearchTypeaheadComponent implements OnInit, OnDestroy, AfterViewIni
151 ) 166 )
152 } 167 }
153 168
154 isUserLoggedIn () {
155 return this.authService.isLoggedIn()
156 }
157
158 handleKeyUp (event: KeyboardEvent, indexSelected?: number) { 169 handleKeyUp (event: KeyboardEvent, indexSelected?: number) {
159 event.stopImmediatePropagation() 170 event.stopImmediatePropagation()
160 if (this.keyboardEventsManager) { 171 if (this.keyboardEventsManager) {