2020-10-13 18:40:28 +02:00
|
|
|
/**
|
|
|
|
* This controller is not currently fully implemented. Screens are
|
|
|
|
* currently managed as part of the pages API, please look in api/routes/page.js
|
|
|
|
* for routes and controllers.
|
|
|
|
*/
|
2020-11-01 16:32:54 +01:00
|
|
|
const CouchDB = require("../../db")
|
2020-11-03 17:27:28 +01:00
|
|
|
const { getScreenParams, generateScreenID } = require("../../db/utils")
|
2020-10-13 18:40:28 +02:00
|
|
|
|
|
|
|
exports.fetch = async ctx => {
|
2020-11-03 17:27:28 +01:00
|
|
|
const db = new CouchDB(ctx.user.appId)
|
|
|
|
|
|
|
|
const screens = await db.allDocs(
|
2020-11-04 13:36:38 +01:00
|
|
|
getScreenParams(null, {
|
2020-11-03 17:27:28 +01:00
|
|
|
include_docs: true,
|
|
|
|
})
|
|
|
|
)
|
|
|
|
|
2020-11-04 13:36:38 +01:00
|
|
|
ctx.body = screens.rows.map(element => element.doc)
|
2020-10-13 18:40:28 +02:00
|
|
|
}
|
|
|
|
|
2020-11-04 13:36:38 +01:00
|
|
|
exports.find = async ctx => {
|
2020-11-01 16:32:54 +01:00
|
|
|
const db = new CouchDB(ctx.user.appId)
|
|
|
|
|
2020-11-04 13:36:38 +01:00
|
|
|
const screens = await db.allDocs(
|
|
|
|
getScreenParams(ctx.params.pageId, {
|
|
|
|
include_docs: true,
|
|
|
|
})
|
|
|
|
)
|
|
|
|
|
|
|
|
ctx.body = screens.response.rows
|
2020-11-01 16:32:54 +01:00
|
|
|
}
|
|
|
|
|
2020-10-13 18:40:28 +02:00
|
|
|
exports.save = async ctx => {
|
2020-11-03 17:27:28 +01:00
|
|
|
const appId = ctx.user.appId
|
|
|
|
const db = new CouchDB(appId)
|
|
|
|
const screen = ctx.request.body
|
|
|
|
|
|
|
|
if (!screen._id) {
|
2020-11-04 13:36:38 +01:00
|
|
|
screen._id = generateScreenID(ctx.params.pageId)
|
2020-11-03 17:27:28 +01:00
|
|
|
}
|
2020-11-04 13:36:38 +01:00
|
|
|
delete screen._css
|
2020-11-03 17:27:28 +01:00
|
|
|
const response = await db.put(screen)
|
|
|
|
|
|
|
|
ctx.message = `Screen ${screen.name} saved.`
|
|
|
|
ctx.body = response
|
2020-10-13 18:40:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
exports.destroy = async ctx => {
|
2020-11-03 17:27:28 +01:00
|
|
|
const db = new CouchDB(ctx.user.appId)
|
|
|
|
await db.remove(ctx.params.screenId, ctx.params.revId)
|
|
|
|
ctx.message = "Screen deleted successfully"
|
2020-10-13 18:40:28 +02:00
|
|
|
}
|