Commit 25a91dff authored by Christopher Fullarton's avatar Christopher Fullarton

Fixes upload of legacy quizzes from arsnova.click v1

parent bf32cf69
Pipeline #30218 passed with stages
in 13 minutes and 10 seconds
...@@ -152,7 +152,7 @@ export class HomeComponent implements OnInit, OnDestroy { ...@@ -152,7 +152,7 @@ export class HomeComponent implements OnInit, OnDestroy {
this.storageService.getAllQuiznames().then(quizNames => { this.storageService.getAllQuiznames().then(quizNames => {
this._ownQuizzes = quizNames; this._ownQuizzes = quizNames;
if (this._ownQuizzes.length && (!environment.requireLoginToCreateQuiz || (this.userService.isAuthorizedFor(UserRole.CreateQuiz)))) { if (this._ownQuizzes.length && (!environment.requireLoginToCreateQuiz || this.userService.isAuthorizedFor(UserRole.CreateQuiz))) {
this.modalService.open(AvailableQuizzesComponent); this.modalService.open(AvailableQuizzesComponent);
} }
}); });
......
...@@ -3,11 +3,11 @@ import { Inject, Injectable, PLATFORM_ID } from '@angular/core'; ...@@ -3,11 +3,11 @@ import { Inject, Injectable, PLATFORM_ID } from '@angular/core';
import { Router } from '@angular/router'; import { Router } from '@angular/router';
import { IDuplicateQuiz } from 'arsnova-click-v2-types/dist/common'; import { IDuplicateQuiz } from 'arsnova-click-v2-types/dist/common';
import { QuizEntity } from '../../../lib/entities/QuizEntity'; import { QuizEntity } from '../../../lib/entities/QuizEntity';
import { DbTable } from '../../../lib/enums/enums'; import { DbState } from '../../../lib/enums/enums';
import { IMessage } from '../../../lib/interfaces/communication/IMessage'; import { IMessage } from '../../../lib/interfaces/communication/IMessage';
import { QuizApiService } from '../api/quiz/quiz-api.service'; import { QuizApiService } from '../api/quiz/quiz-api.service';
import { QuizService } from '../quiz/quiz.service'; import { QuizService } from '../quiz/quiz.service';
import { StorageService } from '../storage/storage.service'; import { IndexedDbService } from '../storage/indexed.db.service';
@Injectable() @Injectable()
export class FileUploadService { export class FileUploadService {
...@@ -27,8 +27,7 @@ export class FileUploadService { ...@@ -27,8 +27,7 @@ export class FileUploadService {
@Inject(PLATFORM_ID) private platformId: Object, @Inject(PLATFORM_ID) private platformId: Object,
private router: Router, private router: Router,
private quizService: QuizService, private quizService: QuizService,
private quizApiService: QuizApiService, private quizApiService: QuizApiService, private indexedDbService: IndexedDbService,
private storageService: StorageService,
) { ) {
if (isPlatformBrowser(this.platformId)) { if (isPlatformBrowser(this.platformId)) {
this._renameFilesQueue = new FormData(); this._renameFilesQueue = new FormData();
...@@ -43,32 +42,25 @@ export class FileUploadService { ...@@ -43,32 +42,25 @@ export class FileUploadService {
if (data.payload.duplicateQuizzes.length) { if (data.payload.duplicateQuizzes.length) {
this._duplicateQuizzes = data.payload.duplicateQuizzes; this._duplicateQuizzes = data.payload.duplicateQuizzes;
data.payload.duplicateQuizzes.forEach((duplicateQuiz: IDuplicateQuiz) => { data.payload.duplicateQuizzes.forEach((duplicateQuiz: IDuplicateQuiz) => {
this._renameFilesQueue.append('uploadFiles[]', <File>formData.getAll('uploadFiles[]').filter((file) => { this._renameFilesQueue.append('uploadFiles[]', <File>formData.getAll('uploadFiles[]').find((file) => {
return (<File>file).name === duplicateQuiz.fileName; return (<File>file).name === duplicateQuiz.fileName;
})[0], duplicateQuiz.fileName); }), duplicateQuiz.fileName);
}); });
this.router.navigate(['/quiz', 'rename']); this.router.navigate(['/quiz', 'rename']);
} else {
const allUploadedFiles = formData.getAll('uploadFiles[]');
allUploadedFiles.forEach(formDataValue => {
const file = <File>formDataValue;
if (file.type !== 'application/json') {
return;
} }
const reader = new FileReader();
reader.onload = () => {
this.quizService.quiz = new QuizEntity(JSON.parse(reader.result.toString())); if (data.payload.quizData.length) {
data.payload.quizData.forEach(quizData => {
this.quizService.quiz = new QuizEntity(quizData.quiz);
this.quizService.persist(); this.quizService.persist();
this.quizService.quiz = null; this.quizService.quiz = null;
this.storageService.delete(DbTable.Quiz, file.name).subscribe();
this.router.navigate(['/']);
};
reader.readAsText(file);
}); });
if (!data.payload.duplicateQuizzes.length) {
this.indexedDbService.stateNotifier.next(DbState.Revalidate);
} }
}
}, error => { }, error => {
console.log('FileUploadService: PostQuizUpload failed', error); console.log('FileUploadService: PostQuizUpload failed', error);
}); });
......
...@@ -19,7 +19,7 @@ export const environment: IEnvironment = { ...@@ -19,7 +19,7 @@ export const environment: IEnvironment = {
infoAboutTabEnabled: false, infoAboutTabEnabled: false,
infoProjectTabEnabled: false, infoProjectTabEnabled: false,
infoBackendApiEnabled: false, infoBackendApiEnabled: false,
requireLoginToCreateQuiz: true, requireLoginToCreateQuiz: false,
forceQuizTheme: false, forceQuizTheme: false,
loginMechanism: [LoginMechanism.UsernamePassword, LoginMechanism.Token], loginMechanism: [LoginMechanism.UsernamePassword, LoginMechanism.Token],
}; };
......
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