Просмотр исходного кода

Merge pull request #619 from nestabentum/fix_comparisonview

Fix ComparisonView
Dominik Fuchß 4 лет назад
Родитель
Сommit
e8ea0ca7e7

+ 1 - 1
jplag/src/main/java/de/jplag/reporting/jsonfactory/DirectoryManager.java

@@ -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.");
         }

+ 45 - 9
report-viewer/package-lock.json

@@ -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",
@@ -5505,6 +5506,15 @@
         "url": "https://github.com/sponsors/sindresorhus"
       }
     },
+    "node_modules/del/node_modules/slash": {
+      "version": "3.0.0",
+      "resolved": "https://registry.npmjs.org/slash/-/slash-3.0.0.tgz",
+      "integrity": "sha512-g9Q1haeby36OSStwb4ntCGGGaKsaVSjQ68fBxoQcutl5fS1vuY18H3wSt3jFyFtrkx+Kz0V1G85A4MyAdDMi2Q==",
+      "dev": true,
+      "engines": {
+        "node": ">=8"
+      }
+    },
     "node_modules/depd": {
       "version": "1.1.2",
       "resolved": "https://registry.npmjs.org/depd/-/depd-1.1.2.tgz",
@@ -7221,6 +7231,15 @@
         "url": "https://github.com/sponsors/sindresorhus"
       }
     },
+    "node_modules/globby/node_modules/slash": {
+      "version": "3.0.0",
+      "resolved": "https://registry.npmjs.org/slash/-/slash-3.0.0.tgz",
+      "integrity": "sha512-g9Q1haeby36OSStwb4ntCGGGaKsaVSjQ68fBxoQcutl5fS1vuY18H3wSt3jFyFtrkx+Kz0V1G85A4MyAdDMi2Q==",
+      "dev": true,
+      "engines": {
+        "node": ">=8"
+      }
+    },
     "node_modules/graceful-fs": {
       "version": "4.2.9",
       "resolved": "https://registry.npmjs.org/graceful-fs/-/graceful-fs-4.2.9.tgz",
@@ -11712,12 +11731,14 @@
       }
     },
     "node_modules/slash": {
-      "version": "3.0.0",
-      "resolved": "https://registry.npmjs.org/slash/-/slash-3.0.0.tgz",
-      "integrity": "sha512-g9Q1haeby36OSStwb4ntCGGGaKsaVSjQ68fBxoQcutl5fS1vuY18H3wSt3jFyFtrkx+Kz0V1G85A4MyAdDMi2Q==",
-      "dev": true,
+      "version": "4.0.0",
+      "resolved": "https://registry.npmjs.org/slash/-/slash-4.0.0.tgz",
+      "integrity": "sha512-3dOsAHXXUkQTpOYcoAxLIorMTp4gIQr5IW3iVb7A7lFIp0VHhnynm9izx6TssdrIcVIESAlVjtnO2K8bg+Coew==",
       "engines": {
-        "node": ">=8"
+        "node": ">=12"
+      },
+      "funding": {
+        "url": "https://github.com/sponsors/sindresorhus"
       }
     },
     "node_modules/slice-ansi": {
@@ -17892,6 +17913,14 @@
         "p-map": "^4.0.0",
         "rimraf": "^3.0.2",
         "slash": "^3.0.0"
+      },
+      "dependencies": {
+        "slash": {
+          "version": "3.0.0",
+          "resolved": "https://registry.npmjs.org/slash/-/slash-3.0.0.tgz",
+          "integrity": "sha512-g9Q1haeby36OSStwb4ntCGGGaKsaVSjQ68fBxoQcutl5fS1vuY18H3wSt3jFyFtrkx+Kz0V1G85A4MyAdDMi2Q==",
+          "dev": true
+        }
       }
     },
     "depd": {
@@ -19175,6 +19204,14 @@
         "ignore": "^5.2.0",
         "merge2": "^1.4.1",
         "slash": "^3.0.0"
+      },
+      "dependencies": {
+        "slash": {
+          "version": "3.0.0",
+          "resolved": "https://registry.npmjs.org/slash/-/slash-3.0.0.tgz",
+          "integrity": "sha512-g9Q1haeby36OSStwb4ntCGGGaKsaVSjQ68fBxoQcutl5fS1vuY18H3wSt3jFyFtrkx+Kz0V1G85A4MyAdDMi2Q==",
+          "dev": true
+        }
       }
     },
     "graceful-fs": {
@@ -22465,10 +22502,9 @@
       }
     },
     "slash": {
-      "version": "3.0.0",
-      "resolved": "https://registry.npmjs.org/slash/-/slash-3.0.0.tgz",
-      "integrity": "sha512-g9Q1haeby36OSStwb4ntCGGGaKsaVSjQ68fBxoQcutl5fS1vuY18H3wSt3jFyFtrkx+Kz0V1G85A4MyAdDMi2Q==",
-      "dev": true
+      "version": "4.0.0",
+      "resolved": "https://registry.npmjs.org/slash/-/slash-4.0.0.tgz",
+      "integrity": "sha512-3dOsAHXXUkQTpOYcoAxLIorMTp4gIQr5IW3iVb7A7lFIp0VHhnynm9izx6TssdrIcVIESAlVjtnO2K8bg+Coew=="
     },
     "slice-ansi": {
       "version": "5.0.0",

+ 1 - 0
report-viewer/package.json

@@ -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",

+ 1 - 1
report-viewer/src/router/index.ts

@@ -18,7 +18,7 @@ const routes: Array<RouteRecordRaw> = [
     component: OverviewView,
   },
   {
-    path: "/comparison",
+    path: "/comparison/:firstId/:secondId",
     name: "ComparisonView",
     component: ComparisonView,
     props: true,

+ 13 - 12
report-viewer/src/store/store.ts

@@ -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) {

+ 1 - 2
report-viewer/src/views/ComparisonView.vue

@@ -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);

+ 10 - 7
report-viewer/src/views/FileUploadView.vue

@@ -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",
@@ -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 });
             });
           }
         }