Skip to content

Commit

Permalink
Merge pull request #903 from Deltares/902-get-file-name-from-topology
Browse files Browse the repository at this point in the history
Get fileName from topology
  • Loading branch information
ceesvoesenek authored Jun 18, 2024
2 parents ee8eef7 + 2bc90fb commit fe7d824
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 8 deletions.
4 changes: 3 additions & 1 deletion src/components/workflows/WorkflowsControl.vue
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,8 @@ async function startWorkflow() {
? WorkflowType.ProcessData
: WorkflowType.RunTask
const fileName = data.value['FILE_NAME']
const filter =
workflowType === WorkflowType.ProcessData
? getProcessDataFilter()
Expand All @@ -403,7 +405,7 @@ async function startWorkflow() {
}
closeDialog()
await workflowsStore.startWorkflow(workflowType, filter)
await workflowsStore.startWorkflow(workflowType, filter, { fileName })
if (workflowType === WorkflowType.ProcessData) {
showSuccessMessage('File download completed')
Expand Down
8 changes: 4 additions & 4 deletions src/lib/download/downloadFiles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ export async function downloadFileAttachment(

export async function downloadFileWithXhr(
url: string,
extension?: string,
fileNameSuffix?: string,
): Promise<void> {
return new Promise((resolve, reject) => {
const req = new XMLHttpRequest()
Expand All @@ -97,14 +97,14 @@ export async function downloadFileWithXhr(
const now = toISOString(new Date())
.replaceAll('-', '')
.replaceAll(':', '')
const fallBackFileName = `${now}_DATA${extension ?? ''}`
const fallBackFileName = `${now}${fileNameSuffix ?? '_DATA'}`

const fileName = headerFileName ?? fallBackFileName
const downloadFileName = headerFileName ?? fallBackFileName
const blobUrl = window.URL.createObjectURL(req.response)

const a = document.createElement('a')
a.href = blobUrl
a.setAttribute('download', fileName)
a.setAttribute('download', downloadFileName)

document.body.appendChild(a)
a.click()
Expand Down
11 changes: 8 additions & 3 deletions src/stores/workflows.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ type OmitForWorkflow<T> = Omit<T, 'workflowId' | 'startTime' | 'endTime'>
export type PartialRunTaskFilter = OmitForWorkflow<RunTaskFilter>
export type PartialProcessDataFilter = OmitForWorkflow<ProcessDataFilter>

export interface StartWorkflowOptions {
body?: string
fileName?: string
}

const useWorkflowsStore = defineStore('workflows', {
state: (): WorkflowsState => ({
workflowId: null,
Expand All @@ -47,7 +52,7 @@ const useWorkflowsStore = defineStore('workflows', {
async startWorkflow(
type: WorkflowType,
filter: PartialRunTaskFilter | PartialProcessDataFilter,
body?: string,
options?: StartWorkflowOptions,
) {
if (this.workflowId === null) {
throw Error('Workflow ID has not been set.')
Expand All @@ -70,13 +75,13 @@ const useWorkflowsStore = defineStore('workflows', {
if (type === WorkflowType.RunTask) {
await webServiceProvider.postRunTask(
completeFilter as RunTaskFilter,
body ?? '',
options?.body ?? '',
)
} else if (type === WorkflowType.ProcessData) {
const url = webServiceProvider.processDataUrl(
completeFilter as ProcessDataFilter,
)
await downloadFileWithXhr(url.toString(), '.grb')
await downloadFileWithXhr(url.toString(), options?.fileName)
}
} finally {
this.numActiveWorkflows--
Expand Down

0 comments on commit fe7d824

Please sign in to comment.