Make the search helper change based on the server config
authorRigel Kent <sendmemail@rigelk.eu>
Mon, 3 Feb 2020 14:19:43 +0000 (15:19 +0100)
committerRigel Kent <sendmemail@rigelk.eu>
Thu, 13 Feb 2020 15:32:58 +0000 (16:32 +0100)
client/src/app/core/server/server.service.ts
client/src/app/header/header.component.html
client/src/app/header/search-typeahead.component.scss
client/src/app/header/search-typeahead.component.ts
client/src/app/shared/instance/instance-features-table.component.html
server/controllers/api/config.ts
server/controllers/static.ts
shared/models/server/server-config.model.ts

index 1f6cfb596aa180fa940544c2a5d838b05c582421..c0e1f08bb1d0ef6c71dcd2edfd5cc1708d03c960 100644 (file)
@@ -47,6 +47,12 @@ export class ServerService {
         css: ''
       }
     },
+    search: {
+      remoteUri: {
+        users: true,
+        anonymous: false
+      }
+    },
     plugin: {
       registered: []
     },
index 561ee6c1634cc62842bd162ec80748cd7b0365e8..8e1d24ea87b005c500ef3a5517f8115fb96e8663 100644 (file)
@@ -1,7 +1,7 @@
 <my-search-typeahead class="w-100 d-flex justify-content-end">
   <input
     type="text" id="search-video" name="search-video" [attr.aria-label]="ariaLabelTextForSearch"
-    i18n-placeholder placeholder="Search videos, channels… known by this instance" [(ngModel)]="searchValue"
+    i18n-placeholder placeholder="Search videos, channels…" [(ngModel)]="searchValue"
   >
   <span class="icon icon-search"></span>
 </my-search-typeahead>
index c2f5a1828c87a423ff33027637091ec8330bd9c9..6d7511c70070f9847cf9bb904cbb8be9b97b5cbf 100644 (file)
@@ -1,4 +1,7 @@
 @import '_mixins';
