Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/same submission #829

Merged
merged 10 commits into from
Dec 19, 2022
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,9 @@ private Match convertMatchToReportMatch(JPlagComparison comparison, de.jplag.Mat

private String relativizedFilePath(File file, Submission submission) {
if (file.toPath().equals(submission.getRoot().toPath())) {
return Path.of(submission.getName(), submission.getName()).toString();
return Path.of(submissionToIdFunction.apply(submission), submission.getName()).toString();
}
return Path.of(submission.getName(), submission.getRoot().toPath().relativize(file.toPath()).toString()).toString();
return Path.of(submissionToIdFunction.apply(submission), submission.getRoot().toPath().relativize(file.toPath()).toString()).toString();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,7 @@ public static File createDirectory(String path, String name, File file, File sub
File directory;
String fileName = file.getPath();
String submissionRootPath = submissionRoot.getPath();
int lastDirectoryIndex = findRootDirIndex(name, submissionRootPath);
fileName = fileName.substring(lastDirectoryIndex).replaceFirst(name, "");
fileName = fileName.substring(submissionRootPath.length());
String outputRootDirectory = Path.of(path, name).toString();
if ("".equals(fileName)) {
directory = new File(Path.of(outputRootDirectory, name).toString());
Expand Down Expand Up @@ -119,15 +118,4 @@ public FileVisitResult visitFileFailed(Path file, IOException exc) throws IOExce
logger.info("Display the results with the report viewer at https://jplag.github.io/JPlag/");
return true;
}

/**
* finds the start index of root directory according to this name
* @param name The name of the root directory. According to this name we can find the index of this directory.
* @param submissionRootPath The path of the root directory
* @return The start index of the root directory
*/
public static int findRootDirIndex(String name, String submissionRootPath) {
int submissionRootPathLength = submissionRootPath.length();
return submissionRootPathLength - name.length();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public class ReportObjectFactory {

private static final ToDiskWriter fileWriter = new ToDiskWriter();
public static final String OVERVIEW_FILE_NAME = "overview.json";
public static final String SUBMISSIONS_FOLDER = "submissions";
public static final String SUBMISSIONS_FOLDER = "files";
public static final Version REPORT_VIEWER_VERSION = JPlag.JPLAG_VERSION;

private Map<String, String> submissionNameToIdMap;
Expand Down
38 changes: 36 additions & 2 deletions report-viewer/src/components/FilesContainer.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
-->
<template>
<div class="files-container">
<h1>Files of {{ filesOwner }}</h1>
<h1>Files of {{ anonymous ? filesOwnerDefault : filesOwner }}</h1>
<VueDraggableNext>
<CodePanel
v-for="(file, index) in files.keys()"
Expand All @@ -13,7 +13,9 @@
:lines="!files.get(file)?.lines ? [] : files.get(file)?.lines"
:matches="!matches.get(file) ? [] : matches.get(file)"
:panel-id="containerId"
:title="file.length>40?'..'+file.substring(file.length-40,file.length):file"
:title="convertSubmissionIdToName(file, submissionId).length > 40?
'..' + convertSubmissionIdToName(file, submissionId).substring(file.length - 40, file.length):
convertSubmissionIdToName(file, submissionId)"
@toggle-collapse="$emit('toggle-collapse', file)"
@line-selected="lineSelected"
/>
Expand All @@ -27,6 +29,7 @@ import CodePanel from "../components/CodePanel.vue";
import { VueDraggableNext } from "vue-draggable-next";
import { SubmissionFile } from "@/model/SubmissionFile";
import { MatchInSingleFile } from "@/model/MatchInSingleFile";
import store from "@/store/store";

export default defineComponent({
name: "FilesContainer",
Expand All @@ -46,6 +49,13 @@ export default defineComponent({
type: String,
required: true,
},
/**
* Default value of the submission to which the files belong.
*/
filesOwnerDefault:{
type: String,
required: true,
},
/**
* Files of the submission.
* type: Array<SubmissionFile>
Expand All @@ -61,6 +71,20 @@ export default defineComponent({
type: Map<string,MatchInSingleFile[]>,
required: true,
},
/**
* Default value of the submission to which the files belong.
*/
submissionId:{
type: String,
required: true,
},
/**
* The bool value of that whether id is hidden.
*/
anonymous:{
type:Boolean,
required: true,
},
},

setup(props, { emit }) {
Expand All @@ -74,8 +98,18 @@ export default defineComponent({
const lineSelected = (e: unknown, index: number, file: string, line: number) => {
emit("lineSelected", e, index, file, line);
};
/**
* converts the submissionId to the name in the path of file.
* @param match
* @param submissionId
* @return new path of file
*/
const convertSubmissionIdToName=(file: string, submissionId: string):string => {
return file.replace(submissionId, store.getters.submissionDisplayName(submissionId));
};
return {
lineSelected,
convertSubmissionIdToName,
};
},
});
Expand Down
20 changes: 15 additions & 5 deletions report-viewer/src/components/MatchTable.vue
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@
>
<td>
<div class="td-content">
<p>{{ match.firstFile }}</p>
<p>{{ convertSubmissionIdToName(match.firstFile, id1) }}</p>
<p>({{ match.startInFirst }} - {{ match.endInFirst }})</p>
</div>
</td>
<td>
<div class="td-content">
<p>{{ match.secondFile }}</p>
<p>{{ convertSubmissionIdToName(match.secondFile, id2) }}</p>
<p>({{ match.startInSecond }} - {{ match.endInSecond }})</p>
</div>
</td>
Expand All @@ -39,8 +39,9 @@
</div>
</template>

<script>
<script lang="ts">
import { defineComponent } from "vue";
import store from "@/store/store";

export default defineComponent({
name: "MatchTable",
Expand All @@ -65,8 +66,17 @@ export default defineComponent({
type: String,
},
},
setup() {
return {};
setup(props) {
/**
* converts the submissionId to the name in the path of match.
* @param match
* @param submissionId
* @return new path of match
*/
const convertSubmissionIdToName=(match: string, submissionId: string):string=>{
return match.replace(submissionId, store.getters.submissionDisplayName(submissionId));
};
return {convertSubmissionIdToName};
},
});
</script>
Expand Down
12 changes: 9 additions & 3 deletions report-viewer/src/views/ComparisonView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -41,17 +41,23 @@
</div>
<FilesContainer
:container-id="1"
:submission-id="firstId"
:files="filesOfFirst"
:matches="comparison.matchesInFirstSubmission"
files-owner="Submission 1"
:files-owner="store.getters.submissionDisplayName(firstId)"
:anonymous="store.state.anonymous.has(firstId)"
files-owner-default="submission 1"
@toggle-collapse="toggleCollapseFirst"
@line-selected="showMatchInSecond"
/>
<FilesContainer
:container-id="2"
:submission-id="secondId"
:files="filesOfSecond"
:matches="comparison.matchesInSecondSubmissions"
files-owner="Submission 2"
:files-owner="store.getters.submissionDisplayName(secondId)"
:anonymous="store.state.anonymous.has(secondId)"
files-owner-default="submission 2"
@toggle-collapse="toggleCollapseSecond"
@line-selected="showMatchInFirst"
/>
Expand Down Expand Up @@ -191,7 +197,7 @@ export default defineComponent({

const isAnonymous = (id: string) => store.state.anonymous.has(id);
//Left panel
const hideLeftPanel = ref(true);
const hideLeftPanel = ref(false);
const togglePanel = () => {
hideLeftPanel.value = !hideLeftPanel.value;
};
Expand Down
42 changes: 29 additions & 13 deletions report-viewer/src/views/FileUploadView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
<img alt="JPlag" src="@/assets/logo-nobg.png" />
<h1>JPlag Report Viewer</h1>
<h2>Select an overview or comparison file or a zip to display.</h2>
<h3>(No files get uploaded anywhere)</h3>
<div class="drop-container">
<p>Drop a .json or .zip on this page</p>
</div>
Expand Down Expand Up @@ -54,23 +55,38 @@ export default defineComponent({
},
});
};

const extractRootName = (filePath: path.ParsedPath) => {
const folders = filePath.dir.split("/");
return folders[0];
};
const extractSubmissionFileName = (filePath: path.ParsedPath) => {
const folders = filePath.dir.split("/");
const submissionFolderIndex = folders.findIndex(
(folder) => folder === "submissions"
);
const rootName = folders[0];
let submissionFolderIndex = -1;
if(rootName === "files") {
submissionFolderIndex = folders.findIndex(
(folder) => folder === "files"
);
}else {
submissionFolderIndex = folders.findIndex(
(folder) => folder === "submissions"
);
}
return folders[submissionFolderIndex + 1];
};
const extractFileNameWithFullPath = (filePath: path.ParsedPath, originalFileName: string) => {
let fullPath="";
const unixPathWithoutSubmissions = filePath.dir.split("submissions");
const originalPathWithoutSubmissions = originalFileName.split("submissions");
const unixSubfolderPathAfterSubmissions = unixPathWithoutSubmissions[1].substring(1);
if(originalPathWithoutSubmissions[1].charAt(0)==='\\'){
fullPath=(unixSubfolderPathAfterSubmissions + path.sep + filePath.base).replaceAll('/','\\');
}else {
fullPath=(unixSubfolderPathAfterSubmissions + path.sep + filePath.base);
}
let fullPath = "";
const rootName = extractRootName(filePath);
const filesOrSubmissionsIndex_filePath = filePath.dir.indexOf(rootName ==="files" ? "files" : "submissions");
const filesOrSubmissionsIndex_originalFileName = originalFileName.indexOf(rootName === "files" ? "files" : "submissions");
const unixSubfolderPathAfterSubmissions = filePath.dir.substring(filesOrSubmissionsIndex_filePath + (rootName === "files" ? "files".length : "submissions".length) + 1);
const originalPathWithoutSubmissions = originalFileName.substring(filesOrSubmissionsIndex_originalFileName + (rootName === "files" ? "files".length : "submissions".length));
if(originalPathWithoutSubmissions.charAt(0)==='\\'){
fullPath = (unixSubfolderPathAfterSubmissions + path.sep + filePath.base).replaceAll('/','\\');
}else {
fullPath = (unixSubfolderPathAfterSubmissions + path.sep + filePath.base);
}
return fullPath;
};
/**
Expand All @@ -82,7 +98,7 @@ export default defineComponent({
for (const originalFileName of Object.keys(zip.files)) {
const unixFileName = slash(originalFileName);
if (
/((.+\/)*)submissions\/(.+)\/(.+)/.test(unixFileName) &&
/((.+\/)*)(files|submissions)\/(.+)\/(.+)/.test(unixFileName) &&
!/^__MACOSX\//.test(unixFileName)
) {
const filePath = path.parse(unixFileName);
Expand Down