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

View File

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

View File

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

View File

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

View File

@ -5,7 +5,7 @@
</div> </div>
<div *ngSwitchCase="'single-choice'"> <div *ngSwitchCase="'single-choice'">
<small>Pytanie jednokrotnego wyboru</small> <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>
<div *ngSwitchCase="'multiple-choice'"> <div *ngSwitchCase="'multiple-choice'">
<small>Pytanie wielokrotnego wyboru</small> <small>Pytanie wielokrotnego wyboru</small>

View File

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

View File

@ -1,16 +1,23 @@
<form #f="ngForm" (ngSubmit)="nextQuestion(f)" novalidate> <form #f="ngForm" (ngSubmit)="nextQuestion(f)" novalidate>
<div class="alert alert-grey question"> <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> 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="pytanie">{{question.question}} </div>
<div class="answers"> <div *ngIf="!fifty" class="answers">
<div *ngFor="let item of question.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> <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> </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> </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> </form>

View File

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

View File

@ -38,7 +38,7 @@
<div class="question-view"> <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> </div>

View File

@ -19,6 +19,7 @@ export class TestDetailsComponent implements OnInit, OnDestroy {
currentQuestionIndex = 0; currentQuestionIndex = 0;
isEnded = false; isEnded = false;
points = 0; points = 0;
public lifebuoyTest: Boolean = true;
maxPoints = 0; maxPoints = 0;
prevMaxResult = 0; prevMaxResult = 0;
prevAnswerResultBool; prevAnswerResultBool;
@ -78,6 +79,10 @@ export class TestDetailsComponent implements OnInit, OnDestroy {
); );
} }
LifebuoyFifty(y) {
this.lifebuoyTest = y;
}
getMaxResult() { getMaxResult() {
if (this.currentUser) { if (this.currentUser) {
this.getResultSubscription = this.testService.getResult(this.test.id, this.currentUser.username).subscribe(d => { 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; owner: Number = 0;
title: String = ''; title: String = '';
permission: Boolean = false; permission: Boolean = false;
test: Array<Object> = []; test: Array<Object> = [];
shown: Boolean = false; shown: Boolean = false;
@ -59,7 +58,8 @@ export class TestEditComponent implements OnInit, OnDestroy {
question: d[i]['question'], question: d[i]['question'],
time: d[i]['time'], time: d[i]['time'],
answers: d[i]['answers'], answers: d[i]['answers'],
points: d[i]['points'] points: d[i]['points'],
help: d[i]['help']
}, },
shortcut: short shortcut: short
}; };
@ -217,7 +217,8 @@ export class TestEditComponent implements OnInit, OnDestroy {
time: this.test[i]['content']['time'], time: this.test[i]['content']['time'],
answers: this.test[i]['content']['answers'], answers: this.test[i]['content']['answers'],
points: this.test[i]['content']['points'], 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; toSend['body'] = body;