@@ -105,7 +108,7 @@
{{ (item.similarities[MetricType.MAXIMUM] * 100).toFixed(2) }}%
-
+
@@ -170,7 +173,6 @@ import { generateColors } from '@/utils/ColorUtils'
import ToolTipComponent from './ToolTipComponent.vue'
import { MetricType, metricToolTips } from '@/model/MetricType'
import NameElement from './NameElement.vue'
-import { router } from '@/router'
import ComparisonTableFilter from './ComparisonTableFilter.vue'
library.add(faUserGroup)
diff --git a/report-viewer/src/components/NameElement.vue b/report-viewer/src/components/NameElement.vue
index a3445bf49..52a89dcfc 100644
--- a/report-viewer/src/components/NameElement.vue
+++ b/report-viewer/src/components/NameElement.vue
@@ -33,6 +33,7 @@ const props = defineProps({
function changeAnonymous(event: Event) {
event.stopPropagation()
+ event.preventDefault()
if (store().isAnonymous(props.id)) {
store().removeAnonymous([props.id])
} else {
diff --git a/report-viewer/src/model/factories/BaseFactory.ts b/report-viewer/src/model/factories/BaseFactory.ts
index 7950745af..4a01d60c9 100644
--- a/report-viewer/src/model/factories/BaseFactory.ts
+++ b/report-viewer/src/model/factories/BaseFactory.ts
@@ -5,6 +5,8 @@ import { ZipFileHandler } from '@/model/fileHandling/ZipFileHandler'
* This class provides some basic functionality for the factories.
*/
export class BaseFactory {
+ public static zipFileName = 'results.zip'
+
/**
* Returns the content of a file through the stored loading type.
* @param path - Path to the file
@@ -17,16 +19,15 @@ export class BaseFactory {
return this.getFileFromStore(path)
}
if (store().state.localModeUsed) {
- if (store().state.zipModeUsed) {
- await new ZipFileHandler().handleFile(await this.getLocalFile('results.zip'))
- return this.getFileFromStore(path)
- } else {
- return await (await this.getLocalFile(`/files/${path}`)).text()
- }
+ return await (await this.getLocalFile(`/files/${path}`)).text()
} else if (store().state.zipModeUsed) {
return this.getFileFromStore(path)
} else if (store().state.singleModeUsed) {
return store().state.singleFillRawContent
+ } else if (await this.useLocalZipMode()) {
+ await new ZipFileHandler().handleFile(await this.getLocalFile(this.zipFileName))
+ store().setLoadingType('zip')
+ return this.getFileFromStore(path)
}
throw new Error('No loading type specified')
}
@@ -49,12 +50,26 @@ export class BaseFactory {
* @return Content of the file
* @throws Error if the file could not be found
*/
- protected static async getLocalFile(path: string): Promise
{
+ public static async getLocalFile(path: string): Promise {
const request = await fetch(`${window.location.origin}${import.meta.env.BASE_URL}${path}`)
if (request.status == 200) {
- return request.blob()
+ const blob = await request.blob()
+ // Check that file is not the index.html
+ if (blob.type == 'text/html') {
+ throw new Error(`Could not find ${path} in local files.`)
+ }
+ return blob
} else {
throw new Error(`Could not find ${path} in local files.`)
}
}
+
+ public static async useLocalZipMode() {
+ try {
+ await this.getLocalFile(this.zipFileName)
+ return true
+ } catch (e) {
+ return false
+ }
+ }
}
diff --git a/report-viewer/src/model/factories/ComparisonFactory.ts b/report-viewer/src/model/factories/ComparisonFactory.ts
index 1ba0eb20c..d6257e93e 100644
--- a/report-viewer/src/model/factories/ComparisonFactory.ts
+++ b/report-viewer/src/model/factories/ComparisonFactory.ts
@@ -10,13 +10,8 @@ import { MetricType } from '../MetricType'
* Factory class for creating Comparison objects
*/
export class ComparisonFactory extends BaseFactory {
- public static async getComparison(id1: string, id2: string): Promise {
- const filePath = store().getComparisonFileName(id1, id2)
- if (!filePath) {
- throw new Error('Comparison file not specified')
- }
-
- return await this.extractComparison(JSON.parse(await this.getFile(filePath)))
+ public static async getComparison(fileName: string): Promise {
+ return await this.extractComparison(JSON.parse(await this.getFile(fileName)))
}
/**
diff --git a/report-viewer/src/router/index.ts b/report-viewer/src/router/index.ts
index 48afa3ffe..16bcd5868 100644
--- a/report-viewer/src/router/index.ts
+++ b/report-viewer/src/router/index.ts
@@ -23,7 +23,7 @@ const router = createRouter({
component: OverviewViewWrapper
},
{
- path: '/comparison/:firstId/:secondId',
+ path: '/comparison/:comparisonFileName',
name: 'ComparisonView',
component: ComparisonViewWrapper,
props: true
diff --git a/report-viewer/src/stores/store.ts b/report-viewer/src/stores/store.ts
index a15e3082c..9829d33d4 100644
--- a/report-viewer/src/stores/store.ts
+++ b/report-viewer/src/stores/store.ts
@@ -1,5 +1,5 @@
import { defineStore } from 'pinia'
-import type { LoadConfiguration, State, UIState } from './state'
+import type { State, UIState } from './state'
import { MetricType } from '@/model/MetricType'
import type { SubmissionFile, File } from '@/model/File'
@@ -198,10 +198,10 @@ const store = defineStore('store', {
* Sets the loading type
* @param payload Type used to input JPlag results
*/
- setLoadingType(payload: LoadConfiguration) {
- this.state.localModeUsed = payload.local
- this.state.zipModeUsed = payload.zip
- this.state.singleModeUsed = payload.single
+ setLoadingType(loadingType: 'zip' | 'local' | 'single') {
+ this.state.localModeUsed = loadingType == 'local'
+ this.state.zipModeUsed = loadingType == 'zip'
+ this.state.singleModeUsed = loadingType == 'single'
},
/**
* Sets the raw content of the single file mode
diff --git a/report-viewer/src/viewWrapper/ComparisonViewWrapper.vue b/report-viewer/src/viewWrapper/ComparisonViewWrapper.vue
index bd169c14c..59be445e1 100644
--- a/report-viewer/src/viewWrapper/ComparisonViewWrapper.vue
+++ b/report-viewer/src/viewWrapper/ComparisonViewWrapper.vue
@@ -1,11 +1,5 @@
-
+
= ref(null)
// This eslint rule is disabled to allow the use of await in the setup function. Disabling this rule is safe, because the props are gathered from the url, so changing them would reload the pafe anyway.
// eslint-disable-next-line vue/no-setup-props-reactivity-loss
-ComparisonFactory.getComparison(props.firstId, props.secondId)
+ComparisonFactory.getComparison(props.comparisonFileName)
.then((comp) => {
comparison.value = comp
})
diff --git a/report-viewer/src/views/ComparisonView.vue b/report-viewer/src/views/ComparisonView.vue
index 99400b640..d84a8b266 100644
--- a/report-viewer/src/views/ComparisonView.vue
+++ b/report-viewer/src/views/ComparisonView.vue
@@ -124,14 +124,6 @@ import ToolTipComponent from '@/components/ToolTipComponent.vue'
library.add(faPrint)
const props = defineProps({
- firstId: {
- type: String,
- required: true
- },
- secondId: {
- type: String,
- required: true
- },
comparison: {
type: Object as PropType
,
required: true
@@ -142,6 +134,8 @@ const props = defineProps({
}
})
+const firstId = computed(() => props.comparison.firstSubmissionId)
+const secondId = computed(() => props.comparison.secondSubmissionId)
const filesOfFirst = computed(() => props.comparison.filesOfFirstSubmission)
const filesOfSecond = computed(() => props.comparison.filesOfSecondSubmission)
diff --git a/report-viewer/src/views/FileUploadView.vue b/report-viewer/src/views/FileUploadView.vue
index e63db2d61..c00d26df8 100644
--- a/report-viewer/src/views/FileUploadView.vue
+++ b/report-viewer/src/views/FileUploadView.vue
@@ -32,7 +32,7 @@
Or click here to select a file
(No files will be uploaded)
-
@@ -59,28 +59,29 @@ import VersionInfoComponent from '@/components/VersionInfoComponent.vue'
import LoadingCircle from '@/components/LoadingCircle.vue'
import { ZipFileHandler } from '@/model/fileHandling/ZipFileHandler'
import { JsonFileHandler } from '@/model/fileHandling/JsonFileHandler'
+import { BaseFactory } from '@/model/factories/BaseFactory'
store().clearStore()
const exampleFiles = ref(import.meta.env.MODE == 'demo')
-const localFiles: Ref<'json' | 'zip' | 'none'> = ref('none')
+const localFiles = ref(false)
// Checks whether local files exist
-fetch('/files/overview.json')
- .then((response) => {
- if (response.status == 200) {
- localFiles.value = 'json'
- }
- })
- .catch(() => {})
-fetch('/results.zip')
- .then((response) => {
- if (response.status == 200) {
- localFiles.value = 'zip'
- }
+BaseFactory.getLocalFile('files/overview.json')
+ .then(() => {
+ localFiles.value = true
})
.catch(() => {})
+BaseFactory.useLocalZipMode().then((value) => {
+ console.log('Using local zip mode:', value)
+ if (value) {
+ store().state.uploadedFileName = BaseFactory.zipFileName
+ navigateToOverview()
+ }
+})
+
document.title = 'JPlag Report Viewer'
+
const loadingFiles = ref(false)
type fileMethod = 'query' | 'local' | 'upload' | 'unknown'
const errors: Ref<{ error: Error; source: fileMethod }[]> = ref([])
@@ -118,11 +119,7 @@ async function handleJsonFile(file: Blob) {
registerError(e as Error, 'upload')
return
}
- store().setLoadingType({
- local: false,
- zip: false,
- single: true
- })
+ store().setLoadingType('single')
navigateToOverview()
}
@@ -137,11 +134,7 @@ async function handleFile(file: Blob) {
case 'application/zip-compressed':
case 'application/x-zip-compressed':
case 'application/x-zip':
- store().setLoadingType({
- local: false,
- zip: true,
- single: false
- })
+ store().setLoadingType('zip')
await new ZipFileHandler().handleFile(file)
return navigateToOverview()
case 'application/json':
@@ -208,12 +201,8 @@ async function loadQueryFile(url: URL) {
* Handles click on Continue with local files.
*/
function continueWithLocal() {
- store().state.uploadedFileName = exampleFiles.value ? 'progpedia.zip' : 'results.zip'
- store().setLoadingType({
- local: true,
- zip: localFiles.value === 'zip',
- single: false
- })
+ store().state.uploadedFileName = exampleFiles.value ? 'progpedia.zip' : BaseFactory.zipFileName
+ store().setLoadingType('local')
navigateToOverview()
}
diff --git a/report-viewer/tests/unit/model/factories/ComparisonFactory.test.ts b/report-viewer/tests/unit/model/factories/ComparisonFactory.test.ts
index eeef89c6f..8b6017849 100644
--- a/report-viewer/tests/unit/model/factories/ComparisonFactory.test.ts
+++ b/report-viewer/tests/unit/model/factories/ComparisonFactory.test.ts
@@ -48,7 +48,9 @@ describe('Test JSON to Comparison', () => {
it('Post 5.0', async () => {
store.state.files['root1-root2.json'] = JSON.stringify(validNew)
- const result = await ComparisonFactory.getComparison('root1', 'root2')
+ const result = await ComparisonFactory.getComparison(
+ store.getComparisonFileName('root1', 'root2')
+ )
expect(result).toBeDefined()
expect(result.firstSubmissionId).toBe('root1')
@@ -65,7 +67,9 @@ describe('Test JSON to Comparison', () => {
it('Pre 5.0', async () => {
store.state.files['root1-root2.json'] = JSON.stringify(validOld)
- const result = await ComparisonFactory.getComparison('root1', 'root2')
+ const result = await ComparisonFactory.getComparison(
+ store.getComparisonFileName('root1', 'root2')
+ )
expect(result).toBeDefined()
expect(result.firstSubmissionId).toBe('root1')