Updates to pages so that they are written to DB and retrieved correctly.
This commit is contained in:
parent
3725a1782b
commit
0665e28ca3
|
@ -18,12 +18,14 @@ const {
|
||||||
SEPARATOR,
|
SEPARATOR,
|
||||||
getPageParams,
|
getPageParams,
|
||||||
generatePageID,
|
generatePageID,
|
||||||
|
generateScreenID,
|
||||||
} = require("../../db/utils")
|
} = require("../../db/utils")
|
||||||
const {
|
const {
|
||||||
downloadExtractComponentLibraries,
|
downloadExtractComponentLibraries,
|
||||||
} = require("../../utilities/createAppPackage")
|
} = require("../../utilities/createAppPackage")
|
||||||
const PAGES = require("../../constants/pages")
|
const { MAIN, UNAUTHENTICATED, PageTypes } = require("../../constants/pages")
|
||||||
const { HOME_SCREEN } = require("../../constants/screens")
|
const { HOME_SCREEN } = require("../../constants/screens")
|
||||||
|
const { cloneDeep } = require("lodash/fp")
|
||||||
|
|
||||||
const APP_PREFIX = DocumentTypes.APP + SEPARATOR
|
const APP_PREFIX = DocumentTypes.APP + SEPARATOR
|
||||||
|
|
||||||
|
@ -69,17 +71,24 @@ exports.fetch = async function(ctx) {
|
||||||
exports.fetchAppPackage = async function(ctx) {
|
exports.fetchAppPackage = async function(ctx) {
|
||||||
const db = new CouchDB(ctx.params.appId)
|
const db = new CouchDB(ctx.params.appId)
|
||||||
const application = await db.get(ctx.params.appId)
|
const application = await db.get(ctx.params.appId)
|
||||||
// ctx.body = await getPackageForBuilder(application)
|
|
||||||
|
|
||||||
const pages = await db.allDocs(
|
let pages = await db.allDocs(
|
||||||
getPageParams(null, {
|
getPageParams(null, {
|
||||||
include_docs: true,
|
include_docs: true,
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
|
pages = pages.rows.map(row => row.doc)
|
||||||
|
|
||||||
|
const mainPage = pages.filter(page => page.name === PageTypes.MAIN)[0]
|
||||||
|
const unauthPage = pages.filter(
|
||||||
|
page => page.name === PageTypes.UNAUTHENTICATED
|
||||||
|
)[0]
|
||||||
ctx.body = {
|
ctx.body = {
|
||||||
application,
|
application,
|
||||||
pages,
|
pages: {
|
||||||
|
main: mainPage,
|
||||||
|
unauthenticated: unauthPage,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
setBuilderToken(ctx, ctx.params.appId, application.version)
|
setBuilderToken(ctx, ctx.params.appId, application.version)
|
||||||
|
@ -165,15 +174,6 @@ const createEmptyAppPackage = async (ctx, app) => {
|
||||||
// 0o777
|
// 0o777
|
||||||
// )
|
// )
|
||||||
|
|
||||||
// TODO: write the main and unauthenticated JSON to couch
|
|
||||||
// const writes = []
|
|
||||||
// for (let pageName in PAGES) {
|
|
||||||
// PAGES[pageName]._id = generatePageID()
|
|
||||||
// writes.push({
|
|
||||||
|
|
||||||
// })
|
|
||||||
// }
|
|
||||||
|
|
||||||
await copy(templateFolder, newAppFolder)
|
await copy(templateFolder, newAppFolder)
|
||||||
|
|
||||||
// this line allows full permission on copied files
|
// this line allows full permission on copied files
|
||||||
|
@ -201,49 +201,58 @@ const createEmptyAppPackage = async (ctx, app) => {
|
||||||
await copy(templatePageDefinitions, join(appsFolder, app._id, "pages"))
|
await copy(templatePageDefinitions, join(appsFolder, app._id, "pages"))
|
||||||
}
|
}
|
||||||
|
|
||||||
const mainJson = await updateJsonFile(
|
// const mainJson = await updateJsonFile(
|
||||||
join(appsFolder, app._id, "pages", "main", "page.json"),
|
// join(appsFolder, app._id, "pages", "main", "page.json"),
|
||||||
app
|
// app
|
||||||
)
|
// )
|
||||||
|
//
|
||||||
|
// mainJson._id = generatePageID()
|
||||||
|
// await db.put(mainJson)
|
||||||
|
|
||||||
mainJson._id = generatePageID()
|
// const unauthenticatedJson = await updateJsonFile(
|
||||||
await db.put(mainJson)
|
// join(appsFolder, app._id, "pages", "unauthenticated", "page.json"),
|
||||||
|
// app
|
||||||
await buildPage(app._id, "main", {
|
// )
|
||||||
page: mainJson,
|
|
||||||
screens: await loadScreens(newAppFolder, "main"),
|
|
||||||
})
|
|
||||||
|
|
||||||
const unauthenticatedJson = await updateJsonFile(
|
|
||||||
join(appsFolder, app._id, "pages", "unauthenticated", "page.json"),
|
|
||||||
app
|
|
||||||
)
|
|
||||||
|
|
||||||
// Write to couch
|
// Write to couch
|
||||||
unauthenticatedJson._id = generatePageID()
|
// unauthenticatedJson._id = generatePageID()
|
||||||
await db.put(unauthenticatedJson)
|
// await db.put(unauthenticatedJson)
|
||||||
|
|
||||||
|
const mainPage = cloneDeep(MAIN)
|
||||||
|
mainPage._id = generatePageID()
|
||||||
|
mainPage.title = app.name
|
||||||
|
const unauthPage = cloneDeep(UNAUTHENTICATED)
|
||||||
|
unauthPage._id = generatePageID()
|
||||||
|
unauthPage.title = app.name
|
||||||
|
const homeScreen = cloneDeep(HOME_SCREEN)
|
||||||
|
homeScreen._id = generateScreenID(mainPage._id)
|
||||||
|
await db.bulkDocs([mainPage, unauthPage, homeScreen])
|
||||||
|
|
||||||
|
await buildPage(app._id, "main", {
|
||||||
|
page: mainPage,
|
||||||
|
screens: [homeScreen],
|
||||||
|
})
|
||||||
await buildPage(app._id, "unauthenticated", {
|
await buildPage(app._id, "unauthenticated", {
|
||||||
page: unauthenticatedJson,
|
page: unauthPage,
|
||||||
screens: await loadScreens(newAppFolder, "unauthenticated"),
|
screens: [],
|
||||||
})
|
})
|
||||||
|
|
||||||
return newAppFolder
|
return newAppFolder
|
||||||
}
|
}
|
||||||
|
|
||||||
const loadScreens = async (appFolder, page) => {
|
// const loadScreens = async (appFolder, page) => {
|
||||||
const screensFolder = join(appFolder, "pages", page, "screens")
|
// const screensFolder = join(appFolder, "pages", page, "screens")
|
||||||
|
//
|
||||||
const screenFiles = (await fs.readdir(screensFolder)).filter(s =>
|
// const screenFiles = (await fs.readdir(screensFolder)).filter(s =>
|
||||||
s.endsWith(".json")
|
// s.endsWith(".json")
|
||||||
)
|
// )
|
||||||
|
//
|
||||||
let screens = []
|
// let screens = []
|
||||||
for (let file of screenFiles) {
|
// for (let file of screenFiles) {
|
||||||
screens.push(await fs.readJSON(join(screensFolder, file)))
|
// screens.push(await fs.readJSON(join(screensFolder, file)))
|
||||||
}
|
// }
|
||||||
return screens
|
// return screens
|
||||||
}
|
// }
|
||||||
|
|
||||||
const updateJsonFile = async (filePath, app) => {
|
const updateJsonFile = async (filePath, app) => {
|
||||||
const json = await readFile(filePath, "utf8")
|
const json = await readFile(filePath, "utf8")
|
||||||
|
|
|
@ -1,8 +1,14 @@
|
||||||
|
const PageTypes = {
|
||||||
|
MAIN: "main",
|
||||||
|
UNAUTHENTICATED: "unauthenticated",
|
||||||
|
}
|
||||||
|
|
||||||
const MAIN = {
|
const MAIN = {
|
||||||
componentLibraries: ["@budibase/standard-components"],
|
componentLibraries: ["@budibase/standard-components"],
|
||||||
title: "{{ name }}",
|
title: "{{ name }}",
|
||||||
favicon: "./_shared/favicon.png",
|
favicon: "./_shared/favicon.png",
|
||||||
stylesheets: [],
|
stylesheets: [],
|
||||||
|
name: PageTypes.MAIN,
|
||||||
props: {
|
props: {
|
||||||
_id: "private-master-root",
|
_id: "private-master-root",
|
||||||
_component: "@budibase/standard-components/container",
|
_component: "@budibase/standard-components/container",
|
||||||
|
@ -148,6 +154,7 @@ const UNAUTHENTICATED = {
|
||||||
title: "{{ name }}",
|
title: "{{ name }}",
|
||||||
favicon: "./_shared/favicon.png",
|
favicon: "./_shared/favicon.png",
|
||||||
stylesheets: [],
|
stylesheets: [],
|
||||||
|
name: PageTypes.UNAUTHENTICATED,
|
||||||
props: {
|
props: {
|
||||||
_id: "public-master-root",
|
_id: "public-master-root",
|
||||||
_component: "@budibase/standard-components/container",
|
_component: "@budibase/standard-components/container",
|
||||||
|
@ -213,4 +220,4 @@ const UNAUTHENTICATED = {
|
||||||
uiFunctions: "",
|
uiFunctions: "",
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = { MAIN, UNAUTHENTICATED }
|
module.exports = { MAIN, UNAUTHENTICATED, PageTypes }
|
||||||
|
|
|
@ -177,14 +177,6 @@ exports.generateWebhookID = () => {
|
||||||
return `${DocumentTypes.WEBHOOK}${SEPARATOR}${newid()}`
|
return `${DocumentTypes.WEBHOOK}${SEPARATOR}${newid()}`
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Generates a new screen ID.
|
|
||||||
* @returns {string} The new screen ID which the screen doc can be stored under.
|
|
||||||
*/
|
|
||||||
exports.generateScreenID = () => {
|
|
||||||
return `${DocumentTypes.SCREEN}${SEPARATOR}${newid()}`
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Generates a new page ID.
|
* Generates a new page ID.
|
||||||
* @returns {string} The new page ID which the page doc can be stored under.
|
* @returns {string} The new page ID which the page doc can be stored under.
|
||||||
|
@ -200,6 +192,14 @@ exports.getPageParams = (pageId = null, otherProps = {}) => {
|
||||||
return getDocParams(DocumentTypes.PAGE, pageId, otherProps)
|
return getDocParams(DocumentTypes.PAGE, pageId, otherProps)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Generates a new screen ID.
|
||||||
|
* @returns {string} The new screen ID which the screen doc can be stored under.
|
||||||
|
*/
|
||||||
|
exports.generateScreenID = pageId => {
|
||||||
|
return `${DocumentTypes.SCREEN}${SEPARATOR}${pageId}${SEPARATOR}${newid()}`
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets parameters for retrieving screens for a particular page, this is a utility function for the getDocParams function.
|
* Gets parameters for retrieving screens for a particular page, this is a utility function for the getDocParams function.
|
||||||
*/
|
*/
|
||||||
|
|
Loading…
Reference in New Issue