Save Command Implementation
This commit is contained in:
1 parent
e12af2c6b8
commit
d77bb807ea
2 files changed
+146
-3
No files matched your search
@@ -301,6 +301,116 @@ exports.newHttpInterface = function newHttpInterface(WEB_SERVER, DATA_FILE_SERVE
|
||||
}
|
||||
break
|
||||
|
||||
case 'Docs':
|
||||
{
|
||||
switch (requestParameters[2]) { // switch by command
|
||||
case 'Save-Node-Schema': {
|
||||
getBody(processRequest)
|
||||
|
||||
async function processRequest(body) {
|
||||
try {
|
||||
let docsSchema = JSON.parse(body)
|
||||
let project = requestParameters[3]
|
||||
const fs = require('fs')
|
||||
|
||||
for (let i = 0; i < docsSchema.length; i++) {
|
||||
let schemaDocument = docsSchema[i]
|
||||
let fileContent = JSON.stringify(schemaDocument)
|
||||
let fileName = schemaDocument.type.toLowerCase().replaceAll(' ', '-') + '.json'
|
||||
let filePath = global.env.PATH_TO_PROJECTS + '/' + project + '/Schemas/Docs-Nodes'
|
||||
fs.writeFileSync(filePath + '/' + fileName, fileContent)
|
||||
}
|
||||
|
||||
respondWithContent(JSON.stringify(global.DEFAULT_OK_RESPONSE), httpResponse)
|
||||
|
||||
} catch (err) {
|
||||
console.log('[ERROR] httpInterface -> Docs -> Save-Node-Schema -> Method call produced an error.')
|
||||
console.log('[ERROR] httpInterface -> WEB3s -> Save-Node-Schema -> err.stack = ' + err.stack)
|
||||
console.log('[ERROR] httpInterface -> WEB3s -> Save-Node-Schema -> Params Received = ' + body)
|
||||
|
||||
let error = {
|
||||
result: 'Fail Because',
|
||||
message: err.message,
|
||||
stack: err.stack
|
||||
}
|
||||
respondWithContent(JSON.stringify(error), httpResponse)
|
||||
}
|
||||
}
|
||||
break
|
||||
}
|
||||
case 'Save-Concept-Schema': {
|
||||
getBody(processRequest)
|
||||
|
||||
async function processRequest(body) {
|
||||
try {
|
||||
let docsSchema = JSON.parse(body)
|
||||
let project = requestParameters[3]
|
||||
const fs = require('fs')
|
||||
|
||||
for (let i = 0; i < docsSchema.length; i++) {
|
||||
let schemaDocument = docsSchema[i]
|
||||
let fileContent = JSON.stringify(schemaDocument)
|
||||
let fileName = schemaDocument.type.toLowerCase().replaceAll(' ', '-') + '.json'
|
||||
let filePath = global.env.PATH_TO_PROJECTS + '/' + project + '/Schemas/Docs-Concepts'
|
||||
fs.writeFileSync(filePath + '/' + fileName, fileContent)
|
||||
}
|
||||
|
||||
respondWithContent(JSON.stringify(global.DEFAULT_OK_RESPONSE), httpResponse)
|
||||
|
||||
} catch (err) {
|
||||
console.log('[ERROR] httpInterface -> Docs -> Save-Concept-Schema -> Method call produced an error.')
|
||||
console.log('[ERROR] httpInterface -> WEB3s -> Save-Concept-Schema -> err.stack = ' + err.stack)
|
||||
console.log('[ERROR] httpInterface -> WEB3s -> Save-Concept-Schema -> Params Received = ' + body)
|
||||
|
||||
let error = {
|
||||
result: 'Fail Because',
|
||||
message: err.message,
|
||||
stack: err.stack
|
||||
}
|
||||
respondWithContent(JSON.stringify(error), httpResponse)
|
||||
}
|
||||
}
|
||||
break
|
||||
}
|
||||
case 'Save-Topic-Schema': {
|
||||
getBody(processRequest)
|
||||
|
||||
async function processRequest(body) {
|
||||
try {
|
||||
let docsSchema = JSON.parse(body)
|
||||
let project = requestParameters[3]
|
||||
const fs = require('fs')
|
||||
|
||||
for (let i = 0; i < docsSchema.length; i++) {
|
||||
let schemaDocument = docsSchema[i]
|
||||
let fileContent = JSON.stringify(schemaDocument)
|
||||
let fileName = schemaDocument.type.toLowerCase().replaceAll(' ', '-') + '.json'
|
||||
let filePath = global.env.PATH_TO_PROJECTS + '/' + project + '/Schemas/Docs-Topics'
|
||||
fs.writeFileSync(filePath + '/' + fileName, fileContent)
|
||||
}
|
||||
|
||||
respondWithContent(JSON.stringify(global.DEFAULT_OK_RESPONSE), httpResponse)
|
||||
|
||||
} catch (err) {
|
||||
console.log('[ERROR] httpInterface -> Docs -> Save-Topic-Schema -> Method call produced an error.')
|
||||
console.log('[ERROR] httpInterface -> WEB3s -> Save-Topic-Schema -> err.stack = ' + err.stack)
|
||||
console.log('[ERROR] httpInterface -> WEB3s -> Save-Topic-Schema -> Params Received = ' + body)
|
||||
|
||||
let error = {
|
||||
result: 'Fail Because',
|
||||
message: err.message,
|
||||
stack: err.stack
|
||||
}
|
||||
respondWithContent(JSON.stringify(error), httpResponse)
|
||||
}
|
||||
}
|
||||
break
|
||||
}
|
||||
}
|
||||
break
|
||||
}
|
||||
break
|
||||
|
||||
case 'LegacyPlotter.js':
|
||||
{
|
||||
respondWithFile(global.env.PATH_TO_CLIENT + 'WebServer/LegacyPlotter.js', httpResponse)
|
||||
|
||||
@@ -818,7 +818,7 @@ function newSuperalgosDocSpace() {
|
||||
"<b>Delete</b>: Use this command to delete existing Nodes, Concepts or Topics from the Docs.",
|
||||
"<b>Save</b>: Use this command whenever you would like to save the changes you made to the Docs.",
|
||||
"<b>Reindex</b>: Use this command to re-index all the info again so that your changes are visible at search results.",
|
||||
"Note that anything you type not identified as a command will be treated as a search query."
|
||||
"Note that anything you type not identified as a command will be treated as a search query."
|
||||
]
|
||||
)
|
||||
return
|
||||
@@ -1000,8 +1000,41 @@ function newSuperalgosDocSpace() {
|
||||
}
|
||||
if (command.indexOf('Save') !== 0 && command.indexOf('save') !== 0) { return 'Not Save Command' }
|
||||
|
||||
|
||||
renderCommandResultsPage(["Succesfully saved all the latest changes."])
|
||||
let requestsSent = 0
|
||||
let responseCount = 0
|
||||
let okResponses = 0
|
||||
for (let j = 0; j < PROJECTS_ARRAY.length; j++) {
|
||||
let docsSchema
|
||||
let project = PROJECTS_ARRAY[j]
|
||||
|
||||
docsSchema = SCHEMAS_BY_PROJECT.get(project).array.docsNodeSchema
|
||||
httpRequest(JSON.stringify(docsSchema), 'Docs/Save-Node-Schema/' + project, onResponse)
|
||||
requestsSent++
|
||||
|
||||
docsSchema = SCHEMAS_BY_PROJECT.get(project).array.docsConceptSchema
|
||||
httpRequest(JSON.stringify(docsSchema), 'Docs/Save-Concept-Schema/' + project, onResponse)
|
||||
requestsSent++
|
||||
|
||||
docsSchema = SCHEMAS_BY_PROJECT.get(project).array.docsTopicSchema
|
||||
httpRequest(JSON.stringify(docsSchema), 'Docs/Save-Topic-Schema/' + project, onResponse)
|
||||
requestsSent++
|
||||
}
|
||||
|
||||
function onResponse(err, data) {
|
||||
/* Lets check the result of the call through the http interface */
|
||||
if (err.result === GLOBAL.DEFAULT_OK_RESPONSE.result) {
|
||||
okResponses++
|
||||
}
|
||||
responseCount++
|
||||
|
||||
if (responseCount === requestsSent) {
|
||||
if (responseCount === okResponses) {
|
||||
renderCommandResultsPage(["Succesfully saved all the latest changes."])
|
||||
} else {
|
||||
renderCommandResultsPage(["Some of the changes could not be saved."])
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function addNode(project, type) {
|
||||
|
||||
Reference in new issue
Block a user