Merge pull request #2198 from dpalou/MOBILE-3233

Mobile 3233
main
Juan Leyva 2019-12-09 12:11:59 +01:00 committed by GitHub
commit ad4fc5c371
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 217 additions and 12 deletions

View File

@ -18,8 +18,10 @@ import { AddonModLtiModuleHandler } from './providers/module-handler';
import { AddonModLtiProvider } from './providers/lti'; import { AddonModLtiProvider } from './providers/lti';
import { AddonModLtiLinkHandler } from './providers/link-handler'; import { AddonModLtiLinkHandler } from './providers/link-handler';
import { AddonModLtiListLinkHandler } from './providers/list-link-handler'; import { AddonModLtiListLinkHandler } from './providers/list-link-handler';
import { AddonModLtiPrefetchHandler } from './providers/prefetch-handler';
import { CoreContentLinksDelegate } from '@core/contentlinks/providers/delegate'; import { CoreContentLinksDelegate } from '@core/contentlinks/providers/delegate';
import { CoreCourseModuleDelegate } from '@core/course/providers/module-delegate'; import { CoreCourseModuleDelegate } from '@core/course/providers/module-delegate';
import { CoreCourseModulePrefetchDelegate } from '@core/course/providers/module-prefetch-delegate';
// List of providers (without handlers). // List of providers (without handlers).
export const ADDON_MOD_LTI_PROVIDERS: any[] = [ export const ADDON_MOD_LTI_PROVIDERS: any[] = [
@ -36,16 +38,22 @@ export const ADDON_MOD_LTI_PROVIDERS: any[] = [
AddonModLtiProvider, AddonModLtiProvider,
AddonModLtiModuleHandler, AddonModLtiModuleHandler,
AddonModLtiLinkHandler, AddonModLtiLinkHandler,
AddonModLtiListLinkHandler AddonModLtiListLinkHandler,
AddonModLtiPrefetchHandler
] ]
}) })
export class AddonModLtiModule { export class AddonModLtiModule {
constructor(moduleDelegate: CoreCourseModuleDelegate, moduleHandler: AddonModLtiModuleHandler, constructor(moduleDelegate: CoreCourseModuleDelegate,
contentLinksDelegate: CoreContentLinksDelegate, linkHandler: AddonModLtiLinkHandler, moduleHandler: AddonModLtiModuleHandler,
listLinkHandler: AddonModLtiListLinkHandler) { contentLinksDelegate: CoreContentLinksDelegate,
linkHandler: AddonModLtiLinkHandler,
listLinkHandler: AddonModLtiListLinkHandler,
prefetchDelegate: CoreCourseModulePrefetchDelegate,
prefetchHandler: AddonModLtiPrefetchHandler) {
moduleDelegate.registerHandler(moduleHandler); moduleDelegate.registerHandler(moduleHandler);
contentLinksDelegate.registerHandler(linkHandler); contentLinksDelegate.registerHandler(linkHandler);
contentLinksDelegate.registerHandler(listLinkHandler); contentLinksDelegate.registerHandler(listLinkHandler);
prefetchDelegate.registerHandler(prefetchHandler);
} }
} }

View File

