Quick update to allow deleting layouts if they are not currently in use.
This commit is contained in:
parent
9b5734b1de
commit
fdd719aadb
|
@ -1,5 +1,5 @@
|
|||
const CouchDB = require("../../db/client")
|
||||
const { generateLayoutID } = require("../../db/utils")
|
||||
const CouchDB = require("../../db")
|
||||
const { generateLayoutID, getScreenParams } = require("../../db/utils")
|
||||
|
||||
exports.save = async function(ctx) {
|
||||
const db = new CouchDB(ctx.user.appId)
|
||||
|
@ -9,3 +9,24 @@ exports.save = async function(ctx) {
|
|||
ctx.body = await db.put(layout)
|
||||
ctx.status = 200
|
||||
}
|
||||
|
||||
exports.destroy = async function(ctx) {
|
||||
const db = new CouchDB(ctx.user.appId)
|
||||
const layoutId = ctx.params.layoutId,
|
||||
layoutRev = ctx.params.layoutRev
|
||||
|
||||
const layoutsUsedByScreens = (
|
||||
await db.allDocs(
|
||||
getScreenParams(null, {
|
||||
include_docs: true,
|
||||
})
|
||||
)
|
||||
).rows.map(element => element.doc.props.layoutId)
|
||||
if (layoutsUsedByScreens.indexOf(layoutId) !== -1) {
|
||||
ctx.throw(400, "Cannot delete a base layout")
|
||||
}
|
||||
|
||||
await db.remove(layoutId, layoutRev)
|
||||
ctx.message = "Layout deleted successfully"
|
||||
ctx.status = 200
|
||||
}
|
||||
|
|
|
@ -36,7 +36,7 @@ exports.save = async ctx => {
|
|||
|
||||
exports.destroy = async ctx => {
|
||||
const db = new CouchDB(ctx.user.appId)
|
||||
await db.remove(ctx.params.screenId, ctx.params.revId)
|
||||
await db.remove(ctx.params.screenId, ctx.params.screenRev)
|
||||
ctx.message = "Screen deleted successfully"
|
||||
ctx.status = 200
|
||||
}
|
||||
|
|
|
@ -5,6 +5,12 @@ const controller = require("../controllers/layout")
|
|||
|
||||
const router = Router()
|
||||
|
||||
router.post("/api/layouts", authorized(BUILDER), controller.save)
|
||||
router
|
||||
.post("/api/layouts", authorized(BUILDER), controller.save)
|
||||
.delete(
|
||||
"/api/layouts/:layoutId/:layoutRev",
|
||||
authorized(BUILDER),
|
||||
controller.destroy
|
||||
)
|
||||
|
||||
module.exports = router
|
||||
|
|
|
@ -38,7 +38,7 @@ router
|
|||
controller.save
|
||||
)
|
||||
.delete(
|
||||
"/api/screens/:screenId/:revId",
|
||||
"/api/screens/:screenId/:screenRev",
|
||||
authorized(BUILDER),
|
||||
controller.destroy
|
||||
)
|
||||
|
|
|
@ -1,3 +1,8 @@
|
|||
const BASE_LAYOUT_PROP_IDS = {
|
||||
PRIVATE: "private-master-layout",
|
||||
PUBLIC: "public-master-layout",
|
||||
}
|
||||
|
||||
const BASE_LAYOUTS = [
|
||||
{
|
||||
componentLibraries: ["@budibase/standard-components"],
|
||||
|
@ -6,7 +11,7 @@ const BASE_LAYOUTS = [
|
|||
stylesheets: [],
|
||||
name: "Main",
|
||||
props: {
|
||||
_id: "private-master-layout",
|
||||
_id: BASE_LAYOUT_PROP_IDS.PRIVATE,
|
||||
_component: "@budibase/standard-components/container",
|
||||
_children: [
|
||||
{
|
||||
|
@ -151,7 +156,7 @@ const BASE_LAYOUTS = [
|
|||
stylesheets: [],
|
||||
name: "Unauthenticated",
|
||||
props: {
|
||||
_id: "public-master-layout",
|
||||
_id: BASE_LAYOUT_PROP_IDS.PUBLIC,
|
||||
_component: "@budibase/standard-components/container",
|
||||
_children: [
|
||||
{
|
||||
|
@ -217,4 +222,5 @@ const BASE_LAYOUTS = [
|
|||
|
||||
module.exports = {
|
||||
BASE_LAYOUTS,
|
||||
BASE_LAYOUT_PROP_IDS,
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue