MOBILE-3371 search: Implement link handler
parent
b2b0262c5b
commit
e4755af9c6
|
@ -18,8 +18,8 @@ import { CoreBlockOnlyTitleComponent } from '@features/block/components/only-tit
|
|||
import { CoreBlockBaseHandler } from '@features/block/classes/base-block-handler';
|
||||
import { makeSingleton } from '@singletons';
|
||||
import { CoreCourseBlock } from '@features/course/services/course';
|
||||
import { CoreSites } from '@services/sites';
|
||||
import { CORE_SEARCH_PAGE_NAME } from '@features/search/services/handlers/mainmenu';
|
||||
import { CoreSearchGlobalSearch } from '@features/search/services/global-search';
|
||||
|
||||
/**
|
||||
* Block handler.
|
||||
|
@ -34,11 +34,7 @@ export class AddonBlockGlobalSearchHandlerService extends CoreBlockBaseHandler {
|
|||
* @inheritdoc
|
||||
*/
|
||||
async isEnabled(): Promise<boolean> {
|
||||
const site = CoreSites.getRequiredCurrentSite();
|
||||
|
||||
return !site.isFeatureDisabled('CoreNoDelegate_GlobalSearch')
|
||||
&& site.wsAvailable('core_search_get_results')
|
||||
&& site.canUseAdvancedFeature('enableglobalsearch');
|
||||
return CoreSearchGlobalSearch.isEnabled();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
import { Component, OnInit, OnDestroy } from '@angular/core';
|
||||
import { Component, OnInit, OnDestroy, AfterViewInit, ViewChild } from '@angular/core';
|
||||
import { CoreDomUtils } from '@services/utils/dom';
|
||||
import { CoreSearchGlobalSearchResultsSource } from '@features/search/classes/global-search-results-source';
|
||||
import { CoreSites } from '@services/sites';
|
||||
|
@ -28,18 +28,21 @@ import {
|
|||
CoreSearchGlobalSearch,
|
||||
} from '@features/search/services/global-search';
|
||||
import { CoreNavigator } from '@services/navigator';
|
||||
import { CoreSearchBoxComponent } from '@features/search/components/search-box/search-box';
|
||||
|
||||
@Component({
|
||||
selector: 'page-core-search-global-search',
|
||||
templateUrl: 'global-search.html',
|
||||
})
|
||||
export class CoreSearchGlobalSearchPage implements OnInit, OnDestroy {
|
||||
export class CoreSearchGlobalSearchPage implements OnInit, OnDestroy, AfterViewInit {
|
||||
|
||||
loadMoreError: string | null = null;
|
||||
searchBanner: string | null = null;
|
||||
resultsSource = new CoreSearchGlobalSearchResultsSource('', {});
|
||||
private filtersObserver?: CoreEventObserver;
|
||||
|
||||
@ViewChild(CoreSearchBoxComponent) searchBox?: CoreSearchBoxComponent;
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
|
@ -62,6 +65,21 @@ export class CoreSearchGlobalSearchPage implements OnInit, OnDestroy {
|
|||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
ngAfterViewInit(): void {
|
||||
const query = CoreNavigator.getRouteParam('query');
|
||||
|
||||
if (query) {
|
||||
if (this.searchBox) {
|
||||
this.searchBox.searchText = query;
|
||||
}
|
||||
|
||||
this.search(query);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
|
|
|
@ -25,6 +25,8 @@ import { CORE_SITE_SCHEMAS } from '@services/sites';
|
|||
import { CoreSearchComponentsModule } from './components/components.module';
|
||||
import { SITE_SCHEMA } from './services/search-history-db';
|
||||
import { CoreSearchHistoryProvider } from './services/search-history.service';
|
||||
import { CoreContentLinksDelegate } from '@features/contentlinks/services/contentlinks-delegate';
|
||||
import { CoreSearchGlobalSearchLinkHandler } from '@features/search/services/handlers/global-search-link';
|
||||
|
||||
export const CORE_SEARCH_SERVICES: Type<unknown>[] = [
|
||||
CoreSearchHistoryProvider,
|
||||
|
@ -51,6 +53,7 @@ const mainMenuChildrenRoutes: Routes = [
|
|||
multi: true,
|
||||
useValue() {
|
||||
CoreMainMenuDelegate.registerHandler(CoreSearchMainMenuHandler.instance);
|
||||
CoreContentLinksDelegate.registerHandler(CoreSearchGlobalSearchLinkHandler.instance);
|
||||
},
|
||||
},
|
||||
],
|
||||
|
|
|
@ -83,6 +83,21 @@ export class CoreSearchGlobalSearchService {
|
|||
|
||||
private static readonly SEARCH_AREAS_CACHE_KEY = 'CoreSearchGlobalSearch:SearchAreas';
|
||||
|
||||
/**
|
||||
* Check whether global search is enabled or not.
|
||||
*
|
||||
* @returns Whether global search is enabled or not.
|
||||
*/
|
||||
async isEnabled(siteId?: string): Promise<boolean> {
|
||||
const site = siteId
|
||||
? await CoreSites.getSite(siteId)
|
||||
: CoreSites.getRequiredCurrentSite();
|
||||
|
||||
return !site?.isFeatureDisabled('CoreNoDelegate_GlobalSearch')
|
||||
&& site?.wsAvailable('core_search_get_results') // @since 4.3
|
||||
&& site?.canUseAdvancedFeature('enableglobalsearch');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get results.
|
||||
*
|
||||
|
|
|
@ -0,0 +1,56 @@
|
|||
// (C) Copyright 2015 Moodle Pty Ltd.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
import { Injectable } from '@angular/core';
|
||||
import { CoreContentLinksHandlerBase } from '@features/contentlinks/classes/base-handler';
|
||||
import { CoreContentLinksAction } from '@features/contentlinks/services/contentlinks-delegate';
|
||||
import { CoreSearchGlobalSearch } from '@features/search/services/global-search';
|
||||
import { CORE_SEARCH_PAGE_NAME } from '@features/search/services/handlers/mainmenu';
|
||||
import { CoreNavigator } from '@services/navigator';
|
||||
import { makeSingleton } from '@singletons';
|
||||
|
||||
/**
|
||||
* Handler to treat links to search page.
|
||||
*/
|
||||
@Injectable( { providedIn: 'root' })
|
||||
export class CoreSearchGlobalSearchLinkHandlerService extends CoreContentLinksHandlerBase {
|
||||
|
||||
name = 'CoreSearchSearchLinkHandler';
|
||||
pattern = /\/search\/index\.php.*/;
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
async isEnabled(siteId: string): Promise<boolean> {
|
||||
return CoreSearchGlobalSearch.isEnabled(siteId);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
getActions(siteIds: string[], url: string, params: Record<string, string>): CoreContentLinksAction[] {
|
||||
return [{
|
||||
action: (siteId: string): void => {
|
||||
CoreNavigator.navigateToSitePath(CORE_SEARCH_PAGE_NAME, {
|
||||
siteId,
|
||||
params: {
|
||||
query: params.q,
|
||||
},
|
||||
});
|
||||
},
|
||||
}];
|
||||
}
|
||||
|
||||
}
|
||||
export const CoreSearchGlobalSearchLinkHandler = makeSingleton(CoreSearchGlobalSearchLinkHandlerService);
|
|
@ -15,7 +15,7 @@
|
|||
import { Injectable } from '@angular/core';
|
||||
import { makeSingleton } from '@singletons';
|
||||
import { CoreMainMenuHandler, CoreMainMenuHandlerData } from '@features/mainmenu/services/mainmenu-delegate';
|
||||
import { CoreSites } from '@services/sites';
|
||||
import { CoreSearchGlobalSearch } from '@features/search/services/global-search';
|
||||
|
||||
export const CORE_SEARCH_PAGE_NAME = 'search';
|
||||
|
||||
|
@ -32,11 +32,7 @@ export class CoreSearchMainMenuHandlerService implements CoreMainMenuHandler {
|
|||
* @inheritdoc
|
||||
*/
|
||||
async isEnabled(): Promise<boolean> {
|
||||
const site = CoreSites.getRequiredCurrentSite();
|
||||
|
||||
return !site.isFeatureDisabled('CoreNoDelegate_GlobalSearch')
|
||||
&& site.wsAvailable('core_search_get_results')
|
||||
&& site.canUseAdvancedFeature('enableglobalsearch');
|
||||
return CoreSearchGlobalSearch.isEnabled();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in New Issue