Merge branch 'chasesBranch' of https://github.com/openwfm/wrfxweb into colorbarUpdates
[wrfxweb.git] / fdds / js / services.js
blob7f12b7f2684d925efdee724b4eb5d1d294117120
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 fetch(path.replaceAll(':', '_')).then(response => response.json()).then(function(selectedSimulation) {
43 // store in global state
44 simVars.rasters = selectedSimulation;
45 // simVars.rasterBase = path.substring(0, path.lastIndexOf('/') + 1);
46 simVars.rasterBase = path.replaceAll(':', '_').substring(0, path.lastIndexOf('/') + 1);
47 // retrieve all domains
48 controllers.domainInstance.setValue(Object.keys(selectedSimulation));
49 }).catch(error => {
50 console.error('Error fetching simulation at ' + path);
51 console.log(error);
52 });