MOBILE-3002 block: Add Glossary random block feature
parent
67be0a6c45
commit
0099385395
|
@ -31,6 +31,7 @@
|
||||||
"addon.block_calendarupcoming.pluginname": "block_calendar_upcoming",
|
"addon.block_calendarupcoming.pluginname": "block_calendar_upcoming",
|
||||||
"addon.block_comments.pluginname": "block_comments",
|
"addon.block_comments.pluginname": "block_comments",
|
||||||
"addon.block_completionstatus.pluginname": "block_completionstatus",
|
"addon.block_completionstatus.pluginname": "block_completionstatus",
|
||||||
|
"addon.block_glossaryrandom.pluginname": "block_glossary_random",
|
||||||
"addon.block_learningplans.pluginname": "block_lp",
|
"addon.block_learningplans.pluginname": "block_lp",
|
||||||
"addon.block_myoverview.all": "block_myoverview",
|
"addon.block_myoverview.all": "block_myoverview",
|
||||||
"addon.block_myoverview.favourites": "block_myoverview",
|
"addon.block_myoverview.favourites": "block_myoverview",
|
||||||
|
|
|
@ -0,0 +1,38 @@
|
||||||
|
// (C) Copyright 2015 Martin Dougiamas
|
||||||
|
//
|
||||||
|
// 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 { NgModule } from '@angular/core';
|
||||||
|
import { IonicModule } from 'ionic-angular';
|
||||||
|
import { TranslateModule } from '@ngx-translate/core';
|
||||||
|
import { CoreBlockDelegate } from '@core/block/providers/delegate';
|
||||||
|
import { AddonBlockGlossaryRandomHandler } from './providers/block-handler';
|
||||||
|
|
||||||
|
@NgModule({
|
||||||
|
declarations: [
|
||||||
|
],
|
||||||
|
imports: [
|
||||||
|
IonicModule,
|
||||||
|
TranslateModule.forChild()
|
||||||
|
],
|
||||||
|
exports: [
|
||||||
|
],
|
||||||
|
providers: [
|
||||||
|
AddonBlockGlossaryRandomHandler
|
||||||
|
]
|
||||||
|
})
|
||||||
|
export class AddonBlockGlossaryRandomModule {
|
||||||
|
constructor(blockDelegate: CoreBlockDelegate, blockHandler: AddonBlockGlossaryRandomHandler) {
|
||||||
|
blockDelegate.registerHandler(blockHandler);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,3 @@
|
||||||
|
{
|
||||||
|
"pluginname": "Random glossary entry"
|
||||||
|
}
|
|
@ -0,0 +1,50 @@
|
||||||
|
// (C) Copyright 2015 Martin Dougiamas
|
||||||
|
//
|
||||||
|
// 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, Injector } from '@angular/core';
|
||||||
|
import { TranslateService } from '@ngx-translate/core';
|
||||||
|
import { CoreBlockHandlerData } from '@core/block/providers/delegate';
|
||||||
|
import { CoreBlockPreRenderedComponent } from '@core/block/components/pre-rendered-block/pre-rendered-block';
|
||||||
|
import { CoreBlockBaseHandler } from '@core/block/classes/base-block-handler';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Block handler.
|
||||||
|
*/
|
||||||
|
@Injectable()
|
||||||
|
export class AddonBlockGlossaryRandomHandler extends CoreBlockBaseHandler {
|
||||||
|
name = 'AddonBlockGlossaryRandom';
|
||||||
|
blockName = 'glossary_random';
|
||||||
|
|
||||||
|
constructor(private translate: TranslateService) {
|
||||||
|
super();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the data needed to render the block.
|
||||||
|
*
|
||||||
|
* @param {Injector} injector Injector.
|
||||||
|
* @param {any} block The block to render.
|
||||||
|
* @param {string} contextLevel The context where the block will be used.
|
||||||
|
* @param {number} instanceId The instance ID associated with the context level.
|
||||||
|
* @return {CoreBlockHandlerData|Promise<CoreBlockHandlerData>} Data or promise resolved with the data.
|
||||||
|
*/
|
||||||
|
getDisplayData(injector: Injector, block: any, contextLevel: string, instanceId: number)
|
||||||
|
: CoreBlockHandlerData | Promise<CoreBlockHandlerData> {
|
||||||
|
return {
|
||||||
|
title: block.contents.title || this.translate.instant('addon.block_glossaryrandom.pluginname'),
|
||||||
|
class: 'addon-block-glossary-random',
|
||||||
|
component: CoreBlockPreRenderedComponent
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
|
@ -27,6 +27,7 @@ import { AddonModGlossarySyncCronHandler } from './providers/sync-cron-handler';
|
||||||
import { AddonModGlossaryIndexLinkHandler } from './providers/index-link-handler';
|
import { AddonModGlossaryIndexLinkHandler } from './providers/index-link-handler';
|
||||||
import { AddonModGlossaryEntryLinkHandler } from './providers/entry-link-handler';
|
import { AddonModGlossaryEntryLinkHandler } from './providers/entry-link-handler';
|
||||||
import { AddonModGlossaryListLinkHandler } from './providers/list-link-handler';
|
import { AddonModGlossaryListLinkHandler } from './providers/list-link-handler';
|
||||||
|
import { AddonModGlossaryEditLinkHandler } from './providers/edit-link-handler';
|
||||||
import { AddonModGlossaryComponentsModule } from './components/components.module';
|
import { AddonModGlossaryComponentsModule } from './components/components.module';
|
||||||
import { CoreUpdateManagerProvider } from '@providers/update-manager';
|
import { CoreUpdateManagerProvider } from '@providers/update-manager';
|
||||||
|
|
||||||
|
@ -54,7 +55,8 @@ export const ADDON_MOD_GLOSSARY_PROVIDERS: any[] = [
|
||||||
AddonModGlossarySyncCronHandler,
|
AddonModGlossarySyncCronHandler,
|
||||||
AddonModGlossaryIndexLinkHandler,
|
AddonModGlossaryIndexLinkHandler,
|
||||||
AddonModGlossaryEntryLinkHandler,
|
AddonModGlossaryEntryLinkHandler,
|
||||||
AddonModGlossaryListLinkHandler
|
AddonModGlossaryListLinkHandler,
|
||||||
|
AddonModGlossaryEditLinkHandler
|
||||||
]
|
]
|
||||||
})
|
})
|
||||||
export class AddonModGlossaryModule {
|
export class AddonModGlossaryModule {
|
||||||
|
@ -62,7 +64,8 @@ export class AddonModGlossaryModule {
|
||||||
prefetchDelegate: CoreCourseModulePrefetchDelegate, prefetchHandler: AddonModGlossaryPrefetchHandler,
|
prefetchDelegate: CoreCourseModulePrefetchDelegate, prefetchHandler: AddonModGlossaryPrefetchHandler,
|
||||||
cronDelegate: CoreCronDelegate, syncHandler: AddonModGlossarySyncCronHandler, linksDelegate: CoreContentLinksDelegate,
|
cronDelegate: CoreCronDelegate, syncHandler: AddonModGlossarySyncCronHandler, linksDelegate: CoreContentLinksDelegate,
|
||||||
indexHandler: AddonModGlossaryIndexLinkHandler, discussionHandler: AddonModGlossaryEntryLinkHandler,
|
indexHandler: AddonModGlossaryIndexLinkHandler, discussionHandler: AddonModGlossaryEntryLinkHandler,
|
||||||
updateManager: CoreUpdateManagerProvider, listLinkHandler: AddonModGlossaryListLinkHandler) {
|
updateManager: CoreUpdateManagerProvider, listLinkHandler: AddonModGlossaryListLinkHandler,
|
||||||
|
editLinkHandler: AddonModGlossaryEditLinkHandler) {
|
||||||
|
|
||||||
moduleDelegate.registerHandler(moduleHandler);
|
moduleDelegate.registerHandler(moduleHandler);
|
||||||
prefetchDelegate.registerHandler(prefetchHandler);
|
prefetchDelegate.registerHandler(prefetchHandler);
|
||||||
|
@ -70,6 +73,7 @@ export class AddonModGlossaryModule {
|
||||||
linksDelegate.registerHandler(indexHandler);
|
linksDelegate.registerHandler(indexHandler);
|
||||||
linksDelegate.registerHandler(discussionHandler);
|
linksDelegate.registerHandler(discussionHandler);
|
||||||
linksDelegate.registerHandler(listLinkHandler);
|
linksDelegate.registerHandler(listLinkHandler);
|
||||||
|
linksDelegate.registerHandler(editLinkHandler);
|
||||||
|
|
||||||
// Allow migrating the tables from the old app to the new schema.
|
// Allow migrating the tables from the old app to the new schema.
|
||||||
updateManager.registerSiteTableMigration({
|
updateManager.registerSiteTableMigration({
|
||||||
|
|
|
@ -0,0 +1,85 @@
|
||||||
|
// (C) Copyright 2015 Martin Dougiamas
|
||||||
|
//
|
||||||
|
// 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 '@core/contentlinks/classes/base-handler';
|
||||||
|
import { CoreContentLinksAction } from '@core/contentlinks/providers/delegate';
|
||||||
|
import { CoreContentLinksHelperProvider } from '@core/contentlinks/providers/helper';
|
||||||
|
import { CoreCourseProvider } from '@core/course/providers/course';
|
||||||
|
import { CoreDomUtilsProvider } from '@providers/utils/dom';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Content links handler for glossary new entry.
|
||||||
|
* Match mod/glossary/edit.php?cmid=6 with a valid data.
|
||||||
|
* Currently it only supports new entry.
|
||||||
|
*/
|
||||||
|
@Injectable()
|
||||||
|
export class AddonModGlossaryEditLinkHandler extends CoreContentLinksHandlerBase {
|
||||||
|
name = 'AddonModGlossaryEditLinkHandler';
|
||||||
|
featureName = 'CoreCourseModuleDelegate_AddonModGlossary';
|
||||||
|
pattern = /\/mod\/glossary\/edit\.php.*([\?\&](cmid)=\d+)/;
|
||||||
|
|
||||||
|
constructor(private linkHelper: CoreContentLinksHelperProvider, private courseProvider: CoreCourseProvider,
|
||||||
|
private domUtils: CoreDomUtilsProvider) {
|
||||||
|
super();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the list of actions for a link (url).
|
||||||
|
*
|
||||||
|
* @param {string[]} siteIds List of sites the URL belongs to.
|
||||||
|
* @param {string} url The URL to treat.
|
||||||
|
* @param {any} params The params of the URL. E.g. 'mysite.com?id=1' -> {id: 1}
|
||||||
|
* @param {number} [courseId] Course ID related to the URL. Optional but recommended.
|
||||||
|
* @return {CoreContentLinksAction[]|Promise<CoreContentLinksAction[]>} List of (or promise resolved with list of) actions.
|
||||||
|
*/
|
||||||
|
getActions(siteIds: string[], url: string, params: any, courseId?: number):
|
||||||
|
CoreContentLinksAction[] | Promise<CoreContentLinksAction[]> {
|
||||||
|
|
||||||
|
return [{
|
||||||
|
action: (siteId, navCtrl?): void => {
|
||||||
|
const modal = this.domUtils.showModalLoading(),
|
||||||
|
cmId = parseInt(params.cmid, 10);
|
||||||
|
|
||||||
|
this.courseProvider.getModuleBasicInfo(cmId, siteId).then((module) => {
|
||||||
|
const pageParams = {
|
||||||
|
courseId: module.course,
|
||||||
|
module: module,
|
||||||
|
glossary: module.module,
|
||||||
|
entry: null // It does not support entry editing.
|
||||||
|
};
|
||||||
|
|
||||||
|
return this.linkHelper.goInSite(navCtrl, 'AddonModGlossaryEditPage', pageParams, siteId);
|
||||||
|
}).finally(() => {
|
||||||
|
// Just in case. In fact we need to dismiss the modal before showing a toast or error message.
|
||||||
|
modal.dismiss();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check if the handler is enabled for a certain site (site + user) and a URL.
|
||||||
|
* If not defined, defaults to true.
|
||||||
|
*
|
||||||
|
* @param {string} siteId The site ID.
|
||||||
|
* @param {string} url The URL to treat.
|
||||||
|
* @param {any} params The params of the URL. E.g. 'mysite.com?id=1' -> {id: 1}
|
||||||
|
* @param {number} [courseId] Course ID related to the URL. Optional but recommended.
|
||||||
|
* @return {boolean|Promise<boolean>} Whether the handler is enabled for the URL and site.
|
||||||
|
*/
|
||||||
|
isEnabled(siteId: string, url: string, params: any, courseId?: number): boolean | Promise<boolean> {
|
||||||
|
return typeof params.cmid != 'undefined';
|
||||||
|
}
|
||||||
|
}
|
|
@ -95,6 +95,7 @@ import { AddonBlockCalendarMonthModule } from '@addon/block/calendarmonth/calend
|
||||||
import { AddonBlockCalendarUpcomingModule } from '@addon/block/calendarupcoming/calendarupcoming.module';
|
import { AddonBlockCalendarUpcomingModule } from '@addon/block/calendarupcoming/calendarupcoming.module';
|
||||||
import { AddonBlockCommentsModule } from '@addon/block/comments/comments.module';
|
import { AddonBlockCommentsModule } from '@addon/block/comments/comments.module';
|
||||||
import { AddonBlockCompletionStatusModule } from '@addon/block/completionstatus/completionstatus.module';
|
import { AddonBlockCompletionStatusModule } from '@addon/block/completionstatus/completionstatus.module';
|
||||||
|
import { AddonBlockGlossaryRandomModule } from '@addon/block/glossaryrandom/glossaryrandom.module';
|
||||||
import { AddonBlockHtmlModule } from '@addon/block/html/html.module';
|
import { AddonBlockHtmlModule } from '@addon/block/html/html.module';
|
||||||
import { AddonBlockMyOverviewModule } from '@addon/block/myoverview/myoverview.module';
|
import { AddonBlockMyOverviewModule } from '@addon/block/myoverview/myoverview.module';
|
||||||
import { AddonBlockNewsItemsModule } from '@addon/block/newsitems/newsitems.module';
|
import { AddonBlockNewsItemsModule } from '@addon/block/newsitems/newsitems.module';
|
||||||
|
@ -227,6 +228,7 @@ export const CORE_PROVIDERS: any[] = [
|
||||||
AddonBlockCalendarUpcomingModule,
|
AddonBlockCalendarUpcomingModule,
|
||||||
AddonBlockCommentsModule,
|
AddonBlockCommentsModule,
|
||||||
AddonBlockCompletionStatusModule,
|
AddonBlockCompletionStatusModule,
|
||||||
|
AddonBlockGlossaryRandomModule,
|
||||||
AddonBlockHtmlModule,
|
AddonBlockHtmlModule,
|
||||||
AddonBlockLearningPlansModule,
|
AddonBlockLearningPlansModule,
|
||||||
AddonBlockMyOverviewModule,
|
AddonBlockMyOverviewModule,
|
||||||
|
|
|
@ -31,6 +31,7 @@
|
||||||
"addon.block_calendarupcoming.pluginname": " Upcoming events",
|
"addon.block_calendarupcoming.pluginname": " Upcoming events",
|
||||||
"addon.block_comments.pluginname": "Comments",
|
"addon.block_comments.pluginname": "Comments",
|
||||||
"addon.block_completionstatus.pluginname": "Course completion status",
|
"addon.block_completionstatus.pluginname": "Course completion status",
|
||||||
|
"addon.block_glossaryrandom.pluginname": "Random glossary entry",
|
||||||
"addon.block_learningplans.pluginname": "Learning plans",
|
"addon.block_learningplans.pluginname": "Learning plans",
|
||||||
"addon.block_myoverview.all": "All",
|
"addon.block_myoverview.all": "All",
|
||||||
"addon.block_myoverview.favourites": "Starred",
|
"addon.block_myoverview.favourites": "Starred",
|
||||||
|
|
Loading…
Reference in New Issue