Skip to content

Commit

Permalink
Merge pull request #1867 from jplag/report-viewer/cleanup
Browse files Browse the repository at this point in the history
Clean up report viewer code
  • Loading branch information
tsaglam authored Jul 19, 2024
2 parents b318832 + 6149b61 commit 6827d44
Show file tree
Hide file tree
Showing 34 changed files with 65 additions and 97 deletions.
2 changes: 1 addition & 1 deletion report-viewer/src/App.vue
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<template>
<div :class="{ dark: store().uiState.useDarkMode }">
<div
class="max-w-screen max-h-fit min-h-screen bg-backgorund-light text-black dark:bg-backgorund-dark dark:text-amber-50"
class="max-w-screen max-h-fit min-h-screen bg-background-light text-black dark:bg-background-dark dark:text-amber-50"
>
<RouterView class="max-h-screen overflow-hidden print:max-h-none print:overflow-visible" />

Expand Down
Binary file modified report-viewer/src/assets/jplag-dark-transparent.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified report-viewer/src/assets/jplag-light-transparent.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion report-viewer/src/components/ClusterRadarChart.vue
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ const radarChartOptions = computed(() => {
}
})

const chartData: Ref<ChartData<'radar', (number | null)[], unknown>> = computed(() => {
const chartData: Ref<ChartData<'radar', (number | null)[]>> = computed(() => {
return {
labels: labels.value,
datasets: [
Expand Down
21 changes: 4 additions & 17 deletions report-viewer/src/components/ComparisonsTable.vue
Original file line number Diff line number Diff line change
Expand Up @@ -213,10 +213,9 @@ const searchString = ref('')

/**
* This function gets called when the search bar for the comparison table has been updated.
* It updates the displayed comparisons to only show the ones that have part of any search result in their id. The search is not case sensitive. The parts can be separated by commas or spaces.
* It also updates the anonymous set to unhide a submission if its name was typed in the search bar at any point in time.
* It returns the input list, with the filter given in searchString applied.
*
* @param newVal The new value of the search bar
* @param comparisons Sorted list of comparisons
*/
function getFilteredComparisons(comparisons: ComparisonListElement[]) {
const searches = searchString.value
Expand Down Expand Up @@ -257,7 +256,7 @@ function getFilteredComparisons(comparisons: ComparisonListElement[]) {
[MetricType.MAXIMUM]: []
}
metricSearches.forEach((s) => {
const regexResult = /^(?:(avg|max):)?((?:[<>])=?[0-9]+%?$)/.exec(s)
const regexResult = /^(?:(avg|max):)?([<>]=?[0-9]+%?$)/.exec(s)
if (regexResult) {
const metricName = regexResult[1]
let metric = MetricType.AVERAGE
Expand All @@ -275,7 +274,7 @@ function getFilteredComparisons(comparisons: ComparisonListElement[]) {
})
for (const metric of [MetricType.AVERAGE, MetricType.MAXIMUM]) {
for (const search of searchPerMetric[metric]) {
const regexResult = /((?:[<>])=?)([0-9]+)%?/.exec(search)!
const regexResult = /([<>]=?)([0-9]+)%?/.exec(search)!
const operator = regexResult[1]
const value = parseInt(regexResult[2])
if (evaluateMetricComparison(c.similarities[metric] * 100, operator, value)) {
Expand Down Expand Up @@ -394,16 +393,4 @@ watch(
.tableCell {
@apply mx-3 flex flex-row items-center justify-center text-center;
}

/* Tooltip arrow. Defined down here bacause of the content attribute */
.tooltipArrow::after {
content: ' ';
position: absolute;
top: 50%;
left: 100%;
margin-top: -5px;
border-width: 5px;
border-style: solid;
border-color: transparent transparent transparent rgba(0, 0, 0, 0.9);
}
</style>
4 changes: 2 additions & 2 deletions report-viewer/src/components/ContainerComponent.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<!--
Base Component to seperate content into multiple chunks
<!--
Base Component to separate content into multiple chunks
-->
<template>
<div
Expand Down
2 changes: 1 addition & 1 deletion report-viewer/src/components/ScrollableComponent.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<!--
Offers a unstyled scrollable container
Offers a un-styled scrollable container
-->
<template>
<div class="overflow-y-auto print:overflow-y-visible">
Expand Down
2 changes: 1 addition & 1 deletion report-viewer/src/components/ToolTipComponent.vue
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ const tooltipPosition = computed(() => {
if (!contentDiv || !tooltipDiv) {
return style
}
// zeros the tooltip on the topleft of the content
// zeros the tooltip on the top-left of the content
let top = -contentDiv.offsetHeight - props.scrollOffsetY
let left =
(props.toolTipContainerWillBeCentered ? -contentDiv.offsetWidth / 2 : 0) - props.scrollOffsetX
Expand Down
3 changes: 1 addition & 2 deletions report-viewer/src/components/VersionInfoComponent.vue
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,8 @@
</template>

<script setup lang="ts">
import { Version } from '@/model/Version'
import { ref } from 'vue'
import { minimalReportVersion, reportViewerVersion } from '@/model/Version'
import { minimalReportVersion, reportViewerVersion, Version } from '@/model/Version'
import RepositoryReference from './RepositoryReference.vue'
const newestVersion = ref(new Version(-1, -1, -1))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,11 +90,11 @@ const options = computed(() => {
: 10 ** Math.ceil(Math.log10(maxVal.value + 5)),
type: graphOptions.value.xScale,
ticks: {
// ensures that in log mode tick labels are not overlappein
// ensures that in log mode tick labels are not overlapping
minRotation: graphOptions.value.xScale === 'logarithmic' ? 30 : 0,
autoSkipPadding: 10,
color: graphColors.ticksAndFont.value,
// ensures that in log mode ticks are placed evenly appart
// ensures that in log mode ticks are placed evenly apart
callback: function (value: any) {
if (graphOptions.value.xScale === 'logarithmic' && (value + '').match(/1(0)*[^1-9.]/)) {
return value
Expand Down
4 changes: 2 additions & 2 deletions report-viewer/src/components/fileDisplaying/CodeLine.vue
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<div
v-for="(part, index) in textParts"
:key="index"
class="print-excact h-full last:flex-1"
class="print-exact h-full last:flex-1"
@click="matchSelected(part.match)"
:style="{
background:
Expand All @@ -21,7 +21,7 @@
>
<pre
v-html="part.line"
class="code-font print-excact break-child !bg-transparent print:whitespace-pre-wrap"
class="code-font print-exact break-child !bg-transparent print:whitespace-pre-wrap"
></pre>
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ function scrollTo(file: string, line: number) {
}

/**
* Collapses all of the code panels.
* Collapses all the code panels.
*/
function collapseAll() {
codePanels.value.forEach((panel) => panel.collapse())
Expand Down
8 changes: 4 additions & 4 deletions report-viewer/src/components/fileDisplaying/MatchList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
</ToolTipComponent>

<div
class="print-excact flex w-full flex-row space-x-1 overflow-x-auto print:flex-wrap print:space-y-1 print:overflow-x-hidden"
class="print-exact flex w-full flex-row space-x-1 overflow-x-auto print:flex-wrap print:space-y-1 print:overflow-x-hidden"
ref="scrollableList"
@scroll="updateScrollOffset()"
>
Expand Down Expand Up @@ -77,7 +77,7 @@
}}) <br />
Match is {{ match.tokens }} tokens long. <br />
<span v-if="showTokenRanges(match)">
Token indeces of match: {{ match.startInFirst.tokenListIndex }}-{{
Token indices of match: {{ match.startInFirst.tokenListIndex }}-{{
match.endInFirst.tokenListIndex
}}
and {{ match.startInSecond.tokenListIndex }}-{{ match.endInSecond.tokenListIndex }}.
Expand All @@ -104,7 +104,7 @@
v-for="[index, match] in matches?.entries()"
v-bind:key="index"
:style="{ background: getMatchColor(0.3, match.colorIndex) }"
class="print-excact"
class="print-exact"
>
<td class="px-2">{{ getFileName(match.firstFile) }}</td>
<td class="px-2">{{ match.startInFirst }} - {{ match.endInFirst }}</td>
Expand All @@ -115,7 +115,7 @@
<tr
v-if="hasBaseCode"
:style="{ background: getMatchColor(0.3, 'base') }"
class="print-excact"
class="print-exact"
>
<td class="px-2" colspan="5">Basecode in submissions</td>
</tr>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<template>
<Interactable
class="print-excact mr-2 box-border flex h-6 w-fit items-center justify-center whitespace-nowrap !rounded-2xl px-[12px] text-center hover:!border-[2px] hover:px-[11px] print:border-2"
class="print-exact mr-2 box-border flex h-6 w-fit items-center justify-center whitespace-nowrap !rounded-2xl px-[12px] text-center hover:!border-[2px] hover:px-[11px] print:border-2"
:class="{ '!border-accent-dark !bg-accent !bg-opacity-40': selected }"
@click="$emit('click')"
>
Expand Down
2 changes: 1 addition & 1 deletion report-viewer/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ app.use(VueVirtualScroller)
app.config.errorHandler = (err, vm, info) => {
console.error(err)
console.error(info)
alert('An unhandeled error occured. Please check the console for more details.')
alert('An unhandled error occurred. Please check the console for more details.')
}

app.mount('#app')
8 changes: 4 additions & 4 deletions report-viewer/src/model/Comparison.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ export class Comparison {
private readonly _firstSubmissionId: string
private readonly _secondSubmissionId: string
private readonly _similarities: Record<MetricType, number>
private _filesOfFirstSubmission: SubmissionFile[]
private _filesOfSecondSubmission: SubmissionFile[]
private _allMatches: Array<Match>
private readonly _filesOfFirstSubmission: SubmissionFile[]
private readonly _filesOfSecondSubmission: SubmissionFile[]
private readonly _allMatches: Array<Match>
private readonly _firstSimilarity: number
private readonly _secondSimilarity: number

Expand Down Expand Up @@ -103,7 +103,7 @@ export class Comparison {
private groupMatchesByFileName(index: 1 | 2): Map<string, Array<MatchInSingleFile>> {
const acc = new Map<string, Array<MatchInSingleFile>>()
this._allMatches.forEach((val) => {
const name = index === 1 ? (val.firstFile as string) : (val.secondFile as string)
const name = index === 1 ? val.firstFile : val.secondFile

if (!acc.get(name)) {
acc.set(name, [])
Expand Down
4 changes: 2 additions & 2 deletions report-viewer/src/model/MetricType.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* This enum maps the metric type to the index they have in the generated JSON and respectivly in the store.
* This enum maps the metric type to the index they have in the generated JSON and respectively in the store.
*/
export enum MetricType {
AVERAGE = 'AVG',
Expand All @@ -23,6 +23,6 @@ export const metricToolTips: Record<MetricType, MetricToolTipData> = {
longName: 'Maximum Similarity',
shortName: 'MAX',
tooltip:
'The maximum similarity of the two files.\nUsefull if programms are very dfferent in size.'
'The maximum similarity of the two files.\nUseful if programms are very different in size.'
}
}
6 changes: 3 additions & 3 deletions report-viewer/src/model/Version.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import versionJson from '@/version.json'
* Version of the report viewer.
*/
export class Version {
private major: number
private minor: number
private patch: number
private readonly major: number
private readonly minor: number
private readonly patch: number

constructor(major: number, minor: number, patch: number) {
this.major = major
Expand Down
3 changes: 1 addition & 2 deletions report-viewer/src/model/factories/BaseCodeReportFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,9 @@ export class BaseCodeReportFactory extends BaseFactory {
private static readonly basePath = 'basecode'

public static async getReport(submissionId: string): Promise<BaseCodeMatch[]> {
const a = await this.extractReport(
return this.extractReport(
JSON.parse(await this.getFile(slash(`${this.basePath}/${submissionId}.json`)))
)
return a
}

private static async extractReport(json: Record<string, unknown>[]): Promise<BaseCodeMatch[]> {
Expand Down
2 changes: 1 addition & 1 deletion report-viewer/src/model/factories/BaseFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { ZipFileHandler } from '@/model/fileHandling/ZipFileHandler'
* This class provides some basic functionality for the factories.
*/
export class BaseFactory {
public static zipFileName = 'results.zip'
public static readonly zipFileName = 'results.zip'

/**
* Returns the content of a file through the stored loading type.
Expand Down
2 changes: 1 addition & 1 deletion report-viewer/src/model/factories/ComparisonFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export class ComparisonFactory extends BaseFactory {
}

/**
* Creates a comparison object from a json object created by by JPlag
* Creates a comparison object from a json object created by JPlag
* @param json the json object
*/
private static async extractComparison(json: Record<string, unknown>): Promise<Comparison> {
Expand Down
15 changes: 8 additions & 7 deletions report-viewer/src/model/factories/OverviewFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export class OverviewFactory extends BaseFactory {
}

/**
* Creates an overview object from a json object created by by JPlag
* Creates an overview object from a json object created by JPlag
* @param json the json object
*/
private static extractOverview(json: Record<string, unknown>): Overview {
Expand Down Expand Up @@ -152,6 +152,7 @@ export class OverviewFactory extends BaseFactory {
* Compares the two versions and shows an alert if they are not equal and puts out a warning if they are not
* @param jsonVersion the version of the json file
* @param reportViewerVersion the version of the report viewer
* @param minimalVersion the minimal report version expected
*/
static compareVersions(
jsonVersion: Version,
Expand Down Expand Up @@ -179,13 +180,13 @@ export class OverviewFactory extends BaseFactory {
sessionStorage.setItem('versionAlert', 'true')
}
if (jsonVersion.compareTo(minimalVersion) < 0) {
throw (
throw new Error(
"The result's version(" +
jsonVersion.toString() +
') is older than the minimal support version of the report viewer(' +
minimalVersion.toString() +
'). ' +
'Can not read the report.'
jsonVersion.toString() +
') is older than the minimal support version of the report viewer(' +
minimalVersion.toString() +
'). ' +
'Can not read the report.'
)
}
}
Expand Down
2 changes: 1 addition & 1 deletion report-viewer/src/model/fileHandling/ZipFileHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ export class ZipFileHandler extends FileHandler {
filesOrSubmissionsIndex_originalFileName +
(rootName === 'files' ? 'files'.length : 'submissions'.length)
)
if (originalPathWithoutSubmissions.charAt(0) === '\\') {
if (originalPathWithoutSubmissions.startsWith('\\')) {
fullPath = unixSubfolderPathAfterSubmissions + '\\' + fileBase
while (fullPath.includes('/')) {
fullPath = fullPath.replace('/', '\\')
Expand Down
9 changes: 0 additions & 9 deletions report-viewer/src/stores/state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,3 @@ export interface UIState {
comparisonTableClusterSorting: boolean
distributionChartConfig: DistributionChartConfig
}

/**
* Load configuration is used to indicate which mode is used.
*/
export interface LoadConfiguration {
local: boolean
zip: boolean
single: boolean
}
4 changes: 2 additions & 2 deletions report-viewer/src/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
@apply h-[6px] w-[6px] cursor-pointer;
}
*::-webkit-scrollbar-track {
@apply rounded-full border-2 bg-scrollbar-backgorund-light dark:bg-scrollbar-backgorund-dark;
@apply rounded-full border-2 bg-scrollbar-background-light dark:bg-scrollbar-background-dark;
}
*::-webkit-scrollbar-thumb {
@apply rounded-full border-2 bg-scrollbar-thumb-light dark:bg-scrollbar-thumb-dark;
Expand All @@ -29,7 +29,7 @@
overflow-wrap: anywhere;
}

.print-excact {
.print-exact {
print-color-adjust: exact;
}

Expand Down
7 changes: 3 additions & 4 deletions report-viewer/src/utils/CodeHighlighter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import llvm from 'highlight.js/lib/languages/llvm'
import typescript from 'highlight.js/lib/languages/typescript'

/**
* Hightlights the given code with the given language.
* Splits the resulting html into seperate lines.
* Highlights the given code with the given language.
* Splits the resulting html into separate lines.
* The returned string is an array of html lines, consisting of spans with the hljs classes and the code.
* Source: https://stackoverflow.com/a/70656181
* @param code Code to highlight
Expand All @@ -16,7 +16,7 @@ import typescript from 'highlight.js/lib/languages/typescript'
export function highlight(code: string, lang: Language) {
const highlightedCode = hljs.highlight(code, { language: getHighlightLanguage(lang) }).value
const openTags: string[] = []
const formattedCode = highlightedCode
return highlightedCode
.replace(/(<span [^>]*>)|(<\/span>)|(\n)/g, (match: string) => {
if (match === '\n') {
return '</span>'.repeat(openTags.length) + '\n' + openTags.join('')
Expand All @@ -31,7 +31,6 @@ export function highlight(code: string, lang: Language) {
return match
})
.split('\n')
return formattedCode
}

function getHighlightLanguage(lang: Language) {
Expand Down
4 changes: 2 additions & 2 deletions report-viewer/src/utils/ColorUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ function generateColors(
}

/**
* Genertes an array of HSL-Colors for a given interval
* Generates an array of HSL-Colors for a given interval
* @param intervalStart start of the interval [0,360]
* @param intervalEnd end of the interval [0,360] and > intervalStart
* @param numberOfColorsInInterval Number of colors to generate in the interval
Expand All @@ -59,7 +59,7 @@ function generateColorsForInterval(
return colors
}

/** This is the list of colors that are used as the background colot of matches in the comparison view */
/** This is the list of colors that are used as the background color of matches in the comparison view */
const matchColors: { red: number; green: number; blue: number }[] = [
{ red: 255, green: 122, blue: 0 },
{ red: 0, green: 133, blue: 255 },
Expand Down
Loading

0 comments on commit 6827d44

Please sign in to comment.