Adds automatic processing of legacy quizzes

parent c47ba4bf
......@@ -88,6 +88,12 @@ export enum TrackingCategoryType {
export enum DeprecatedKeys {
privateKey = 'privateKey', //
token = 'token', //
language = 'language', //
showProductTour = 'showProductTour', //
localStorageAvailable = 'localStorageAvailable', //
intro_state = 'intro_state', //
lastPage = 'lastPage', //
'__amplify__tap-i18n-language' = '__amplify__tap-i18n-language', //
}
export enum DeprecatedDb {
......
......@@ -6,7 +6,7 @@ import { RxStompService } from '@stomp/ng2-stompjs';
import { IMessage } from '@stomp/stompjs/esm6';
import { SimpleMQ } from 'ng2-simple-mq';
import { Subject, Subscription } from 'rxjs';
import { distinctUntilChanged, filter, takeUntil } from 'rxjs/operators';
import { distinctUntilChanged, filter, take, takeUntil } from 'rxjs/operators';
import themeData from '../../../assets/themeData.json';
import { environment } from '../../../environments/environment';
import { QuizEntity } from '../../lib/entities/QuizEntity';
......@@ -52,7 +52,8 @@ export class RootComponent implements OnInit, AfterViewInit {
private storageService: StorageService,
private quizService: QuizService,
private connectionService: ConnectionService,
private messageQueue: SimpleMQ, private trackingService: TrackingService,
private messageQueue: SimpleMQ,
private trackingService: TrackingService,
) {
this.themeService.themeChanged.pipe(takeUntil(this._destroy), distinctUntilChanged(), filter(t => !!t)).subscribe(themeName => {
if (String(themeName) === 'default') {
......@@ -72,6 +73,22 @@ export class RootComponent implements OnInit, AfterViewInit {
public ngOnInit(): void {
if (isPlatformBrowser(this.platformId)) {
if (localStorage.getItem('hashtags')) {
// Migrate arsnova.click v1 quizzes
try {
console.log('found old hashtags');
this.storageService.stateNotifier.pipe(filter(val => val === DbState.Initialized), take(1), takeUntil(this._destroy)).subscribe(() => {
console.log('db state notifier triggered');
const quizNames: Array<string> = JSON.parse(localStorage.getItem('hashtags'));
quizNames.forEach(quizName => {
const quiz = JSON.parse(localStorage.getItem(quizName));
console.log('persisting old quiz', quiz);
this.quizService.saveParsedQuiz(quiz).subscribe(() => localStorage.removeItem(quizName));
});
});
} catch {
}
}
Object.values(DeprecatedKeys).forEach(deprecatedKey => {
localStorage.removeItem(deprecatedKey);
sessionStorage.removeItem(deprecatedKey);
......
......@@ -2,10 +2,12 @@ import { isPlatformServer } from '@angular/common';
import { Inject, Injectable, PLATFORM_ID } from '@angular/core';
import { NgbModal } from '@ng-bootstrap/ng-bootstrap';
import { TranslateService } from '@ngx-translate/core';
import { ReplaySubject } from 'rxjs';
import { Observable, ReplaySubject } from 'rxjs';
import { tap } from 'rxjs/operators';
import { AbstractQuestionEntity } from '../../lib/entities/question/AbstractQuestionEntity';
import { QuizEntity } from '../../lib/entities/QuizEntity';
import { StorageKey } from '../../lib/enums/enums';
import { IMessage } from '../../lib/interfaces/communication/IMessage';
import { NoDataErrorComponent } from '../../shared/no-data-error/no-data-error.component';
import { QuizApiService } from '../api/quiz/quiz-api.service';
import { SettingsService } from '../settings/settings.service';
......@@ -92,11 +94,15 @@ export class QuizService {
return;
}
this.storageService.db.Quiz.put(quiz);
if (this._isInEditMode) {
this.quizApiService.putSavedQuiz(quiz).subscribe();
this.saveParsedQuiz(quiz);
}
}
public saveParsedQuiz(quiz: QuizEntity): Observable<IMessage> {
return this.quizApiService.putSavedQuiz(quiz).pipe(tap(result => {
this.storageService.db.Quiz.put(result.payload);
}));
}
public currentQuestion(): AbstractQuestionEntity {
......
......@@ -9,9 +9,9 @@ export const environment: IEnvironment = {
enableCasLogin: true,
sentryDSN: 'https://f16c02fdefe64c018f5d580d1cf05b56@sentry.io/1819496',
ssrEndpoint: 'http://localhost:4000',
serverEndpoint: 'http://localhost:3010',
httpApiEndpoint: 'http://localhost:3010/api/v1',
httpLibEndpoint: 'http://localhost:3010/lib',
serverEndpoint: 'http://localhost:3030',
httpApiEndpoint: 'http://localhost:3030/api/v1',
httpLibEndpoint: 'http://localhost:3030/lib',
stompConfig: {
endpoint: 'ws://localhost:15674/ws',
user: 'arsnova-click',
......
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