From ae8868c88f41a0b8f947d09eac045659934e68cc Mon Sep 17 00:00:00 2001 From: Nesta Bentum Date: Sun, 7 Aug 2022 10:19:32 +0200 Subject: [PATCH 1/3] Fix Saving of Submission Files to Store --- report-viewer/src/components/CodePanel.vue | 51 +++++++++++++--------- report-viewer/src/views/FileUploadView.vue | 21 ++++++--- 2 files changed, 44 insertions(+), 28 deletions(-) diff --git a/report-viewer/src/components/CodePanel.vue b/report-viewer/src/components/CodePanel.vue index 20370474b..66edb0c82 100644 --- a/report-viewer/src/components/CodePanel.vue +++ b/report-viewer/src/components/CodePanel.vue @@ -25,27 +25,32 @@ /> -
- +
+
+ +
+
+

Empty File

+
@@ -112,6 +117,9 @@ export default defineComponent({ * @type {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. * Id object contains panel, file name, first line number of linked matched. @@ -170,6 +178,7 @@ export default defineComponent({ linksArray, isFirst, isLast, + isEmpty, }; }, }); diff --git a/report-viewer/src/views/FileUploadView.vue b/report-viewer/src/views/FileUploadView.vue index 5502354b7..40e3655fc 100644 --- a/report-viewer/src/views/FileUploadView.vue +++ b/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. * @param file @@ -60,12 +67,15 @@ export default defineComponent({ 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 }, }); }); @@ -105,10 +115,7 @@ export default defineComponent({ single: true, fileString: str, }); - navigateToComparisonView( - json["id1"], - json["id2"] - ); + navigateToComparisonView(json["id1"], json["id2"]); } }; /** From ef5fb0851fb320984294b6f5168222df5463f51e Mon Sep 17 00:00:00 2001 From: Nesta Bentum Date: Mon, 8 Aug 2022 18:45:21 +0200 Subject: [PATCH 2/3] Repair Report Match Generation --- .../mapper/ComparisonReportMapper.java | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/jplag/src/main/java/de/jplag/reporting/reportobject/mapper/ComparisonReportMapper.java b/jplag/src/main/java/de/jplag/reporting/reportobject/mapper/ComparisonReportMapper.java index 5785bf444..1cc7d410d 100644 --- a/jplag/src/main/java/de/jplag/reporting/reportobject/mapper/ComparisonReportMapper.java +++ b/jplag/src/main/java/de/jplag/reporting/reportobject/mapper/ComparisonReportMapper.java @@ -36,7 +36,7 @@ private List convertMatchesToReportMatches(JPlagResult result, JPlagCompa .map(match -> convertMatchToReportMatch(comparison, match, result.getOptions().getLanguage().supportsColumns())).toList(); } - private Match convertMatchToReportMatch(JPlagComparison comparison, de.jplag.Match match, boolean usesIndex) { + private Match convertMatchToReportMatch(JPlagComparison comparison, de.jplag.Match match, boolean languageSupportsColumnsAndLines) { TokenList tokensFirst = comparison.getFirstSubmission().getTokenList(); TokenList tokensSecond = comparison.getSecondSubmission().getTokenList(); Token startTokenFirst = tokensFirst.getToken(match.startOfFirst()); @@ -44,13 +44,17 @@ private Match convertMatchToReportMatch(JPlagComparison comparison, de.jplag.Mat Token startTokenSecond = tokensSecond.getToken(match.startOfSecond()); Token endTokenSecond = tokensSecond.getToken(match.startOfSecond() + match.length() - 1); - int startFirst = usesIndex ? startTokenFirst.getIndex() : startTokenFirst.getLine(); - int endFirst = usesIndex ? endTokenFirst.getIndex() : endTokenFirst.getLine(); - int startSecond = usesIndex ? startTokenSecond.getIndex() : startTokenSecond.getLine(); - int endSecond = usesIndex ? endTokenSecond.getIndex() : endTokenSecond.getLine(); + int startFirst = getPosition(languageSupportsColumnsAndLines, startTokenFirst); + int endFirst = getPosition(languageSupportsColumnsAndLines, endTokenFirst); + int startSecond = getPosition(languageSupportsColumnsAndLines, startTokenSecond); + int endSecond = getPosition(languageSupportsColumnsAndLines, endTokenSecond); int tokens = match.length(); return new Match(startTokenFirst.getFile(), startTokenSecond.getFile(), startFirst, endFirst, startSecond, endSecond, tokens); } + private int getPosition(boolean languageSupportsColumnsAndLines, Token token) { + return languageSupportsColumnsAndLines ? token.getLine() : token.getIndex(); + } + } From 75e7d76c587e0740597975e2e65b032277d73f36 Mon Sep 17 00:00:00 2001 From: Nesta Bentum Date: Mon, 8 Aug 2022 18:45:50 +0200 Subject: [PATCH 3/3] Fix Index in MatchTable --- report-viewer/src/components/MatchTable.vue | 36 +++++++++++---------- 1 file changed, 19 insertions(+), 17 deletions(-) diff --git a/report-viewer/src/components/MatchTable.vue b/report-viewer/src/components/MatchTable.vue index 9215cf396..24b1682e1 100644 --- a/report-viewer/src/components/MatchTable.vue +++ b/report-viewer/src/components/MatchTable.vue @@ -13,20 +13,24 @@ File 2 Tokens - +

{{ match.firstFile }}

-

({{ match.startInFirst }} - {{ match.endInFirst }})

+

({{ match.startInFirst + 1 }} - {{ match.endInFirst + 1 }})

{{ match.secondFile }}

-

({{ match.startInSecond }} - {{ match.endInSecond }})

+

({{ match.startInSecond + 1 }} - {{ match.endInSecond + 1 }})

{{ match.tokens }} @@ -36,7 +40,7 @@ \ No newline at end of file +