Skip to content

Commit

Permalink
feat(FilePage): add the File Page
Browse files Browse the repository at this point in the history
  • Loading branch information
MellyGray committed Dec 13, 2023
1 parent 14a74ae commit c5852c6
Show file tree
Hide file tree
Showing 114 changed files with 1,127 additions and 963 deletions.
6 changes: 6 additions & 0 deletions public/locales/en/file.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"tabs": {
"metadata": "Metadata"
},
"subtext": "This file is part of \"{{datasetTitle}}\"."
}
2 changes: 1 addition & 1 deletion src/dataset/domain/models/Dataset.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Alert, AlertMessageKey } from '../../../alert/domain/models/Alert'
import { FileDownloadSize } from '../../../files/domain/models/File'
import { FileDownloadSize } from '../../../files/domain/models/FilePreview'

export enum DatasetLabelSemanticMeaning {
DATASET = 'dataset',
Expand Down
209 changes: 3 additions & 206 deletions src/files/domain/models/File.ts
Original file line number Diff line number Diff line change
@@ -1,207 +1,4 @@
import FileTypeToFriendlyTypeMap from './FileTypeToFriendlyTypeMap'

export enum FileSizeUnit {
BYTES = 'B',
KILOBYTES = 'KB',
MEGABYTES = 'MB',
GIGABYTES = 'GB',
TERABYTES = 'TB',
PETABYTES = 'PB'
}

export class FileSize {
static readonly multiplier = {
[FileSizeUnit.BYTES]: 1,
[FileSizeUnit.KILOBYTES]: 1024,
[FileSizeUnit.MEGABYTES]: 1024 ** 2,
[FileSizeUnit.GIGABYTES]: 1024 ** 3,
[FileSizeUnit.TERABYTES]: 1024 ** 4,
[FileSizeUnit.PETABYTES]: 1024 ** 5
}

constructor(readonly value: number, readonly unit: FileSizeUnit) {
;[this.value, this.unit] = this.convertToLargestUnit(value, unit)
}

toString(): string {
const formattedValue =
this.value % 1 === 0 ? this.value.toFixed(0) : (Math.round(this.value * 10) / 10).toString()
return `${formattedValue} ${this.unit}`
}

toBytes(): number {
return this.value * FileSize.multiplier[this.unit]
}

private convertToLargestUnit(value: number, unit: FileSizeUnit): [number, FileSizeUnit] {
let convertedValue = value
let convertedUnit = unit

while (convertedValue >= 1024 && convertedUnit !== FileSizeUnit.PETABYTES) {
convertedValue /= 1024
convertedUnit = this.getNextUnit(convertedUnit)
}

return [convertedValue, convertedUnit]
}

private getNextUnit(unit: FileSizeUnit): FileSizeUnit {
switch (unit) {
case FileSizeUnit.BYTES:
return FileSizeUnit.KILOBYTES
case FileSizeUnit.KILOBYTES:
return FileSizeUnit.MEGABYTES
case FileSizeUnit.MEGABYTES:
return FileSizeUnit.GIGABYTES
case FileSizeUnit.GIGABYTES:
return FileSizeUnit.TERABYTES
case FileSizeUnit.TERABYTES:
return FileSizeUnit.PETABYTES
default:
return unit
}
}
}

export enum FileDownloadSizeMode {
ALL = 'All',
ORIGINAL = 'Original',
ARCHIVAL = 'Archival'
}

export class FileDownloadSize extends FileSize {
constructor(
readonly value: number,
readonly unit: FileSizeUnit,
readonly mode: FileDownloadSizeMode
) {
super(value, unit)
}
}

export interface FileAccess {
restricted: boolean
latestVersionRestricted: boolean
canBeRequested: boolean
requested: boolean
}

export enum FilePublishingStatus {
DRAFT = 'draft',
RELEASED = 'released',
DEACCESSIONED = 'deaccessioned'
}

export interface FileVersion {
number: number
publishingStatus: FilePublishingStatus
}

export enum FileDateType {
METADATA_RELEASED = 'metadataReleased',
PUBLISHED = 'published',
DEPOSITED = 'deposited'
}

export enum FileVersionNotNumber {
LATEST = 'latest',
DRAFT = 'draft'
}

export interface FileDate {
type: FileDateType
date: Date
}

export class FileEmbargo {
constructor(readonly dateAvailable: Date) {}

get isActive(): boolean {
return this.dateAvailable > new Date()
}
}

export interface FileTabularData {
variablesCount: number
observationsCount: number
unf?: string
}

export enum FileLabelType {
CATEGORY = 'category',
TAG = 'tag'
}

export interface FileLabel {
type: FileLabelType
value: string
}

export class FileType {
constructor(readonly value: string, readonly original?: string) {}

toDisplayFormat(): string {
return FileTypeToFriendlyTypeMap[this.value] || FileTypeToFriendlyTypeMap.unknown
}
}

export interface FileChecksum {
algorithm: string
value: string
}

export enum FileIngestStatus {
NONE = 'none',
IN_PROGRESS = 'inProgress',
SCHEDULED = 'scheduled',
ERROR = 'error'
}

export interface FileIngest {
status: FileIngestStatus
reportMessage?: string
}

export interface FileDownloadUrls {
original: string
tabular?: string
rData?: string
}

export class File {
constructor(
readonly id: number,
readonly version: FileVersion,
readonly name: string,
readonly access: FileAccess,
readonly type: FileType,
readonly size: FileSize,
readonly date: FileDate,
readonly downloadCount: number,
readonly labels: FileLabel[],
public readonly isDeleted: boolean,
public readonly ingest: FileIngest,
public readonly downloadUrls: FileDownloadUrls,
public thumbnail?: string,
readonly directory?: string,
readonly embargo?: FileEmbargo,
readonly tabularData?: FileTabularData,
readonly description?: string,
readonly checksum?: FileChecksum
) {}

getLink(): string {
return `/file?id=${this.id}&version=${this.version.number}`
}

get isActivelyEmbargoed(): boolean {
if (this.embargo) {
return this.embargo.isActive
}
return false
}

get isTabularData(): boolean {
return this.tabularData !== undefined
}
export interface File {
name: string
datasetTitle: string
}
2 changes: 1 addition & 1 deletion src/files/domain/models/FileCriteria.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { FileType } from './File'
import { FileType } from './FilePreview'

export class FileCriteria {
constructor(
Expand Down
Loading

0 comments on commit c5852c6

Please sign in to comment.