From 9ae7714658c9b6b98ec9422a2acfa9442b62b49f Mon Sep 17 00:00:00 2001 From: William Moore Date: Sat, 17 Jun 2023 08:24:08 +0100 Subject: [PATCH] Add state_saved listener to ChartManager in static_index.js --- src/modules/static_index.ts | 45 ++++++++++++++++++++++++++++++++++++- 1 file changed, 44 insertions(+), 1 deletion(-) diff --git a/src/modules/static_index.ts b/src/modules/static_index.ts index c8f3409d..bb78d8ea 100644 --- a/src/modules/static_index.ts +++ b/src/modules/static_index.ts @@ -57,6 +57,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`); @@ -65,7 +108,7 @@ 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); const dsName = datasources[0].name; const ds = cm.dsIndex[dsName]; const tadModel = new TagModel(ds.dataStore);