From 4ef8928ec973e5416ccce674dd091212b1c8726b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Przemys=C5=82aw=20Stawujak?= Date: Wed, 2 Jan 2019 19:27:18 +0100 Subject: [PATCH] SKE-64 solve competition component --- .../competition-detail.component.css | 27 ++++++++ .../competition-detail.component.html | 47 ++++++++++++++ .../competition-detail.component.ts | 62 ++++++++++++++++++- .../shared/service-proxies/service-proxies.ts | 4 ++ .../CompetitionAppService.cs | 8 +++ .../Dto/QuestionOptionDto.cs | 2 + 6 files changed, 149 insertions(+), 1 deletion(-) diff --git a/SystemKonkursow/4.2.1/angular/src/app/competition-detail/competition-detail.component.css b/SystemKonkursow/4.2.1/angular/src/app/competition-detail/competition-detail.component.css index 84899fc..dc5595a 100644 --- a/SystemKonkursow/4.2.1/angular/src/app/competition-detail/competition-detail.component.css +++ b/SystemKonkursow/4.2.1/angular/src/app/competition-detail/competition-detail.component.css @@ -16,4 +16,31 @@ hr { .section-color{ color: #771111; +} + +.badge { + border-radius: 10px; + background-color: #359088; +} + +.option { + background-color: #cadaee; + font-size: 20px; + padding: 10px; + margin: 3px; +} + +.option-size { + font-size: 18px; +} + +.btn { + border-radius: 0; + margin: 6px; +} + +.result-question { + background-color: #eee; + margin: 4px; + padding: 6px; } \ No newline at end of file diff --git a/SystemKonkursow/4.2.1/angular/src/app/competition-detail/competition-detail.component.html b/SystemKonkursow/4.2.1/angular/src/app/competition-detail/competition-detail.component.html index 371a407..938caa3 100644 --- a/SystemKonkursow/4.2.1/angular/src/app/competition-detail/competition-detail.component.html +++ b/SystemKonkursow/4.2.1/angular/src/app/competition-detail/competition-detail.component.html @@ -11,5 +11,52 @@ {{l("Start")}}
+ +
+
+
Pytanie {{pager.index + 1}}/{{pager.count}}
+

{{pager.index + 1}}. + +

+
+
+
+ + +
+
+
+
+ +
+ +
+ + + + +
+ +
+ +
+
+ +
+

Twoje odpowiedzi

+
+
+
{{index + 1}}. {{question.name}}
+
+
+ + +
+
+
Twoja odpowiedź jest {{isCorrect(question)}}.
+
+
+
+ \ No newline at end of file diff --git a/SystemKonkursow/4.2.1/angular/src/app/competition-detail/competition-detail.component.ts b/SystemKonkursow/4.2.1/angular/src/app/competition-detail/competition-detail.component.ts index e21a1b4..22c1eeb 100644 --- a/SystemKonkursow/4.2.1/angular/src/app/competition-detail/competition-detail.component.ts +++ b/SystemKonkursow/4.2.1/angular/src/app/competition-detail/competition-detail.component.ts @@ -5,7 +5,10 @@ import { Subscription } from 'rxjs/Rx'; import { ActivatedRoute } from '@angular/router'; import { mergeMap } from 'rxjs/operators'; import { finalize } from 'rxjs/operators'; -import { CompetitionServiceProxy, CompetitionDto } from '@shared/service-proxies/service-proxies'; +import { CompetitionServiceProxy, + CompetitionDto, + QuestionDto, + QuestionOptionDto } from '@shared/service-proxies/service-proxies'; @Component({ templateUrl: './competition-detail.component.html', @@ -22,6 +25,12 @@ export class CompetitionDetailComponent extends AppComponentBase implements OnIn public mode = 'detail'; + public pager = { + index: 0, + size: 1, + count: 1 + }; + constructor( injector: Injector, private route: ActivatedRoute, @@ -47,15 +56,66 @@ export class CompetitionDetailComponent extends AppComponentBase implements OnIn return competitionDetailStream })).subscribe((result: CompetitionDto) => { this.competition = result; + this.competition.questions.forEach((x) => this.shuffleOptions(x.questionOptions)); + this.pager.count = this.competition.questions.length; console.log(this.competition); }); } + private shuffleOptions(array) { + let currentIndex = array.length, temp, randomIndex; + + while (0 !== currentIndex) { + randomIndex = Math.floor(Math.random() * currentIndex); + currentIndex -= 1; + + temp = array[currentIndex]; + array[currentIndex] = array[randomIndex]; + array[randomIndex] = temp; + } + + return array; + } + public solveCompetition(): void { console.log('Solve Competition'); this.mode = 'quiz'; } + get filteredQuestions() { + return (this.competition.questions) ? + this.competition.questions.slice(this.pager.index, this.pager.index + this.pager.size) : []; + } + + public onSelect(question: QuestionDto, option: QuestionOptionDto) { + question.questionOptions.forEach((x) => { if (x.id !== option.id) x.selected = false; }); + console.log(question); + } + + public goTo(index: number) { + if (index >= 0 && index < this.pager.count) { + this.pager.index = index; + this.mode = 'quiz'; + } + } + + public isCorrect(question: QuestionDto) { + return question.questionOptions.every(x => x.selected === x.isAnswer) ? 'poprawna' : 'niepoprawna'; + } + + public onSubmit() { + let points: number = 0; + this.competition.questions.forEach( + (x) => { + if (x.questionOptions.every( + (y) => y.selected === y.isAnswer) + ) points += 1; + }); + + console.log('Punkty: ' + points); + this.mode = 'result'; + } + public ngOnDestroy() { if (this.paramSubscription) { this.paramSubscription.unsubscribe(); diff --git a/SystemKonkursow/4.2.1/angular/src/shared/service-proxies/service-proxies.ts b/SystemKonkursow/4.2.1/angular/src/shared/service-proxies/service-proxies.ts index 0b41014..c157cef 100644 --- a/SystemKonkursow/4.2.1/angular/src/shared/service-proxies/service-proxies.ts +++ b/SystemKonkursow/4.2.1/angular/src/shared/service-proxies/service-proxies.ts @@ -2398,6 +2398,7 @@ export class QuestionOptionDto implements IQuestionOptionDto { name: string | undefined; questionId: number | undefined; isAnswer: boolean | undefined; + selected: boolean | undefined; id: number | undefined; constructor(data?: IQuestionOptionDto) { @@ -2414,6 +2415,7 @@ export class QuestionOptionDto implements IQuestionOptionDto { this.name = data["name"]; this.questionId = data["questionId"]; this.isAnswer = data["isAnswer"]; + this.selected = data["selected"]; this.id = data["id"]; } } @@ -2430,6 +2432,7 @@ export class QuestionOptionDto implements IQuestionOptionDto { data["name"] = this.name; data["questionId"] = this.questionId; data["isAnswer"] = this.isAnswer; + data["selected"] = this.selected; data["id"] = this.id; return data; } @@ -2446,6 +2449,7 @@ export interface IQuestionOptionDto { name: string | undefined; questionId: number | undefined; isAnswer: boolean | undefined; + selected: boolean | undefined; id: number | undefined; } diff --git a/SystemKonkursow/4.2.1/aspnet-core/src/SystemKonkursow.Application/Competition/CompetitionCategory/CompetitionAppService.cs b/SystemKonkursow/4.2.1/aspnet-core/src/SystemKonkursow.Application/Competition/CompetitionCategory/CompetitionAppService.cs index dd9e3b1..3108270 100644 --- a/SystemKonkursow/4.2.1/aspnet-core/src/SystemKonkursow.Application/Competition/CompetitionCategory/CompetitionAppService.cs +++ b/SystemKonkursow/4.2.1/aspnet-core/src/SystemKonkursow.Application/Competition/CompetitionCategory/CompetitionAppService.cs @@ -105,6 +105,14 @@ namespace SystemKonkursow.Competition.CompetitionCategory var mappedObject = ObjectMapper.Map(competition); + foreach (var question in mappedObject.Questions) + { + foreach (var option in question.QuestionOptions) + { + option.Selected = false; + } + } + return mappedObject; } diff --git a/SystemKonkursow/4.2.1/aspnet-core/src/SystemKonkursow.Application/Competition/CompetitionCategory/Dto/QuestionOptionDto.cs b/SystemKonkursow/4.2.1/aspnet-core/src/SystemKonkursow.Application/Competition/CompetitionCategory/Dto/QuestionOptionDto.cs index 9474dc0..195c7c1 100644 --- a/SystemKonkursow/4.2.1/aspnet-core/src/SystemKonkursow.Application/Competition/CompetitionCategory/Dto/QuestionOptionDto.cs +++ b/SystemKonkursow/4.2.1/aspnet-core/src/SystemKonkursow.Application/Competition/CompetitionCategory/Dto/QuestionOptionDto.cs @@ -9,5 +9,7 @@ namespace SystemKonkursow.Competition.CompetitionCategory.Dto public int QuestionId { get; set; } public bool IsAnswer { get; set; } + + public bool Selected { get; set; } } }