MOBILE-3523 essay: Improve essay files prefetch
parent
6631488ec3
commit
c1411c3ed4
|
@ -18,6 +18,7 @@ import { CoreQuestionProvider } from '@core/question/providers/question';
|
||||||
import { CoreQuestionHandler } from '@core/question/providers/delegate';
|
import { CoreQuestionHandler } from '@core/question/providers/delegate';
|
||||||
import { CoreQuestionHelperProvider } from '@core/question/providers/helper';
|
import { CoreQuestionHelperProvider } from '@core/question/providers/helper';
|
||||||
import { AddonQtypeDdMarkerComponent } from '../component/ddmarker';
|
import { AddonQtypeDdMarkerComponent } from '../component/ddmarker';
|
||||||
|
import { CoreWSExternalFile } from '@providers/ws';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handler to support drag-and-drop markers question type.
|
* Handler to support drag-and-drop markers question type.
|
||||||
|
@ -119,9 +120,9 @@ export class AddonQtypeDdMarkerHandler implements CoreQuestionHandler {
|
||||||
*
|
*
|
||||||
* @param question Question.
|
* @param question Question.
|
||||||
* @param usageId Usage ID.
|
* @param usageId Usage ID.
|
||||||
* @return List of URLs.
|
* @return List of files or URLs.
|
||||||
*/
|
*/
|
||||||
getAdditionalDownloadableFiles(question: any, usageId: number): string[] {
|
getAdditionalDownloadableFiles(question: any, usageId: number): (string | CoreWSExternalFile)[] {
|
||||||
this.questionHelper.extractQuestionScripts(question, usageId);
|
this.questionHelper.extractQuestionScripts(question, usageId);
|
||||||
|
|
||||||
if (question.amdArgs && typeof question.amdArgs[1] == 'string') {
|
if (question.amdArgs && typeof question.amdArgs[1] == 'string') {
|
||||||
|
|
|
@ -24,6 +24,7 @@ import { CoreQuestionHandler } from '@core/question/providers/delegate';
|
||||||
import { CoreQuestionHelperProvider } from '@core/question/providers/helper';
|
import { CoreQuestionHelperProvider } from '@core/question/providers/helper';
|
||||||
import { CoreQuestion } from '@core/question/providers/question';
|
import { CoreQuestion } from '@core/question/providers/question';
|
||||||
import { AddonQtypeEssayComponent } from '../component/essay';
|
import { AddonQtypeEssayComponent } from '../component/essay';
|
||||||
|
import { CoreWSExternalFile } from '@providers/ws';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handler to support essay question type.
|
* Handler to support essay question type.
|
||||||
|
@ -67,6 +68,23 @@ export class AddonQtypeEssayHandler implements CoreQuestionHandler {
|
||||||
return this.questionHelper.deleteStoredQuestionFiles(question, component, componentId, siteId);
|
return this.questionHelper.deleteStoredQuestionFiles(question, component, componentId, siteId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the list of files that needs to be downloaded in addition to the files embedded in the HTML.
|
||||||
|
*
|
||||||
|
* @param question Question.
|
||||||
|
* @param usageId Usage ID.
|
||||||
|
* @return List of files or URLs.
|
||||||
|
*/
|
||||||
|
getAdditionalDownloadableFiles(question: any, usageId: number): (string | CoreWSExternalFile)[] {
|
||||||
|
if (!question.responsefileareas) {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
|
return question.responsefileareas.reduce((urlsList, area) => {
|
||||||
|
return urlsList.concat(area.files || []);
|
||||||
|
}, []);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check whether the question allows text and/or attachments.
|
* Check whether the question allows text and/or attachments.
|
||||||
*
|
*
|
||||||
|
|
|
@ -18,6 +18,7 @@ import { CoreEventsProvider } from '@providers/events';
|
||||||
import { CoreSitesProvider } from '@providers/sites';
|
import { CoreSitesProvider } from '@providers/sites';
|
||||||
import { CoreDelegate, CoreDelegateHandler } from '@classes/delegate';
|
import { CoreDelegate, CoreDelegateHandler } from '@classes/delegate';
|
||||||
import { CoreQuestionDefaultHandler } from './default-question-handler';
|
import { CoreQuestionDefaultHandler } from './default-question-handler';
|
||||||
|
import { CoreWSExternalFile } from '@providers/ws';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Interface that all question type handlers must implement.
|
* Interface that all question type handlers must implement.
|
||||||
|
@ -119,9 +120,9 @@ export interface CoreQuestionHandler extends CoreDelegateHandler {
|
||||||
*
|
*
|
||||||
* @param question Question.
|
* @param question Question.
|
||||||
* @param usageId Usage ID.
|
* @param usageId Usage ID.
|
||||||
* @return List of URLs.
|
* @return List of files or URLs.
|
||||||
*/
|
*/
|
||||||
getAdditionalDownloadableFiles?(question: any, usageId: number): string[];
|
getAdditionalDownloadableFiles?(question: any, usageId: number): (string | CoreWSExternalFile)[];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Clear temporary data after the data has been saved.
|
* Clear temporary data after the data has been saved.
|
||||||
|
@ -324,9 +325,9 @@ export class CoreQuestionDelegate extends CoreDelegate {
|
||||||
*
|
*
|
||||||
* @param question Question.
|
* @param question Question.
|
||||||
* @param usageId Usage ID.
|
* @param usageId Usage ID.
|
||||||
* @return List of URLs.
|
* @return List of files or URLs.
|
||||||
*/
|
*/
|
||||||
getAdditionalDownloadableFiles(question: any, usageId: number): string[] {
|
getAdditionalDownloadableFiles(question: any, usageId: number): (string | CoreWSExternalFile)[] {
|
||||||
const type = this.getTypeName(question);
|
const type = this.getTypeName(question);
|
||||||
|
|
||||||
return this.executeFunctionOnEnabled(type, 'getAdditionalDownloadableFiles', [question, usageId]) || [];
|
return this.executeFunctionOnEnabled(type, 'getAdditionalDownloadableFiles', [question, usageId]) || [];
|
||||||
|
|
|
@ -590,29 +590,39 @@ export class CoreQuestionHelperProvider {
|
||||||
*/
|
*/
|
||||||
prefetchQuestionFiles(question: any, component?: string, componentId?: string | number, siteId?: string, usageId?: number)
|
prefetchQuestionFiles(question: any, component?: string, componentId?: string | number, siteId?: string, usageId?: number)
|
||||||
: Promise<any> {
|
: Promise<any> {
|
||||||
const urls = this.filepoolProvider.extractDownloadableFilesFromHtml(question.html);
|
|
||||||
|
|
||||||
if (!component) {
|
if (!component) {
|
||||||
component = CoreQuestionProvider.COMPONENT;
|
component = CoreQuestionProvider.COMPONENT;
|
||||||
componentId = question.number;
|
componentId = question.number;
|
||||||
}
|
}
|
||||||
|
|
||||||
urls.push(...this.questionDelegate.getAdditionalDownloadableFiles(question, usageId));
|
const files = this.questionDelegate.getAdditionalDownloadableFiles(question, usageId) || [];
|
||||||
|
|
||||||
|
files.push(...this.filepoolProvider.extractDownloadableFilesFromHtml(question.html));
|
||||||
|
|
||||||
return this.sitesProvider.getSite(siteId).then((site) => {
|
return this.sitesProvider.getSite(siteId).then((site) => {
|
||||||
const promises = [];
|
const promises = [];
|
||||||
|
const treated = {};
|
||||||
|
|
||||||
urls.forEach((url) => {
|
files.forEach((file) => {
|
||||||
if (!site.canDownloadFiles() && this.urlUtils.isPluginFileUrl(url)) {
|
const fileUrl = typeof file == 'string' ? file : file.fileurl;
|
||||||
|
const timemodified = (typeof file != 'string' && file.timemodified) || 0;
|
||||||
|
|
||||||
|
if (treated[fileUrl]) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
treated[fileUrl] = true;
|
||||||
|
|
||||||
|
if (!site.canDownloadFiles() && this.urlUtils.isPluginFileUrl(fileUrl)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (url.indexOf('theme/image.php') > -1 && url.indexOf('flagged') > -1) {
|
if (fileUrl.indexOf('theme/image.php') > -1 && fileUrl.indexOf('flagged') > -1) {
|
||||||
// Ignore flag images.
|
// Ignore flag images.
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
promises.push(this.filepoolProvider.addToQueueByUrl(siteId, url, component, componentId));
|
promises.push(this.filepoolProvider.addToQueueByUrl(siteId, fileUrl, component, componentId, timemodified));
|
||||||
});
|
});
|
||||||
|
|
||||||
return Promise.all(promises);
|
return Promise.all(promises);
|
||||||
|
|
Loading…
Reference in New Issue