Commit 5640dd4e authored by Christopher Fullarton's avatar Christopher Fullarton

Does not auto-send responses when leaving the quiz voting route anymore

parent f963ea4b
Pipeline #33541 passed with stages
in 14 minutes and 46 seconds
......@@ -147,6 +147,11 @@ export class VotingComponent implements OnInit, OnDestroy, IHasTriggeredNavigati
this.hasTriggeredNavigation = true;
this.router.navigate(this.getNextRoute(route));
this.memberApiService.putResponse(this._selectedAnswers).subscribe((data: IMessage) => {
if (data.status !== StatusProtocol.Success) {
console.log('VotingComponent: PutResponse failed', data);
}
});
}
public initData(): void {
......@@ -163,7 +168,6 @@ export class VotingComponent implements OnInit, OnDestroy, IHasTriggeredNavigati
}
public ngOnInit(): void {
this.quizService.quizUpdateEmitter.pipe(takeUntil(this._destroy)).subscribe(quiz => {
if (!quiz) {
return;
......@@ -220,12 +224,6 @@ export class VotingComponent implements OnInit, OnDestroy, IHasTriggeredNavigati
}
public ngOnDestroy(): void {
this.memberApiService.putResponse(this._selectedAnswers).subscribe((data: IMessage) => {
if (data.status !== StatusProtocol.Success) {
console.log('VotingComponent: PutResponse failed', data);
}
});
if (this.countdown) {
this.countdown.onChange.unsubscribe();
this.countdown.stop();
......@@ -272,7 +270,7 @@ export class VotingComponent implements OnInit, OnDestroy, IHasTriggeredNavigati
}), this.messageQueue.subscribe(MessageProtocol.Stop, payload => {
this._selectedAnswers = [];
this.hasTriggeredNavigation = true;
this.router.navigate(['/quiz', 'flow', 'results']);
this.sendResponses('results');
}),
]);
}
......
......@@ -71,11 +71,12 @@
<fa-icon [icon]="'download'"></fa-icon>
</button>
<button (click)="deleteQuiz(i)"
<button (click)="deleteQuiz(elem)"
[disabled]="!connectionService.serverAvailable"
[title]="'component.name_management.delete_session' | translate"
class="btn btn-secondary">
<fa-icon [icon]="'trash'"></fa-icon>
<fa-icon [icon]="isDeletingQuiz === elem ? 'spinner' : 'trash'"
[spin]="isDeletingQuiz === elem"></fa-icon>
</button>
</div>
......
......@@ -173,7 +173,7 @@ describe('QuizOverviewComponent', () => {
it('should return null if the quiz does not exist', inject([StorageService], (storageService: StorageService) => {
const quizName = 'validtestquiz';
component.deleteQuiz(0);
component.deleteQuiz(validQuiz);
storageService.db.Quiz.get(quizName).then(quiz => {
expect(quiz).toBe(null);
});
......
......@@ -26,6 +26,7 @@ export class QuizOverviewComponent implements OnInit {
public static TYPE = 'QuizOverviewComponent';
public publicQuizAmount: number;
public isStartingQuiz: QuizEntity;
public isDeletingQuiz: QuizEntity;
private _sessions: Array<QuizEntity> = [];
......@@ -145,7 +146,8 @@ export class QuizOverviewComponent implements OnInit {
});
}
public deleteQuiz(index: number): void {
public deleteQuiz(elem: QuizEntity): void {
this.isStartingQuiz = elem;
this.trackingService.trackClickEvent({
action: QuizOverviewComponent.TYPE,
label: `delete-quiz`,
......@@ -155,13 +157,17 @@ export class QuizOverviewComponent implements OnInit {
return;
}
this.quizApiService.deleteQuiz(this.sessions[index]).subscribe((response: IMessage) => {
this.quizApiService.deleteQuiz(elem).subscribe((response: IMessage) => {
if (response.status !== StatusProtocol.Success) {
console.log('QuizOverviewComponent: DeleteQuiz failed', response);
} else {
const sessionName = this.sessions[index].name;
this.sessions.splice(index, 1);
this.storageService.db.Quiz.delete(sessionName);
const sessionName = elem.name;
this.storageService.db.Quiz.delete(sessionName).then(() => {
const index = this.sessions.findIndex(quiz => quiz.name === sessionName);
if (index > -1) {
this.sessions.splice(index, 1);
}
});
}
});
}
......
......@@ -11,7 +11,7 @@ export class ShowUnloadWarningGuard<T extends IHasTriggeredNavigation> implement
constructor(private translate: TranslateService) {}
public canDeactivate(component): boolean {
if (component.hasTriggeredNavigation) {
if (component && component.hasTriggeredNavigation) {
return true;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment