mirror of https://github.com/Budibase/budibase.git
141 changed files with 3435 additions and 1664 deletions
@ -0,0 +1,23 @@ |
|||||
|
<script> |
||||
|
import { TextButton as Button, Modal } from "@budibase/bbui" |
||||
|
import EditRolesModal from "../modals/EditRoles.svelte" |
||||
|
|
||||
|
let modal |
||||
|
</script> |
||||
|
|
||||
|
<div> |
||||
|
<Button text small on:click={modal.show}> |
||||
|
<i class="ri-lock-line" /> |
||||
|
Edit Roles |
||||
|
</Button> |
||||
|
</div> |
||||
|
<Modal bind:this={modal}> |
||||
|
<EditRolesModal /> |
||||
|
</Modal> |
||||
|
|
||||
|
<style> |
||||
|
i { |
||||
|
margin-right: var(--spacing-xs); |
||||
|
font-size: var(--font-size-s); |
||||
|
} |
||||
|
</style> |
||||
@ -0,0 +1,101 @@ |
|||||
|
<script> |
||||
|
import { onMount } from "svelte" |
||||
|
import { backendUiStore } from "builderStore" |
||||
|
import { notifier } from "builderStore/store/notifications" |
||||
|
import RowFieldControl from "../RowFieldControl.svelte" |
||||
|
import * as backendApi from "../api" |
||||
|
import builderApi from "builderStore/api" |
||||
|
import { ModalContent, Select } from "@budibase/bbui" |
||||
|
import ErrorsBox from "components/common/ErrorsBox.svelte" |
||||
|
|
||||
|
export let row = {} |
||||
|
|
||||
|
let errors = [] |
||||
|
let roles = [] |
||||
|
let rolesLoaded = false |
||||
|
|
||||
|
$: creating = row?._id == null |
||||
|
$: table = row.tableId |
||||
|
? $backendUiStore.tables.find(table => table._id === row?.tableId) |
||||
|
: $backendUiStore.selectedTable |
||||
|
$: tableSchema = getUserSchema(table) |
||||
|
$: customSchemaKeys = getCustomSchemaKeys(tableSchema) |
||||
|
|
||||
|
const getUserSchema = table => { |
||||
|
let schema = table?.schema ?? {} |
||||
|
if (schema.username) { |
||||
|
schema.username.name = "Username" |
||||
|
} |
||||
|
return schema |
||||
|
} |
||||
|
|
||||
|
const getCustomSchemaKeys = schema => { |
||||
|
let customSchema = { ...schema } |
||||
|
delete customSchema["email"] |
||||
|
delete customSchema["roleId"] |
||||
|
return Object.entries(customSchema) |
||||
|
} |
||||
|
|
||||
|
const saveRow = async () => { |
||||
|
const rowResponse = await backendApi.saveRow( |
||||
|
{ ...row, tableId: table._id }, |
||||
|
table._id |
||||
|
) |
||||
|
|
||||
|
if (rowResponse.errors) { |
||||
|
if (Array.isArray(rowResponse.errors)) { |
||||
|
errors = rowResponse.errors.map(error => ({ message: error })) |
||||
|
} else { |
||||
|
errors = Object.entries(rowResponse.errors) |
||||
|
.map(([key, error]) => ({ dataPath: key, message: error })) |
||||
|
.flat() |
||||
|
} |
||||
|
return false |
||||
|
} |
||||
|
|
||||
|
notifier.success("User saved successfully.") |
||||
|
backendUiStore.actions.rows.save(rowResponse) |
||||
|
} |
||||
|
|
||||
|
const fetchRoles = async () => { |
||||
|
const rolesResponse = await builderApi.get("/api/roles") |
||||
|
roles = await rolesResponse.json() |
||||
|
rolesLoaded = true |
||||
|
} |
||||
|
|
||||
|
onMount(fetchRoles) |
||||
|
</script> |
||||
|
|
||||
|
<ModalContent |
||||
|
title={creating ? 'Create User' : 'Edit User'} |
||||
|
confirmText={creating ? 'Create User' : 'Save User'} |
||||
|
onConfirm={saveRow}> |
||||
|
<ErrorsBox {errors} /> |
||||
|
<RowFieldControl |
||||
|
meta={{ ...tableSchema.email, name: 'Email' }} |
||||
|
bind:value={row.email} |
||||
|
readonly={!creating} /> |
||||
|
{#if creating} |
||||
|
<RowFieldControl |
||||
|
meta={{ name: 'password', type: 'password' }} |
||||
|
bind:value={row.password} /> |
||||
|
{/if} |
||||
|
<!-- Defer rendering this select until roles load, otherwise the initial |
||||
|
selection is always undefined --> |
||||
|
{#if rolesLoaded} |
||||
|
<Select |
||||
|
thin |
||||
|
secondary |
||||
|
label="Role" |
||||
|
data-cy="roleId-select" |
||||
|
bind:value={row.roleId}> |
||||
|
<option value="">Choose an option</option> |
||||
|
{#each roles as role} |
||||
|
<option value={role._id}>{role.name}</option> |
||||
|
{/each} |
||||
|
</Select> |
||||
|
{/if} |
||||
|
{#each customSchemaKeys as [key, meta]} |
||||
|
<RowFieldControl {meta} bind:value={row[key]} {creating} /> |
||||
|
{/each} |
||||
|
</ModalContent> |
||||
@ -0,0 +1,136 @@ |
|||||
|
<script> |
||||
|
import { ModalContent, Select, Input, Button } from "@budibase/bbui" |
||||
|
import { onMount } from "svelte" |
||||
|
import api from "builderStore/api" |
||||
|
import { notifier } from "builderStore/store/notifications" |
||||
|
import ErrorsBox from "components/common/ErrorsBox.svelte" |
||||
|
|
||||
|
let roles = [] |
||||
|
let permissions = [] |
||||
|
let selectedRole = {} |
||||
|
let errors = [] |
||||
|
$: selectedRoleId = selectedRole._id |
||||
|
$: otherRoles = roles.filter(role => role._id !== selectedRoleId) |
||||
|
$: isCreating = selectedRoleId == null || selectedRoleId === "" |
||||
|
|
||||
|
// Loads available roles and permissions from the server |
||||
|
const fetchRoles = async () => { |
||||
|
const rolesResponse = await api.get("/api/roles") |
||||
|
roles = await rolesResponse.json() |
||||
|
const permissionsResponse = await api.get("/api/permissions") |
||||
|
permissions = await permissionsResponse.json() |
||||
|
} |
||||
|
|
||||
|
// Changes the seleced role |
||||
|
const changeRole = event => { |
||||
|
const id = event?.target?.value |
||||
|
const role = roles.find(role => role._id === id) |
||||
|
if (role) { |
||||
|
selectedRole = { |
||||
|
...role, |
||||
|
inherits: role.inherits ?? "", |
||||
|
permissionId: role.permissionId ?? "", |
||||
|
} |
||||
|
} else { |
||||
|
selectedRole = { _id: "", inherits: "", permissionId: "" } |
||||
|
} |
||||
|
errors = [] |
||||
|
} |
||||
|
|
||||
|
// Saves or creates the selected role |
||||
|
const saveRole = async () => { |
||||
|
errors = [] |
||||
|
|
||||
|
// Clean up empty strings |
||||
|
const keys = ["_id", "inherits", "permissionId"] |
||||
|
keys.forEach(key => { |
||||
|
if (selectedRole[key] === "") { |
||||
|
delete selectedRole[key] |
||||
|
} |
||||
|
}) |
||||
|
|
||||
|
// Validation |
||||
|
if (!selectedRole.name || selectedRole.name.trim() === "") { |
||||
|
errors.push({ message: "Please enter a role name" }) |
||||
|
} |
||||
|
if (!selectedRole.permissionId) { |
||||
|
errors.push({ message: "Please choose permissions" }) |
||||
|
} |
||||
|
if (errors.length) { |
||||
|
return false |
||||
|
} |
||||
|
|
||||
|
// Save/create the role |
||||
|
const response = await api.post("/api/roles", selectedRole) |
||||
|
if (response.status === 200) { |
||||
|
notifier.success("Role saved successfully.") |
||||
|
} else { |
||||
|
notifier.danger("Error saving role.") |
||||
|
return false |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
// Deletes the selected role |
||||
|
const deleteRole = async () => { |
||||
|
const response = await api.delete( |
||||
|
`/api/roles/${selectedRole._id}/${selectedRole._rev}` |
||||
|
) |
||||
|
if (response.status === 200) { |
||||
|
await fetchRoles() |
||||
|
changeRole() |
||||
|
notifier.success("Role deleted successfully.") |
||||
|
} else { |
||||
|
notifier.danger("Error deleting role.") |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
onMount(fetchRoles) |
||||
|
</script> |
||||
|
|
||||
|
<ModalContent |
||||
|
title="Edit Roles" |
||||
|
confirmText={isCreating ? 'Create' : 'Save'} |
||||
|
onConfirm={saveRole}> |
||||
|
{#if errors.length} |
||||
|
<ErrorsBox {errors} /> |
||||
|
{/if} |
||||
|
<Select |
||||
|
thin |
||||
|
secondary |
||||
|
label="Role" |
||||
|
value={selectedRoleId} |
||||
|
on:change={changeRole}> |
||||
|
<option value="">Create new role</option> |
||||
|
{#each roles as role} |
||||
|
<option value={role._id}>{role.name}</option> |
||||
|
{/each} |
||||
|
</Select> |
||||
|
{#if selectedRole} |
||||
|
<Input label="Name" bind:value={selectedRole.name} thin /> |
||||
|
<Select |
||||
|
thin |
||||
|
secondary |
||||
|
label="Inherits Role" |
||||
|
bind:value={selectedRole.inherits}> |
||||
|
<option value="">None</option> |
||||
|
{#each otherRoles as role} |
||||
|
<option value={role._id}>{role.name}</option> |
||||
|
{/each} |
||||
|
</Select> |
||||
|
<Select |
||||
|
thin |
||||
|
secondary |
||||
|
label="Permissions" |
||||
|
bind:value={selectedRole.permissionId}> |
||||
|
<option value="">Choose permissions</option> |
||||
|
{#each permissions as permission} |
||||
|
<option value={permission._id}>{permission.name}</option> |
||||
|
{/each} |
||||
|
</Select> |
||||
|
{/if} |
||||
|
<div slot="footer"> |
||||
|
{#if !isCreating} |
||||
|
<Button red on:click={deleteRole}>Delete</Button> |
||||
|
{/if} |
||||
|
</div> |
||||
|
</ModalContent> |
||||
@ -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>
|
export { default } from "./iframeTemplate.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>` |
|
||||
|
|||||
@ -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> |
<script> |
||||
|
import { store } from "builderStore" |
||||
import { params } from "@sveltech/routify" |
import { params } from "@sveltech/routify" |
||||
store.actions.pages.select($params.page) |
|
||||
|
store.actions.layouts.select($params.layout) |
||||
</script> |
</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> |
<script> |
||||
import { goto } from "@sveltech/routify" |
import { goto } from "@sveltech/routify" |
||||
$goto("../main") |
import { FrontendTypes } from "constants" |
||||
|
|
||||
|
$goto(`../${FrontendTypes.SCREEN}`) |
||||
</script> |
</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("") |
|
||||
}) |
|
||||
}) |
|
||||
@ -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 |
|
||||
} |
|
||||
Some files were not shown because too many files changed in this diff
Loading…
Reference in new issue