-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
MOBILE-3371 search: Implement globalsearch block
- Loading branch information
1 parent
e9bbf7b
commit 26514ed
Showing
7 changed files
with
127 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
// (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 { APP_INITIALIZER, NgModule } from '@angular/core'; | ||
import { IonicModule } from '@ionic/angular'; | ||
import { TranslateModule } from '@ngx-translate/core'; | ||
import { CoreBlockDelegate } from '@features/block/services/block-delegate'; | ||
import { AddonBlockGlobalSearchHandler } from './services/block-handler'; | ||
import { CoreBlockComponentsModule } from '@features/block/components/components.module'; | ||
|
||
@NgModule({ | ||
imports: [ | ||
IonicModule, | ||
CoreBlockComponentsModule, | ||
TranslateModule.forChild(), | ||
], | ||
providers: [ | ||
{ | ||
provide: APP_INITIALIZER, | ||
multi: true, | ||
useValue: () => { | ||
CoreBlockDelegate.registerHandler(AddonBlockGlobalSearchHandler.instance); | ||
}, | ||
}, | ||
], | ||
}) | ||
export class AddonBlockGlobalSearchModule {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"pluginname": "Global search" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
// (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 { CoreBlockHandlerData } from '@features/block/services/block-delegate'; | ||
import { CoreBlockOnlyTitleComponent } from '@features/block/components/only-title-block/only-title-block'; | ||
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'; | ||
|
||
/** | ||
* Block handler. | ||
*/ | ||
@Injectable({ providedIn: 'root' }) | ||
export class AddonBlockGlobalSearchHandlerService extends CoreBlockBaseHandler { | ||
|
||
name = 'AddonBlockGlobalSearch'; | ||
blockName = 'globalsearch'; | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
async isEnabled(): Promise<boolean> { | ||
const site = CoreSites.getRequiredCurrentSite(); | ||
|
||
return !site.isFeatureDisabled('CoreNoDelegate_GlobalSearch') | ||
&& site.wsAvailable('core_search_get_results') | ||
&& site.canUseAdvancedFeature('enableglobalsearch'); | ||
} | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
getDisplayData(block: CoreCourseBlock, contextLevel: string, instanceId: number): CoreBlockHandlerData | undefined { | ||
return { | ||
title: 'addon.block_globalsearch.pluginname', | ||
class: 'addon-block-globalsearch', | ||
component: CoreBlockOnlyTitleComponent, | ||
link: CORE_SEARCH_PAGE_NAME, | ||
linkParams: contextLevel === 'course' | ||
? { courseId: instanceId } | ||
: {}, | ||
}; | ||
} | ||
|
||
} | ||
|
||
export const AddonBlockGlobalSearchHandler = makeSingleton(AddonBlockGlobalSearchHandlerService); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters