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 {
this.storageService.getAllQuiznames().then(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);
}
});
......
......@@ -3,11 +3,11 @@ import { Inject, Injectable, PLATFORM_ID } from '@angular/core';
import { Router } from '@angular/router';
import { IDuplicateQuiz } from 'arsnova-click-v2-types/dist/common';
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 { QuizApiService } from '../api/quiz/quiz-api.service';
import { QuizService } from '../quiz/quiz.service';
import { StorageService } from '../storage/storage.service';
import { IndexedDbService } from '../storage/indexed.db.service';
@Injectable()
export class FileUploadService {
......@@ -27,8 +27,7 @@ export class FileUploadService {
@Inject(PLATFORM_ID) private platformId: Object,
private router: Router,
private quizService: QuizService,
private quizApiService: QuizApiService,
private storageService: StorageService,
private quizApiService: QuizApiService, private indexedDbService: IndexedDbService,
) {
if (isPlatformBrowser(this.platformId)) {
this._renameFilesQueue = new FormData();
......@@ -43,32 +42,25 @@ export class FileUploadService {
if (data.payload.duplicateQuizzes.length) {
this._duplicateQuizzes = data.payload.duplicateQuizzes;
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;
})[0], duplicateQuiz.fileName);
}), duplicateQuiz.fileName);
});
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.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 => {
console.log('FileUploadService: PostQuizUpload failed', error);
});
......
......@@ -19,7 +19,7 @@ export const environment: IEnvironment = {
infoAboutTabEnabled: false,
infoProjectTabEnabled: false,
infoBackendApiEnabled: false,
requireLoginToCreateQuiz: true,
requireLoginToCreateQuiz: false,
forceQuizTheme: false,
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