From d8b7d365c329c5bb61c520779e7a3e2642d6583b Mon Sep 17 00:00:00 2001
From: Jake Read <jake.read@cba.mit.edu>
Date: Mon, 7 Oct 2019 10:16:31 -0400
Subject: [PATCH] save contexts and systems to server OK
---
cf.js | 23 ++++++++++++++++++-----
view/vcontextmenu.js | 20 ++++++++++++++++----
2 files changed, 34 insertions(+), 9 deletions(-)
diff --git a/cf.js b/cf.js
index 3adfa8f..8589b95 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 eb94594..79637cc 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
--
GitLab