Skip to content

Commit be865e6

Browse files
committed
MOBILE-1577 quiz: Improve the offline question status detection
1 parent 52b0d5d commit be865e6

File tree

18 files changed

+250
-158
lines changed

18 files changed

+250
-158
lines changed

www/addons/qtype/calculated/handlers.js

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,13 @@ angular.module('mm.addons.qtype_calculated')
2828
/**
2929
* Check if a response is complete.
3030
*
31-
* @param {Object} answers Question answers (without prefix).
32-
* @return {Mixed} True if complete, false if not complete, -1 if cannot determine.
31+
* @param {Object} question Question.
32+
* @param {Object} answers Question answers (without prefix).
33+
* @return {Mixed} True if complete, false if not complete, -1 if cannot determine.
3334
*/
34-
self.isCompleteResponse = function(answers) {
35+
self.isCompleteResponse = function(question, answers) {
3536
// This question type depends on numerical.
36-
return $mmaQtypeNumericalHandler.isCompleteResponse(answers);
37+
return $mmaQtypeNumericalHandler.isCompleteResponse(question, answers);
3738
};
3839

3940
/**
@@ -49,24 +50,26 @@ angular.module('mm.addons.qtype_calculated')
4950
* Check if a student has provided enough of an answer for the question to be graded automatically,
5051
* or whether it must be considered aborted.
5152
*
52-
* @param {Object} answers Question answers (without prefix).
53-
* @return {Mixed} True if gradable, false if not gradable, -1 if cannot determine.
53+
* @param {Object} question Question.
54+
* @param {Object} answers Question answers (without prefix).
55+
* @return {Mixed} True if gradable, false if not gradable, -1 if cannot determine.
5456
*/
55-
self.isGradableResponse = function(answers) {
57+
self.isGradableResponse = function(question, answers) {
5658
// This question type depends on numerical.
57-
return $mmaQtypeNumericalHandler.isGradableResponse(answers);
59+
return $mmaQtypeNumericalHandler.isGradableResponse(question, answers);
5860
};
5961

6062
/**
6163
* Check if two responses are the same.
6264
*
65+
* @param {Object} question Question.
6366
* @param {Object} prevAnswers Previous answers.
6467
* @param {Object} newAnswers New answers.
6568
* @return {Boolean} True if same, false otherwise.
6669
*/
67-
self.isSameResponse = function(prevAnswers, newAnswers) {
70+
self.isSameResponse = function(question, prevAnswers, newAnswers) {
6871
// This question type depends on numerical.
69-
return $mmaQtypeNumericalHandler.isSameResponse(prevAnswers, newAnswers);
72+
return $mmaQtypeNumericalHandler.isSameResponse(question, prevAnswers, newAnswers);
7073
};
7174

7275
/**

www/addons/qtype/calculatedmulti/handlers.js

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,11 @@ angular.module('mm.addons.qtype_calculatedmulti')
2828
/**
2929
* Check if a response is complete.
3030
*
31-
* @param {Object} answers Question answers (without prefix).
32-
* @return {Mixed} True if complete, false if not complete, -1 if cannot determine.
31+
* @param {Object} question Question.
32+
* @param {Object} answers Question answers (without prefix).
33+
* @return {Mixed} True if complete, false if not complete, -1 if cannot determine.
3334
*/
34-
self.isCompleteResponse = function(answers) {
35+
self.isCompleteResponse = function(question, answers) {
3536
// This question type depends on multichoice.
3637
return $mmaQtypeMultichoiceHandler.isCompleteResponseSingle(answers);
3738
};
@@ -49,22 +50,24 @@ angular.module('mm.addons.qtype_calculatedmulti')
4950
* Check if a student has provided enough of an answer for the question to be graded automatically,
5051
* or whether it must be considered aborted.
5152
*
52-
* @param {Object} answers Question answers (without prefix).
53-
* @return {Mixed} True if gradable, false if not gradable, -1 if cannot determine.
53+
* @param {Object} question Question.
54+
* @param {Object} answers Question answers (without prefix).
55+
* @return {Mixed} True if gradable, false if not gradable, -1 if cannot determine.
5456
*/
55-
self.isGradableResponse = function(answers) {
57+
self.isGradableResponse = function(question, answers) {
5658
// This question type depends on multichoice.
5759
return $mmaQtypeMultichoiceHandler.isGradableResponseSingle(answers);
5860
};
5961

6062
/**
6163
* Check if two responses are the same.
6264
*
65+
* @param {Object} question Question.
6366
* @param {Object} prevAnswers Previous answers.
6467
* @param {Object} newAnswers New answers.
6568
* @return {Boolean} True if same, false otherwise.
6669
*/
67-
self.isSameResponse = function(prevAnswers, newAnswers) {
70+
self.isSameResponse = function(question, prevAnswers, newAnswers) {
6871
// This question type depends on multichoice.
6972
return $mmaQtypeMultichoiceHandler.isSameResponseSingle(prevAnswers, newAnswers);
7073
};

www/addons/qtype/calculatedsimple/handlers.js

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,13 @@ angular.module('mm.addons.qtype_calculatedsimple')
2828
/**
2929
* Check if a response is complete.
3030
*
31-
* @param {Object} answers Question answers (without prefix).
32-
* @return {Mixed} True if complete, false if not complete, -1 if cannot determine.
31+
* @param {Object} question Question.
32+
* @param {Object} answers Question answers (without prefix).
33+
* @return {Mixed} True if complete, false if not complete, -1 if cannot determine.
3334
*/
34-
self.isCompleteResponse = function(answers) {
35+
self.isCompleteResponse = function(question, answers) {
3536
// This question type depends on calculated.
36-
return $mmaQtypeCalculatedHandler.isCompleteResponse(answers);
37+
return $mmaQtypeCalculatedHandler.isCompleteResponse(question, answers);
3738
};
3839

3940
/**
@@ -49,24 +50,26 @@ angular.module('mm.addons.qtype_calculatedsimple')
4950
* Check if a student has provided enough of an answer for the question to be graded automatically,
5051
* or whether it must be considered aborted.
5152
*
52-
* @param {Object} answers Question answers (without prefix).
53-
* @return {Mixed} True if gradable, false if not gradable, -1 if cannot determine.
53+
* @param {Object} question Question.
54+
* @param {Object} answers Question answers (without prefix).
55+
* @return {Mixed} True if gradable, false if not gradable, -1 if cannot determine.
5456
*/
55-
self.isGradableResponse = function(answers) {
57+
self.isGradableResponse = function(question, answers) {
5658
// This question type depends on calculated.
57-
return $mmaQtypeCalculatedHandler.isGradableResponse(answers);
59+
return $mmaQtypeCalculatedHandler.isGradableResponse(question, answers);
5860
};
5961

6062
/**
6163
* Check if two responses are the same.
6264
*
65+
* @param {Object} question Question.
6366
* @param {Object} prevAnswers Previous answers.
6467
* @param {Object} newAnswers New answers.
6568
* @return {Boolean} True if same, false otherwise.
6669
*/
67-
self.isSameResponse = function(prevAnswers, newAnswers) {
70+
self.isSameResponse = function(question, prevAnswers, newAnswers) {
6871
// This question type depends on calculated.
69-
return $mmaQtypeCalculatedHandler.isSameResponse(prevAnswers, newAnswers);
72+
return $mmaQtypeCalculatedHandler.isSameResponse(question, prevAnswers, newAnswers);
7073
};
7174

7275
/**

www/addons/qtype/ddimageortext/handlers.js

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -28,19 +28,20 @@ angular.module('mm.addons.qtype_ddimageortext')
2828
/**
2929
* Check if a response is complete.
3030
*
31-
* @param {Object} answers Question answers (without prefix).
32-
* @return {Mixed} True if complete, false if not complete, -1 if cannot determine.
31+
* @param {Object} question Question.
32+
* @param {Object} answers Question answers (without prefix).
33+
* @return {Mixed} True if complete, false if not complete, -1 if cannot determine.
3334
*/
34-
self.isCompleteResponse = function(answers) {
35-
// An answer is complete if all drop zones have an answer. Since we don't have the list of drop zones
36-
// we cannot determine if the answer is complete, only if it's unanswered.
37-
var hasReponse = false;
35+
self.isCompleteResponse = function(question, answers) {
36+
// An answer is complete if all drop zones have an answer.
37+
// We should always receive all the drop zones with their value ('' if not answered).
38+
var isComplete = true;
3839
angular.forEach(answers, function(value) {
39-
if (value && value !== '0') {
40-
hasReponse = true;
40+
if (!value || value === '0') {
41+
isComplete = false;
4142
}
4243
});
43-
return hasReponse ? -1 : false;
44+
return isComplete;
4445
};
4546

4647
/**
@@ -56,10 +57,11 @@ angular.module('mm.addons.qtype_ddimageortext')
5657
* Check if a student has provided enough of an answer for the question to be graded automatically,
5758
* or whether it must be considered aborted.
5859
*
59-
* @param {Object} answers Question answers (without prefix).
60-
* @return {Mixed} True if gradable, false if not gradable, -1 if cannot determine.
60+
* @param {Object} question Question.
61+
* @param {Object} answers Question answers (without prefix).
62+
* @return {Mixed} True if gradable, false if not gradable, -1 if cannot determine.
6163
*/
62-
self.isGradableResponse = function(answers) {
64+
self.isGradableResponse = function(question, answers) {
6365
var hasReponse = false;
6466
angular.forEach(answers, function(value) {
6567
if (value && value !== '0') {
@@ -72,11 +74,12 @@ angular.module('mm.addons.qtype_ddimageortext')
7274
/**
7375
* Check if two responses are the same.
7476
*
77+
* @param {Object} question Question.
7578
* @param {Object} prevAnswers Previous answers.
7679
* @param {Object} newAnswers New answers.
7780
* @return {Boolean} True if same, false otherwise.
7881
*/
79-
self.isSameResponse = function(prevAnswers, newAnswers) {
82+
self.isSameResponse = function(question, prevAnswers, newAnswers) {
8083
return $mmQuestion.compareAllAnswers(prevAnswers, newAnswers);
8184
};
8285

www/addons/qtype/ddmarker/handlers.js

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,12 @@ angular.module('mm.addons.qtype_ddmarker')
2828
/**
2929
* Check if a response is complete.
3030
*
31-
* @param {Object} answers Question answers (without prefix).
32-
* @return {Mixed} True if complete, false if not complete, -1 if cannot determine.
31+
* @param {Object} question Question.
32+
* @param {Object} answers Question answers (without prefix).
33+
* @return {Mixed} True if complete, false if not complete, -1 if cannot determine.
3334
*/
34-
self.isCompleteResponse = function(answers) {
35-
// We should always get a value for each dragitem so we can assume we receive all the possible answers.
35+
self.isCompleteResponse = function(question, answers) {
36+
// If 1 dragitem is set we assume the answer is complete (like Moodle does).
3637
var hasReponse = false;
3738
angular.forEach(answers, function(value) {
3839
if (value) {
@@ -55,21 +56,23 @@ angular.module('mm.addons.qtype_ddmarker')
5556
* Check if a student has provided enough of an answer for the question to be graded automatically,
5657
* or whether it must be considered aborted.
5758
*
58-
* @param {Object} answers Question answers (without prefix).
59-
* @return {Mixed} True if gradable, false if not gradable, -1 if cannot determine.
59+
* @param {Object} question Question.
60+
* @param {Object} answers Question answers (without prefix).
61+
* @return {Mixed} True if gradable, false if not gradable, -1 if cannot determine.
6062
*/
61-
self.isGradableResponse = function(answers) {
62-
return self.isCompleteResponse(answers);
63+
self.isGradableResponse = function(question, answers) {
64+
return self.isCompleteResponse(question, answers);
6365
};
6466

6567
/**
6668
* Check if two responses are the same.
6769
*
70+
* @param {Object} question Question.
6871
* @param {Object} prevAnswers Previous answers.
6972
* @param {Object} newAnswers New answers.
7073
* @return {Boolean} True if same, false otherwise.
7174
*/
72-
self.isSameResponse = function(prevAnswers, newAnswers) {
75+
self.isSameResponse = function(question, prevAnswers, newAnswers) {
7376
return $mmQuestion.compareAllAnswers(prevAnswers, newAnswers);
7477
};
7578

www/addons/qtype/ddwtos/handlers.js

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -28,19 +28,20 @@ angular.module('mm.addons.qtype_ddwtos')
2828
/**
2929
* Check if a response is complete.
3030
*
31-
* @param {Object} answers Question answers (without prefix).
32-
* @return {Mixed} True if complete, false if not complete, -1 if cannot determine.
31+
* @param {Object} question Question.
32+
* @param {Object} answers Question answers (without prefix).
33+
* @return {Mixed} True if complete, false if not complete, -1 if cannot determine.
3334
*/
34-
self.isCompleteResponse = function(answers) {
35-
// An answer is complete if all drop zones have an answer. Since we don't have the list of drop zones
36-
// we cannot determine if the answer is complete, only if it's unanswered.
37-
var hasReponse = false;
35+
self.isCompleteResponse = function(question, answers) {
36+
// An answer is complete if all drop zones have an answer.
37+
// We should always receive all the drop zones with their value ('0' if not answered).
38+
var isComplete = true;
3839
angular.forEach(answers, function(value) {
39-
if (value && value !== '0') {
40-
hasReponse = true;
40+
if (!value || value === '0') {
41+
isComplete = false;
4142
}
4243
});
43-
return hasReponse ? -1 : false;
44+
return isComplete;
4445
};
4546

4647
/**
@@ -56,10 +57,11 @@ angular.module('mm.addons.qtype_ddwtos')
5657
* Check if a student has provided enough of an answer for the question to be graded automatically,
5758
* or whether it must be considered aborted.
5859
*
59-
* @param {Object} answers Question answers (without prefix).
60-
* @return {Mixed} True if gradable, false if not gradable, -1 if cannot determine.
60+
* @param {Object} question Question.
61+
* @param {Object} answers Question answers (without prefix).
62+
* @return {Mixed} True if gradable, false if not gradable, -1 if cannot determine.
6163
*/
62-
self.isGradableResponse = function(answers) {
64+
self.isGradableResponse = function(question, answers) {
6365
var hasReponse = false;
6466
angular.forEach(answers, function(value) {
6567
if (value && value !== '0') {
@@ -72,11 +74,12 @@ angular.module('mm.addons.qtype_ddwtos')
7274
/**
7375
* Check if two responses are the same.
7476
*
77+
* @param {Object} question Question.
7578
* @param {Object} prevAnswers Previous answers.
7679
* @param {Object} newAnswers New answers.
7780
* @return {Boolean} True if same, false otherwise.
7881
*/
79-
self.isSameResponse = function(prevAnswers, newAnswers) {
82+
self.isSameResponse = function(question, prevAnswers, newAnswers) {
8083
return $mmQuestion.compareAllAnswers(prevAnswers, newAnswers);
8184
};
8285

www/addons/qtype/essay/handlers.js

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -39,14 +39,20 @@ angular.module('mm.addons.qtype_essay')
3939
/**
4040
* Check if a response is complete.
4141
*
42-
* @param {Object} answers Question answers (without prefix).
43-
* @return {Mixed} True if complete, false if not complete, -1 if cannot determine.
42+
* @param {Object} question Question.
43+
* @param {Object} answers Question answers (without prefix).
44+
* @return {Mixed} True if complete, false if not complete, -1 if cannot determine.
4445
*/
45-
self.isCompleteResponse = function(answers) {
46-
if (answers['answer'] && answers['answer'] !== '') {
47-
return true;
46+
self.isCompleteResponse = function(question, answers) {
47+
var hasInlineText = answers['answer'] && answers['answer'] !== '',
48+
questionEl = angular.element(question.html)[0],
49+
allowsAttachments = !!questionEl.querySelector('div[id*=filemanager]');
50+
51+
if (!allowsAttachments) {
52+
return hasInlineText;
4853
}
49-
// Since we can't know if the text is required or not we return -1.
54+
55+
// We can't know if the attachments are required or if the user added any in web.
5056
return -1;
5157
};
5258

@@ -63,21 +69,23 @@ angular.module('mm.addons.qtype_essay')
6369
* Check if a student has provided enough of an answer for the question to be graded automatically,
6470
* or whether it must be considered aborted.
6571
*
66-
* @param {Object} answers Question answers (without prefix).
67-
* @return {Mixed} True if gradable, false if not gradable, -1 if cannot determine.
72+
* @param {Object} question Question.
73+
* @param {Object} answers Question answers (without prefix).
74+
* @return {Mixed} True if gradable, false if not gradable, -1 if cannot determine.
6875
*/
69-
self.isGradableResponse = function(answers) {
76+
self.isGradableResponse = function(question, answers) {
7077
return false;
7178
};
7279

7380
/**
7481
* Check if two responses are the same.
7582
*
83+
* @param {Object} question Question.
7684
* @param {Object} prevAnswers Previous answers.
7785
* @param {Object} newAnswers New answers.
7886
* @return {Boolean} True if same, false otherwise.
7987
*/
80-
self.isSameResponse = function(prevAnswers, newAnswers) {
88+
self.isSameResponse = function(question, prevAnswers, newAnswers) {
8189
// For now we don't support attachments so we only compare the answer.
8290
return $mmUtil.sameAtKeyMissingIsBlank(prevAnswers, newAnswers, 'answer');
8391
};

0 commit comments

Comments
 (0)