-
Notifications
You must be signed in to change notification settings - Fork 5
/
QuizContextAction.java
77 lines (58 loc) · 2.47 KB
/
QuizContextAction.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
package org.genericsystem.quiz.utils;
import org.genericsystem.common.Generic;
import org.genericsystem.quiz.components.QuestionDiv.QuestionDiv_.FooterDiv.FinishBtn;
import org.genericsystem.quiz.components.QuestionDiv.QuestionDiv_.FooterDiv.NextBtn;
import org.genericsystem.quiz.components.QuestionDiv.QuestionDiv_.FooterDiv.PreviousBtn;
import org.genericsystem.reactor.Context;
import org.genericsystem.reactor.Tag;
import org.genericsystem.reactor.context.ContextAction;
import org.genericsystem.security.model.User;
import javafx.beans.property.Property;
public class QuizContextAction {
public static class NEXT_TAG implements ContextAction {
@Override
public void accept(Context context, Tag tagNext) {
if (QuizStepper.class.isAssignableFrom(tagNext.getClass())) {
Tag tagParent = tagNext.getParent();
Tag tagPrevious = tagParent.find(PreviousBtn.class);
Tag tagFinish = tagParent.find(FinishBtn.class);
((QuizStepper) tagNext).next(context, tagNext, tagPrevious, tagFinish);
} else
log.warn("The NEXT action is applicable only to a tag implementing StepperDefaults.");
}
}
public static class PREVIOUS_TAG implements ContextAction {
@Override
public void accept(Context context, Tag tagPrevious) {
if (QuizStepper.class.isAssignableFrom(tagPrevious.getClass())) {
Tag tagParent = tagPrevious.getParent();
Tag tagNext = tagParent.find(NextBtn.class);
Tag tagFinish = tagParent.find(FinishBtn.class);
((QuizStepper) tagPrevious).prev(context, tagNext, tagPrevious, tagFinish);
} else
log.warn("The PREVIOUS action is applicable only to a tag implementing StepperDefaults.");
}
}
public static class SAVE_QUIZ_RESULT implements ContextAction {
@Override
public void accept(Context context, Tag tag) {
Generic quiz = context.getGeneric();
Generic sUser = context.find(User.class).getInstance("Anti-Seche");
Generic loggedUser = tag.getLoggedUserProperty(context).getValue();
ScoreUtils.setResult(context, quiz, sUser, loggedUser);
ScoreUtils.getResult(context, quiz, loggedUser);
tag.getProperty("QuizDone", context).setValue(true);
}
}
// NAVIGATION ENTRE LES PAGES
public static class CALL_RESULT_PAGE implements ContextAction {
@Override
public void accept(Context context, Tag tag) {
Property<Boolean> resultPage = tag.getProperty("ResultPage", context);
if (resultPage == null)
tag.createNewInitializedProperty("ResultPage", context, c -> true);
else
resultPage.setValue(true);
}
}
}