mirror of https://github.com/Budibase/budibase.git
committed by
GitHub
115 changed files with 2141 additions and 1667 deletions
@ -0,0 +1,52 @@ |
|||
<html> |
|||
<head> |
|||
<link rel="stylesheet" href="https://rsms.me/inter/inter.css"> |
|||
<style> |
|||
body, html { |
|||
height: 100% !important; |
|||
font-family: Inter, sans-serif !important; |
|||
margin: 0 !important; |
|||
} |
|||
*, *:before, *:after { |
|||
box-sizing: border-box; |
|||
} |
|||
</style> |
|||
<script src='/assets/budibase-client.js'></script> |
|||
<script> |
|||
function receiveMessage(event) { |
|||
if (!event.data) { |
|||
return |
|||
} |
|||
|
|||
// Extract data from message |
|||
const { selectedComponentId, layout, screen } = JSON.parse(event.data) |
|||
|
|||
// Set some flags so the app knows we're in the builder |
|||
window["##BUDIBASE_IN_BUILDER##"] = true |
|||
window["##BUDIBASE_PREVIEW_LAYOUT##"] = layout |
|||
window["##BUDIBASE_PREVIEW_SCREEN##"] = screen |
|||
window["##BUDIBASE_SELECTED_COMPONENT_ID##"] = selectedComponentId |
|||
window["##BUDIBASE_PREVIEW_ID##"] = Math.random() |
|||
|
|||
// Initialise app |
|||
if (window.loadBudibase) { |
|||
loadBudibase() |
|||
} |
|||
} |
|||
|
|||
// Ignore clicks |
|||
["click", "mousedown"].forEach(type => { |
|||
document.addEventListener(type, function(e) { |
|||
e.preventDefault() |
|||
e.stopPropagation() |
|||
return false |
|||
}, true) |
|||
}) |
|||
|
|||
window.addEventListener("message", receiveMessage) |
|||
window.dispatchEvent(new Event("bb-ready")) |
|||
</script> |
|||
</head> |
|||
<body> |
|||
</body> |
|||
</html> |
|||
@ -1,55 +1 @@ |
|||
export default `<html>
|
|||
<head> |
|||
<link rel="stylesheet" href="https://rsms.me/inter/inter.css"> |
|||
<link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=Roboto+Mono"> |
|||
<style> |
|||
body, html { |
|||
height: 100% !important; |
|||
font-family: Inter !important; |
|||
margin: 0px !important; |
|||
} |
|||
*, *:before, *:after { |
|||
box-sizing: border-box; |
|||
} |
|||
</style> |
|||
<script src='/assets/budibase-client.js'></script> |
|||
<script> |
|||
function receiveMessage(event) { |
|||
if (!event.data) { |
|||
return |
|||
} |
|||
|
|||
// Extract data from message
|
|||
const { selectedComponentId, page, screen } = JSON.parse(event.data) |
|||
|
|||
// Set some flags so the app knows we're in the builder
|
|||
window["##BUDIBASE_IN_BUILDER##"] = true |
|||
window["##BUDIBASE_PREVIEW_PAGE##"] = page |
|||
window["##BUDIBASE_PREVIEW_SCREEN##"] = screen |
|||
window["##BUDIBASE_SELECTED_COMPONENT_ID##"] = selectedComponentId |
|||
window["##BUDIBASE_PREVIEW_ID##"] = Math.random() |
|||
|
|||
// Initialise app
|
|||
if (window.loadBudibase) { |
|||
loadBudibase() |
|||
} |
|||
} |
|||
|
|||
let selectedComponentStyle |
|||
|
|||
// Ignore clicks
|
|||
["click", "mousedown"].forEach(type => { |
|||
document.addEventListener(type, function(e) { |
|||
e.preventDefault() |
|||
e.stopPropagation() |
|||
return false |
|||
}, true) |
|||
}) |
|||
|
|||
window.addEventListener("message", receiveMessage) |
|||
window.dispatchEvent(new Event("bb-ready")) |
|||
</script> |
|||
</head> |
|||
<body> |
|||
</body> |
|||
</html>` |
|||
export { default } from "./iframeTemplate.html" |
|||
|
|||
@ -0,0 +1,77 @@ |
|||
<script> |
|||
import { goto } from "@sveltech/routify" |
|||
import { store } from "builderStore" |
|||
import { notifier } from "builderStore/store/notifications" |
|||
import ConfirmDialog from "components/common/ConfirmDialog.svelte" |
|||
import { DropdownMenu, Modal, ModalContent, Input } from "@budibase/bbui" |
|||
import { DropdownContainer, DropdownItem } from "components/common/Dropdowns" |
|||
import { cloneDeep } from "lodash/fp" |
|||
|
|||
export let layout |
|||
|
|||
let confirmDeleteDialog |
|||
let editLayoutNameModal |
|||
let dropdown |
|||
let anchor |
|||
let name = layout.name |
|||
|
|||
const deleteLayout = async () => { |
|||
try { |
|||
await store.actions.layouts.delete(layout) |
|||
notifier.success(`Layout ${layout.name} deleted successfully.`) |
|||
} catch (err) { |
|||
notifier.danger(`Error deleting layout: ${err.message}`) |
|||
} |
|||
} |
|||
|
|||
const saveLayout = async () => { |
|||
try { |
|||
const layoutToSave = cloneDeep(layout) |
|||
layoutToSave.name = name |
|||
await store.actions.layouts.save(layoutToSave) |
|||
notifier.success(`Layout saved successfully.`) |
|||
} catch (err) { |
|||
notifier.danger(`Error saving layout: ${err.message}`) |
|||
} |
|||
} |
|||
</script> |
|||
|
|||
<div bind:this={anchor} on:click|stopPropagation> |
|||
<div class="icon" on:click={() => dropdown.show()}> |
|||
<i class="ri-more-line" /> |
|||
</div> |
|||
<DropdownMenu bind:this={dropdown} {anchor} align="left"> |
|||
<DropdownContainer> |
|||
<DropdownItem |
|||
icon="ri-pencil-line" |
|||
title="Edit" |
|||
on:click={() => editLayoutNameModal.show()} /> |
|||
<DropdownItem |
|||
icon="ri-delete-bin-line" |
|||
title="Delete" |
|||
on:click={() => confirmDeleteDialog.show()} /> |
|||
</DropdownContainer> |
|||
</DropdownMenu> |
|||
</div> |
|||
<ConfirmDialog |
|||
bind:this={confirmDeleteDialog} |
|||
title="Confirm Deletion" |
|||
body={'Are you sure you wish to delete this layout?'} |
|||
okText="Delete Layout" |
|||
onOk={deleteLayout} /> |
|||
|
|||
<Modal bind:this={editLayoutNameModal}> |
|||
<ModalContent |
|||
title="Edit Layout Name" |
|||
confirmText="Save" |
|||
onConfirm={saveLayout} |
|||
disabled={!name}> |
|||
<Input thin type="text" label="Name" bind:value={name} /> |
|||
</ModalContent> |
|||
</Modal> |
|||
|
|||
<style> |
|||
.icon i { |
|||
font-size: 16px; |
|||
} |
|||
</style> |
|||
@ -0,0 +1,41 @@ |
|||
<script> |
|||
import { goto } from "@sveltech/routify" |
|||
import { FrontendTypes } from "constants" |
|||
import ComponentTree from "./ComponentNavigationTree/ComponentTree.svelte" |
|||
import LayoutDropdownMenu from "./ComponentNavigationTree/LayoutDropdownMenu.svelte" |
|||
import initDragDropStore from "./ComponentNavigationTree/dragDropStore" |
|||
import NavItem from "components/common/NavItem.svelte" |
|||
import { last } from "lodash/fp" |
|||
import { store, currentAsset, selectedComponent } from "builderStore" |
|||
import { writable } from "svelte/store" |
|||
|
|||
export let layout |
|||
|
|||
let confirmDeleteDialog |
|||
let componentToDelete = "" |
|||
|
|||
const dragDropStore = initDragDropStore() |
|||
|
|||
const selectLayout = () => { |
|||
store.actions.layouts.select(layout._id) |
|||
$goto(`./${layout._id}`) |
|||
} |
|||
</script> |
|||
|
|||
<NavItem |
|||
border={false} |
|||
icon="ri-layout-3-line" |
|||
text={layout.name} |
|||
withArrow |
|||
selected={$store.currentAssetId === layout._id} |
|||
opened={$store.currentAssetId === layout._id} |
|||
on:click={selectLayout}> |
|||
<LayoutDropdownMenu {layout} /> |
|||
</NavItem> |
|||
|
|||
{#if $store.currentAssetId === layout._id && layout.props?._children} |
|||
<ComponentTree |
|||
components={layout.props._children} |
|||
currentComponent={$selectedComponent} |
|||
{dragDropStore} /> |
|||
{/if} |
|||
@ -0,0 +1,13 @@ |
|||
<script> |
|||
import { store, currentAsset } from "builderStore" |
|||
import { Select } from "@budibase/bbui" |
|||
|
|||
export let value |
|||
</script> |
|||
|
|||
<Select bind:value extraThin secondary on:change> |
|||
<option value="">Choose an option</option> |
|||
{#each $store.layouts as layout} |
|||
<option value={layout._id}>{layout.name}</option> |
|||
{/each} |
|||
</Select> |
|||
@ -0,0 +1,26 @@ |
|||
<script> |
|||
import { goto } from "@sveltech/routify" |
|||
import api from "builderStore/api" |
|||
import { notifier } from "builderStore/store/notifications" |
|||
import { store, backendUiStore, allScreens } from "builderStore" |
|||
import { Input, ModalContent } from "@budibase/bbui" |
|||
import analytics from "analytics" |
|||
|
|||
const CONTAINER = "@budibase/standard-components/container" |
|||
|
|||
let name = "" |
|||
|
|||
async function save() { |
|||
try { |
|||
await store.actions.layouts.save({ name }) |
|||
$goto(`./${$store.currentAssetId}`) |
|||
notifier.success(`Layout ${name} created successfully`) |
|||
} catch (err) { |
|||
notifier.danger(`Error creating layout ${name}.`) |
|||
} |
|||
} |
|||
</script> |
|||
|
|||
<ModalContent title="Create Layout" confirmText="Create" onConfirm={save}> |
|||
<Input thin label="Name" bind:value={name} /> |
|||
</ModalContent> |
|||
@ -1,44 +0,0 @@ |
|||
<script> |
|||
import { goto } from "@sveltech/routify" |
|||
import ComponentTree from "./ComponentNavigationTree/ComponentTree.svelte" |
|||
import NavItem from "components/common/NavItem.svelte" |
|||
import { last } from "lodash/fp" |
|||
import { store } from "builderStore" |
|||
import { writable } from "svelte/store" |
|||
|
|||
export let layout |
|||
|
|||
let confirmDeleteDialog |
|||
let componentToDelete = "" |
|||
|
|||
const dragDropStore = writable({}) |
|||
|
|||
const lastPartOfName = c => |
|||
c && last(c.name ? c.name.split("/") : c._component.split("/")) |
|||
|
|||
$: _layout = { |
|||
component: layout, |
|||
title: lastPartOfName(layout), |
|||
} |
|||
|
|||
const setCurrentScreenToLayout = () => { |
|||
store.actions.selectPageOrScreen("page") |
|||
$goto("./:page/page-layout") |
|||
} |
|||
</script> |
|||
|
|||
<NavItem |
|||
border={false} |
|||
icon="ri-layout-3-line" |
|||
text="Master Screen" |
|||
withArrow |
|||
selected={$store.currentComponentInfo?._id === _layout.component.props._id} |
|||
opened={$store.currentPreviewItem?.name === _layout.title} |
|||
on:click={setCurrentScreenToLayout} /> |
|||
|
|||
{#if $store.currentPreviewItem?.name === _layout.title && _layout.component.props._children} |
|||
<ComponentTree |
|||
components={_layout.component.props._children} |
|||
currentComponent={$store.currentComponentInfo} |
|||
{dragDropStore} /> |
|||
{/if} |
|||
@ -1,3 +0,0 @@ |
|||
<script> |
|||
import ComponentsHierarchyChildren from "./ComponentsHierarchyChildren.svelte" |
|||
</script> |
|||
@ -1,60 +0,0 @@ |
|||
import { isPlainObject, isArray, cloneDeep } from "lodash/fp" |
|||
import { getExactComponent } from "./searchComponents" |
|||
|
|||
export const rename = (pages, screens, oldname, newname) => { |
|||
pages = cloneDeep(pages) |
|||
screens = cloneDeep(screens) |
|||
const changedScreens = [] |
|||
|
|||
const existingWithNewName = getExactComponent(screens, newname, true) |
|||
if (existingWithNewName) |
|||
return { |
|||
components: screens, |
|||
pages, |
|||
error: "Component by that name already exists", |
|||
} |
|||
|
|||
const traverseProps = props => { |
|||
let hasEdited = false |
|||
if (props._component && props._component === oldname) { |
|||
props._component = newname |
|||
hasEdited = true |
|||
} |
|||
|
|||
for (let propName in props) { |
|||
const prop = props[propName] |
|||
if (isPlainObject(prop) && prop._component) { |
|||
hasEdited = traverseProps(prop) || hasEdited |
|||
} |
|||
if (isArray(prop)) { |
|||
for (let element of prop) { |
|||
hasEdited = traverseProps(element) || hasEdited |
|||
} |
|||
} |
|||
} |
|||
return hasEdited |
|||
} |
|||
|
|||
for (let screen of screens) { |
|||
let hasEdited = false |
|||
|
|||
if (screen.props.instanceName === oldname) { |
|||
screen.props.instanceName = newname |
|||
hasEdited = true |
|||
} |
|||
|
|||
hasEdited = traverseProps(screen.props) || hasEdited |
|||
|
|||
if (hasEdited && screen.props.instanceName !== newname) |
|||
changedScreens.push(screen.props.instanceName) |
|||
} |
|||
|
|||
for (let pageName in pages) { |
|||
const page = pages[pageName] |
|||
if (page.appBody === oldname) { |
|||
page.appBody = newname |
|||
} |
|||
} |
|||
|
|||
return { screens, pages, changedScreens } |
|||
} |
|||
@ -1,4 +1,6 @@ |
|||
<script> |
|||
import { store } from "builderStore" |
|||
import { params } from "@sveltech/routify" |
|||
store.actions.pages.select($params.page) |
|||
|
|||
store.actions.layouts.select($params.layout) |
|||
</script> |
|||
|
|||
@ -0,0 +1,63 @@ |
|||
<script> |
|||
import { params, leftover, goto } from "@sveltech/routify" |
|||
import { FrontendTypes } from "constants" |
|||
import { store, allScreens } from "builderStore" |
|||
|
|||
// Get any leftover params not caught by Routifys params store. |
|||
const componentIds = $leftover.split("/").filter(id => id !== "") |
|||
|
|||
const currentAssetId = decodeURI($params.asset) |
|||
|
|||
let assetList |
|||
let actions |
|||
|
|||
// Determine screens or layouts based on the URL |
|||
if ($params.assetType === FrontendTypes.SCREEN) { |
|||
assetList = $allScreens |
|||
actions = store.actions.screens |
|||
} else { |
|||
assetList = $store.layouts |
|||
actions = store.actions.layouts |
|||
} |
|||
|
|||
// select the screen or layout in the UI |
|||
actions.select(currentAssetId) |
|||
|
|||
// There are leftover stuff, like IDs, so navigate the components and find the ID and select it. |
|||
if ($leftover) { |
|||
// Get the correct screen children. |
|||
const assetChildren = assetList.find( |
|||
asset => |
|||
asset._id === $params.asset || |
|||
asset._id === decodeURIComponent($params.asset) |
|||
).props._children |
|||
findComponent(componentIds, assetChildren) |
|||
} |
|||
// } |
|||
|
|||
// Find Component with ID and continue |
|||
function findComponent(ids, children) { |
|||
// Setup stuff |
|||
let componentToSelect |
|||
let currentChildren = children |
|||
|
|||
// Loop through each ID |
|||
ids.forEach(id => { |
|||
// Find ID |
|||
const component = currentChildren.find(child => child._id === id) |
|||
|
|||
// If it does not exist, ignore (use last valid route) |
|||
if (!component) return |
|||
|
|||
componentToSelect = component |
|||
|
|||
// Update childrens array to selected components children |
|||
currentChildren = componentToSelect._children |
|||
}) |
|||
|
|||
// Select Component! |
|||
if (componentToSelect) store.actions.components.select(componentToSelect) |
|||
} |
|||
</script> |
|||
|
|||
<slot /> |
|||
@ -0,0 +1,17 @@ |
|||
<script> |
|||
import { store, allScreens } from "builderStore" |
|||
import { FrontendTypes } from "constants" |
|||
import { goto, params } from "@sveltech/routify" |
|||
|
|||
// Go to first layout |
|||
if ($params.assetType === FrontendTypes.LAYOUT) { |
|||
$goto(`../${$store.layouts[0]?._id}`) |
|||
} |
|||
|
|||
// Go to first screen |
|||
if ($params.assetType === FrontendTypes.SCREEN) { |
|||
$goto(`../${$allScreens[0]?._id}`) |
|||
} |
|||
</script> |
|||
|
|||
<!-- routify:options index=false --> |
|||
@ -1,69 +0,0 @@ |
|||
<script> |
|||
import { onMount } from "svelte" |
|||
import { params, leftover, goto } from "@sveltech/routify" |
|||
import { store, allScreens } from "builderStore" |
|||
|
|||
// Get any leftover params not caught by Routifys params store. |
|||
const componentIds = $leftover.split("/").filter(id => id !== "") |
|||
|
|||
// It's a screen, set it to that screen |
|||
if ($params.screen !== "page-layout") { |
|||
const currentScreenName = decodeURI($params.screen) |
|||
const validScreen = |
|||
$allScreens.findIndex(screen => screen._id === currentScreenName) !== -1 |
|||
|
|||
if (!validScreen) { |
|||
// Go to main layout if URL set to invalid screen |
|||
store.actions.pages.select("main") |
|||
$goto("../../main") |
|||
} else { |
|||
// Otherwise proceed to set screen |
|||
store.actions.screens.select(currentScreenName) |
|||
|
|||
// There are leftover stuff, like IDs, so navigate the components and find the ID and select it. |
|||
if ($leftover) { |
|||
// Get the correct screen children. |
|||
const screenChildren = $store.pages[$params.page]._screens.find( |
|||
screen => |
|||
screen._id === $params.screen || |
|||
screen._id === decodeURIComponent($params.screen) |
|||
).props._children |
|||
findComponent(componentIds, screenChildren) |
|||
} |
|||
} |
|||
} else { |
|||
// It's a page, so set the screentype to page. |
|||
store.actions.selectPageOrScreen("page") |
|||
|
|||
// There are leftover stuff, like IDs, so navigate the components and find the ID and select it. |
|||
if ($leftover) { |
|||
findComponent(componentIds, $store.pages[$params.page].props._children) |
|||
} |
|||
} |
|||
|
|||
// Find Component with ID and continue |
|||
function findComponent(ids, children) { |
|||
// Setup stuff |
|||
let componentToSelect |
|||
let currentChildren = children |
|||
|
|||
// Loop through each ID |
|||
ids.forEach(id => { |
|||
// Find ID |
|||
const component = currentChildren.find(child => child._id === id) |
|||
|
|||
// If it does not exist, ignore (use last valid route) |
|||
if (!component) return |
|||
|
|||
componentToSelect = component |
|||
|
|||
// Update childrens array to selected components children |
|||
currentChildren = componentToSelect._children |
|||
}) |
|||
|
|||
// Select Component! |
|||
if (componentToSelect) store.actions.components.select(componentToSelect) |
|||
} |
|||
</script> |
|||
|
|||
<slot /> |
|||
@ -1,8 +0,0 @@ |
|||
<script> |
|||
import { params } from "@sveltech/routify" |
|||
import { store } from "builderStore" |
|||
|
|||
store.actions.pages.select($params.page) |
|||
</script> |
|||
|
|||
<slot /> |
|||
@ -1,4 +0,0 @@ |
|||
<script> |
|||
import { goto } from "@sveltech/routify" |
|||
$goto("../page-layout") |
|||
</script> |
|||
@ -1,6 +1,8 @@ |
|||
<script> |
|||
import { goto } from "@sveltech/routify" |
|||
$goto("../main") |
|||
import { FrontendTypes } from "constants" |
|||
|
|||
$goto(`../${FrontendTypes.SCREEN}`) |
|||
</script> |
|||
|
|||
<!-- routify:options index=false --> |
|||
<!-- routify:options index=1 --> |
|||
|
|||
@ -1,51 +0,0 @@ |
|||
import { |
|||
generate_css, |
|||
generate_screen_css, |
|||
} from "../src/builderStore/generate_css.js" |
|||
|
|||
describe("generate_css", () => { |
|||
|
|||
|
|||
test("Check how array styles are output", () => { |
|||
expect(generate_css({ margin: ["0", "10", "0", "15"] })).toBe("margin: 0px 10px 0px 15px;") |
|||
}) |
|||
|
|||
test("Check handling of an array with empty string values", () => { |
|||
expect(generate_css({ padding: ["", "", "", ""] })).toBe("") |
|||
}) |
|||
|
|||
test("Check handling of an empty array", () => { |
|||
expect(generate_css({ margin: [] })).toBe("") |
|||
}) |
|||
|
|||
test("Check handling of valid font property", () => { |
|||
expect(generate_css({ "font-size": "10px" })).toBe("font-size: 10px;") |
|||
}) |
|||
}) |
|||
|
|||
|
|||
describe("generate_screen_css", () => { |
|||
const normalComponent = { _id: "123-456", _component: "@standard-components/header", _children: [], _styles: { normal: { "font-size": "16px" }, hover: {}, active: {}, selected: {} } } |
|||
|
|||
test("Test generation of normal css styles", () => { |
|||
expect(generate_screen_css([normalComponent])).toBe(".header-123-456 {\nfont-size: 16px;\n}") |
|||
}) |
|||
|
|||
const hoverComponent = { _id: "123-456", _component: "@standard-components/header", _children: [], _styles: { normal: {}, hover: {"font-size": "16px"}, active: {}, selected: {} } } |
|||
|
|||
test("Test generation of hover css styles", () => { |
|||
expect(generate_screen_css([hoverComponent])).toBe(".header-123-456:hover {\nfont-size: 16px;\n}") |
|||
}) |
|||
|
|||
const selectedComponent = { _id: "123-456", _component: "@standard-components/header", _children: [], _styles: { normal: {}, hover: {}, active: {}, selected: { "font-size": "16px" } } } |
|||
|
|||
test("Test generation of selection css styles", () => { |
|||
expect(generate_screen_css([selectedComponent])).toBe(".header-123-456::selection {\nfont-size: 16px;\n}") |
|||
}) |
|||
|
|||
const emptyComponent = { _id: "123-456", _component: "@standard-components/header", _children: [], _styles: { normal: {}, hover: {}, active: {}, selected: {} } } |
|||
|
|||
test.only("Testing handling of empty component styles", () => { |
|||
expect(generate_screen_css([emptyComponent])).toBe("") |
|||
}) |
|||
}) |
|||
@ -1,52 +0,0 @@ |
|||
const CouchDB = require("../../db") |
|||
const { |
|||
BUILTIN_LEVELS, |
|||
AccessLevel, |
|||
getAccessLevel, |
|||
} = require("../../utilities/security/accessLevels") |
|||
const { |
|||
generateAccessLevelID, |
|||
getAccessLevelParams, |
|||
} = require("../../db/utils") |
|||
|
|||
exports.fetch = async function(ctx) { |
|||
const db = new CouchDB(ctx.user.appId) |
|||
const body = await db.allDocs( |
|||
getAccessLevelParams(null, { |
|||
include_docs: true, |
|||
}) |
|||
) |
|||
const customAccessLevels = body.rows.map(row => row.doc) |
|||
|
|||
const staticAccessLevels = [BUILTIN_LEVELS.ADMIN, BUILTIN_LEVELS.POWER] |
|||
ctx.body = [...staticAccessLevels, ...customAccessLevels] |
|||
} |
|||
|
|||
exports.find = async function(ctx) { |
|||
ctx.body = await getAccessLevel(ctx.user.appId, ctx.params.levelId) |
|||
} |
|||
|
|||
exports.save = async function(ctx) { |
|||
const db = new CouchDB(ctx.user.appId) |
|||
|
|||
let id = ctx.request.body._id || generateAccessLevelID() |
|||
const level = new AccessLevel( |
|||
id, |
|||
ctx.request.body.name, |
|||
ctx.request.body.inherits |
|||
) |
|||
if (ctx.request.body._rev) { |
|||
level._rev = ctx.request.body._rev |
|||
} |
|||
const result = await db.put(level) |
|||
level._rev = result.rev |
|||
ctx.body = level |
|||
ctx.message = `Access Level '${level.name}' created successfully.` |
|||
} |
|||
|
|||
exports.destroy = async function(ctx) { |
|||
const db = new CouchDB(ctx.user.appId) |
|||
await db.remove(ctx.params.levelId, ctx.params.rev) |
|||
ctx.message = `Access Level ${ctx.params.id} deleted successfully` |
|||
ctx.status = 200 |
|||
} |
|||
@ -0,0 +1,43 @@ |
|||
const { EMPTY_LAYOUT } = require("../../constants/layouts") |
|||
const CouchDB = require("../../db") |
|||
const { generateLayoutID, getScreenParams } = require("../../db/utils") |
|||
|
|||
exports.save = async function(ctx) { |
|||
const db = new CouchDB(ctx.user.appId) |
|||
let layout = ctx.request.body |
|||
|
|||
if (!layout.props) { |
|||
layout = { |
|||
...layout, |
|||
...EMPTY_LAYOUT, |
|||
} |
|||
} |
|||
|
|||
layout._id = layout._id || generateLayoutID() |
|||
const response = await db.put(layout) |
|||
layout._rev = response.rev |
|||
|
|||
ctx.body = 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.layoutId) |
|||
if (layoutsUsedByScreens.includes(layoutId)) { |
|||
ctx.throw(400, "Cannot delete a base layout") |
|||
} |
|||
|
|||
await db.remove(layoutId, layoutRev) |
|||
ctx.message = "Layout deleted successfully" |
|||
ctx.status = 200 |
|||
} |
|||
@ -1,19 +0,0 @@ |
|||
const CouchDB = require("../../db/client") |
|||
const { generatePageID } = require("../../db/utils") |
|||
const compileStaticAssetsForPage = require("../../utilities/builder/compileStaticAssetsForPage") |
|||
|
|||
exports.save = async function(ctx) { |
|||
const db = new CouchDB(ctx.user.appId) |
|||
|
|||
const appPackage = ctx.request.body |
|||
|
|||
const page = await db.get(ctx.params.pageId) |
|||
await compileStaticAssetsForPage(ctx.user.appId, page.name, ctx.request.body) |
|||
|
|||
// remove special doc props which couch will complain about
|
|||
delete appPackage.page._css |
|||
delete appPackage.page._screens |
|||
appPackage.page._id = appPackage.page._id || generatePageID() |
|||
ctx.body = await db.put(appPackage.page) |
|||
ctx.status = 200 |
|||
} |
|||
@ -0,0 +1,45 @@ |
|||
const CouchDB = require("../../db") |
|||
const { |
|||
BUILTIN_ROLES, |
|||
Role, |
|||
getRole, |
|||
} = require("../../utilities/security/roles") |
|||
const { generateRoleID, getRoleParams } = require("../../db/utils") |
|||
|
|||
exports.fetch = async function(ctx) { |
|||
const db = new CouchDB(ctx.user.appId) |
|||
const body = await db.allDocs( |
|||
getRoleParams(null, { |
|||
include_docs: true, |
|||
}) |
|||
) |
|||
const customRoles = body.rows.map(row => row.doc) |
|||
|
|||
const staticRoles = [BUILTIN_ROLES.ADMIN, BUILTIN_ROLES.POWER] |
|||
ctx.body = [...staticRoles, ...customRoles] |
|||
} |
|||
|
|||
exports.find = async function(ctx) { |
|||
ctx.body = await getRole(ctx.user.appId, ctx.params.roleId) |
|||
} |
|||
|
|||
exports.save = async function(ctx) { |
|||
const db = new CouchDB(ctx.user.appId) |
|||
|
|||
let id = ctx.request.body._id || generateRoleID() |
|||
const role = new Role(id, ctx.request.body.name, ctx.request.body.inherits) |
|||
if (ctx.request.body._rev) { |
|||
role._rev = ctx.request.body._rev |
|||
} |
|||
const result = await db.put(role) |
|||
role._rev = result.rev |
|||
ctx.body = role |
|||
ctx.message = `Role '${role.name}' created successfully.` |
|||
} |
|||
|
|||
exports.destroy = async function(ctx) { |
|||
const db = new CouchDB(ctx.user.appId) |
|||
await db.remove(ctx.params.roleId, ctx.params.rev) |
|||
ctx.message = `Role ${ctx.params.id} deleted successfully` |
|||
ctx.status = 200 |
|||
} |
|||
@ -1,18 +0,0 @@ |
|||
const Router = require("@koa/router") |
|||
const controller = require("../controllers/accesslevel") |
|||
const authorized = require("../../middleware/authorized") |
|||
const { BUILDER } = require("../../utilities/security/permissions") |
|||
|
|||
const router = Router() |
|||
|
|||
router |
|||
.post("/api/accesslevels", authorized(BUILDER), controller.save) |
|||
.get("/api/accesslevels", authorized(BUILDER), controller.fetch) |
|||
.get("/api/accesslevels/:levelId", authorized(BUILDER), controller.find) |
|||
.delete( |
|||
"/api/accesslevels/:levelId/:rev", |
|||
authorized(BUILDER), |
|||
controller.destroy |
|||
) |
|||
|
|||
module.exports = router |
|||
@ -0,0 +1,16 @@ |
|||
const Router = require("@koa/router") |
|||
const authorized = require("../../middleware/authorized") |
|||
const { BUILDER } = require("../../utilities/security/permissions") |
|||
const controller = require("../controllers/layout") |
|||
|
|||
const router = Router() |
|||
|
|||
router |
|||
.post("/api/layouts", authorized(BUILDER), controller.save) |
|||
.delete( |
|||
"/api/layouts/:layoutId/:layoutRev", |
|||
authorized(BUILDER), |
|||
controller.destroy |
|||
) |
|||
|
|||
module.exports = router |
|||
@ -1,10 +0,0 @@ |
|||
const Router = require("@koa/router") |
|||
const authorized = require("../../middleware/authorized") |
|||
const { BUILDER } = require("../../utilities/security/permissions") |
|||
const controller = require("../controllers/page") |
|||
|
|||
const router = Router() |
|||
|
|||
router.post("/api/pages/:pageId", authorized(BUILDER), controller.save) |
|||
|
|||
module.exports = router |
|||
@ -0,0 +1,14 @@ |
|||
const Router = require("@koa/router") |
|||
const controller = require("../controllers/role") |
|||
const authorized = require("../../middleware/authorized") |
|||
const { BUILDER } = require("../../utilities/security/permissions") |
|||
|
|||
const router = Router() |
|||
|
|||
router |
|||
.post("/api/roles", authorized(BUILDER), controller.save) |
|||
.get("/api/roles", authorized(BUILDER), controller.fetch) |
|||
.get("/api/roles/:roleId", authorized(BUILDER), controller.find) |
|||
.delete("/api/roles/:roleId/:rev", authorized(BUILDER), controller.destroy) |
|||
|
|||
module.exports = router |
|||
@ -0,0 +1,46 @@ |
|||
const { generateAssetCss, generateCss } = require("../../../utilities/builder/generateCss") |
|||
|
|||
describe("generate_css", () => { |
|||
it("Check how array styles are output", () => { |
|||
expect(generateCss({ margin: ["0", "10", "0", "15"] })).toBe("margin: 0 10 0 15;") |
|||
}) |
|||
|
|||
it("Check handling of an array with empty string values", () => { |
|||
expect(generateCss({ padding: ["", "", "", ""] })).toBe("") |
|||
}) |
|||
|
|||
it("Check handling of an empty array", () => { |
|||
expect(generateCss({ margin: [] })).toBe("") |
|||
}) |
|||
|
|||
it("Check handling of valid font property", () => { |
|||
expect(generateCss({ "font-size": "10px" })).toBe("font-size: 10px;") |
|||
}) |
|||
}) |
|||
|
|||
|
|||
describe("generate_screen_css", () => { |
|||
const normalComponent = { _id: "123-456", _component: "@standard-components/header", _children: [], _styles: { normal: { "font-size": "16px" }, hover: {}, active: {}, selected: {} } } |
|||
|
|||
it("Test generation of normal css styles", () => { |
|||
expect(generateAssetCss([normalComponent])).toBe(".header-123-456 {\nfont-size: 16px;\n}") |
|||
}) |
|||
|
|||
const hoverComponent = { _id: "123-456", _component: "@standard-components/header", _children: [], _styles: { normal: {}, hover: {"font-size": "16px"}, active: {}, selected: {} } } |
|||
|
|||
it("Test generation of hover css styles", () => { |
|||
expect(generateAssetCss([hoverComponent])).toBe(".header-123-456:hover {\nfont-size: 16px;\n}") |
|||
}) |
|||
|
|||
const selectedComponent = { _id: "123-456", _component: "@standard-components/header", _children: [], _styles: { normal: {}, hover: {}, active: {}, selected: { "font-size": "16px" } } } |
|||
|
|||
it("Test generation of selection css styles", () => { |
|||
expect(generateAssetCss([selectedComponent])).toBe(".header-123-456::selection {\nfont-size: 16px;\n}") |
|||
}) |
|||
|
|||
const emptyComponent = { _id: "123-456", _component: "@standard-components/header", _children: [], _styles: { normal: {}, hover: {}, active: {}, selected: {} } } |
|||
|
|||
it("Testing handling of empty component styles", () => { |
|||
expect(generateAssetCss([emptyComponent])).toBe("") |
|||
}) |
|||
}) |
|||
Some files were not shown because too many files changed in this diff
Loading…
Reference in new issue