mirror of https://github.com/Budibase/budibase.git
35 changed files with 1078 additions and 1155 deletions
@ -0,0 +1,84 @@ |
|||
<script> |
|||
import { Icon, Input, Drawer, Body, Button } from "@budibase/bbui" |
|||
import { |
|||
readableToRuntimeBinding, |
|||
runtimeToReadableBinding, |
|||
} from "builderStore/dataBinding" |
|||
import BindingPanel from "components/design/PropertiesPanel/BindingPanel.svelte" |
|||
import { createEventDispatcher } from "svelte" |
|||
const dispatch = createEventDispatcher() |
|||
|
|||
export let value = "" |
|||
export let bindings = [] |
|||
|
|||
let bindingDrawer |
|||
let tempValue = value |
|||
|
|||
$: readableValue = runtimeToReadableBinding(bindings, value) |
|||
|
|||
const handleClose = () => { |
|||
onChange(tempValue) |
|||
bindingDrawer.hide() |
|||
} |
|||
|
|||
const onChange = value => { |
|||
dispatch("change", readableToRuntimeBinding(bindings, value)) |
|||
} |
|||
</script> |
|||
|
|||
<div class="control"> |
|||
<Input |
|||
thin |
|||
value={readableValue} |
|||
on:change={event => onChange(event.target.value)} |
|||
placeholder="/screen" /> |
|||
<div class="icon" on:click={bindingDrawer.show}> |
|||
<Icon name="lightning" /> |
|||
</div> |
|||
</div> |
|||
<Drawer bind:this={bindingDrawer} title="Bindings"> |
|||
<div slot="description"> |
|||
<Body extraSmall grey> |
|||
Add the objects on the left to enrich your text. |
|||
</Body> |
|||
</div> |
|||
<heading slot="buttons"> |
|||
<Button thin blue on:click={handleClose}>Save</Button> |
|||
</heading> |
|||
<div slot="body"> |
|||
<BindingPanel |
|||
value={readableValue} |
|||
close={handleClose} |
|||
on:update={event => (tempValue = event.detail)} |
|||
bindableProperties={bindings} /> |
|||
</div> |
|||
</Drawer> |
|||
|
|||
<style> |
|||
.control { |
|||
flex: 1; |
|||
margin-left: var(--spacing-l); |
|||
position: relative; |
|||
} |
|||
|
|||
.icon { |
|||
right: 2px; |
|||
top: 2px; |
|||
bottom: 2px; |
|||
position: absolute; |
|||
align-items: center; |
|||
display: flex; |
|||
box-sizing: border-box; |
|||
padding-left: 7px; |
|||
border-left: 1px solid var(--grey-4); |
|||
background-color: var(--grey-2); |
|||
border-top-right-radius: var(--border-radius-m); |
|||
border-bottom-right-radius: var(--border-radius-m); |
|||
color: var(--grey-7); |
|||
font-size: 14px; |
|||
} |
|||
.icon:hover { |
|||
color: var(--ink); |
|||
cursor: pointer; |
|||
} |
|||
</style> |
|||
@ -1,80 +0,0 @@ |
|||
<script> |
|||
import { DataList } from "@budibase/bbui" |
|||
import { createEventDispatcher } from "svelte" |
|||
import { store, allScreens, currentAsset } from "builderStore" |
|||
import { getBindableProperties } from "builderStore/dataBinding" |
|||
|
|||
export let value = "" |
|||
|
|||
$: urls = getUrls($allScreens, $currentAsset, $store.selectedComponentId) |
|||
|
|||
// Update value on blur |
|||
const dispatch = createEventDispatcher() |
|||
const handleBlur = () => dispatch("change", value) |
|||
|
|||
// Get all valid screen URL, as well as detail screens which can be used in |
|||
// the current data context |
|||
const getUrls = (screens, asset, componentId) => { |
|||
// Get all screens which aren't detail screens |
|||
let urls = screens |
|||
.filter(screen => !screen.props._component.endsWith("/rowdetail")) |
|||
.map(screen => ({ |
|||
name: screen.props._instanceName, |
|||
url: screen.routing.route, |
|||
sort: screen.props._component, |
|||
})) |
|||
|
|||
// Add detail screens enriched with the current data context |
|||
const bindableProperties = getBindableProperties(asset.props, componentId) |
|||
screens |
|||
.filter(screen => screen.props._component.endsWith("/rowdetail")) |
|||
.forEach(detailScreen => { |
|||
// Find any _id bindings that match the detail screen's table |
|||
const binding = bindableProperties.find(p => { |
|||
return ( |
|||
p.type === "context" && |
|||
p.runtimeBinding.endsWith("._id") && |
|||
p.tableId === detailScreen.props.table |
|||
) |
|||
}) |
|||
if (binding) { |
|||
urls.push({ |
|||
name: detailScreen.props._instanceName, |
|||
url: detailScreen.routing.route.replace( |
|||
":id", |
|||
`{{ ${binding.runtimeBinding} }}` |
|||
), |
|||
sort: detailScreen.props._component, |
|||
}) |
|||
} |
|||
}) |
|||
|
|||
return urls |
|||
} |
|||
</script> |
|||
|
|||
<div> |
|||
<DataList |
|||
editable |
|||
secondary |
|||
extraThin |
|||
on:blur={handleBlur} |
|||
on:change |
|||
bind:value> |
|||
<option value="" /> |
|||
{#each urls as url} |
|||
<option value={url.url}>{url.name}</option> |
|||
{/each} |
|||
</DataList> |
|||
</div> |
|||
|
|||
<style> |
|||
div { |
|||
flex: 1 1 auto; |
|||
display: flex; |
|||
flex-direction: row; |
|||
} |
|||
div :global(> div) { |
|||
flex: 1 1 auto; |
|||
} |
|||
</style> |
|||
File diff suppressed because it is too large
@ -1,59 +0,0 @@ |
|||
<script> |
|||
import { Label, Multiselect } from "@budibase/bbui" |
|||
import { capitalise } from "./helpers" |
|||
import { getContext } from "svelte" |
|||
|
|||
const { API } = getContext("sdk") |
|||
|
|||
export let schema = {} |
|||
export let linkedRows = [] |
|||
export let showLabel = true |
|||
export let secondary |
|||
|
|||
let linkedTable |
|||
let allRows = [] |
|||
|
|||
$: label = capitalise(schema.name) |
|||
$: linkedTableId = schema.tableId |
|||
$: fetchRows(linkedTableId) |
|||
$: fetchTable(linkedTableId) |
|||
|
|||
async function fetchTable(id) { |
|||
if (id != null) { |
|||
linkedTable = await API.fetchTableDefinition(id) |
|||
} |
|||
} |
|||
|
|||
async function fetchRows(id) { |
|||
if (id != null) { |
|||
allRows = await API.fetchTableData(id) |
|||
} |
|||
} |
|||
|
|||
function getPrettyName(row) { |
|||
return row[(linkedTable && linkedTable.primaryDisplay) || "_id"] |
|||
} |
|||
</script> |
|||
|
|||
{#if linkedTable != null} |
|||
{#if linkedTable.primaryDisplay == null} |
|||
{#if showLabel} |
|||
<Label extraSmall grey>{label}</Label> |
|||
{/if} |
|||
<Label small black> |
|||
Please choose a display column for the |
|||
<b>{linkedTable.name}</b> |
|||
table. |
|||
</Label> |
|||
{:else} |
|||
<Multiselect |
|||
{secondary} |
|||
bind:value={linkedRows} |
|||
label={showLabel ? label : null} |
|||
placeholder="Choose some options"> |
|||
{#each allRows as row} |
|||
<option value={row._id}>{getPrettyName(row)}</option> |
|||
{/each} |
|||
</Multiselect> |
|||
{/if} |
|||
{/if} |
|||
Loading…
Reference in new issue