+@import '_variables';
+@import '_bootstrap-variables';
+@import '~bootstrap/scss/mixins/_breakpoints';
 
 .jump-to-suggestions {
   top: 100%;
@@ -46,11 +49,11 @@ my-suggestions ::ng-deep ul {
     transition: box-shadow .3s ease, width .2s ease;
   }
 
-  @media screen and (min-width: 500px) {
+  @media screen and (min-width: $mobile-view) {
     margin-left: 10px;
   }
 
-  @media screen and (max-width: 800px) {
+  @media screen and (max-width: $small-view) {
     flex: 1;
 
     ::ng-deep input {
@@ -71,7 +74,7 @@ my-suggestions ::ng-deep ul {
   &:focus,
   ::ng-deep &:focus-within {
     & > div:last-child {
-      @media screen and (min-width: 500px) {
+      @media screen and (min-width: $mobile-view) {
         display: initial !important;
       }
       
@@ -87,7 +90,7 @@ my-suggestions ::ng-deep ul {
       border-end-start-radius: 0;
       border-end-end-radius: 0;
 
-      @media screen and (min-width: 900px) {
+      @include media-breakpoint-up(lg) {
         width: 500px;
       }
     }
index 514c04704cfde1227f028411bfb634c26b513cab..9b414bc568b3496333f206a67e86c4325ea12238 100644 (file)
@@ -8,14 +8,15 @@ import {
   QueryList
 } from '@angular/core'
 import { Router, NavigationEnd, Params, ActivatedRoute } from '@angular/router'
-import { AuthService } from '@app/core'
+import { AuthService, ServerService } from '@app/core'
 import { I18n } from '@ngx-translate/i18n-polyfill'
 import { filter, first, tap, map } from 'rxjs/operators'
 import { ListKeyManager } from '@angular/cdk/a11y'
-import { UP_ARROW, DOWN_ARROW, ENTER, TAB } from '@angular/cdk/keycodes'
+import { UP_ARROW, DOWN_ARROW, ENTER } from '@angular/cdk/keycodes'
 import { SuggestionComponent, Result } from './suggestion.component'
 import { of } from 'rxjs'
 import { getParameterByName } from '@app/shared/misc/utils'
+import { ServerConfig } from '@shared/models'
 
 @Component({
   selector: 'my-search-typeahead',
@@ -30,7 +31,7 @@ export class SearchTypeaheadComponent implements OnInit, OnDestroy, AfterViewIni
   newSearch = true
 
   searchInput: HTMLInputElement
-  URIPolicy: 'only-followed' | 'any' = 'any'
+  serverConfig: ServerConfig
 
   URIPolicyText: string
   inAllText: string
@@ -44,6 +45,7 @@ export class SearchTypeaheadComponent implements OnInit, OnDestroy, AfterViewIni
     private authService: AuthService,
     private router: Router,
     private route: ActivatedRoute,
+    private serverService: ServerService,
     private i18n: I18n
   ) {
     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
         map(() => getParameterByName('search', window.location.href))
       )
       .subscribe(searchQuery => this.searchInput.value = searchQuery || '')
+
+    this.serverService.getConfig()
+      .subscribe(config => this.serverConfig = config)
   }
 
   ngOnDestroy () {
@@ -90,6 +95,16 @@ export class SearchTypeaheadComponent implements OnInit, OnDestroy, AfterViewIni
     return this.hasSearch && this.newSearch && this.activeResult && this.activeResult.type === 'search-global' || false
   }
 
+  get URIPolicy (): 'only-followed' | 'any' {
+    return (
+      this.authService.isLoggedIn()
+        ? this.serverConfig.search.remoteUri.users
+        : this.serverConfig.search.remoteUri.anonymous
+    )
+      ? 'any'
+      : 'only-followed'
+  }
+
   computeResults () {
     this.newSearch = true
     let results: Result[] = []
@@ -151,10 +166,6 @@ export class SearchTypeaheadComponent implements OnInit, OnDestroy, AfterViewIni
     )
   }
 
-  isUserLoggedIn () {
-    return this.authService.isLoggedIn()
-  }
-
   handleKeyUp (event: KeyboardEvent, indexSelected?: number) {
     event.stopImmediatePropagation()
     if (this.keyboardEventsManager) {
index fd8b3354f1043ce9abc42c1c6fcf02a92f26460f..51a56d414499044cd808ac4a60528463583fc05c 100644 (file)
         <my-feature-boolean [value]="serverConfig.tracker.enabled"></my-feature-boolean>
       </td>
     </tr>
+
+    <tr>
+      <td i18n class="label" colspan="2">Search</td>
+    </tr>
+
+    <tr>
+      <td i18n class="sub-label">Users can resolve distant content</td>
+      <td>
+        <my-feature-boolean [value]="serverConfig.search.remoteUri.users"></my-feature-boolean>
+      </td>
+    </tr>
   </table>
 </div>
index 69940f3952f6c3eb1f47e5bb8f63b4682f23e759..a383a723f8e42581015dad775763672eb536887d 100644 (file)
@@ -73,6 +73,12 @@ async function getConfig (req: express.Request, res: express.Response) {
         css: CONFIG.INSTANCE.CUSTOMIZATIONS.CSS
       }
     },
+    search: {
+      remoteUri: {
+        users: CONFIG.SEARCH.REMOTE_URI.USERS,
+        anonymous: CONFIG.SEARCH.REMOTE_URI.ANONYMOUS
+      }
+    },
     plugin: {
       registered: getRegisteredPlugins()
     },
index 4c6cf9597174b22558f3940faaa998790c3dc06b..75d1a816bb7bbd339ae33ac3dfc4764b4875665b 100644 (file)
@@ -235,6 +235,12 @@ async function generateNodeinfo (req: express.Request, res: express.Response) {
         nodeName: CONFIG.INSTANCE.NAME,
         nodeDescription: CONFIG.INSTANCE.SHORT_DESCRIPTION,
         nodeConfig: {
+          search: {
+            remoteUri: {
+              users: CONFIG.SEARCH.REMOTE_URI.USERS,
+              anonymous: CONFIG.SEARCH.REMOTE_URI.ANONYMOUS
+            }
+          },
           plugin: {
             registered: getRegisteredPlugins()
           },
index 76e0d6f2ddfa562ae42b4a8efd720a4636d8f22f..c3976a3461c35375ccfb0411bc98a3e644f0d996 100644 (file)
@@ -28,6 +28,13 @@ export interface ServerConfig {
     }
   }
 
+  search: {
+    remoteUri: {
+      users: boolean
+      anonymous: boolean
+    }
+  }
+
   plugin: {
     registered: ServerConfigPlugin[]
   }