Skip to content

Commit

Permalink
Merge pull request #619 from nestabentum/fix_comparisonview
Browse files Browse the repository at this point in the history
Fix ComparisonView
  • Loading branch information
dfuchss authored Aug 30, 2022
2 parents f36a075 + 16c1bae commit e8ea0ca
Show file tree
Hide file tree
Showing 7 changed files with 72 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public class DirectoryManager {
* @return The created directory
*/
public static File createDirectory(String path, String name) throws IOException {
File directory = new File(path.concat("/").concat(name));
File directory = new File(path.concat(File.separator).concat(name));
if (!directory.exists() && !directory.mkdirs()) {
throw new IOException("Failed to create dir.");
}
Expand Down
54 changes: 45 additions & 9 deletions report-viewer/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions report-viewer/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"highlight.js": "^11.6.0",
"jszip": "^3.10.0",
"node-polyfill-webpack-plugin": "^2.0.0",
"slash": "^4.0.0",
"vue": "^3.2.37",
"vue-chart-3": "^3.1.8",
"vue-draggable-next": "^2.1.1",
Expand Down
2 changes: 1 addition & 1 deletion report-viewer/src/router/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const routes: Array<RouteRecordRaw> = [
component: OverviewView,
},
{
path: "/comparison",
path: "/comparison/:firstId/:secondId",
name: "ComparisonView",
component: ComparisonView,
props: true,
Expand Down
25 changes: 13 additions & 12 deletions report-viewer/src/store/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,21 +95,22 @@ const store = createStore<State>({
return Array.from(state.fileIdToDisplayName.keys());
},
getComparisonFileName:
(state) => (submissionId: string, fileId: string) => {
(state) => (submissionId1: string, submissionId2: string) => {
return state.submissionIdsToComparisonFileName
.get(submissionId)
?.get(fileId);
.get(submissionId1)
?.get(submissionId2);
},
getComparisonFileForSubmissions: (state, getters) => (submissionId1: string, submissionId2: string) => {
const expectedFileName = getters.getComparisonFileName(submissionId1, submissionId2);
const index = Object.keys(store.state.files).find(
(name) =>
name.endsWith(expectedFileName)
getComparisonFileForSubmissions:
(state, getters) => (submissionId1: string, submissionId2: string) => {
const expectedFileName = getters.getComparisonFileName(
submissionId1,
submissionId2
);
return index != undefined
? store.state.files[index]
: undefined
}
const index = Object.keys(store.state.files).find((name) =>
name.endsWith(expectedFileName)
);
return index != undefined ? store.state.files[index] : undefined;
},
},
mutations: {
addAnonymous(state: State, id) {
Expand Down
3 changes: 1 addition & 2 deletions report-viewer/src/views/ComparisonView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,7 @@ export default defineComponent({
);
}
if (!comparison) {
console.warn("Could not build comparison file");
return;
throw "Could not build comparison file";
}
const filesOfFirst = ref(comparison.filesOfFirstSubmission);
const filesOfSecond = ref(comparison.filesOfSecondSubmission);
Expand Down
17 changes: 10 additions & 7 deletions report-viewer/src/views/FileUploadView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import router from "@/router";
import store from "@/store/store";
import { getFileExtension } from "@/utils/Utils";
import path from "path";
import slash from "slash";

export default defineComponent({
name: "FileUploadView",
Expand Down Expand Up @@ -66,22 +67,24 @@ export default defineComponent({
*/
const handleZipFile = (file: File) => {
jszip.loadAsync(file).then(async (zip) => {
for (const fileName of Object.keys(zip.files)) {
for (const originalFileName of Object.keys(zip.files)) {
const unixFileName = slash(originalFileName);
if (
/((.+\/)*)submissions\/(.+)\/(.+)/.test(fileName) &&
!/^__MACOSX\//.test(fileName)
/((.+\/)*)submissions\/(.+)\/(.+)/.test(unixFileName) &&
!/^__MACOSX\//.test(unixFileName)
) {
const filePath = path.parse(fileName);
const filePath = path.parse(unixFileName);

const submissionFileName = extractSubmissionFileName(filePath);
await zip.files[fileName].async("string").then((data) => {
await zip.files[originalFileName].async("string").then((data) => {
store.commit("saveSubmissionFile", {
name: submissionFileName,
file: { fileName: filePath.base, data: data },
});
});
} else {
await zip.files[fileName].async("string").then((data) => {
store.commit("saveFile", { fileName: fileName, data: data });
await zip.files[originalFileName].async("string").then((data) => {
store.commit("saveFile", { fileName: unixFileName, data: data });
});
}
}
Expand Down

0 comments on commit e8ea0ca

Please sign in to comment.