Skip to content

Commit

Permalink
Frontend for Uploads
Browse files Browse the repository at this point in the history
  • Loading branch information
gbdubs committed Dec 7, 2023
1 parent 73ea028 commit ba13aa3
Show file tree
Hide file tree
Showing 31 changed files with 1,460 additions and 126 deletions.
49 changes: 49 additions & 0 deletions frontend/components/incompleteupload/Editor.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<script setup lang="ts">
import { type EditorIncompleteUpload } from '@/lib/editor'
interface Props {
editorIncompleteUpload: EditorIncompleteUpload
}
interface Emits {
(e: 'update:editorIncompleteUpload', ei: EditorIncompleteUpload): void
}
const props = defineProps<Props>()
const emit = defineEmits<Emits>()
const model = computed({
get: () => props.editorIncompleteUpload,
set: (editorIncompleteUpload: EditorIncompleteUpload) => { emit('update:editorIncompleteUpload', editorIncompleteUpload) },
})
</script>

<template>
<div>
<FormEditorField
help-text="The name of this uploaded source file."
:editor-field="model.name"
>
<PVInputText
v-model="model.name.currentValue"
/>
</FormEditorField>
<FormEditorField
help-text="The description of this upload - helpful for record keeping, not used for anything."
:editor-field="model.description"
>
<PVTextarea
v-model="model.description.currentValue"
auto-resize
/>
</FormEditorField>
<FormEditorField
help-text="When enabled, this upload can be accessed by administrators to help with debugging. Only turn this on if you're comfortable with system administrators accessing this data."
:editor-field="model.adminDebugEnabled"
>
<ExplicitInputSwitch
v-model:value="model.adminDebugEnabled.currentValue"
on-label="Administrator Debugging Access Enabled"
off-label="No Administrator Access Enabled"
/>
</FormEditorField>
</div>
</template>
49 changes: 49 additions & 0 deletions frontend/components/portfolio/Editor.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<script setup lang="ts">
import { type EditorPortfolio } from '@/lib/editor'
interface Props {
editorPortfolio: EditorPortfolio
}
interface Emits {
(e: 'update:editorPortfolio', ei: EditorPortfolio): void
}
const props = defineProps<Props>()
const emit = defineEmits<Emits>()
const model = computed({
get: () => props.editorPortfolio,
set: (editorPortfolio: EditorPortfolio) => { emit('update:editorPortfolio', editorPortfolio) },
})
</script>

<template>
<div>
<FormEditorField
help-text="The name of this portfolio."
:editor-field="model.name"
>
<PVInputText
v-model="model.name.currentValue"
/>
</FormEditorField>
<FormEditorField
help-text="The description of this portfolio - helpful for record keeping, not used for anything."
:editor-field="model.description"
>
<PVTextarea
v-model="model.description.currentValue"
auto-resize
/>
</FormEditorField>
<FormEditorField
help-text="When enabled, this portfolio can be accessed by administrators to help with debugging. Only turn this on if you're comfortable with system administrators accessing this data."
:editor-field="model.adminDebugEnabled"
>
<ExplicitInputSwitch
v-model:value="model.adminDebugEnabled.currentValue"
on-label="Administrator Debugging Access Enabled"
off-label="No Administrator Access Enabled"
/>
</FormEditorField>
</div>
</template>
14 changes: 3 additions & 11 deletions frontend/composables/useTime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,9 @@ export const useTime = () => {
})
}

const humanReadableDateLongFromStandardString = (s: string): ComputedRef<string> => {
return humanReadableDateLong(new Date(Date.parse(s)))
}

const humanReadableDateFromStandardString = (s: string): ComputedRef<string> => {
return humanReadableDate(new Date(Date.parse(s)))
}

const humanReadableTimeFromStandardString = (asStr: string): ComputedRef<string> => {
return humanReadableTime(new Date(Date.parse(asStr)))
}
const humanReadableDateLongFromStandardString = (s: string): ComputedRef<string> => humanReadableDateLong(new Date(Date.parse(s)))
const humanReadableDateFromStandardString = (s: string): ComputedRef<string> => humanReadableDate(new Date(Date.parse(s)))
const humanReadableTimeFromStandardString = (asStr: string): ComputedRef<string> => humanReadableTime(new Date(Date.parse(asStr)))

