MOBILE-2998 quiz: Fix drag and drop in Moodle 3.7

main
Dani Palou 2019-04-25 16:36:17 +02:00
parent 265f4a40f4
commit f746b28dfe
7 changed files with 22 additions and 14 deletions

View File

@ -58,7 +58,7 @@
</ion-note>
</ion-item-divider>
<!-- Body of the question. -->
<core-question text-wrap [question]="question" [component]="component" [componentId]="quiz.coursemodule" [attemptId]="attempt.id" [offlineEnabled]="offline" (onAbort)="abortQuiz()" (buttonClicked)="behaviourButtonClicked($event)"></core-question>
<core-question text-wrap [question]="question" [component]="component" [componentId]="quiz.coursemodule" [attemptId]="attempt.id" [usageId]="attempt.uniqueid" [offlineEnabled]="offline" (onAbort)="abortQuiz()" (buttonClicked)="behaviourButtonClicked($event)"></core-question>
</ion-card>
</div>
</form>

View File

@ -75,7 +75,7 @@
</ion-note>
</ion-item-divider>
<!-- Body of the question. -->
<core-question text-wrap [question]="question" [component]="component" [componentId]="componentId" [attemptId]="attempt.id" [offlineEnabled]="false"></core-question>
<core-question text-wrap [question]="question" [component]="component" [componentId]="componentId" [attemptId]="attempt.id" [usageId]="attempt.uniqueid" [offlineEnabled]="false"></core-question>
</ion-card>
</div>

View File

@ -409,7 +409,7 @@ export class AddonModQuizPrefetchHandler extends CoreCourseActivityPrefetchHandl
data.questions.forEach((question) => {
questionPromises.push(this.questionHelper.prefetchQuestionFiles(
question, this.component, quiz.coursemodule, siteId));
question, this.component, quiz.coursemodule, siteId, attempt.uniqueid));
});
return Promise.all(questionPromises);
@ -437,7 +437,7 @@ export class AddonModQuizPrefetchHandler extends CoreCourseActivityPrefetchHandl
data.questions.forEach((question) => {
questionPromises.push(this.questionHelper.prefetchQuestionFiles(
question, this.component, quiz.coursemodule, siteId));
question, this.component, quiz.coursemodule, siteId, attempt.uniqueid));
});
return Promise.all(questionPromises);

View File

@ -112,10 +112,11 @@ export class AddonQtypeDdMarkerHandler implements CoreQuestionHandler {
* Get the list of files that needs to be downloaded in addition to the files embedded in the HTML.
*
* @param {any} question Question.
* @param {number} usageId Usage ID.
* @return {string[]} List of URLs.
*/
getAdditionalDownloadableFiles(question: any): string[] {
this.questionHelper.extractQuestionScripts(question);
getAdditionalDownloadableFiles(question: any, usageId: number): string[] {
this.questionHelper.extractQuestionScripts(question, usageId);
if (question.amdArgs && typeof question.amdArgs[1] !== 'undefined') {
// Moodle 3.6+.

View File

@ -34,6 +34,7 @@ export class CoreQuestionComponent implements OnInit {
@Input() component: string; // The component the question belongs to.
@Input() componentId: number; // ID of the component the question belongs to.
@Input() attemptId: number; // Attempt ID.
@Input() usageId: number; // Usage ID.
@Input() offlineEnabled?: boolean | string; // Whether the question can be answered in offline.
@Output() buttonClicked: EventEmitter<any>; // Will emit an event when a behaviour button is clicked.
@Output() onAbort: EventEmitter<void>; // Will emit an event if the question should be aborted.
@ -86,7 +87,7 @@ export class CoreQuestionComponent implements OnInit {
};
// Treat the question.
this.questionHelper.extractQuestionScripts(this.question);
this.questionHelper.extractQuestionScripts(this.question, this.usageId);
// Handle question behaviour.
const behaviour = this.questionDelegate.getBehaviourForQuestion(this.question, this.question.preferredBehaviour);

View File

@ -112,9 +112,10 @@ export interface CoreQuestionHandler extends CoreDelegateHandler {
* Get the list of files that needs to be downloaded in addition to the files embedded in the HTML.
*
* @param {any} question Question.
* @param {number} usageId Usage ID.
* @return {string[]} List of URLs.
*/
getAdditionalDownloadableFiles?(question: any): string[];
getAdditionalDownloadableFiles?(question: any, usageId: number): string[];
}
/**
@ -274,11 +275,12 @@ export class CoreQuestionDelegate extends CoreDelegate {
* Get the list of files that needs to be downloaded in addition to the files embedded in the HTML.
*
* @param {any} question Question.
* @param {number} usageId Usage ID.
* @return {string[]} List of URLs.
*/
getAdditionalDownloadableFiles(question: any): string[] {
getAdditionalDownloadableFiles(question: any, usageId: number): string[] {
const type = this.getTypeName(question);
return this.executeFunctionOnEnabled(type, 'getAdditionalDownloadableFiles', [question]) || [];
return this.executeFunctionOnEnabled(type, 'getAdditionalDownloadableFiles', [question, usageId]) || [];
}
}

View File

@ -239,8 +239,9 @@ export class CoreQuestionHelperProvider {
* It will also search for init_question functions of the question type and add the object to an 'initObjects' property.
*
* @param {any} question Question.
* @param {number} usageId Usage ID.
*/
extractQuestionScripts(question: any): void {
extractQuestionScripts(question: any, usageId: number): void {
question.scriptsCode = '';
question.initObjects = null;
question.amdArgs = null;
@ -272,7 +273,8 @@ export class CoreQuestionHelperProvider {
}
const amdRegExp = new RegExp('require\\(\\["qtype_' + question.type + '/question"\\], ' +
'function\\(amd\\) \\{ amd\.init\\(("q' + question.slot + '".*?)\\); \\}\\);;', 'm');
'function\\(amd\\) \\{ amd\.init\\(("(q|question-' + usageId + '-)' + question.slot +
'".*?)\\); \\}\\);;', 'm');
const amdMatch = match.match(amdRegExp);
if (amdMatch) {
// Try to convert the arguments to an array and add them to the question.
@ -506,9 +508,11 @@ export class CoreQuestionHelperProvider {
* @param {string} [component] The component to link the files to. If not defined, question component.
* @param {string|number} [componentId] An ID to use in conjunction with the component. If not defined, question ID.
* @param {string} [siteId] Site ID. If not defined, current site.
* @param {number} [usageId] Usage ID. Required in Moodle 3.7+.
* @return {Promise<any>} Promise resolved when all the files have been downloaded.
*/
prefetchQuestionFiles(question: any, component?: string, componentId?: string | number, siteId?: string): Promise<any> {
prefetchQuestionFiles(question: any, component?: string, componentId?: string | number, siteId?: string, usageId?: number)
: Promise<any> {
const urls = this.domUtils.extractDownloadableFilesFromHtml(question.html);
if (!component) {
@ -516,7 +520,7 @@ export class CoreQuestionHelperProvider {
componentId = question.id;
}
urls.push(...this.questionDelegate.getAdditionalDownloadableFiles(question));
urls.push(...this.questionDelegate.getAdditionalDownloadableFiles(question, usageId));
return this.sitesProvider.getSite(siteId).then((site) => {
const promises = [];