Skip to content

Commit

Permalink
Add state_saved listener to ChartManager in static_index.js
Browse files Browse the repository at this point in the history
  • Loading branch information
will-moore committed Jun 17, 2023
1 parent a5b7978 commit f8a2a90
Showing 1 changed file with 45 additions and 1 deletion.
46 changes: 45 additions & 1 deletion src/modules/static_index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,49 @@ async function fetchAndPatchJSON(url) {
return config;
}

async function executeProjectAction(action, args) {
if (!args) {
args = {}
}
let data = {
method: action,
args: args
}
const resp = await fetch("/meths/execute_project_action/",
{
method: "POST",
body: JSON.stringify(data),
headers: {
"Accept": "application/json,text/plain,*/*",
"Content-Type": "application/json"
}
});
let rspData = {};
try {
rspData = await resp.json();
} catch (error) {
console.error(error);
}
return rspData;
}

function listener(type,cm,info){
switch(type){
case "state_saved":
console.log("listener state_saved", cm, info)
executeProjectAction("save_state",{state: info}).then(resp=>{
if (resp.success){
cm.createInfoAlert("Data Saved",{duration:2000});
cm.setAllColumnsClean();
}
else{
cm.createInfoAlert("UnableToSaveData",{duration:3000,type:"danger"});
}
});
break;
}
}

async function loadData() {
const datasources = await fetchAndPatchJSON(`${root}/datasources.json`);
const config = await fetchAndPatchJSON(`${root}/state.json`);
Expand All @@ -56,5 +99,6 @@ async function loadData() {
function: getLocalCompressedBinaryDataLoader(datasources, root),
viewLoader: async (view) => views[view]
}
const cm = new ChartManager("app1", datasources, dataLoader, config);

const cm = new ChartManager("app1", datasources, dataLoader, config, listener);
};

0 comments on commit f8a2a90

Please sign in to comment.