-
Notifications
You must be signed in to change notification settings - Fork 5
/
QuizContextAction.java
93 lines (72 loc) · 3.01 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
package org.genericsystem.quiz.utils;
import org.genericsystem.common.Generic;
import org.genericsystem.quiz.app.pages.HomePage;
import org.genericsystem.quiz.app.pages.QuizPage;
import org.genericsystem.quiz.app.pages.ResultPage;
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.reactor.contextproperties.SelectionDefaults;
import org.genericsystem.security.model.User;
public class QuizContextAction {
public static class QuizNextAction implements ContextAction {
@Override
public void accept(Context context, Tag tag) {
Class<?> from = tag.getParent().getClass();
Class<?> to = null;
if (HomePage.class.equals(from))
to = QuizPage.class;
if (QuizPage.class.equals(from))
to = ResultPage.class;
if (ResultPage.class.equals(from))
to = HomePage.class;
tag.getProperty("selectedClass", context).setValue(to);
}
}
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();
context.flush();
ScoreUtils.setResult(context, quiz, sUser, loggedUser);
ScoreUtils.getResult(context, quiz, loggedUser);
tag.getProperty("Quiz Done", context).setValue(true);
}
}
public static class SELECT_CONTEXT implements ContextAction {
@Override
public void accept(Context context, Tag tag) {
if (SelectionDefaults.class.isAssignableFrom(tag.getClass()))
((SelectionDefaults) tag).getSelectionProperty(context).getValue();
}
}
}