@vived/app 4.4.0 → 4.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/Components/Question/Entities/QuestionAnswerEntity.d.ts +2 -1
- package/lib/Components/Question/Entities/QuestionAnswerEntity.js +9 -5
- package/lib/Components/Question/Entities/QuestionEntity.d.ts +1 -1
- package/lib/Components/Question/Entities/QuestionEntity.js +2 -9
- package/lib/Components/Question/PM/QuestionChallengePM.d.ts +2 -0
- package/lib/Components/Question/PM/QuestionChallengePM.js +21 -3
- package/lib/Components/Question/UC/ValidateQuestionChallengeStateUC.d.ts +19 -0
- package/lib/Components/Question/UC/ValidateQuestionChallengeStateUC.js +83 -0
- package/lib/Components/Question/UC/index.d.ts +1 -0
- package/lib/Components/Question/UC/index.js +1 -0
- package/package.json +1 -1
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { AppObject } from "../../../AppObject/AppObject";
|
|
2
2
|
import { AppObjectEntity } from "../../../AppObject/AppObjectEntity";
|
|
3
|
-
export declare const EMPTY_TEXT_VALIDATION_MESSAGE = "
|
|
3
|
+
export declare const EMPTY_TEXT_VALIDATION_MESSAGE = "Answer text is required.";
|
|
4
4
|
export declare const MAX_QUESTION_LENGTH = 40;
|
|
5
5
|
export declare const LONG_TEXT_VALIDATION_MESSAGE: string;
|
|
6
6
|
export declare const MAX_FEEDBACK_LENGTH = 200;
|
|
7
7
|
export declare const LONG_FEEDBACK_VALIDATION_MESSAGE: string;
|
|
8
|
+
export declare const FEEDBACK_STRING_CANNOT_BE_0_CHARACTERS = "Feedback string cannot be 0 characters.";
|
|
8
9
|
export declare abstract class QuestionAnswerEntity extends AppObjectEntity {
|
|
9
10
|
static readonly type = "QuestionAnswerEntity";
|
|
10
11
|
abstract readonly id: string;
|
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.makeQuestionAnswerEntity = exports.QuestionAnswerEntity = exports.LONG_FEEDBACK_VALIDATION_MESSAGE = exports.MAX_FEEDBACK_LENGTH = exports.LONG_TEXT_VALIDATION_MESSAGE = exports.MAX_QUESTION_LENGTH = exports.EMPTY_TEXT_VALIDATION_MESSAGE = void 0;
|
|
3
|
+
exports.makeQuestionAnswerEntity = exports.QuestionAnswerEntity = exports.FEEDBACK_STRING_CANNOT_BE_0_CHARACTERS = exports.LONG_FEEDBACK_VALIDATION_MESSAGE = exports.MAX_FEEDBACK_LENGTH = exports.LONG_TEXT_VALIDATION_MESSAGE = exports.MAX_QUESTION_LENGTH = exports.EMPTY_TEXT_VALIDATION_MESSAGE = void 0;
|
|
4
4
|
const AppObjectEntity_1 = require("../../../AppObject/AppObjectEntity");
|
|
5
5
|
const Entities_1 = require("../../../Entities");
|
|
6
|
-
exports.EMPTY_TEXT_VALIDATION_MESSAGE = "
|
|
6
|
+
exports.EMPTY_TEXT_VALIDATION_MESSAGE = "Answer text is required.";
|
|
7
7
|
exports.MAX_QUESTION_LENGTH = 40;
|
|
8
|
-
exports.LONG_TEXT_VALIDATION_MESSAGE = `
|
|
8
|
+
exports.LONG_TEXT_VALIDATION_MESSAGE = `Answer text may not exceed ${exports.MAX_QUESTION_LENGTH} characters.`;
|
|
9
9
|
exports.MAX_FEEDBACK_LENGTH = 200;
|
|
10
|
-
exports.LONG_FEEDBACK_VALIDATION_MESSAGE = `
|
|
10
|
+
exports.LONG_FEEDBACK_VALIDATION_MESSAGE = `Answer feedback may not exceed ${exports.MAX_FEEDBACK_LENGTH} characters.`;
|
|
11
|
+
exports.FEEDBACK_STRING_CANNOT_BE_0_CHARACTERS = "Feedback string cannot be 0 characters.";
|
|
11
12
|
class QuestionAnswerEntity extends AppObjectEntity_1.AppObjectEntity {
|
|
12
13
|
}
|
|
13
14
|
exports.QuestionAnswerEntity = QuestionAnswerEntity;
|
|
@@ -51,7 +52,10 @@ class QuestionAnswerEntityImp extends QuestionAnswerEntity {
|
|
|
51
52
|
this.memoizedFeedback.val = val;
|
|
52
53
|
}
|
|
53
54
|
get feedbackValidationMessage() {
|
|
54
|
-
if (this.feedbackText.length
|
|
55
|
+
if (this.feedbackText.length === 0) {
|
|
56
|
+
return exports.FEEDBACK_STRING_CANNOT_BE_0_CHARACTERS;
|
|
57
|
+
}
|
|
58
|
+
else if (this.feedbackText.length > exports.MAX_FEEDBACK_LENGTH) {
|
|
55
59
|
return exports.LONG_FEEDBACK_VALIDATION_MESSAGE;
|
|
56
60
|
}
|
|
57
61
|
else {
|
|
@@ -2,7 +2,7 @@ import { AppObject } from "../../../AppObject/AppObject";
|
|
|
2
2
|
import { AppObjectEntity } from "../../../AppObject/AppObjectEntity";
|
|
3
3
|
import { AppObjectRepo } from "../../../AppObject/AppObjectRepo";
|
|
4
4
|
import { QuestionAnswerEntity } from "./QuestionAnswerEntity";
|
|
5
|
-
export declare const VALIDATION_NO_CORRECT = "At least one answer must be
|
|
5
|
+
export declare const VALIDATION_NO_CORRECT = "At least one answer must be correct.";
|
|
6
6
|
export declare const VALIDATION_NOT_ENOUGH_ANSWERS = "Question must have at least two answers";
|
|
7
7
|
export declare abstract class QuestionEntity extends AppObjectEntity {
|
|
8
8
|
static readonly type = "QuestionEntity";
|
|
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.makeQuestionEntity = exports.QuestionEntity = exports.VALIDATION_NOT_ENOUGH_ANSWERS = exports.VALIDATION_NO_CORRECT = void 0;
|
|
4
4
|
const AppObject_1 = require("../../../AppObject");
|
|
5
5
|
const AppObjectEntity_1 = require("../../../AppObject/AppObjectEntity");
|
|
6
|
-
exports.VALIDATION_NO_CORRECT = "At least one answer must be
|
|
6
|
+
exports.VALIDATION_NO_CORRECT = "At least one answer must be correct.";
|
|
7
7
|
exports.VALIDATION_NOT_ENOUGH_ANSWERS = "Question must have at least two answers";
|
|
8
8
|
class QuestionEntity extends AppObjectEntity_1.AppObjectEntity {
|
|
9
9
|
}
|
|
@@ -97,21 +97,14 @@ class QuestionChallengeImp extends QuestionEntity {
|
|
|
97
97
|
return exports.VALIDATION_NOT_ENOUGH_ANSWERS;
|
|
98
98
|
}
|
|
99
99
|
let hasCorrect = false;
|
|
100
|
-
let answerValidationMsg;
|
|
101
100
|
this.answerLookup.forEach((ans) => {
|
|
102
101
|
if (ans.isCorrect) {
|
|
103
102
|
hasCorrect = true;
|
|
104
103
|
}
|
|
105
|
-
if (ans.textValidationMessage) {
|
|
106
|
-
answerValidationMsg = ans.textValidationMessage;
|
|
107
|
-
}
|
|
108
|
-
if (ans.feedbackValidationMessage) {
|
|
109
|
-
answerValidationMsg = ans.feedbackValidationMessage;
|
|
110
|
-
}
|
|
111
104
|
});
|
|
112
105
|
if (!hasCorrect) {
|
|
113
106
|
return exports.VALIDATION_NO_CORRECT;
|
|
114
107
|
}
|
|
115
|
-
return
|
|
108
|
+
return;
|
|
116
109
|
}
|
|
117
110
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { AppObject } from "../../../AppObject/AppObject";
|
|
2
2
|
import { AppObjectPM } from "../../../AppObject/AppObjectPM";
|
|
3
3
|
import { AppObjectRepo } from "../../../AppObject/AppObjectRepo";
|
|
4
|
+
export declare const SLIDE_TEXT_CANNOT_BE_FALSY = "Slide text is required.";
|
|
4
5
|
export declare const defaultQuestionChallengeVM: QuestionChallengeVM;
|
|
5
6
|
export interface QuestionChallengeVM {
|
|
6
7
|
gotItRight: boolean;
|
|
@@ -12,6 +13,7 @@ export declare class QuestionChallengePM extends AppObjectPM<QuestionChallengeVM
|
|
|
12
13
|
static readonly type = "QuestionChallengePM";
|
|
13
14
|
static get: (appObjects: AppObjectRepo) => QuestionChallengePM | undefined;
|
|
14
15
|
private questionEntity?;
|
|
16
|
+
private baseAppState?;
|
|
15
17
|
private onEntityChange;
|
|
16
18
|
vmsAreEqual(a: QuestionChallengeVM, b: QuestionChallengeVM): boolean;
|
|
17
19
|
dispose: () => void;
|
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.QuestionChallengePM = exports.defaultQuestionChallengeVM = void 0;
|
|
3
|
+
exports.QuestionChallengePM = exports.defaultQuestionChallengeVM = exports.SLIDE_TEXT_CANNOT_BE_FALSY = void 0;
|
|
4
4
|
const AppObject_1 = require("../../../AppObject");
|
|
5
5
|
const AppObjectPM_1 = require("../../../AppObject/AppObjectPM");
|
|
6
|
+
const App_1 = require("../../App");
|
|
6
7
|
const QuestionEntity_1 = require("../Entities/QuestionEntity");
|
|
8
|
+
exports.SLIDE_TEXT_CANNOT_BE_FALSY = "Slide text is required.";
|
|
7
9
|
exports.defaultQuestionChallengeVM = {
|
|
8
10
|
answerIds: [],
|
|
9
11
|
gotItRight: false,
|
|
@@ -13,23 +15,39 @@ class QuestionChallengePM extends AppObjectPM_1.AppObjectPM {
|
|
|
13
15
|
constructor(appObject) {
|
|
14
16
|
super(appObject, QuestionChallengePM.type);
|
|
15
17
|
this.onEntityChange = () => {
|
|
18
|
+
if (!this.baseAppState)
|
|
19
|
+
return;
|
|
16
20
|
if (!this.questionEntity)
|
|
17
21
|
return;
|
|
22
|
+
let slideTextValidationMessage;
|
|
23
|
+
if (this.baseAppState.slideText.length === 0) {
|
|
24
|
+
slideTextValidationMessage = exports.SLIDE_TEXT_CANNOT_BE_FALSY;
|
|
25
|
+
}
|
|
18
26
|
const { gotItRight } = this.questionEntity;
|
|
19
27
|
const answerIds = this.questionEntity.getAllAnswers().map((ans) => ans.id);
|
|
20
28
|
const vm = {
|
|
21
29
|
gotItRight,
|
|
22
30
|
answerIds,
|
|
23
31
|
reviewFeedback: this.questionEntity.reviewFeedback,
|
|
24
|
-
validationMessage: this.questionEntity.validationMessage,
|
|
32
|
+
validationMessage: slideTextValidationMessage !== null && slideTextValidationMessage !== void 0 ? slideTextValidationMessage : this.questionEntity.validationMessage,
|
|
25
33
|
};
|
|
26
34
|
this.doUpdateView(vm);
|
|
27
35
|
};
|
|
28
36
|
this.dispose = () => {
|
|
29
|
-
var _a;
|
|
37
|
+
var _a, _b;
|
|
30
38
|
super.dispose();
|
|
31
39
|
(_a = this.questionEntity) === null || _a === void 0 ? void 0 : _a.removeChangeObserver(this.onEntityChange);
|
|
40
|
+
(_b = this.baseAppState) === null || _b === void 0 ? void 0 : _b.removeChangeObserver(this.onEntityChange);
|
|
32
41
|
};
|
|
42
|
+
this.baseAppState = App_1.BaseAppState.get(this.appObjects);
|
|
43
|
+
if (!this.baseAppState) {
|
|
44
|
+
this.warn("QuestionChallengePM has been added to an app object that does not have BaseAppStateEntity");
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
else {
|
|
48
|
+
this.baseAppState.addChangeObserver(this.onEntityChange);
|
|
49
|
+
this.onEntityChange();
|
|
50
|
+
}
|
|
33
51
|
this.questionEntity = appObject.getComponent(QuestionEntity_1.QuestionEntity.type);
|
|
34
52
|
if (this.questionEntity) {
|
|
35
53
|
this.questionEntity.addChangeObserver(this.onEntityChange);
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { AppObject, AppObjectRepo, AppObjectUC } from "../../../AppObject";
|
|
2
|
+
export declare abstract class ValidateQuestionChallengeStateUC extends AppObjectUC {
|
|
3
|
+
static readonly type = "ValidateQuestionChallengeStateUC";
|
|
4
|
+
SLIDE_TEXT_CANNOT_BE_FALSY: string;
|
|
5
|
+
IF_QUESTION_AT_LEAST_TWO_ANSWERS: string;
|
|
6
|
+
QUESTION_CHALLENGE_NO_CORRECT_ANSWER: string;
|
|
7
|
+
ANSWER_STRING_CANNOT_BE_0_CHARACTERS: string;
|
|
8
|
+
FEEDBACK_STRING_CANNOT_BE_LONGER_THAN_200_CHARACTERS: string;
|
|
9
|
+
ANSWER_STRING_CANNOT_BE_LONGER_THAN_40_CHARACTERS: string;
|
|
10
|
+
abstract validate(): string | undefined;
|
|
11
|
+
static get: (appObjects: AppObjectRepo) => ValidateQuestionChallengeStateUC | undefined;
|
|
12
|
+
}
|
|
13
|
+
export declare function makeValidateQuestionChallengeStateUC(appObject: AppObject): ValidateQuestionChallengeStateUC;
|
|
14
|
+
export declare class ValidateQuestionChallengeStateImp extends ValidateQuestionChallengeStateUC {
|
|
15
|
+
private baseAppState?;
|
|
16
|
+
private questionEntity?;
|
|
17
|
+
validate(): string | undefined;
|
|
18
|
+
constructor(appObject: AppObject);
|
|
19
|
+
}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ValidateQuestionChallengeStateImp = exports.makeValidateQuestionChallengeStateUC = exports.ValidateQuestionChallengeStateUC = void 0;
|
|
4
|
+
const AppObject_1 = require("../../../AppObject");
|
|
5
|
+
const App_1 = require("../../App");
|
|
6
|
+
const Entities_1 = require("../Entities");
|
|
7
|
+
class ValidateQuestionChallengeStateUC extends AppObject_1.AppObjectUC {
|
|
8
|
+
constructor() {
|
|
9
|
+
super(...arguments);
|
|
10
|
+
this.SLIDE_TEXT_CANNOT_BE_FALSY = "Slide text is required.";
|
|
11
|
+
this.IF_QUESTION_AT_LEAST_TWO_ANSWERS = "A question must have at lest two answers.";
|
|
12
|
+
this.QUESTION_CHALLENGE_NO_CORRECT_ANSWER = "At least one answer must be correct.";
|
|
13
|
+
this.ANSWER_STRING_CANNOT_BE_0_CHARACTERS = "Answer text is required.";
|
|
14
|
+
this.FEEDBACK_STRING_CANNOT_BE_LONGER_THAN_200_CHARACTERS = "Answer feedback may not exceed 200 characters.";
|
|
15
|
+
this.ANSWER_STRING_CANNOT_BE_LONGER_THAN_40_CHARACTERS = "Answer text may not exceed 40 characters.";
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
exports.ValidateQuestionChallengeStateUC = ValidateQuestionChallengeStateUC;
|
|
19
|
+
ValidateQuestionChallengeStateUC.type = "ValidateQuestionChallengeStateUC";
|
|
20
|
+
ValidateQuestionChallengeStateUC.get = (appObjects) => AppObject_1.getSingletonComponent(ValidateQuestionChallengeStateUC.type, appObjects);
|
|
21
|
+
function makeValidateQuestionChallengeStateUC(appObject) {
|
|
22
|
+
return new ValidateQuestionChallengeStateImp(appObject);
|
|
23
|
+
}
|
|
24
|
+
exports.makeValidateQuestionChallengeStateUC = makeValidateQuestionChallengeStateUC;
|
|
25
|
+
class ValidateQuestionChallengeStateImp extends ValidateQuestionChallengeStateUC {
|
|
26
|
+
constructor(appObject) {
|
|
27
|
+
super(appObject, ValidateQuestionChallengeStateUC.type);
|
|
28
|
+
this.baseAppState = App_1.BaseAppState.get(this.appObjects);
|
|
29
|
+
if (!this.baseAppState) {
|
|
30
|
+
this.warn("ToggleQuestionChallengeAnswerIsCorrectUC has been added to an app object that does not have BaseAppSateEntity");
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
this.questionEntity = Entities_1.QuestionEntity.get(this.appObjects);
|
|
34
|
+
if (!this.questionEntity) {
|
|
35
|
+
this.warn("ToggleQuestionChallengeAnswerIsCorrectUC has been added to an app object that does not have QuestionEntity");
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
validate() {
|
|
40
|
+
if (!this.baseAppState)
|
|
41
|
+
return;
|
|
42
|
+
if (!this.questionEntity)
|
|
43
|
+
return;
|
|
44
|
+
if (!this.baseAppState.slideText) {
|
|
45
|
+
return this.SLIDE_TEXT_CANNOT_BE_FALSY;
|
|
46
|
+
}
|
|
47
|
+
if (this.questionEntity.getAllAnswers().length < 2) {
|
|
48
|
+
return this.IF_QUESTION_AT_LEAST_TWO_ANSWERS;
|
|
49
|
+
}
|
|
50
|
+
let emptyAnswerTest = false;
|
|
51
|
+
let hasCorrect = false;
|
|
52
|
+
let hasLongFeedback = false;
|
|
53
|
+
let hasLongText = false;
|
|
54
|
+
this.questionEntity.getAllAnswers().forEach((ans) => {
|
|
55
|
+
if (ans.text === "") {
|
|
56
|
+
emptyAnswerTest = true;
|
|
57
|
+
}
|
|
58
|
+
if (ans.text.length > 40) {
|
|
59
|
+
hasLongText = true;
|
|
60
|
+
}
|
|
61
|
+
if (ans.feedbackText.length > 200) {
|
|
62
|
+
hasLongFeedback = true;
|
|
63
|
+
}
|
|
64
|
+
if (ans.isCorrect) {
|
|
65
|
+
hasCorrect = true;
|
|
66
|
+
}
|
|
67
|
+
});
|
|
68
|
+
if (!hasCorrect) {
|
|
69
|
+
return this.QUESTION_CHALLENGE_NO_CORRECT_ANSWER;
|
|
70
|
+
}
|
|
71
|
+
if (emptyAnswerTest) {
|
|
72
|
+
return this.ANSWER_STRING_CANNOT_BE_0_CHARACTERS;
|
|
73
|
+
}
|
|
74
|
+
if (hasLongFeedback) {
|
|
75
|
+
return this.FEEDBACK_STRING_CANNOT_BE_LONGER_THAN_200_CHARACTERS;
|
|
76
|
+
}
|
|
77
|
+
if (hasLongText) {
|
|
78
|
+
return this.ANSWER_STRING_CANNOT_BE_LONGER_THAN_40_CHARACTERS;
|
|
79
|
+
}
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
exports.ValidateQuestionChallengeStateImp = ValidateQuestionChallengeStateImp;
|
|
@@ -17,3 +17,4 @@ __exportStar(require("./SetAnswerFeedbackUC"), exports);
|
|
|
17
17
|
__exportStar(require("./SetAnswerTextUC"), exports);
|
|
18
18
|
__exportStar(require("./SubmitQuestionAnswerUC"), exports);
|
|
19
19
|
__exportStar(require("./ToggleQuestionAnswerIsCorrect"), exports);
|
|
20
|
+
__exportStar(require("./ValidateQuestionChallengeStateUC"), exports);
|