const humanReadableTimeWithSeconds = (t: Date): ComputedRef<string> => {
return computed(() => {
Expand Down
75 changes: 75 additions & 0 deletions frontend/lib/editor/incomplete_upload.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
import { type IncompleteUpload } from '@/openapi/generated/pacta'
import { Validation, type EditorFieldsFor, type EditorComputedValues } from './common'
import { getEditorComputedValues } from './utils'

export type EditorIncompleteUpload = EditorFieldsFor<IncompleteUpload>

const createEditorIncompleteUpload = (incompleteUpload: IncompleteUpload): EditorIncompleteUpload => {
return {
id: {
name: 'id',
label: 'ID',
originalValue: incompleteUpload.id,
currentValue: incompleteUpload.id,
},
name: {
name: 'name',
label: 'Name',
validation: [Validation.NotEmpty],
originalValue: incompleteUpload.name,
currentValue: incompleteUpload.name,
},
description: {
name: 'description',
label: 'Description',
originalValue: incompleteUpload.description,
currentValue: incompleteUpload.description,
},
adminDebugEnabled: {
name: 'adminDebugEnabled',
label: 'Admin Debugging Enabled',
originalValue: incompleteUpload.adminDebugEnabled,
currentValue: incompleteUpload.adminDebugEnabled,
},
holdingsDate: {
name: 'holdingsDate',
label: 'Holdings Date',
originalValue: incompleteUpload.holdingsDate,
currentValue: incompleteUpload.holdingsDate,
},
createdAt: {
name: 'createdAt',
label: 'Created At',
originalValue: incompleteUpload.createdAt,
currentValue: incompleteUpload.createdAt,
},
ranAt: {
name: 'ranAt',
label: 'Ran At',
originalValue: incompleteUpload.ranAt,
currentValue: incompleteUpload.ranAt,
},
completedAt: {
name: 'completedAt',
label: 'Completed At',
originalValue: incompleteUpload.completedAt,
currentValue: incompleteUpload.completedAt,
},
failureMessage: {
name: 'failureMessage',
label: 'Failure Message',
originalValue: incompleteUpload.failureMessage,
currentValue: incompleteUpload.failureMessage,
},
failureCode: {
name: 'failureCode',
label: 'Failure Code',
originalValue: incompleteUpload.failureCode,
currentValue: incompleteUpload.failureCode,
},
}
}

export const incompleteUploadEditor = (i: IncompleteUpload): EditorComputedValues<IncompleteUpload> => {
return getEditorComputedValues(`lib/editor/incompleteUpload[${i.id}]`, i, createEditorIncompleteUpload)
}
2 changes: 2 additions & 0 deletions frontend/lib/editor/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@ export * from './common'
export * from './initiative'
export * from './pacta_version'
export * from './user'
export * from './incomplete_upload'
export * from './portfolio'
57 changes: 57 additions & 0 deletions frontend/lib/editor/portfolio.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import { type Portfolio } from '@/openapi/generated/pacta'
import { Validation, type EditorFieldsFor, type EditorComputedValues } from './common'
import { getEditorComputedValues } from './utils'

export type EditorPortfolio = EditorFieldsFor<Portfolio>

const createEditorPortfolio = (portfolio: Portfolio): EditorPortfolio => {
return {
id: {
name: 'id',
label: 'ID',
originalValue: portfolio.id,
currentValue: portfolio.id,
},
name: {
name: 'name',
label: 'Name',
validation: [Validation.NotEmpty],
originalValue: portfolio.name,
currentValue: portfolio.name,
},
description: {
name: 'description',
label: 'Description',
originalValue: portfolio.description,
currentValue: portfolio.description,
},
adminDebugEnabled: {
name: 'adminDebugEnabled',
label: 'Admin Debugging Enabled',
originalValue: portfolio.adminDebugEnabled,
currentValue: portfolio.adminDebugEnabled,
},
holdingsDate: {
name: 'holdingsDate',
label: 'Holdings Date',
originalValue: portfolio.holdingsDate,
currentValue: portfolio.holdingsDate,
},
createdAt: {
name: 'createdAt',
label: 'Created At',
originalValue: portfolio.createdAt,
currentValue: portfolio.createdAt,
},
numberOfRows: {
name: 'numberOfRows',
label: 'Number of Rows',
originalValue: portfolio.numberOfRows,
currentValue: portfolio.numberOfRows,
},
}
}

export const portfolioEditor = (i: Portfolio): EditorComputedValues<Portfolio> => {
return getEditorComputedValues(`lib/editor/portfolio[${i.id}]`, i, createEditorPortfolio)
}
9 changes: 9 additions & 0 deletions frontend/lib/filesize/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
export const formatFileSize = (bytes: number): string => {
if (bytes === 0) return 'Empty'
const sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB']

const k = 1024
const i = Math.floor(Math.log(bytes) / Math.log(k))

return parseFloat((bytes / Math.pow(k, i)).toFixed(2)) + ' ' + sizes[i]
}
16 changes: 16 additions & 0 deletions frontend/openapi/generated/pacta/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,13 @@ export { CancelablePromise, CancelError } from './core/CancelablePromise';
export { OpenAPI } from './core/OpenAPI';
export type { OpenAPIConfig } from './core/OpenAPI';

export type { CompletePortfolioUploadReq } from './models/CompletePortfolioUploadReq';
export type { CompletePortfolioUploadReqItem } from './models/CompletePortfolioUploadReqItem';
export type { CompletePortfolioUploadResp } from './models/CompletePortfolioUploadResp';
export type { Error } from './models/Error';
export type { HoldingsDate } from './models/HoldingsDate';
export type { IncompleteUpload } from './models/IncompleteUpload';
export type { IncompleteUploadChanges } from './models/IncompleteUploadChanges';
export { Initiative } from './models/Initiative';
export { InitiativeChanges } from './models/InitiativeChanges';
export { InitiativeCreate } from './models/InitiativeCreate';
Expand All @@ -19,12 +25,22 @@ export type { InitiativeInvitationCreate } from './models/InitiativeInvitationCr
export type { InitiativeUserRelationship } from './models/InitiativeUserRelationship';
export type { InitiativeUserRelationshipChanges } from './models/InitiativeUserRelationshipChanges';
export { Language } from './models/Language';
export type { ListIncompleteUploadsReq } from './models/ListIncompleteUploadsReq';
export type { ListIncompleteUploadsResp } from './models/ListIncompleteUploadsResp';
export type { ListPortfoliosReq } from './models/ListPortfoliosReq';
export type { ListPortfoliosResp } from './models/ListPortfoliosResp';
export type { NewPortfolioAsset } from './models/NewPortfolioAsset';
export type { PactaVersion } from './models/PactaVersion';
export type { PactaVersionChanges } from './models/PactaVersionChanges';
export type { PactaVersionCreate } from './models/PactaVersionCreate';
export type { ParsePortfolioReq } from './models/ParsePortfolioReq';
export type { ParsePortfolioResp } from './models/ParsePortfolioResp';
export type { Portfolio } from './models/Portfolio';
export type { PortfolioChanges } from './models/PortfolioChanges';
export type { StartPortfolioUploadReq } from './models/StartPortfolioUploadReq';
export type { StartPortfolioUploadReqItem } from './models/StartPortfolioUploadReqItem';
export type { StartPortfolioUploadResp } from './models/StartPortfolioUploadResp';
export type { StartPortfolioUploadRespItem } from './models/StartPortfolioUploadRespItem';
export { User } from './models/User';
export { UserChanges } from './models/UserChanges';

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/* generated using openapi-typescript-codegen -- do no edit */
/* istanbul ignore file */
/* tslint:disable */
/* eslint-disable */

import type { CompletePortfolioUploadReqItem } from './CompletePortfolioUploadReqItem';

export type CompletePortfolioUploadReq = {
/**
* The incomplete uploads that have been successfully uploaded to storage and are ready for parsing.
*/
items: Array<CompletePortfolioUploadReqItem>;
};

Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/* generated using openapi-typescript-codegen -- do no edit */
/* istanbul ignore file */
/* tslint:disable */
/* eslint-disable */

export type CompletePortfolioUploadReqItem = {
/**
* The unique identifier for the uploaded asset
*/
incomplete_upload_id: string;
};

Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/* generated using openapi-typescript-codegen -- do no edit */
/* istanbul ignore file */
/* tslint:disable */
/* eslint-disable */

export type CompletePortfolioUploadResp = Record<string, any>;
12 changes: 12 additions & 0 deletions frontend/openapi/generated/pacta/models/HoldingsDate.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/* generated using openapi-typescript-codegen -- do no edit */
/* istanbul ignore file */
/* tslint:disable */
/* eslint-disable */

export type HoldingsDate = {
/**
* The time at which the holdings are represented at
*/
time: string;
};

Loading

0 comments on commit ba13aa3

Please sign in to comment.