Some minor fixes, plus typescript conversion to avoid issue in future.
This commit is contained in:
parent
b9321701b8
commit
5b9c3a5608
3 changed files with 52 additions and 40 deletions
|
@ -1,15 +1,15 @@
|
||||||
const { DocumentType, getPluginParams } = require("../../db/utils")
|
import { DocumentType } from "../../db/utils"
|
||||||
const { getComponentLibraryManifest } = require("../../utilities/fileSystem")
|
import { Plugin } from "@budibase/types"
|
||||||
const { getAppDB } = require("@budibase/backend-core/context")
|
import { db as dbCore, context, tenancy } from "@budibase/backend-core"
|
||||||
const { getGlobalDB } = require("@budibase/backend-core/tenancy")
|
import { getComponentLibraryManifest } from "../../utilities/fileSystem"
|
||||||
|
|
||||||
exports.fetchAppComponentDefinitions = async function (ctx) {
|
exports.fetchAppComponentDefinitions = async function (ctx: any) {
|
||||||
try {
|
try {
|
||||||
const db = getAppDB()
|
const db = context.getAppDB()
|
||||||
const app = await db.get(DocumentType.APP_METADATA)
|
const app = await db.get(DocumentType.APP_METADATA)
|
||||||
|
|
||||||
let componentManifests = await Promise.all(
|
let componentManifests = await Promise.all(
|
||||||
app.componentLibraries.map(async library => {
|
app.componentLibraries.map(async (library: any) => {
|
||||||
let manifest = await getComponentLibraryManifest(library)
|
let manifest = await getComponentLibraryManifest(library)
|
||||||
return {
|
return {
|
||||||
manifest,
|
manifest,
|
||||||
|
@ -17,7 +17,7 @@ exports.fetchAppComponentDefinitions = async function (ctx) {
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
const definitions = {}
|
const definitions: { [key: string]: any } = {}
|
||||||
for (let { manifest, library } of componentManifests) {
|
for (let { manifest, library } of componentManifests) {
|
||||||
for (let key of Object.keys(manifest)) {
|
for (let key of Object.keys(manifest)) {
|
||||||
if (key === "features") {
|
if (key === "features") {
|
||||||
|
@ -33,16 +33,16 @@ exports.fetchAppComponentDefinitions = async function (ctx) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add custom components
|
// Add custom components
|
||||||
const globalDB = getGlobalDB()
|
const globalDB = tenancy.getGlobalDB()
|
||||||
const response = await globalDB.allDocs(
|
const response = await globalDB.allDocs(
|
||||||
getPluginParams(null, {
|
dbCore.getPluginParams(null, {
|
||||||
include_docs: true,
|
include_docs: true,
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
response.rows
|
response.rows
|
||||||
.map(row => row.doc)
|
.map((row: any) => row.doc)
|
||||||
.filter(plugin => plugin.schema.type === "component")
|
.filter((plugin: Plugin) => plugin.schema.type === "component")
|
||||||
.forEach(plugin => {
|
.forEach((plugin: Plugin) => {
|
||||||
const fullComponentName = `plugin/${plugin.name}`
|
const fullComponentName = `plugin/${plugin.name}`
|
||||||
definitions[fullComponentName] = {
|
definitions[fullComponentName] = {
|
||||||
component: fullComponentName,
|
component: fullComponentName,
|
|
@ -1,17 +1,16 @@
|
||||||
const {
|
import { getScreenParams, generateScreenID, DocumentType } from "../../db/utils"
|
||||||
getScreenParams,
|
import {
|
||||||
generateScreenID,
|
events,
|
||||||
getPluginParams,
|
context,
|
||||||
DocumentType,
|
tenancy,
|
||||||
} = require("../../db/utils")
|
db as dbCore,
|
||||||
const { AccessController } = require("@budibase/backend-core/roles")
|
roles,
|
||||||
const { getAppDB } = require("@budibase/backend-core/context")
|
} from "@budibase/backend-core"
|
||||||
const { events } = require("@budibase/backend-core")
|
import { updateAppPackage } from "./application"
|
||||||
const { getGlobalDB } = require("@budibase/backend-core/tenancy")
|
import { Plugin, ScreenProps } from "@budibase/types"
|
||||||
const { updateAppPackage } = require("./application")
|
|
||||||
|
|
||||||
exports.fetch = async ctx => {
|
exports.fetch = async (ctx: any) => {
|
||||||
const db = getAppDB()
|
const db = context.getAppDB()
|
||||||
|
|
||||||
const screens = (
|
const screens = (
|
||||||
await db.allDocs(
|
await db.allDocs(
|
||||||
|
@ -19,16 +18,16 @@ exports.fetch = async ctx => {
|
||||||
include_docs: true,
|
include_docs: true,
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
).rows.map(element => element.doc)
|
).rows.map((el: any) => el.doc)
|
||||||
|
|
||||||
ctx.body = await new AccessController().checkScreensAccess(
|
ctx.body = await new roles.AccessController().checkScreensAccess(
|
||||||
screens,
|
screens,
|
||||||
ctx.user.role._id
|
ctx.user.role._id
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
exports.save = async ctx => {
|
exports.save = async (ctx: any) => {
|
||||||
const db = getAppDB()
|
const db = context.getAppDB()
|
||||||
let screen = ctx.request.body
|
let screen = ctx.request.body
|
||||||
|
|
||||||
let eventFn
|
let eventFn
|
||||||
|
@ -40,19 +39,19 @@ exports.save = async ctx => {
|
||||||
const response = await db.put(screen)
|
const response = await db.put(screen)
|
||||||
|
|
||||||
// Find any custom components being used
|
// Find any custom components being used
|
||||||
let pluginNames = []
|
let pluginNames: string[] = []
|
||||||
let pluginAdded = false
|
let pluginAdded = false
|
||||||
findPlugins(screen.props, pluginNames)
|
findPlugins(screen.props, pluginNames)
|
||||||
if (pluginNames.length) {
|
if (pluginNames.length) {
|
||||||
const globalDB = getGlobalDB()
|
const globalDB = tenancy.getGlobalDB()
|
||||||
const pluginsResponse = await globalDB.allDocs(
|
const pluginsResponse = await globalDB.allDocs(
|
||||||
getPluginParams(null, {
|
dbCore.getPluginParams(null, {
|
||||||
include_docs: true,
|
include_docs: true,
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
const requiredPlugins = pluginsResponse.rows
|
const requiredPlugins = pluginsResponse.rows
|
||||||
.map(row => row.doc)
|
.map((row: any) => row.doc)
|
||||||
.filter(plugin => {
|
.filter((plugin: Plugin) => {
|
||||||
return (
|
return (
|
||||||
plugin.schema.type === "component" &&
|
plugin.schema.type === "component" &&
|
||||||
pluginNames.includes(`plugin/${plugin.name}`)
|
pluginNames.includes(`plugin/${plugin.name}`)
|
||||||
|
@ -63,8 +62,8 @@ exports.save = async ctx => {
|
||||||
const application = await db.get(DocumentType.APP_METADATA)
|
const application = await db.get(DocumentType.APP_METADATA)
|
||||||
let usedPlugins = application.usedPlugins || []
|
let usedPlugins = application.usedPlugins || []
|
||||||
|
|
||||||
requiredPlugins.forEach(plugin => {
|
requiredPlugins.forEach((plugin: Plugin) => {
|
||||||
if (!usedPlugins.find(x => x._id === plugin._id)) {
|
if (!usedPlugins.find((x: Plugin) => x._id === plugin._id)) {
|
||||||
pluginAdded = true
|
pluginAdded = true
|
||||||
usedPlugins.push({
|
usedPlugins.push({
|
||||||
_id: plugin._id,
|
_id: plugin._id,
|
||||||
|
@ -93,8 +92,8 @@ exports.save = async ctx => {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
exports.destroy = async ctx => {
|
exports.destroy = async (ctx: any) => {
|
||||||
const db = getAppDB()
|
const db = context.getAppDB()
|
||||||
const id = ctx.params.screenId
|
const id = ctx.params.screenId
|
||||||
const screen = await db.get(id)
|
const screen = await db.get(id)
|
||||||
|
|
||||||
|
@ -107,7 +106,7 @@ exports.destroy = async ctx => {
|
||||||
ctx.status = 200
|
ctx.status = 200
|
||||||
}
|
}
|
||||||
|
|
||||||
const findPlugins = (component, foundPlugins) => {
|
const findPlugins = (component: ScreenProps, foundPlugins: string[]) => {
|
||||||
if (!component) {
|
if (!component) {
|
||||||
return
|
return
|
||||||
}
|
}
|
|
@ -1,5 +1,17 @@
|
||||||
import { Document } from "../document"
|
import { Document } from "../document"
|
||||||
|
|
||||||
|
export interface ScreenProps extends Document {
|
||||||
|
_instanceName: string
|
||||||
|
_styles: { [key: string]: any }
|
||||||
|
_component: string
|
||||||
|
_children: ScreenProps[]
|
||||||
|
size?: string
|
||||||
|
gap?: string
|
||||||
|
direction?: string
|
||||||
|
vAlign?: string
|
||||||
|
hAlign?: string
|
||||||
|
}
|
||||||
|
|
||||||
export interface Screen extends Document {
|
export interface Screen extends Document {
|
||||||
layoutId?: string
|
layoutId?: string
|
||||||
showNavigation?: boolean
|
showNavigation?: boolean
|
||||||
|
@ -9,4 +21,5 @@ export interface Screen extends Document {
|
||||||
roleId: string
|
roleId: string
|
||||||
homeScreen?: boolean
|
homeScreen?: boolean
|
||||||
}
|
}
|
||||||
|
props: ScreenProps
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue