Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions src/components/simulation/SimulationPanel.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -331,12 +331,34 @@
function onCancelSimulation(event: CustomEvent) {
effects.cancelSimulation(event.detail.id, user);
}

let simulationUploadInput: HTMLInputElement;

async function onUploadSimulationResults(event: Event) {
const target = event.target as HTMLInputElement;
if (target.files && target.files.length > 0 && $plan) {
await effects.uploadSimulationDataset($plan, target.files[0], user);
target.value = '';
}
}
</script>

<Panel padBody={false}>
<svelte:fragment slot="header">
<GridMenu {gridSection} title="Simulation" />
<PanelHeaderActions>
<input
bind:this={simulationUploadInput}
class="hidden"
type="file"
accept=".json"
on:change={onUploadSimulationResults}
/>
<PanelHeaderActionButton
title="Upload Simulation Results"
showLabel
on:click={() => simulationUploadInput.click()}
/>
{#if enableReSimulation}
<PanelHeaderActionButton
disabled={!enableReSimulation || $startTimeField.invalid || $endTimeField.invalid}
Expand Down Expand Up @@ -515,6 +537,10 @@
</Panel>

<style>
.hidden {
display: none;
}

.simulation-history {
display: flex;
flex-direction: column;
Expand Down
22 changes: 22 additions & 0 deletions src/utilities/effects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8777,6 +8777,28 @@ const effects = {
}
},

async uploadSimulationDataset(plan: Plan, file: File, user: User | null): Promise<number | null> {
try {
const body = new FormData();
body.append('plan_id', `${plan.id}`);
body.append('simulation_results_file', file, file.name);

const simulationDatasetId = await reqGateway<number | null>('/uploadSimulationDataset', 'POST', body, user, true);

if (simulationDatasetId != null) {
showSuccessToast('Simulation Dataset Uploaded Successfully');
logMessage(`Uploaded simulation dataset ID=${simulationDatasetId}.`);
return simulationDatasetId;
}

throw Error('Uploaded simulation dataset not found');
} catch (e) {
catchError('Unable to upload simulation dataset', e as Error);
showFailureToast('Simulation Dataset Upload Failed');
return null;
}
},

async uploadExternalDataset(
plan: Plan,
files: FileList,
Expand Down