From ee7e6a7b2f6892c170641b235c5adf7edcf9bc4d Mon Sep 17 00:00:00 2001 From: nitrotap <9121718+nitrotap@users.noreply.github.com> Date: Fri, 9 Jun 2023 03:47:44 -0600 Subject: [PATCH] fixing bug for results page --- client/src/app/quiz/quiz.page.ts | 16 ++++++++++++++-- client/src/app/results/results.page.html | 2 +- client/src/app/results/results.page.ts | 5 +++++ 3 files changed, 20 insertions(+), 3 deletions(-) diff --git a/client/src/app/quiz/quiz.page.ts b/client/src/app/quiz/quiz.page.ts index e05de1e..53f707a 100644 --- a/client/src/app/quiz/quiz.page.ts +++ b/client/src/app/quiz/quiz.page.ts @@ -2,6 +2,7 @@ import { Component, OnInit } from '@angular/core'; import { AnswerDataService } from '../services/answer-data.service'; import { TaskDataService } from '../services/task-data.service'; import { ToastController } from '@ionic/angular'; +import { Router } from '@angular/router'; @Component({ selector: 'app-quiz', templateUrl: './quiz.page.html', @@ -63,11 +64,22 @@ export class QuizPage implements OnInit { this.answerDataService.postData(this.formData).subscribe({ next: response => console.log('Response from server:', response), - error: error => console.error('Error:', error) + error: async error => { + console.error('Error:', error) + const alert = this.toastController.create({ + message: 'Error saving your task! Please try logging in again.', + duration: 2000, + position: 'bottom', + color: 'danger' + }); + (await alert).present(); + this.router.navigateByUrl('/login') + return; + } }); } - constructor(private answerDataService: AnswerDataService, private taskDataService: TaskDataService, private toastController: ToastController) { } + constructor(private answerDataService: AnswerDataService, private taskDataService: TaskDataService, private toastController: ToastController, private router: Router) { } questions: any[] = [ diff --git a/client/src/app/results/results.page.html b/client/src/app/results/results.page.html index beb65ca..6310d3e 100644 --- a/client/src/app/results/results.page.html +++ b/client/src/app/results/results.page.html @@ -22,7 +22,7 @@
See Your Past Results for {{ task.taskName }} - + Mental Demand: {{ demoResult.taskAnswer_1 }} Physical Demand: {{ demoResult.answerID }} Time (Temporal) Demand: {{ demoResult.answerID }} diff --git a/client/src/app/results/results.page.ts b/client/src/app/results/results.page.ts index 7270072..d38db6a 100644 --- a/client/src/app/results/results.page.ts +++ b/client/src/app/results/results.page.ts @@ -33,6 +33,11 @@ export class ResultsPage implements OnInit { }, ] + getResultsForTask(taskID: number): any[] { + return this.answerResults.filter((result: any) => result.taskID === taskID); + } + + getTaskData() { // user specific tasks