Fixes a routing bug. Fixes log error from ssr

parent eceab010
......@@ -50,15 +50,15 @@ export const appRoutes: Routes = [
}, {
path: 'quiz/manager',
loadChildren: 'app/quiz/quiz-manager/quiz-manager.module#QuizManagerModule',
}, {
path: 'quiz',
loadChildren: 'app/quiz/quiz.module#QuizModule',
}, {
path: 'quiz/flow',
loadChildren: 'app/quiz/quiz-flow/quiz-flow.module#QuizFlowModule',
data: {
preload: true,
},
}, {
path: 'quiz',
loadChildren: 'app/quiz/quiz.module#QuizModule',
}, {
path: 'nicks',
loadChildren: 'app/root/nickname-chooser/nickname-chooser.module#NicknameChooserModule',
......
......@@ -24,53 +24,50 @@ export class FileUploadService {
private router: Router,
private activeQuestionGroupService: ActiveQuestionGroupService,
private quizApiService: QuizApiService,
) {
this._renameFilesQueue = new FormData();
}
) {}
public uploadFile(formData: FormData): void {
this._renameFilesQueue = new FormData();
this._duplicateQuizzes = [];
formData.append('privateKey', window.localStorage.getItem('config.private_key'));
this.quizApiService.postQuizUpload(formData).subscribe(
(data: IMessage) => {
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) => {
return (<File>file).name === duplicateQuiz.fileName;
})[0], duplicateQuiz.fileName);
});
this.router.navigate(['/quiz', 'rename']);
} else {
const allUploadedFiles = formData.getAll('uploadFiles[]');
allUploadedFiles.forEach((formDataValue, index) => {
const file = <File>formDataValue;
if (file.type !== 'application/json') {
return;
}
const reader = new FileReader();
reader.onload = () => {
this.quizApiService.postQuizUpload(formData).subscribe((data: IMessage) => {
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) => {
return (
<File>file
).name === duplicateQuiz.fileName;
})[0], duplicateQuiz.fileName);
});
this.router.navigate(['/quiz', 'rename']);
} else {
const allUploadedFiles = formData.getAll('uploadFiles[]');
allUploadedFiles.forEach((formDataValue, index) => {
const file = <File>formDataValue;
if (file.type !== 'application/json') {
return;
}
const reader = new FileReader();
reader.onload = () => {
const parsedFile = JSON.parse(reader.result);
this.activeQuestionGroupService.activeQuestionGroup = questionGroupReflection[parsedFile.TYPE](parsedFile);
this.activeQuestionGroupService.persist();
const parsedFile = JSON.parse(reader.result);
this.activeQuestionGroupService.activeQuestionGroup = questionGroupReflection[parsedFile.TYPE](parsedFile);
this.activeQuestionGroupService.persist();
window.localStorage.removeItem(file.name);
const questionList = JSON.parse(window.localStorage.getItem('config.owned_quizzes')) || [];
questionList.splice(questionList.indexOf(file.name), 1);
window.localStorage.setItem('config.owned_quizzes', JSON.stringify(questionList));
window.localStorage.removeItem(file.name);
const questionList = JSON.parse(window.localStorage.getItem('config.owned_quizzes')) || [];
questionList.splice(questionList.indexOf(file.name), 1);
window.localStorage.setItem('config.owned_quizzes', JSON.stringify(questionList));
this.router.navigate(['/']);
};
reader.readAsText(file);
});
}
},
error => {
console.log(error);
},
);
this.router.navigate(['/']);
};
reader.readAsText(file);
});
}
}, error => {
console.log(error);
});
}
}
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