-
Notifications
You must be signed in to change notification settings - Fork 5
/
QuizContextAction.java
111 lines (85 loc) · 3.57 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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
package org.genericsystem.quiz.utils;
import org.genericsystem.common.Generic;
import org.genericsystem.quiz.app.pages.components.QuestionDiv.FooterDiv.FinishBtn;
import org.genericsystem.quiz.app.pages.components.QuestionDiv.FooterDiv.NextBtn;
import org.genericsystem.quiz.app.pages.components.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);
}
}
// NAVIGATION ENTRE LES PAGES
public static class CLEAR_PAGES implements ContextAction {
@Override
public void accept(Context context, Tag tag) {
if (tag.getProperty(QuizTagSwitcher.PAGE, context) != null)
tag.getProperty(QuizTagSwitcher.PAGE, context).setValue(null);
}
}
// Possibilité de factoriser
public static class CALL_HOME_PAGE implements ContextAction {
@Override
public void accept(Context context, Tag tag) {
Property<String> pageProperty = tag.getProperty(QuizTagSwitcher.PAGE, context);
if (pageProperty == null)
tag.createNewInitializedProperty(QuizTagSwitcher.PAGE, context, c -> QuizTagSwitcher.HOME_PAGE);
else
pageProperty.setValue(QuizTagSwitcher.HOME_PAGE);
}
}
public static class CALL_RESULT_PAGE implements ContextAction {
@Override
public void accept(Context context, Tag tag) {
Property<String> pageProperty = tag.getProperty(QuizTagSwitcher.PAGE, context);
if (pageProperty == null)
tag.createNewInitializedProperty(QuizTagSwitcher.PAGE, context, c -> QuizTagSwitcher.RESULT_PAGE);
else
pageProperty.setValue(QuizTagSwitcher.RESULT_PAGE);
}
}
public static class CALL_QUESTION_PAGE implements ContextAction {
@Override
public void accept(Context context, Tag tag) {
Property<String> pageProperty = tag.getProperty(QuizTagSwitcher.PAGE, context);
if (pageProperty == null)
tag.createNewInitializedProperty(QuizTagSwitcher.PAGE, context, c -> QuizTagSwitcher.QUESTION_PAGE);
else
pageProperty.setValue(QuizTagSwitcher.QUESTION_PAGE);
}
}
}