PUNKT-33 Bug fix: Problem z odliczaniem czasu

This commit is contained in:
Marcin Szczepański 2019-12-07 19:36:04 +01:00
parent 9eb166274a
commit d8c503bda7
12 changed files with 90 additions and 30 deletions

View File

@ -1,6 +1,6 @@
<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">
{{question.question}} ({{question.points}}pkt.) <br /><span *ngIf="timeLeft > 0">Czas: {{ timeLeft }} sek. </span><span *ngIf="timeLeft === 0">Czas: bez limitu</span> {{question.question}} ({{question.points}}pkt.) <br /><span *ngIf="timeLeft > 0">Czas: {{ timeLeft }} sek. </span><span *ngIf="question.time === 0">Czas: bez limitu</span>
<div class="answers"> <div class="answers">
<div *ngFor="let item of question.answers"> <div *ngFor="let item of question.answers">
<span *ngIf="!item.is_gap">{{item.content}}</span> <span *ngIf="!item.is_gap">{{item.content}}</span>

View File

@ -11,8 +11,7 @@ import { NgForm } from '@angular/forms';
styleUrls: ['./gaps.component.css'] styleUrls: ['./gaps.component.css']
}) })
export class GapsComponent implements OnInit, OnDestroy { export class GapsComponent implements OnInit, OnDestroy {
@Input() private _question;
question;
@Output() emitNextQuestionRequest = new EventEmitter(); @Output() emitNextQuestionRequest = new EventEmitter();
private id; private id;
private verifyAnswerSubscription: ISubscription; private verifyAnswerSubscription: ISubscription;
@ -48,15 +47,26 @@ export class GapsComponent implements OnInit, OnDestroy {
}, 1000); }, 1000);
} }
ngOnInit() { public get question() {
return this._question;
}
@Input('question')
public set question(data) {
this._question = data;
this.ngOnDestroy();
this.timeLeft = this.question.time; this.timeLeft = this.question.time;
if (this.timeLeft > 0) { if (this.timeLeft > 0) {
this.startTimer(); this.startTimer();
} }
} }
ngOnInit() {}
ngOnDestroy() { ngOnDestroy() {
clearInterval(this.interval); if (this.interval) {
clearInterval(this.interval);
}
if (this.verifyAnswerSubscription) { if (this.verifyAnswerSubscription) {
this.verifyAnswerSubscription.unsubscribe(); this.verifyAnswerSubscription.unsubscribe();
} }

View File

@ -1,6 +1,6 @@
<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">
{{question.question}} ({{question.points}}pkt.) <br /><span *ngIf="timeLeft > 0">Czas: {{ timeLeft }} sek. </span><span *ngIf="timeLeft === 0">Czas: bez limitu</span> {{question.question}} ({{question.points}}pkt.) <br /><span *ngIf="timeLeft > 0">Czas: {{ timeLeft }} sek. </span><span *ngIf="question.time === 0">Czas: bez limitu</span>
<div class="answers"> <div class="answers">
<div *ngFor="let item of question.answers"> <div *ngFor="let item of question.answers">
<input type="checkbox" [name]="item.id" [value]="item" ngModel /> {{item.content}} <input type="checkbox" [name]="item.id" [value]="item" ngModel /> {{item.content}}

View File

@ -11,8 +11,7 @@ import { NgForm } from '@angular/forms';
styleUrls: ['./multiple-choice.component.css'] styleUrls: ['./multiple-choice.component.css']
}) })
export class MultipleChoiceComponent implements OnInit, OnDestroy{ export class MultipleChoiceComponent implements OnInit, OnDestroy{
@Input() private _question;
question;
@Output() emitNextQuestionRequest = new EventEmitter(); @Output() emitNextQuestionRequest = new EventEmitter();
private id; private id;
private verifyAnswerSubscription: ISubscription; private verifyAnswerSubscription: ISubscription;
@ -45,15 +44,26 @@ export class MultipleChoiceComponent implements OnInit, OnDestroy{
}, 1000); }, 1000);
} }
ngOnInit() { public get question() {
return this._question;
}
@Input('question')
public set question(data) {
this._question = data;
this.ngOnDestroy();
this.timeLeft = this.question.time; this.timeLeft = this.question.time;
if (this.timeLeft > 0) { if (this.timeLeft > 0) {
this.startTimer(); this.startTimer();
} }
} }
ngOnInit() {}
ngOnDestroy() { ngOnDestroy() {
clearInterval(this.interval); if (this.interval) {
clearInterval(this.interval);
}
if (this.verifyAnswerSubscription) { if (this.verifyAnswerSubscription) {
this.verifyAnswerSubscription.unsubscribe(); this.verifyAnswerSubscription.unsubscribe();
} }

View File

@ -1,5 +1,5 @@
<div> <div>
{{question.question}} ({{question.points}}pkt.) <br /><span *ngIf="timeLeft > 0">Czas: {{ timeLeft }} sek. </span><span *ngIf="timeLeft === 0">Czas: bez limitu</span> {{question.question}} ({{question.points}}pkt.) <br /><span *ngIf="timeLeft > 0">Czas: {{ timeLeft }} sek. </span><span *ngIf="question.time === 0">Czas: bez limitu</span>
<h3>Dostępne lewe strony:</h3> <h3>Dostępne lewe strony:</h3>
<div class="puzzles-container"> <div class="puzzles-container">
<div class='puzzle' *ngFor="let item of leftSides; let i = index" (click)="leftSideClick(item,i)" [ngClass]="{'active': (selectedLeftSide.leftSideText === item && selectedLeftSide.indexOfLeftSide === i && selectedLeftSide.from === 'leftSides'), 'empty': (item === undefined || item === '')}"> <div class='puzzle' *ngFor="let item of leftSides; let i = index" (click)="leftSideClick(item,i)" [ngClass]="{'active': (selectedLeftSide.leftSideText === item && selectedLeftSide.indexOfLeftSide === i && selectedLeftSide.from === 'leftSides'), 'empty': (item === undefined || item === '')}">

View File

@ -10,8 +10,7 @@ import { ISubscription } from 'rxjs/Subscription';
styleUrls: ['./pairs.component.css'] styleUrls: ['./pairs.component.css']
}) })
export class PairsComponent implements OnInit, OnChanges, OnDestroy { export class PairsComponent implements OnInit, OnChanges, OnDestroy {
@Input() private _question;
question;
@Output() emitNextQuestionRequest = new EventEmitter(); @Output() emitNextQuestionRequest = new EventEmitter();
private id; private id;
private verifyAnswerSubscription: ISubscription; private verifyAnswerSubscription: ISubscription;
@ -91,7 +90,14 @@ export class PairsComponent implements OnInit, OnChanges, OnDestroy {
}); });
} }
ngOnInit() { public get question() {
return this._question;
}
@Input('question')
public set question(data) {
this._question = data;
this.ngOnDestroy();
this.timeLeft = this.question.time; this.timeLeft = this.question.time;
this.prepareLists(); this.prepareLists();
if (this.timeLeft > 0) { if (this.timeLeft > 0) {
@ -99,12 +105,16 @@ export class PairsComponent implements OnInit, OnChanges, OnDestroy {
} }
} }
ngOnInit() {}
ngOnChanges() { ngOnChanges() {
this.prepareLists(); this.prepareLists();
} }
ngOnDestroy() { ngOnDestroy() {
clearInterval(this.interval); if (this.interval) {
clearInterval(this.interval);
}
if (this.verifyAnswerSubscription) { if (this.verifyAnswerSubscription) {
this.verifyAnswerSubscription.unsubscribe(); this.verifyAnswerSubscription.unsubscribe();
} }

View File

@ -1,5 +1,5 @@
<div> <div>
{{question.question}} ({{question.points}}pkt.) <br /><span *ngIf="timeLeft > 0">Czas: {{ timeLeft }} sek. </span><span *ngIf="timeLeft === 0">Czas: bez limitu</span> {{question.question}} ({{question.points}}pkt.) <br /><span *ngIf="timeLeft > 0">Czas: {{ timeLeft }} sek. </span><span *ngIf="question.time === 0">Czas: bez limitu</span>
<h3>Dostępne elementy rozsypanki:</h3> <h3>Dostępne elementy rozsypanki:</h3>
<div class="puzzles-container"> <div class="puzzles-container">
<div class='puzzle' *ngFor="let item of puzzles; let i = index" (click)="puzzleClick(item,i)" [ngClass]="{'active': (selectedPuzzle.puzzleText === item && selectedPuzzle.indexOfPuzzle === i && selectedPuzzle.from === 'puzzles'), 'empty': (item === undefined || item === '')}"> <div class='puzzle' *ngFor="let item of puzzles; let i = index" (click)="puzzleClick(item,i)" [ngClass]="{'active': (selectedPuzzle.puzzleText === item && selectedPuzzle.indexOfPuzzle === i && selectedPuzzle.from === 'puzzles'), 'empty': (item === undefined || item === '')}">

View File

@ -10,8 +10,7 @@ import { ISubscription } from 'rxjs/Subscription';
styleUrls: ['./puzzle.component.css'] styleUrls: ['./puzzle.component.css']
}) })
export class PuzzleComponent implements OnInit, OnChanges, OnDestroy { export class PuzzleComponent implements OnInit, OnChanges, OnDestroy {
@Input() private _question;
question;
@Output() emitNextQuestionRequest = new EventEmitter(); @Output() emitNextQuestionRequest = new EventEmitter();
private id; private id;
private verifyAnswerSubscription: ISubscription; private verifyAnswerSubscription: ISubscription;
@ -78,7 +77,14 @@ export class PuzzleComponent implements OnInit, OnChanges, OnDestroy {
}); });
} }
ngOnInit() { public get question() {
return this._question;
}
@Input('question')
public set question(data) {
this._question = data;
this.ngOnDestroy();
this.timeLeft = this.question.time; this.timeLeft = this.question.time;
this.prepareLists(); this.prepareLists();
if (this.timeLeft > 0) { if (this.timeLeft > 0) {
@ -86,12 +92,16 @@ export class PuzzleComponent implements OnInit, OnChanges, OnDestroy {
} }
} }
ngOnInit() {}
ngOnChanges() { ngOnChanges() {
this.prepareLists(); this.prepareLists();
} }
ngOnDestroy() { ngOnDestroy() {
clearInterval(this.interval); if (this.interval) {
clearInterval(this.interval);
}
if (this.verifyAnswerSubscription) { if (this.verifyAnswerSubscription) {
this.verifyAnswerSubscription.unsubscribe(); this.verifyAnswerSubscription.unsubscribe();
} }

View File

@ -1,6 +1,6 @@
<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">
{{question.question}} ({{question.points}}pkt.) <br /><span *ngIf="timeLeft > 0">Czas: {{ timeLeft }} sek. </span><span *ngIf="timeLeft === 0">Czas: bez limitu</span> {{question.question}} ({{question.points}}pkt.) <br /><span *ngIf="timeLeft > 0">Czas: {{ timeLeft }} sek. </span><span *ngIf="question.time === 0">Czas: bez limitu</span>
<div class="answers"> <div class="answers">
<div *ngFor="let item of question.answers"> <div *ngFor="let item of question.answers">
<input type="radio" name="answer" [value]="item.content" ngModel> {{item.content}} <input type="radio" name="answer" [value]="item.content" ngModel> {{item.content}}

View File

@ -11,8 +11,7 @@ import { NgForm } from '@angular/forms';
styleUrls: ['./single-choice.component.css'] styleUrls: ['./single-choice.component.css']
}) })
export class SingleChoiceComponent implements OnInit, OnDestroy { export class SingleChoiceComponent implements OnInit, OnDestroy {
@Input() private _question;
question;
private answer; private answer;
@Output() emitNextQuestionRequest = new EventEmitter(); @Output() emitNextQuestionRequest = new EventEmitter();
private id; private id;
@ -46,15 +45,26 @@ export class SingleChoiceComponent implements OnInit, OnDestroy {
}, 1000); }, 1000);
} }
ngOnInit() { public get question() {
return this._question;
}
@Input('question')
public set question(data) {
this._question = data;
this.ngOnDestroy();
this.timeLeft = this.question.time; this.timeLeft = this.question.time;
if (this.timeLeft > 0) { if (this.timeLeft > 0) {
this.startTimer(); this.startTimer();
} }
} }
ngOnInit() {}
ngOnDestroy() { ngOnDestroy() {
clearInterval(this.interval); if (this.interval) {
clearInterval(this.interval);
}
if (this.verifyAnswerSubscription) { if (this.verifyAnswerSubscription) {
this.verifyAnswerSubscription.unsubscribe(); this.verifyAnswerSubscription.unsubscribe();
} }

View File

@ -1,5 +1,5 @@
<div class="alert alert-grey question"> <div class="alert alert-grey question">
{{question.question}} ({{question.points}}pkt.) <br /><span *ngIf="timeLeft > 0">Czas: {{ timeLeft }} sek. </span><span *ngIf="timeLeft === 0">Czas: bez limitu</span> {{question.question}} ({{question.points}}pkt.) <br /><span *ngIf="timeLeft > 0">Czas: {{ timeLeft }} sek. </span><span *ngIf="question.time === 0">Czas: bez limitu</span>
<div class="btn-group btn-group-toggle" data-toggle="buttons"> <div class="btn-group btn-group-toggle" data-toggle="buttons">
<label class="btn btn-study-cave mr-2" (click)="chooseAnswer('Prawda')"> <label class="btn btn-study-cave mr-2" (click)="chooseAnswer('Prawda')">

View File

@ -10,8 +10,7 @@ import { ISubscription, Subscription } from 'rxjs/Subscription';
styleUrls: ['./true-false.component.css'] styleUrls: ['./true-false.component.css']
}) })
export class TrueFalseComponent implements OnInit, OnDestroy { export class TrueFalseComponent implements OnInit, OnDestroy {
@Input() private _question;
question;
private answer; private answer;
@Output() emitNextQuestionRequest = new EventEmitter(); @Output() emitNextQuestionRequest = new EventEmitter();
private id; private id;
@ -49,15 +48,26 @@ export class TrueFalseComponent implements OnInit, OnDestroy {
this.answer = answer; this.answer = answer;
} }
ngOnInit() { public get question() {
return this._question;
}
@Input('question')
public set question(data) {
this._question = data;
this.ngOnDestroy();
this.timeLeft = this.question.time; this.timeLeft = this.question.time;
if (this.timeLeft > 0) { if (this.timeLeft > 0) {
this.startTimer(); this.startTimer();
} }
} }
ngOnInit() {}
ngOnDestroy() { ngOnDestroy() {
clearInterval(this.interval); if (this.interval) {
clearInterval(this.interval);
}
if (this.verifyAnswerSubscription) { if (this.verifyAnswerSubscription) {
this.verifyAnswerSubscription.unsubscribe(); this.verifyAnswerSubscription.unsubscribe();
} }