PUNKT-20 Czas na odpowiedź w teście

This commit is contained in:
Marcin Szczepański 2019-11-30 14:27:43 +01:00
parent 47934971ad
commit 1ea31568c4
12 changed files with 112 additions and 10 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.) {{question.question}} ({{question.points}}pkt.) <span *ngIf="timeLeft > 0">Czas: {{ timeLeft }} </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

@ -1,8 +1,9 @@
import { Component, OnInit, Input, Output, EventEmitter, OnDestroy } from '@angular/core'; import { Component, OnInit, Input, Output, EventEmitter, OnDestroy, ViewChild } from '@angular/core';
import { ActivatedRoute } from '@angular/router'; import { ActivatedRoute } from '@angular/router';
import { TestsService } from '../../../tests.service'; import { TestsService } from '../../../tests.service';
import * as $ from 'jquery'; import * as $ from 'jquery';
import { ISubscription } from 'rxjs/Subscription'; import { ISubscription } from 'rxjs/Subscription';
import { NgForm } from '@angular/forms';
@Component({ @Component({
selector: 'app-gaps', selector: 'app-gaps',
@ -15,6 +16,9 @@ export class GapsComponent implements OnInit, OnDestroy {
@Output() emitNextQuestionRequest = new EventEmitter(); @Output() emitNextQuestionRequest = new EventEmitter();
private id; private id;
private verifyAnswerSubscription: ISubscription; private verifyAnswerSubscription: ISubscription;
interval: any;
public timeLeft = 0;
@ViewChild('f') public form: NgForm;
constructor(private route: ActivatedRoute, private testsService: TestsService) { } constructor(private route: ActivatedRoute, private testsService: TestsService) { }
@ -34,10 +38,24 @@ export class GapsComponent implements OnInit, OnDestroy {
}); });
} }
startTimer() {
this.interval = setInterval(() => {
if (this.timeLeft > 0) {
this.timeLeft--;
} else {
this.nextQuestion(this.form);
}
}, 1000);
}
ngOnInit() { ngOnInit() {
if (this.timeLeft > 0) {
this.startTimer();
}
} }
ngOnDestroy() { ngOnDestroy() {
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.) {{question.question}} ({{question.points}}pkt.) <span *ngIf="timeLeft > 0">Czas: {{ timeLeft }} </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

@ -1,8 +1,9 @@
import { Component, OnInit, Input, Output, EventEmitter, OnDestroy } from '@angular/core'; import { Component, OnInit, Input, Output, EventEmitter, OnDestroy, ViewChild } from '@angular/core';
import { ActivatedRoute } from '@angular/router'; import { ActivatedRoute } from '@angular/router';
import { TestsService } from '../../../tests.service'; import { TestsService } from '../../../tests.service';
import * as $ from 'jquery'; import * as $ from 'jquery';
import { ISubscription } from 'rxjs/Subscription'; import { ISubscription } from 'rxjs/Subscription';
import { NgForm } from '@angular/forms';
@Component({ @Component({
selector: 'app-multiple-choice', selector: 'app-multiple-choice',
@ -15,6 +16,9 @@ export class MultipleChoiceComponent implements OnInit, OnDestroy{
@Output() emitNextQuestionRequest = new EventEmitter(); @Output() emitNextQuestionRequest = new EventEmitter();
private id; private id;
private verifyAnswerSubscription: ISubscription; private verifyAnswerSubscription: ISubscription;
interval: any;
public timeLeft = 0;
@ViewChild('f') public form: NgForm;
constructor(private route: ActivatedRoute, private testsService: TestsService) { } constructor(private route: ActivatedRoute, private testsService: TestsService) { }
@ -31,10 +35,24 @@ export class MultipleChoiceComponent implements OnInit, OnDestroy{
}); });
} }
startTimer() {
this.interval = setInterval(() => {
if (this.timeLeft > 0) {
this.timeLeft--;
} else {
this.nextQuestion(this.form);
}
}, 1000);
}
ngOnInit() { ngOnInit() {
if (this.timeLeft > 0) {
this.startTimer();
}
} }
ngOnDestroy() { ngOnDestroy() {
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.) {{question.question}} ({{question.points}}pkt.) <span *ngIf="timeLeft > 0">Czas: {{ timeLeft }} </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

@ -19,6 +19,8 @@ export class PairsComponent implements OnInit, OnChanges, OnDestroy {
rightSides = []; rightSides = [];
leftSidesToSend = []; leftSidesToSend = [];
selectedLeftSide = { indexOfLeftSide: Number, leftSideText: String, from: '' }; selectedLeftSide = { indexOfLeftSide: Number, leftSideText: String, from: '' };
interval: any;
public timeLeft = 0;
constructor(private route: ActivatedRoute, private testsService: TestsService) { } constructor(private route: ActivatedRoute, private testsService: TestsService) { }
@ -41,6 +43,16 @@ export class PairsComponent implements OnInit, OnChanges, OnDestroy {
}); });
} }
startTimer() {
this.interval = setInterval(() => {
if (this.timeLeft > 0) {
this.timeLeft--;
} else {
this.nextQuestion();
}
}, 1000);
}
leftSideClick(item, i) { leftSideClick(item, i) {
if (item !== '' && item !== undefined) { if (item !== '' && item !== undefined) {
if (this.selectedLeftSide.from === 'leftSides') { if (this.selectedLeftSide.from === 'leftSides') {
@ -81,6 +93,9 @@ export class PairsComponent implements OnInit, OnChanges, OnDestroy {
ngOnInit() { ngOnInit() {
this.prepareLists(); this.prepareLists();
if (this.timeLeft > 0) {
this.startTimer();
}
} }
ngOnChanges() { ngOnChanges() {
@ -88,6 +103,7 @@ export class PairsComponent implements OnInit, OnChanges, OnDestroy {
} }
ngOnDestroy() { ngOnDestroy() {
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.) {{question.question}} ({{question.points}}pkt.) <span *ngIf="timeLeft > 0">Czas: {{ timeLeft }} </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

@ -18,6 +18,8 @@ export class PuzzleComponent implements OnInit, OnChanges, OnDestroy {
puzzles = []; puzzles = [];
puzzlesToSend = []; puzzlesToSend = [];
private selectedPuzzle = { indexOfPuzzle: Number, puzzleText: String, from: '' }; private selectedPuzzle = { indexOfPuzzle: Number, puzzleText: String, from: '' };
interval: any;
public timeLeft = 0;
constructor(private route: ActivatedRoute, private testsService: TestsService) { } constructor(private route: ActivatedRoute, private testsService: TestsService) { }
@ -30,6 +32,16 @@ export class PuzzleComponent implements OnInit, OnChanges, OnDestroy {
}); });
} }
startTimer() {
this.interval = setInterval(() => {
if (this.timeLeft > 0) {
this.timeLeft--;
} else {
this.nextQuestion();
}
}, 1000);
}
puzzleClick(item, i) { puzzleClick(item, i) {
if (item !== '' && item !== undefined) { if (item !== '' && item !== undefined) {
if (this.selectedPuzzle.from === 'puzzles') { if (this.selectedPuzzle.from === 'puzzles') {
@ -68,6 +80,9 @@ export class PuzzleComponent implements OnInit, OnChanges, OnDestroy {
ngOnInit() { ngOnInit() {
this.prepareLists(); this.prepareLists();
if (this.timeLeft > 0) {
this.startTimer();
}
} }
ngOnChanges() { ngOnChanges() {
@ -75,6 +90,7 @@ export class PuzzleComponent implements OnInit, OnChanges, OnDestroy {
} }
ngOnDestroy() { ngOnDestroy() {
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.) {{question.question}} ({{question.points}}pkt.) <span *ngIf="timeLeft > 0">Czas: {{ timeLeft }} </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

@ -1,8 +1,9 @@
import { Component, OnInit, Input, Output, EventEmitter, OnDestroy } from '@angular/core'; import { Component, OnInit, Input, Output, EventEmitter, OnDestroy, ViewChild } from '@angular/core';
import { ActivatedRoute } from '@angular/router'; import { ActivatedRoute } from '@angular/router';
import { TestsService } from '../../../tests.service'; import { TestsService } from '../../../tests.service';
import * as $ from 'jquery'; import * as $ from 'jquery';
import { ISubscription } from 'rxjs/Subscription'; import { ISubscription } from 'rxjs/Subscription';
import { NgForm } from '@angular/forms';
@Component({ @Component({
selector: 'app-single-choice', selector: 'app-single-choice',
@ -16,6 +17,9 @@ export class SingleChoiceComponent implements OnInit, OnDestroy {
@Output() emitNextQuestionRequest = new EventEmitter(); @Output() emitNextQuestionRequest = new EventEmitter();
private id; private id;
private verifyAnswerSubscription: ISubscription; private verifyAnswerSubscription: ISubscription;
interval: any;
public timeLeft = 0;
@ViewChild('f') public form: NgForm;
constructor(private route: ActivatedRoute, private testsService: TestsService) { } constructor(private route: ActivatedRoute, private testsService: TestsService) { }
@ -32,10 +36,24 @@ export class SingleChoiceComponent implements OnInit, OnDestroy {
}); });
} }
startTimer() {
this.interval = setInterval(() => {
if (this.timeLeft > 0) {
this.timeLeft--;
} else {
this.nextQuestion(this.form);
}
}, 1000);
}
ngOnInit() { ngOnInit() {
if (this.timeLeft > 0) {
this.startTimer();
}
} }
ngOnDestroy() { ngOnDestroy() {
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.) {{question.question}} ({{question.points}}pkt.) <span *ngIf="timeLeft > 0">Czas: {{ timeLeft }} </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

@ -2,7 +2,7 @@ import { Component, OnInit, Input, Output, EventEmitter, OnDestroy } from '@angu
import { ActivatedRoute } from '@angular/router'; import { ActivatedRoute } from '@angular/router';
import { TestsService } from '../../../tests.service'; import { TestsService } from '../../../tests.service';
import * as $ from 'jquery'; import * as $ from 'jquery';
import { ISubscription } from 'rxjs/Subscription'; import { ISubscription, Subscription } from 'rxjs/Subscription';
@Component({ @Component({
selector: 'app-true-false', selector: 'app-true-false',
@ -16,6 +16,8 @@ export class TrueFalseComponent implements OnInit, OnDestroy {
@Output() emitNextQuestionRequest = new EventEmitter(); @Output() emitNextQuestionRequest = new EventEmitter();
private id; private id;
private verifyAnswerSubscription: ISubscription; private verifyAnswerSubscription: ISubscription;
interval: any;
public timeLeft = 0;
constructor(private route: ActivatedRoute, private testsService: TestsService) { } constructor(private route: ActivatedRoute, private testsService: TestsService) { }
@ -33,14 +35,28 @@ export class TrueFalseComponent implements OnInit, OnDestroy {
}); });
} }
startTimer() {
this.interval = setInterval(() => {
if (this.timeLeft > 0) {
this.timeLeft--;
} else {
this.nextQuestion();
}
}, 1000);
}
chooseAnswer(answer: any) { chooseAnswer(answer: any) {
this.answer = answer; this.answer = answer;
} }
ngOnInit() { ngOnInit() {
if (this.timeLeft > 0) {
this.startTimer();
}
} }
ngOnDestroy() { ngOnDestroy() {
clearInterval(this.interval);
if (this.verifyAnswerSubscription) { if (this.verifyAnswerSubscription) {
this.verifyAnswerSubscription.unsubscribe(); this.verifyAnswerSubscription.unsubscribe();
} }