- ngAfterViewInit () {
- this.searchInput = this.contentWrapper.nativeElement.childNodes[0]
- this.searchInput.addEventListener('input', this.computeResults.bind(this))
- this.searchInput.addEventListener('keyup', this.handleKeyUp.bind(this))
- }
-
- get hasSearch () {
- return !!this.searchInput && !!this.searchInput.value
- }
-
- get activeResult () {
- return this.keyboardEventsManager && this.keyboardEventsManager.activeItem && this.keyboardEventsManager.activeItem.result
- }
-
- get showHelp () {
- return this.hasSearch && this.newSearch && this.activeResult && this.activeResult.type === 'search-global' || false
- }
-
- computeResults () {
- this.newSearch = true
- let results: Result[] = []
-
- if (this.hasSearch) {
- results = [
- /* Channel search is still unimplemented. Uncomment when it is.
- {
- text: this.searchInput.value,
- type: 'search-channel'
- },
- */
- {
- text: this.searchInput.value,
- type: 'search-instance',
- default: true
- },
- /* Global search is still unimplemented. Uncomment when it is.
- {
- text: this.searchInput.value,
- type: 'search-global'
- },
- */
- ...results
- ]
+ areInstructionsDisplayed () {
+ return !this.search
+ }
+
+ showSearchGlobalHelp () {
+ return this.search && this.areSuggestionsOpened && this.keyboardEventsManager?.activeItem?.result?.type === 'search-index'
+ }
+
+ canSearchAnyURI () {
+ if (!this.serverConfig) return false
+
+ return this.authService.isLoggedIn()
+ ? this.serverConfig.search.remoteUri.users
+ : this.serverConfig.search.remoteUri.anonymous
+ }
+
+ onSearchChange () {
+ this.computeTypeahead()
+ }
+
+ initKeyboardEventsManager () {
+ if (this.keyboardEventsManager) return
+
+ this.keyboardEventsManager = new ListKeyManager(this.suggestionItems)
+
+ const activeIndex = this.suggestionItems.toArray().findIndex(i => i.result.default === true)
+ if (activeIndex === -1) {
+ console.error('Cannot find active index.', { suggestionItems: this.suggestionItems })