Skip to content

Commit

Permalink
Merge pull request #829 from cyfml/fix/same-submission-and-root-name
Browse files Browse the repository at this point in the history
Fix/same submission
  • Loading branch information
sebinside authored Dec 19, 2022
2 parents 13ff1ce + fa24e16 commit 8aec8c0
Show file tree
Hide file tree
Showing 7 changed files with 96 additions and 42 deletions.
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 @@ -32,15 +32,14 @@ public class DirectoryManager {
*/
public static File createDirectory(String path, String name, File file, File submissionRoot) throws IOException {
File directory;
String fileName = file.getPath();
String fileFullPath = file.getPath();
String submissionRootPath = submissionRoot.getPath();
int lastDirectoryIndex = findRootDirIndex(name, submissionRootPath);
fileName = fileName.substring(lastDirectoryIndex).replaceFirst(name, "");
String filePathWithoutRootName = fileFullPath.substring(submissionRootPath.length());
String outputRootDirectory = Path.of(path, name).toString();
if ("".equals(fileName)) {
if ("".equals(filePathWithoutRootName)) {
directory = new File(Path.of(outputRootDirectory, name).toString());
} else {
directory = new File(outputRootDirectory + fileName);
directory = new File(outputRootDirectory + filePathWithoutRootName);
}
if (!directory.exists() && !directory.mkdirs()) {
throw new IOException("Failed to create dir.");
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,7 @@
: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)"
@toggle-collapse="$emit('toggle-collapse', file)"
@line-selected="lineSelected"
/>
Expand All @@ -27,6 +27,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 +47,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 +69,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 +96,20 @@ 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. If the length of path exceeds 40, then the file path displays the abbreviation.
* @param match
* @param submissionId
* @return new path of file
*/
const convertSubmissionIdToName=(file: string, submissionId: string):string => {
const filePath = file.replace(submissionId, store.getters.submissionDisplayName(submissionId));
const filePathLength = filePath.length;
return filePathLength > 40 ? ".." + filePath.substring(filePathLength - 40, filePathLength) : filePath;
};
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

0 comments on commit 8aec8c0

Please sign in to comment.