From d30e8defdb7729d61ce7e7e0bff02dbeb5c6ba98 Mon Sep 17 00:00:00 2001 From: Alexander Vogt Date: Thu, 18 Jul 2024 09:44:39 +0200 Subject: [PATCH 1/6] calculate longest prefix of file name and display name --- report-viewer/src/model/File.ts | 4 +++ .../src/model/factories/ComparisonFactory.ts | 25 +++++++++++++++++-- 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/report-viewer/src/model/File.ts b/report-viewer/src/model/File.ts index ad56d5ca4..0d2503940 100644 --- a/report-viewer/src/model/File.ts +++ b/report-viewer/src/model/File.ts @@ -28,4 +28,8 @@ export interface SubmissionFile extends File { * Number of tokens in the file that are matched. */ matchedTokenCount: number + /** + * The name to be displayed in the report viewer. If not defined, the file name should be chosen + */ + displayFileName?: string } diff --git a/report-viewer/src/model/factories/ComparisonFactory.ts b/report-viewer/src/model/factories/ComparisonFactory.ts index 04ffbfdee..af5c50353 100644 --- a/report-viewer/src/model/factories/ComparisonFactory.ts +++ b/report-viewer/src/model/factories/ComparisonFactory.ts @@ -5,6 +5,7 @@ import { getMatchColorCount } from '@/utils/ColorUtils' import slash from 'slash' import { BaseFactory } from './BaseFactory' import { MetricType } from '../MetricType' +import type { SubmissionFile } from '../File' /** * Factory class for creating Comparison objects @@ -57,8 +58,8 @@ export class ComparisonFactory extends BaseFactory { firstSubmissionId, secondSubmissionId, this.extractSimilarities(json.similarities as Record), - filesOfFirstSubmission, - filesOfSecondSubmission, + this.getFilesWithDisplayNames(filesOfFirstSubmission), + this.getFilesWithDisplayNames(filesOfSecondSubmission), this.colorMatches(matches), json.first_similarity as number, json.second_similarity as number @@ -152,4 +153,24 @@ export class ComparisonFactory extends BaseFactory { } return sortedSize } + + private static getFilesWithDisplayNames(files: SubmissionFile[]): SubmissionFile[] { + let longestPrefix = files[0].fileName + for (let i = 1; i < files.length; i++) { + if (longestPrefix == '') { + break + } + + while (!files[i].fileName.startsWith(longestPrefix)) { + longestPrefix = longestPrefix.substring(0, longestPrefix.length - 1) + } + } + + return files.map((f) => { + return { + ...f, + displayFileName: f.fileName.substring(longestPrefix.length) + } + }) + } } From 34d28979f929452e4069621f82daa8bb25462670 Mon Sep 17 00:00:00 2001 From: Alexander Vogt Date: Thu, 18 Jul 2024 09:48:20 +0200 Subject: [PATCH 2/6] use display name --- report-viewer/src/components/fileDisplaying/CodePanel.vue | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/report-viewer/src/components/fileDisplaying/CodePanel.vue b/report-viewer/src/components/fileDisplaying/CodePanel.vue index 9ba2ebe7f..d3452fc30 100644 --- a/report-viewer/src/components/fileDisplaying/CodePanel.vue +++ b/report-viewer/src/components/fileDisplaying/CodePanel.vue @@ -145,9 +145,10 @@ defineExpose({ * @return new path of file */ function getFileDisplayName(file: SubmissionFile): string { - const filePathLength = file.fileName.length + const fileDisplayName = file.displayFileName ?? file.fileName + const filePathLength = fileDisplayName.length return filePathLength > 40 - ? '...' + file.fileName.substring(filePathLength - 40, filePathLength) - : file.fileName + ? '...' + fileDisplayName.substring(filePathLength - 40, filePathLength) + : fileDisplayName } From 70df263dd34f4590e7c3a9036c6d91e908189044 Mon Sep 17 00:00:00 2001 From: Alexander Vogt Date: Thu, 18 Jul 2024 09:52:59 +0200 Subject: [PATCH 3/6] fix single file case --- report-viewer/src/model/File.ts | 4 ++-- report-viewer/src/model/factories/ComparisonFactory.ts | 6 +++++- report-viewer/src/model/fileHandling/ZipFileHandler.ts | 3 ++- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/report-viewer/src/model/File.ts b/report-viewer/src/model/File.ts index 0d2503940..cd18dc30c 100644 --- a/report-viewer/src/model/File.ts +++ b/report-viewer/src/model/File.ts @@ -29,7 +29,7 @@ export interface SubmissionFile extends File { */ matchedTokenCount: number /** - * The name to be displayed in the report viewer. If not defined, the file name should be chosen + * The name to be displayed in the report viewer */ - displayFileName?: string + displayFileName: string } diff --git a/report-viewer/src/model/factories/ComparisonFactory.ts b/report-viewer/src/model/factories/ComparisonFactory.ts index af5c50353..beea43ca1 100644 --- a/report-viewer/src/model/factories/ComparisonFactory.ts +++ b/report-viewer/src/model/factories/ComparisonFactory.ts @@ -92,7 +92,8 @@ export class ComparisonFactory extends BaseFactory { submissionId: submissionId, data: await this.getSubmissionFileContent(submissionId, slash(filePath)), tokenCount: fileList[filePath].token_count, - matchedTokenCount: 0 + matchedTokenCount: 0, + displayFileName: slash(filePath) }) } } catch (e) { @@ -155,6 +156,9 @@ export class ComparisonFactory extends BaseFactory { } private static getFilesWithDisplayNames(files: SubmissionFile[]): SubmissionFile[] { + if (files.length == 0) { + return files + } let longestPrefix = files[0].fileName for (let i = 1; i < files.length; i++) { if (longestPrefix == '') { diff --git a/report-viewer/src/model/fileHandling/ZipFileHandler.ts b/report-viewer/src/model/fileHandling/ZipFileHandler.ts index 69990b1f6..cf8ad3989 100644 --- a/report-viewer/src/model/fileHandling/ZipFileHandler.ts +++ b/report-viewer/src/model/fileHandling/ZipFileHandler.ts @@ -29,7 +29,8 @@ export class ZipFileHandler extends FileHandler { data: data, // These two properties will be determined at a later time (when loading the submission file index) tokenCount: NaN, - matchedTokenCount: NaN + matchedTokenCount: NaN, + displayFileName: slash(fullPathFileName) }) }) } else { From 8004b862bb326c17d296745d4f7cd02593642fe6 Mon Sep 17 00:00:00 2001 From: Alexander Vogt Date: Thu, 18 Jul 2024 10:00:42 +0200 Subject: [PATCH 4/6] file name tooltip --- .../src/components/fileDisplaying/CodePanel.vue | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/report-viewer/src/components/fileDisplaying/CodePanel.vue b/report-viewer/src/components/fileDisplaying/CodePanel.vue index d3452fc30..7da41df0c 100644 --- a/report-viewer/src/components/fileDisplaying/CodePanel.vue +++ b/report-viewer/src/components/fileDisplaying/CodePanel.vue @@ -4,7 +4,20 @@