Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove comparison single file upload #1492

Merged
merged 1 commit into from
Jan 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion report-viewer/src/utils/fileHandling/FileHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ export abstract class FileHandler {
* Loads the content of the given file and stores it in the store.
* @param file File to handle
*/
public abstract handleFile(file: Blob): Promise<any>
public abstract handleFile(file: Blob): Promise<void>
}
12 changes: 3 additions & 9 deletions report-viewer/src/utils/fileHandling/JsonFileHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,13 @@ import { FileHandler } from './FileHandler'
* Class for handling single json files.
*/
export class JsonFileHandler extends FileHandler {
public async handleFile(
file: Blob
): Promise<{ fileType: 'overview' } | { fileType: 'comparison'; id1: string; id2: string }> {
public async handleFile(file: Blob) {
const content = await file.text()
const json = JSON.parse(content)

store().setSingleFileRawContent(content)
if (json['submission_folder_path']) {
return { fileType: 'overview' }
} else if (json['id1'] && json['id2']) {
return { fileType: 'comparison', id1: json['id1'], id2: json['id2'] }
} else {
throw new Error(`Invalid JSON: ${json}`)
if (!json['submission_folder_path']) {
throw new Error(`Invalid JSON: File is not an overview file.`)
}
}
}
2 changes: 1 addition & 1 deletion report-viewer/src/utils/fileHandling/ZipFileHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { FileHandler } from './FileHandler'
* Class for handling zip files.
*/
export class ZipFileHandler extends FileHandler {
public async handleFile(file: Blob): Promise<void> {
public async handleFile(file: Blob) {
console.log('Start handling zip file and storing necessary data...')
return jszip.loadAsync(file).then(async (zip) => {
for (const originalFileName of Object.keys(zip.files)) {
Expand Down
23 changes: 7 additions & 16 deletions report-viewer/src/views/FileUploadView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -107,32 +107,23 @@ function navigateToOverview() {
})
}

function navigateToComparisonView(firstId: string, secondId: string) {
router.push({
name: 'ComparisonView',
params: {
firstId,
secondId
}
})
}

/**
* Handles a json file on drop. It read the file and passes the file string to next window.
* @param file The json file to handle
*/
async function handleJsonFile(file: Blob) {
try {
await new JsonFileHandler().handleFile(file)
} catch (e) {
registerError(e as Error, 'upload')
return
}
store().setLoadingType({
local: false,
zip: false,
single: true
})
const fileContentType = await new JsonFileHandler().handleFile(file)
if (fileContentType.fileType === 'overview') {
navigateToOverview()
} else if (fileContentType.fileType === 'comparison') {
navigateToComparisonView(fileContentType.id1, fileContentType.id2)
}
navigateToOverview()
}

/**
Expand Down