@ -0,0 +1,96 @@
// (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 { TranslateService } from '@ngx-translate/core';
import { CoreAppProvider } from '@providers/app';
import { CoreFilepoolProvider } from '@providers/filepool';
import { CoreSitesProvider } from '@providers/sites';
import { CoreDomUtilsProvider } from '@providers/utils/dom';
import { CoreUtilsProvider } from '@providers/utils/utils';
import { CoreCourseProvider } from '@core/course/providers/course';
import { CoreCourseActivityPrefetchHandlerBase } from '@core/course/classes/activity-prefetch-handler';
import { AddonModLtiProvider } from './lti';
import { CoreFilterHelperProvider } from '@core/filter/providers/helper';
/**
* Handler to prefetch LTIs. LTIs cannot be prefetched, but the handler will be used to invalidate some data on course PTR.
*/
@Injectable()
export class AddonModLtiPrefetchHandler extends CoreCourseActivityPrefetchHandlerBase {
name = 'AddonModLti';
modName = 'lti';
component = AddonModLtiProvider.COMPONENT;
constructor(translate: TranslateService,
appProvider: CoreAppProvider,
utils: CoreUtilsProvider,
courseProvider: CoreCourseProvider,
filepoolProvider: CoreFilepoolProvider,
sitesProvider: CoreSitesProvider,
domUtils: CoreDomUtilsProvider,
filterHelper: CoreFilterHelperProvider,
protected ltiProvider: AddonModLtiProvider) {
super(translate, appProvider, utils, courseProvider, filepoolProvider, sitesProvider, domUtils, filterHelper);
}
/**
* Download the module.
*
* @param module The module object returned by WS.
* @param courseId Course ID.
* @param dirPath Path of the directory where to store all the content files.
* @return Promise resolved when all content is downloaded.
*/
download(module: any, courseId: number, dirPath?: string): Promise<any> {
return Promise.resolve();
}
/**
* Invalidate WS calls needed to determine module status (usually, to check if module is downloadable).
* It doesn't need to invalidate check updates. It should NOT invalidate files nor all the prefetched data.
*
* @param module Module.
* @param courseId Course ID the module belongs to.
* @return Promise resolved when invalidated.
*/
invalidateModule(module: any, courseId: number): Promise<any> {
return this.ltiProvider.invalidateLti(courseId);
}
/**
* Check if a module can be downloaded.
*
* @param module Module.
* @param courseId Course ID the module belongs to.
* @return Whether the module can be downloaded. The promise should never be rejected.
*/
isDownloadable(module: any, courseId: number): boolean | Promise<boolean> {
return false; // LTIs aren't downloadable.
}
/**
* Prefetch a module.
*
* @param module Module.
* @param courseId Course ID the module belongs to.
* @param single True if we're downloading a single module, false if we're downloading a whole section.
* @param dirPath Path of the directory where to store all the content files.
* @return Promise resolved when done.
*/
prefetch(module: any, courseId?: number, single?: boolean, dirPath?: string): Promise<any> {
return Promise.resolve();
}
}

View File

