2020-02-09 07:58:29 +00:00
|
|
|
const Controller = require('libflitter/controller/Controller')
|
|
|
|
const Codium = require('../../../models/api/Codium.model')
|
|
|
|
|
|
|
|
/*
|
|
|
|
* FormCode Controller
|
|
|
|
* -------------------------------------------------------------
|
|
|
|
* Put some description here!
|
|
|
|
*/
|
|
|
|
class FormCode extends Controller {
|
|
|
|
|
|
|
|
async create_new(req, res) {
|
2020-11-11 19:54:20 +00:00
|
|
|
const { page, node } = req.form
|
2020-02-09 07:58:29 +00:00
|
|
|
|
|
|
|
const code = new Codium({
|
|
|
|
NodeId: node.UUID,
|
|
|
|
PageId: page.UUID,
|
|
|
|
code: '',
|
|
|
|
})
|
|
|
|
|
2020-10-29 03:55:04 +00:00
|
|
|
if ( req.body.Language ) {
|
|
|
|
code.Language = req.body.Language
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( req.body.code ) {
|
|
|
|
code.code = req.body.code
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( req.body.UUID ) {
|
|
|
|
const existingUUID = await Codium.findOne({ UUID: req.body.UUID })
|
|
|
|
if ( !existingUUID ) {
|
|
|
|
code.UUID = req.body.UUID
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-02 18:47:34 +00:00
|
|
|
await code.version_save(`Added to page "${page.Name}"`, req.user.id)
|
2020-02-09 07:58:29 +00:00
|
|
|
return res.api(code)
|
|
|
|
}
|
|
|
|
|
|
|
|
async get_config(req, res) {
|
2021-03-16 15:35:57 +00:00
|
|
|
const { codium } = req.form
|
|
|
|
|
|
|
|
if ( req.query.version ) {
|
|
|
|
return res.api(await codium.as_version(req.query.version))
|
|
|
|
}
|
|
|
|
|
|
|
|
return res.api(codium)
|
2020-02-09 07:58:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
async set_values(req, res) {
|
2020-11-11 19:54:20 +00:00
|
|
|
const { page, node, codium } = req.form
|
|
|
|
|
|
|
|
codium.code = req.body.code
|
|
|
|
codium.Language = req.body.Language
|
|
|
|
codium.NodeId = node.UUID
|
|
|
|
codium.PageId = page.UUID
|
|
|
|
await codium.version_save(`Updated in page "${page.Name}"`, req.user.id)
|
|
|
|
return res.api(codium)
|
2020-02-09 07:58:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
async drop_code(req, res) {
|
2020-11-11 19:54:20 +00:00
|
|
|
const { codium } = req.form
|
2020-02-09 07:58:29 +00:00
|
|
|
|
2020-11-11 19:54:20 +00:00
|
|
|
codium.Active = false
|
|
|
|
await codium.version_save(`Deleted`, req.user.id)
|
2020-02-09 07:58:29 +00:00
|
|
|
return res.api({})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = exports = FormCode
|