Skip to content

Commit

Permalink
Add choice between Azure/local/Pyodide
Browse files Browse the repository at this point in the history
cf. #69
  • Loading branch information
yongrenjie committed Nov 27, 2023
1 parent 4e29a95 commit 19df996
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 7 deletions.
15 changes: 8 additions & 7 deletions web/src/lib/leftSidebar/Create.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@
let step: "choose" | "modify" | "metadata" | "calc" | "error" = "choose";
// Only displayed if there is actually an error
let errorMessage: string = "An error occurred.";
// Whether to run with WASM or HTTP API
let runner: "wasm" | "api" = "wasm";
// Whether to run with Azure REST API, WASM, or local REST API
let runner: "azure" | "wasm" | "local";
// Controller to abort the fetch request if the user cancels. This is in
// the global scope so that it can be accessed by the abort button, but
// only initialised inside acceptChangesAndCalculate()
Expand Down Expand Up @@ -144,6 +144,8 @@
// Create a new Controller each time the button is pressed
controller = new AbortController();
console.log("Running with runner", runner);
// WASM
if (runner === "wasm") {
runScenario(changedJson)
Expand All @@ -158,11 +160,9 @@
}
})
.catch((err) => handleError(err));
} else if (runner === "api") {
// Azure API
const url = window.location.href
.toLowerCase()
.includes(config.baseUrl.toLowerCase())
} else if (runner === "azure" || runner === "local") {
// REST API
const url = runner === "azure"
? config.webApiUrl // deployed to Azure
: "/api/"; // Docker, or local dev: this is a proxy to the backend on localhost:5174
fetch(url, {
Expand Down Expand Up @@ -196,6 +196,7 @@ Create your own scenario by modifying an existing one.
<InputMetadata
bind:scenarioShort
bind:scenarioDescription
bind:calculationMethod={runner}
on:returnToModify={() => (step = "modify")}
on:acceptChangesAndCalculate={acceptChangesAndCalculate}
/>
Expand Down
17 changes: 17 additions & 0 deletions web/src/lib/leftSidebar/create/InputMetadata.svelte
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
<script lang="ts">
export let scenarioShort: string = "";
export let scenarioDescription: string = "";
export let calculationMethod: "azure" | "wasm" | "local" = "azure";
import { config } from "src/data/config";
import { createEventDispatcher } from "svelte";
const dispatch = createEventDispatcher();
// Check if the app is deployed on the server
const deployed = window.location.href
.toLowerCase()
.includes(config.baseUrl.toLowerCase());
</script>

<h3>Step 3: Input scenario metadata</h3>
Expand All @@ -18,6 +25,16 @@
value="Accept changes and calculate"
on:click={() => dispatch("acceptChangesAndCalculate")}
/>

<b>Calculation method</b>
<select bind:value={calculationMethod}>
<option value="azure">Azure REST API</option>
{#if !deployed}
<option value="local">Local REST API</option>
{/if}
<option value="wasm">WebAssembly</option>
</select>

<input
type="text"
bind:value={scenarioShort}
Expand Down

0 comments on commit 19df996

Please sign in to comment.