@ -120,10 +120,8 @@ export class AddonModUrlIndexComponent extends CoreCourseModuleMainResourceCompo
} else { } else {
mod = this.module; mod = this.module;
if (!mod.contents || !mod.contents.length) {
// Try to load module contents, it's needed to get the URL with parameters. // Try to load module contents, it's needed to get the URL with parameters.
return this.courseProvider.loadModuleContents(mod, this.courseId, undefined, false, false, undefined, 'url'); return this.courseProvider.loadModuleContents(mod, this.courseId, undefined, false, refresh, undefined, 'url');
}
} }
}).then(() => { }).then(() => {
// Always use the URL from the module because it already includes the parameters. // Always use the URL from the module because it already includes the parameters.

View File

@ -0,0 +1,95 @@
// (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 { TranslateService } from '@ngx-translate/core';
import { CoreAppProvider } from '@providers/app';
import { CoreFilepoolProvider } from '@providers/filepool';
import { CoreSitesProvider } from '@providers/sites';
import { CoreDomUtilsProvider } from '@providers/utils/dom';
import { CoreUtilsProvider } from '@providers/utils/utils';
import { CoreCourseProvider } from '@core/course/providers/course';
import { CoreCourseResourcePrefetchHandlerBase } from '@core/course/classes/resource-prefetch-handler';
import { AddonModUrlProvider } from './url';
import { CoreFilterHelperProvider } from '@core/filter/providers/helper';
/**
* Handler to prefetch URLs. URLs cannot be prefetched, but the handler will be used to invalidate some data on course PTR.
*/
@Injectable()
export class AddonModUrlPrefetchHandler extends CoreCourseResourcePrefetchHandlerBase {
name = 'AddonModUrl';
modName = 'url';
component = AddonModUrlProvider.COMPONENT;
constructor(translate: TranslateService,
appProvider: CoreAppProvider,
utils: CoreUtilsProvider,
courseProvider: CoreCourseProvider,
filepoolProvider: CoreFilepoolProvider,
sitesProvider: CoreSitesProvider,
domUtils: CoreDomUtilsProvider,
filterHelper: CoreFilterHelperProvider) {
super(translate, appProvider, utils, courseProvider, filepoolProvider, sitesProvider, domUtils, filterHelper);
}
/**
* Download the module.
*
* @param module The module object returned by WS.
* @param courseId Course ID.
* @param dirPath Path of the directory where to store all the content files.
* @return Promise resolved when all content is downloaded.
*/
download(module: any, courseId: number, dirPath?: string): Promise<any> {
return Promise.resolve();
}
/**
* Invalidate WS calls needed to determine module status (usually, to check if module is downloadable).
* It doesn't need to invalidate check updates. It should NOT invalidate files nor all the prefetched data.
*
* @param module Module.
* @param courseId Course ID the module belongs to.
* @return Promise resolved when invalidated.
*/
invalidateModule(module: any, courseId: number): Promise<any> {
return this.courseProvider.invalidateModule(module.id, undefined, this.modName);
}
/**
* Check if a module can be downloaded.
*
* @param module Module.
* @param courseId Course ID the module belongs to.
* @return Whether the module can be downloaded. The promise should never be rejected.
*/
isDownloadable(module: any, courseId: number): boolean | Promise<boolean> {
return false; // URLs aren't downloadable.
}
/**
* Prefetch a module.
*
* @param module Module.
* @param courseId Course ID the module belongs to.
* @param single True if we're downloading a single module, false if we're downloading a whole section.
* @param dirPath Path of the directory where to store all the content files.
* @return Promise resolved when done.
*/
prefetch(module: any, courseId?: number, single?: boolean, dirPath?: string): Promise<any> {
return Promise.resolve();
}
}

View File

@ -18,9 +18,11 @@ import { AddonModUrlModuleHandler } from './providers/module-handler';
import { AddonModUrlProvider } from './providers/url'; import { AddonModUrlProvider } from './providers/url';
import { AddonModUrlLinkHandler } from './providers/link-handler'; import { AddonModUrlLinkHandler } from './providers/link-handler';
import { AddonModUrlListLinkHandler } from './providers/list-link-handler'; import { AddonModUrlListLinkHandler } from './providers/list-link-handler';
import { AddonModUrlPrefetchHandler } from './providers/prefetch-handler';
import { AddonModUrlHelperProvider } from './providers/helper'; import { AddonModUrlHelperProvider } from './providers/helper';
import { CoreContentLinksDelegate } from '@core/contentlinks/providers/delegate'; import { CoreContentLinksDelegate } from '@core/contentlinks/providers/delegate';
import { CoreCourseModuleDelegate } from '@core/course/providers/module-delegate'; import { CoreCourseModuleDelegate } from '@core/course/providers/module-delegate';
import { CoreCourseModulePrefetchDelegate } from '@core/course/providers/module-prefetch-delegate';
// List of providers (without handlers). // List of providers (without handlers).
export const ADDON_MOD_URL_PROVIDERS: any[] = [ export const ADDON_MOD_URL_PROVIDERS: any[] = [
@ -39,16 +41,22 @@ export const ADDON_MOD_URL_PROVIDERS: any[] = [
AddonModUrlHelperProvider, AddonModUrlHelperProvider,
AddonModUrlModuleHandler, AddonModUrlModuleHandler,
AddonModUrlLinkHandler, AddonModUrlLinkHandler,
AddonModUrlListLinkHandler AddonModUrlListLinkHandler,
AddonModUrlPrefetchHandler
] ]
}) })
export class AddonModUrlModule { export class AddonModUrlModule {
constructor(moduleDelegate: CoreCourseModuleDelegate, moduleHandler: AddonModUrlModuleHandler, constructor(moduleDelegate: CoreCourseModuleDelegate,
contentLinksDelegate: CoreContentLinksDelegate, linkHandler: AddonModUrlLinkHandler, moduleHandler: AddonModUrlModuleHandler,
listLinkHandler: AddonModUrlListLinkHandler) { contentLinksDelegate: CoreContentLinksDelegate,
linkHandler: AddonModUrlLinkHandler,
listLinkHandler: AddonModUrlListLinkHandler,
prefetchDelegate: CoreCourseModulePrefetchDelegate,
prefetchHandler: AddonModUrlPrefetchHandler) {
moduleDelegate.registerHandler(moduleHandler); moduleDelegate.registerHandler(moduleHandler);
contentLinksDelegate.registerHandler(linkHandler); contentLinksDelegate.registerHandler(linkHandler);
contentLinksDelegate.registerHandler(listLinkHandler); contentLinksDelegate.registerHandler(listLinkHandler);
prefetchDelegate.registerHandler(prefetchHandler);
} }
} }