diff --git a/cf.js b/cf.js index 3adfa8f1200818d0972fe38f63cd41f1115f3335..8589b95ebe757cba5c535c4d753921444f4d6065 100644 --- a/cf.js +++ b/cf.js @@ -45,13 +45,26 @@ app.get('/fileList', (req, res) => { // we also handle file-saving this way, app.post('/save/contexts/:context/:file', (req, res) => { // this is probably fine for now, but I kind of want a websocket to do this kind of stuff ? - console.log('put req to context :' + req.params.context + ': with name :' + req.params.file + ':') - console.log('the file as', typeof req.body, req.body) let serialized = JSON.stringify(req.body, null, 2) fs.writeFile(`save/contexts/${req.params.context}/${req.params.file}.json`, serialized, (err) => { - if (err) throw err; - console.log('the file saved') - res.send({ok: true}) + if (err) { + console.log(`ERR while saving to save/contexts/${req.params.context}/${req.params.file}.json`) + res.send({success: false}) + } + console.log(`saved a context to to save/contexts/${req.params.context}/${req.params.file}.json`) + res.send({success: true}) + }) +}) +// and for systems, +app.post('/save/systems/:file', (req, res) => { + let serialized = JSON.stringify(req.body, null, 2) + fs.writeFile(`save/systems/${req.params.file}.json`, serialized, (err) => { + if (err) { + console.log(`ERR while saving to save/systems/${req.params.file}.json`) + res.send({success: false}) + } + console.log(`saved a system to to save/systems/${req.params.file}.json`) + res.send({success: true}) }) }) diff --git a/view/vcontextmenu.js b/view/vcontextmenu.js index eb94594af4cc552b024f595329322132b0d089bc..79637cc5ccd6dac0dc5877daea8e5fac1faf02b5 100644 --- a/view/vcontextmenu.js +++ b/view/vcontextmenu.js @@ -231,7 +231,12 @@ function cfContextMenu(evt, view, dt) { let ptch = scope.patchset.writeCurrent() setupForSave(ce, (name) => { jQuery.post(`/save/contexts/${scope.interpreterName}/${name}`, ptch, (res) => { - console.log('post result', res) + if(!res.success){ + console.error("server-side error while saving") + } else { + console.log('save context ok') + fadeOut(400) + } }, 'json') }) }) @@ -248,7 +253,7 @@ function cfContextMenu(evt, view, dt) { scope.patchset.getPatch(item).then((ptch) => { return scope.patchset.mergePatch(ptch) }).then((defs) => { - console.log("patch loaded, running Globale Organize") + console.log("patch loaded, running GO") view.globalOrganize() fadeOut(400) }).catch((errmsg) => { @@ -324,10 +329,17 @@ function cfContextMenu(evt, view, dt) { } // end recursive cycle ? // once that runs to completion, should have the hierarchichal patch - console.log('CONSIDER THIS: a system patch ... ', tlp) + // console.log('CONSIDER THIS: a system patch ... ', tlp) // now present-and-save setupForSave(ce, (name) => { - // ship blob 2 server at put / + jQuery.post(`/save/systems/${name}`, tlp, (res) => { + if(!res.success){ + console.error("server-side error while saving") + } else { + console.log('save system ok') + fadeOut(400) + } + }, 'json') }) }) // end save entire system