Merge branch 'immediateChanges' of https://github.com/openwfm/wrfxweb into mergeBranches
[wrfxweb.git] / fdds / js / services.js
blob372a208c97f5d4c7e54fca76f5dc201aeea6d047
1 import { controllers } from './components/Controller.js';
2 import { simVars } from './simVars.js';
4 /** Service request for fetching the conf.json file. */
5 export async function getConfigurations() {
6 await fetch('conf.json').then(response => response.json()).then(function(configData) {
7 if (configData.organization) {
8 simVars.organization = configData.organization;
10 document.title = simVars.organization;
12 if (configData.flags) {
13 const simulationFlags = document.querySelector('#simulation-flags');
14 let flags = configData.flags;
15 flags.map(flag => {
16 let spanElement = document.createElement('span');
17 spanElement.className = 'displayTest';
18 spanElement.innerText = flag;
19 simulationFlags.appendChild(spanElement);
20 });
22 }).catch(error => {
23 console.error('Error fetching conf.json : ' + error);
24 });
27 /** Service request for building the initial catalogMenu */
28 export async function getCatalogEntries() {
29 let json = {};
30 try {
31 const response = await fetch('simulations/catalog.json');
32 json = response.json();
33 } catch(error) {
34 console.error('Error fetching catalog entries: ' + error);
36 return json;
39 /** Service request for fetching a selected simulation from the menu. */
40 export function getSimulation(path) {
41 fetch(path).then(response => response.json()).then(function(selectedSimulation) {
42 // store in global state
43 simVars.rasters = selectedSimulation;
44 simVars.rasterBase = path.substring(0, path.lastIndexOf('/') + 1);
45 // retrieve all domains
46 controllers.domainInstance.setValue(Object.keys(selectedSimulation));
47 }).catch(error => {
48 console.error('Error fetching simulation at ' + path);
49 console.log(error);
50 });