This commit is contained in:
Marcin Szczepański 2020-01-17 18:49:15 +01:00
commit 900f8a70c2
11 changed files with 51 additions and 19 deletions

View File

@ -91,8 +91,9 @@ public class TestController {
(o1, o2) -> o1.getId().compareTo(o2.getId()));
}
}
if (testToReturn.getHelp()){
for (Question question : testToReturn.getQuestions()) {
if (question.getHelp()){
if (question instanceof QuestionChoices){
QuestionChoices questionChoices = (QuestionChoices) question;
List<AnswerChoices> answers = questionChoices.getAnswers();
@ -146,7 +147,7 @@ public class TestController {
}
List<AnswerChoices> helpers = new ArrayList<>();
if (question.getType().equals("single-choice")) {
if (test.get().getHelp()){
if (question.getHelp()){
List<AnswerChoices> answers = answersDTOs;
if (answers.size() > 2) {
for (AnswerChoices answerChoices : answers){
@ -369,8 +370,6 @@ public class TestController {
test.setAddDate();
test.setEditDate();
test.setGrade();
if (testDTO.getHelp() != null)
test.setHelp(testDTO.getHelp());
// Badge for creating first test
if(userBadgeRepository.findByIdAndUser((long)4, user.getId()).isEmpty()) {
@ -551,8 +550,6 @@ public class TestController {
// System.out.println("usuwam "+oldquestion.getId());
}
}
if (testDTO.getHelp() != null)
test.setHelp(testDTO.getHelp());
testRepository.save(test);
for (Long a : deletea)

View File

@ -66,8 +66,7 @@ public class Test {
@Nullable
private Long availableTo = null;
@Column(columnDefinition = "TINYINT(1)")
private Boolean help = false;
public void setAddDate() {

View File

@ -31,8 +31,6 @@ public class TestCreateDTO {
@ApiModelProperty(value = "Default value for note", required = true,example = "public")
private String permission;
private Boolean help = false;
@JsonIgnore
private Long grade;
@JsonProperty("body")

View File

@ -68,4 +68,9 @@ public abstract class Question {
@Setter
private int time;
@Getter
@Setter
@Column(columnDefinition = "TINYINT(1)")
private Boolean help = false;
}

View File

@ -5,7 +5,7 @@
</div>
<div *ngSwitchCase="'single-choice'">
<small>Pytanie jednokrotnego wyboru</small>
<app-single-choice [question]="question" (emitNextQuestionRequest)="handleEmitNextQuestionRequest($event)"></app-single-choice>
<app-single-choice [question]="question" [activeFifty]='activeFifty' (emitNextQuestionRequest)="handleEmitNextQuestionRequest($event)" (lifebuoy)="LifebuoyFifty($event)"></app-single-choice>
</div>
<div *ngSwitchCase="'multiple-choice'">
<small>Pytanie wielokrotnego wyboru</small>

View File

@ -10,7 +10,10 @@ export class QuestionViewComponent implements OnInit {
question;
@Input()
private questionIndex;
@Input() activeFifty;
@Output() emitNextQuestionRequest = new EventEmitter();
@Output() lifebuoyTest = new EventEmitter<boolean>();
constructor() { }
@ -22,6 +25,10 @@ export class QuestionViewComponent implements OnInit {
this.nextQuestion(e);
}
LifebuoyFifty(y) {
this.lifebuoyTest.emit(y);
}
ngOnInit() {
}

View File

@ -1,16 +1,23 @@
<form #f="ngForm" (ngSubmit)="nextQuestion(f)" novalidate>
<div class="alert alert-grey question">
Pytanie za {{question.points}}pkt. <br /><span *ngIf="timeLeft > 0">Czas: {{ timeLeft }} sek. </span><span *ngIf="question.time === 0">Czas: bez limitu</span>
<div *ngIf="question.help" class="fifty"><img src="./././././assets/50-50.png" width="80px" height="50px"></div>
<div *ngIf="(question.help && activeFifty)" class="fifty" (click)="fiftyFifty()"><img src="./././././assets/50-50.png" width="80px" height="50px"></div>
<div class="pytanie">{{question.question}} </div>
<div class="answers">
<div *ngIf="!fifty" class="answers">
<div *ngFor="let item of question.answers" >
<input type="radio" name="answer" class="radio-answer" id="{{item.content}}" [value]="item.content" ngModel ><label for="{{item.content}}">{{item.content}}</label>
</div>
</div>
<div *ngIf="(fifty)" class="answers">
<div *ngFor="let item of question.answers_help" >
<input type="radio" name="answer" class="radio-answer" id="{{item.content}}" [value]="item.content" ngModel ><label for="{{item.content}}">{{item.content}}</label>
</div>
</div>
</div>
<button class="btn btn-study-cave" type="submit"><i class="fas fa-arrow-right"></i> Dalej</button>
<button class="btn btn-study-cave" type="submit" (click)="noHelp()"><i class="fas fa-arrow-right"></i> Dalej</button>
</form>

View File

@ -14,12 +14,16 @@ export class SingleChoiceComponent implements OnInit, OnDestroy {
private _question;
private answer;
@Output() emitNextQuestionRequest = new EventEmitter();
@Output() lifebuoy = new EventEmitter<boolean>();
@Input() activeFifty;
private id;
private verifyAnswerSubscription: ISubscription;
interval: any;
public timeLeft = 0;
public fifty: Boolean = false;
@ViewChild('f') public form: NgForm;
constructor(private route: ActivatedRoute, private testsService: TestsService) { }
nextQuestion(f) {
@ -35,6 +39,15 @@ export class SingleChoiceComponent implements OnInit, OnDestroy {
});
}
fiftyFifty() {
this.fifty = true;
this.lifebuoy.emit(false);
}
noHelp() {
this.fifty = false;
}
startTimer() {
this.interval = setInterval(() => {
if (this.timeLeft > 0) {

View File

@ -38,7 +38,7 @@
<div class="question-view">
<app-question-view [question]="test.body[currentQuestionIndex]" [questionIndex]="currentQuestionIndex" (emitNextQuestionRequest)="handleEmitNextQuestionRequest($event)"></app-question-view>
<app-question-view [question]="test.body[currentQuestionIndex]" [questionIndex]="currentQuestionIndex" [activeFifty]='lifebuoyTest' (emitNextQuestionRequest)="handleEmitNextQuestionRequest($event)" (lifebuoyTest)="LifebuoyFifty($event)" ></app-question-view>
</div>

View File

@ -19,6 +19,7 @@ export class TestDetailsComponent implements OnInit, OnDestroy {
currentQuestionIndex = 0;
isEnded = false;
points = 0;
public lifebuoyTest: Boolean = true;
maxPoints = 0;
prevMaxResult = 0;
prevAnswerResultBool;
@ -78,6 +79,10 @@ export class TestDetailsComponent implements OnInit, OnDestroy {
);
}
LifebuoyFifty(y) {
this.lifebuoyTest = y;
}
getMaxResult() {
if (this.currentUser) {
this.getResultSubscription = this.testService.getResult(this.test.id, this.currentUser.username).subscribe(d => {

View File

@ -15,7 +15,6 @@ export class TestEditComponent implements OnInit, OnDestroy {
owner: Number = 0;
title: String = '';
permission: Boolean = false;
test: Array<Object> = [];
shown: Boolean = false;
@ -59,7 +58,8 @@ export class TestEditComponent implements OnInit, OnDestroy {
question: d[i]['question'],
time: d[i]['time'],
answers: d[i]['answers'],
points: d[i]['points']
points: d[i]['points'],
help: d[i]['help']
},
shortcut: short
};
@ -217,7 +217,8 @@ export class TestEditComponent implements OnInit, OnDestroy {
time: this.test[i]['content']['time'],
answers: this.test[i]['content']['answers'],
points: this.test[i]['content']['points'],
id: this.test[i]['content']['id']
id: this.test[i]['content']['id'],
help: this.test[i]['content']['help']
});
}
toSend['body'] = body;