Skip to content

Commit

Permalink
Fix Saving of Submission Files to Store
Browse files Browse the repository at this point in the history
  • Loading branch information
nestabentum committed Aug 8, 2022
1 parent 8d28e95 commit ae8868c
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 28 deletions.
51 changes: 30 additions & 21 deletions report-viewer/src/components/CodePanel.vue
Original file line number Diff line number Diff line change
Expand Up @@ -25,27 +25,32 @@
/>
</button>
</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>
</template>
Expand Down Expand Up @@ -112,6 +117,9 @@ export default defineComponent({
* @type {Ref<UnwrapRef<{}>>}
*/
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.
* Id object contains panel, file name, first line number of linked matched.
Expand Down Expand Up @@ -170,6 +178,7 @@ export default defineComponent({
linksArray,
isFirst,
isLast,
isEmpty,
};
},
});
Expand Down
21 changes: 14 additions & 7 deletions report-viewer/src/views/FileUploadView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -53,19 +53,29 @@ 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.
* @param file
*/
const handleZipFile = (file: File) => {
jszip.loadAsync(file).then(async (zip) => {
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 submissionName = filePath.dir.split("/")[2];
const submissionFileName = extractSubmissionFileName(filePath);
await zip.files[fileName].async("string").then((data) => {
store.commit("saveSubmissionFile", {
name: submissionName,
name: submissionFileName,
file: { fileName: filePath.base, data: data },
});
});
Expand Down Expand Up @@ -105,10 +115,7 @@ export default defineComponent({
single: true,
fileString: str,
});
navigateToComparisonView(
json["id1"],
json["id2"]
);
navigateToComparisonView(json["id1"], json["id2"]);
}
};
/**
Expand Down

0 comments on commit ae8868c

Please sign in to comment.