Selaa lähdekoodia

Fix Saving of Submission Files to Store

Nesta Bentum 4 vuotta sitten
vanhempi
commit
ae8868c88f

+ 30 - 21
report-viewer/src/components/CodePanel.vue

@@ -25,27 +25,32 @@
         />
         />
       </button>
       </button>
     </div>
     </div>
-    <div :class="{ hidden: !collapse }" class="code-container">
-      <LineOfCode
-        v-for="(line, index) in lines"
-        :id="String(panelId).concat(title).concat(index)"
-        :key="index"
-        :color="coloringArray[index]"
-        :is-first="isFirst[index]"
-        :is-last="isLast[index]"
-        :line-number="index + 1"
-        :text="line"
-        :visible="collapse"
-        @click="
-          $emit(
-            'lineSelected',
-            $event,
-            linksArray[index].panel,
-            linksArray[index].file,
-            linksArray[index].line
-          )
-        "
-      />
+    <div :class="{ hidden: !collapse }">
+      <div v-if="!isEmpty(lines)" class="code-container">
+        <LineOfCode
+          v-for="(line, index) in lines"
+          :id="String(panelId).concat(title).concat(index)"
+          :key="index"
+          :color="coloringArray[index]"
+          :is-first="isFirst[index]"
+          :is-last="isLast[index]"
+          :line-number="index + 1"
+          :text="line"
+          :visible="collapse"
+          @click="
+            $emit(
+              'lineSelected',
+              $event,
+              linksArray[index].panel,
+              linksArray[index].file,
+              linksArray[index].line
+            )
+          "
+        />
+      </div>
+      <div v-else class="code-container">
+        <p>Empty File</p>
+      </div>
     </div>
     </div>
   </div>
   </div>
 </template>
 </template>
@@ -112,6 +117,9 @@ export default defineComponent({
      * @type {Ref<UnwrapRef<{}>>}
      * @type {Ref<UnwrapRef<{}>>}
      */
      */
     const coloringArray = ref({});
     const coloringArray = ref({});
+    const isEmpty = (lines) => {
+      return lines.length === 0 || lines.every((line) => !(line.trim()));
+    };
     /**
     /**
      * An object containing an object from which an id is to of the line to which this is linked is constructed.
      * An object containing an object from which an id is to of the line to which this is linked is constructed.
      * Id object contains panel, file name, first line number of linked matched.
      * Id object contains panel, file name, first line number of linked matched.
@@ -170,6 +178,7 @@ export default defineComponent({
       linksArray,
       linksArray,
       isFirst,
       isFirst,
       isLast,
       isLast,
+      isEmpty,
     };
     };
   },
   },
 });
 });

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

@@ -53,6 +53,13 @@ export default defineComponent({
         },
         },
       });
       });
     };
     };
+    const extractSubmissionFileName = (filePath: path.ParsedPath) => {
+      const folders = filePath.dir.split("/");
+      const submissionFolderIndex = folders.findIndex(
+        (folder) => folder === "submissions"
+      );
+      return folders[submissionFolderIndex + 1];
+    };
     /**
     /**
      * Handles zip file on drop. It extracts the zip and saves each file in the store.
      * Handles zip file on drop. It extracts the zip and saves each file in the store.
      * @param file
      * @param file
@@ -60,12 +67,15 @@ export default defineComponent({
     const handleZipFile = (file: File) => {
     const handleZipFile = (file: File) => {
       jszip.loadAsync(file).then(async (zip) => {
       jszip.loadAsync(file).then(async (zip) => {
         for (const fileName of Object.keys(zip.files)) {
         for (const fileName of Object.keys(zip.files)) {
-          if (fileName.match(/submissions\/(.+)\/(.+)/)) {
+          if (
+            /((.+\/)*)submissions\/(.+)\/(.+)/.test(fileName) &&
+            !/^__MACOSX\//.test(fileName)
+          ) {
             const filePath = path.parse(fileName);
             const filePath = path.parse(fileName);
-            const submissionName = filePath.dir.split("/")[2];
+            const submissionFileName = extractSubmissionFileName(filePath);
             await zip.files[fileName].async("string").then((data) => {
             await zip.files[fileName].async("string").then((data) => {
               store.commit("saveSubmissionFile", {
               store.commit("saveSubmissionFile", {
-                name: submissionName,
+                name: submissionFileName,
                 file: { fileName: filePath.base, data: data },
                 file: { fileName: filePath.base, data: data },
               });
               });
             });
             });
@@ -105,10 +115,7 @@ export default defineComponent({
           single: true,
           single: true,
           fileString: str,
           fileString: str,
         });
         });
-        navigateToComparisonView(
-          json["id1"],
-          json["id2"]
-        );
+        navigateToComparisonView(json["id1"], json["id2"]);
       }
       }
     };
     };
     /**
     /**