Skip to content

Commit

Permalink
remove code duplication
Browse files Browse the repository at this point in the history
  • Loading branch information
Kr0nox committed Nov 27, 2023
1 parent 2f5efab commit 961f98d
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 35 deletions.
13 changes: 1 addition & 12 deletions report-viewer/src/components/VersionInfoComponent.vue
Original file line number Diff line number Diff line change
Expand Up @@ -29,19 +29,8 @@

<script setup lang="ts">
import { Version } from '@/model/Version'
import versionJson from '@/version.json'
import { ref } from 'vue'
import { OverviewFactory } from '@/model/factories/OverviewFactory'
const reportViewerVersion: Version =
versionJson['report_viewer_version'] !== undefined
? OverviewFactory.extractVersion(versionJson['report_viewer_version'])
: new Version(-1, -1, -1)
const minimalReportVersion: Version =
versionJson['minimal_report_version'] !== undefined
? OverviewFactory.extractVersion(versionJson['minimal_report_version'])
: new Version(-1, -1, -1)
import { minimalReportVersion, reportViewerVersion } from '@/model/Version'
const newestVersion = ref(new Version(-1, -1, -1))
Expand Down
12 changes: 12 additions & 0 deletions report-viewer/src/model/Version.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import versionJson from '@/version.json'

/**
* Version of the report viewer.
*/
Expand Down Expand Up @@ -33,4 +35,14 @@ export class Version {
public isInvalid(): boolean {
return this.major < 0 || this.minor < 0 || this.patch < 0
}

public static fromJsonField(versionField: Record<string, number> | undefined): Version {
if (versionField) {
return new Version(versionField.major, versionField.minor, versionField.patch)
}
return new Version(-1, -1, -1)
}
}

export const reportViewerVersion = Version.fromJsonField(versionJson['report_viewer_version'])
export const minimalReportVersion = Version.fromJsonField(versionJson['minimal_report_version'])
27 changes: 4 additions & 23 deletions report-viewer/src/model/factories/OverviewFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ import { Overview } from '../Overview'
import type { ComparisonListElement } from '../ComparisonListElement'
import type { Cluster } from '@/model/Cluster'
import { store } from '@/stores/store'
import { Version } from '../Version'
import versionJson from '@/version.json'
import { Version, minimalReportVersion, reportViewerVersion } from '../Version'
import { getLanguageParser } from '../Language'
import { Distribution } from '../Distribution'
import { MetricType } from '../MetricType'
Expand All @@ -15,16 +14,6 @@ import { TenValueDistribution } from '../TenValueDistribution'
* Factory class for creating Overview objects
*/
export class OverviewFactory extends BaseFactory {
static reportViewerVersion: Version =
versionJson['report_viewer_version'] !== undefined
? this.extractVersion(versionJson['report_viewer_version'] as Record<string, number>)
: new Version(-1, -1, -1)

static minimalReportVersion: Version =
versionJson['minimal_report_version'] !== undefined
? this.extractVersion(versionJson['minimal_report_version'] as Record<string, number>)
: new Version(-1, -1, -1)

/**
* Gets the overview file based on the used mode (zip, local, single).
*/
Expand All @@ -38,13 +27,9 @@ export class OverviewFactory extends BaseFactory {
*/
private static extractOverview(json: Record<string, unknown>): Overview {
const versionField = json.jplag_version as Record<string, number>
const jplagVersion = this.extractVersion(versionField)
const jplagVersion = Version.fromJsonField(versionField)

OverviewFactory.compareVersions(
jplagVersion,
this.reportViewerVersion,
this.minimalReportVersion
)
OverviewFactory.compareVersions(jplagVersion, reportViewerVersion, minimalReportVersion)

const submissionFolder = json.submission_folder_path as Array<string>
const baseCodeFolder = json.base_code_folder_path as string
Expand Down Expand Up @@ -73,10 +58,6 @@ export class OverviewFactory extends BaseFactory {
)
}

public static extractVersion(versionField: Record<string, number>): Version {
return new Version(versionField.major, versionField.minor, versionField.patch)
}

private static extractDistributions(
json: Record<string, unknown>
): Record<MetricType, Distribution> {
Expand Down Expand Up @@ -244,7 +225,7 @@ export class OverviewFactory extends BaseFactory {
') is older than the minimal support version of the report viewer(' +
reportViewerVersion.toString() +
'). ' +
'Can not read report.'
'Can not read the report.'
)
}
}
Expand Down

0 comments on commit 961f98d

Please sign in to comment.