6
6
import ErrorScreen from " src/lib/reusable/ErrorScreen.svelte" ;
7
7
import {
8
8
type ValuesObject ,
9
- type ScenarioChanges ,
10
9
type ScenarioObject ,
11
10
type Scenario ,
12
11
config ,
42
41
let userChangesPromptText: string =
43
42
" Are you sure you want to go back? All changes will be lost." ;
44
43
let userChangesPresent: boolean = false ;
45
- // Changes that user has made relative to baseline
46
- let changes: ScenarioChanges = new Map ();
47
44
48
45
// Deselect OAs if the user navigates away
49
46
onDestroy (() => {
53
50
function returnToSelection() {
54
51
if (userChangesPresent ) {
55
52
if (window .confirm (userChangesPromptText )) {
56
- changes = new Map ();
57
53
userChangesPresent = false ;
58
54
$clickedOAs = [];
59
55
step = " choose" ;
56
+ // Reset scenario name to default
57
+ $scenarioName = config .referenceScenarioObject .metadata .name ;
58
+ dispatch (" changeScenario" );
60
59
}
61
60
} else {
62
61
$clickedOAs = [];
68
67
dispatch (" changeScenario" , {});
69
68
step = " modify" ; // move on to the next step
70
69
$clickedOAs = []; // deselect any OAs
71
- changes = new Map ($allScenarios .get ($scenarioName ).changes );
72
70
}
73
71
74
72
function handleResult(values : ValuesObject , changesJson : string ) {
100
98
newScenario .metadata .name = ` ${newScenario .metadata .name }_${i } ` ;
101
99
}
102
100
$allScenarios .set (newScenario .metadata .name , newScenario );
103
- // Get rid of changes; this also ensures that the "are you
104
- // sure" confirmation prompt doesn't show up.
101
+ // Suppress "are you sure" confirmation prompt
105
102
userChangesPresent = false ;
106
- changes = new Map ();
107
103
// Display the new scenario on the map.
108
104
dispatch (" import" , { name: newScenario .metadata .name });
109
105
}
135
131
136
132
function acceptChangesAndCalculate() {
137
133
const changedJson = JSON .stringify ({
138
- scenario_json: toChangesObject (changes ),
134
+ scenario_json: toChangesObject (
135
+ $allScenarios .get ($scenarioName ).changes
136
+ ),
139
137
});
138
+ console .log (" changedJson" , changedJson );
140
139
step = " calc" ; // move on
141
- changes = new Map (); // reset changes
142
140
$clickedOAs = []; // deselect any OAs
143
141
144
142
// Create a new Controller each time the button is pressed
162
160
.catch ((err ) => handleError (err ));
163
161
} else if (runner === " azure" || runner === " local" ) {
164
162
// REST API
165
- const url = runner === " azure"
166
- ? config .webApiUrl // deployed to Azure
167
- : " /api/" ; // Docker, or local dev: this is a proxy to the backend on localhost:5174
163
+ const url =
164
+ runner === " azure"
165
+ ? config .webApiUrl // deployed to Azure
166
+ : " /api/" ; // Docker, or local dev: this is a proxy to the backend on localhost:5174
168
167
fetch (url , {
169
168
method: " POST" ,
170
169
headers: { " Content-Type" : " application/json" },
@@ -186,8 +185,10 @@ Create your own scenario by modifying an existing one.
186
185
{#if step === " modify" }
187
186
<ModifyOutputAreas
188
187
bind:userChangesPresent
189
- bind:changes
190
188
on:returnToSelection ={returnToSelection }
189
+ on:changesUpdated ={() => {
190
+ dispatch (" changesUpdated" );
191
+ }}
191
192
on:proceedToMetadata ={() => (step = " metadata" )}
192
193
/>
193
194
{/if }
0 commit comments