2020-08-07 17:13:57 +02:00
|
|
|
<script>
|
|
|
|
import { onMount } from "svelte"
|
|
|
|
import { Input, TextArea, Button, Select } from "@budibase/bbui"
|
|
|
|
import { store, backendUiStore } from "builderStore"
|
|
|
|
import { FIELDS } from "constants/backend"
|
|
|
|
import { notifier } from "builderStore/store/notifications"
|
|
|
|
import Dropdown from "components/common/Dropdown.svelte"
|
|
|
|
import Textbox from "components/common/Textbox.svelte"
|
|
|
|
import ButtonGroup from "components/common/ButtonGroup.svelte"
|
|
|
|
import NumberBox from "components/common/NumberBox.svelte"
|
|
|
|
import ValuesList from "components/common/ValuesList.svelte"
|
|
|
|
import ErrorsBox from "components/common/ErrorsBox.svelte"
|
|
|
|
import Checkbox from "components/common/Checkbox.svelte"
|
|
|
|
import ActionButton from "components/common/ActionButton.svelte"
|
|
|
|
import DatePicker from "components/common/DatePicker.svelte"
|
|
|
|
import LinkedRecordSelector from "components/common/LinkedRecordSelector.svelte"
|
|
|
|
import * as api from "../api"
|
|
|
|
|
|
|
|
export let onClosed
|
|
|
|
export let field = {}
|
|
|
|
|
2020-08-10 16:34:37 +02:00
|
|
|
let originalName = field.name
|
2020-08-07 18:41:20 +02:00
|
|
|
|
2020-08-07 17:13:57 +02:00
|
|
|
$: required =
|
|
|
|
field.constraints &&
|
|
|
|
field.constraints.presence &&
|
|
|
|
!field.constraints.presence.allowEmpty
|
|
|
|
$: if (field.type) {
|
|
|
|
field.constraints = FIELDS[field.type.toUpperCase()].constraints
|
|
|
|
}
|
|
|
|
|
|
|
|
async function saveColumn() {
|
2020-08-07 18:41:20 +02:00
|
|
|
backendUiStore.update(state => {
|
|
|
|
backendUiStore.actions.models.saveField({
|
|
|
|
originalName,
|
2020-08-11 12:23:07 +02:00
|
|
|
field,
|
2020-08-07 18:41:20 +02:00
|
|
|
})
|
2020-08-07 17:13:57 +02:00
|
|
|
|
2020-08-07 18:41:20 +02:00
|
|
|
return state
|
2020-08-07 17:13:57 +02:00
|
|
|
})
|
|
|
|
onClosed()
|
|
|
|
}
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<div class="actions">
|
2020-08-10 16:34:37 +02:00
|
|
|
<Input placeholder="Name" thin bind:value={field.name} />
|
2020-08-07 17:13:57 +02:00
|
|
|
|
|
|
|
<Select secondary thin bind:value={field.type}>
|
|
|
|
{#each Object.values(FIELDS) as field}
|
|
|
|
<option value={field.type}>{field.name}</option>
|
|
|
|
{/each}
|
|
|
|
</Select>
|
|
|
|
|
|
|
|
<div class="info">
|
|
|
|
<div class="field">
|
|
|
|
<label>Required</label>
|
|
|
|
<input
|
|
|
|
type="checkbox"
|
|
|
|
bind:checked={required}
|
|
|
|
on:change={() => (field.constraints.presence.allowEmpty = required)} />
|
|
|
|
</div>
|
|
|
|
|
|
|
|
{#if field.type === 'string'}
|
|
|
|
<NumberBox
|
|
|
|
label="Max Length"
|
|
|
|
bind:value={field.constraints.length.maximum} />
|
|
|
|
<ValuesList
|
|
|
|
label="Categories"
|
|
|
|
bind:values={field.constraints.inclusion} />
|
|
|
|
{:else if field.type === 'datetime'}
|
|
|
|
<DatePicker
|
|
|
|
label="Min Value"
|
|
|
|
bind:value={field.constraints.datetime.earliest} />
|
|
|
|
<DatePicker
|
|
|
|
label="Max Value"
|
|
|
|
bind:value={field.constraints.datetime.latest} />
|
|
|
|
{:else if field.type === 'number'}
|
|
|
|
<NumberBox
|
|
|
|
label="Min Value"
|
|
|
|
bind:value={field.constraints.numericality.greaterThanOrEqualTo} />
|
|
|
|
<NumberBox
|
|
|
|
label="Max Value"
|
|
|
|
bind:value={field.constraints.numericality.lessThanOrEqualTo} />
|
|
|
|
{:else if field.type === 'link'}
|
|
|
|
<div class="field">
|
|
|
|
<label>Link</label>
|
|
|
|
<select class="budibase__input" bind:value={field.modelId}>
|
|
|
|
<option value={''} />
|
|
|
|
{#each $backendUiStore.models as model}
|
|
|
|
{#if model._id !== $backendUiStore.draftModel._id}
|
|
|
|
<option value={model._id}>{model.name}</option>
|
|
|
|
{/if}
|
|
|
|
{/each}
|
|
|
|
</select>
|
|
|
|
</div>
|
|
|
|
{/if}
|
|
|
|
</div>
|
|
|
|
|
|
|
|
</div>
|
|
|
|
<footer>
|
|
|
|
<div class="button-margin-3">
|
|
|
|
<Button secondary on:click={onClosed}>Cancel</Button>
|
|
|
|
</div>
|
|
|
|
<div class="button-margin-4">
|
|
|
|
<Button primary on:click={saveColumn}>Save Column</Button>
|
|
|
|
</div>
|
|
|
|
</footer>
|
|
|
|
|
|
|
|
<style>
|
|
|
|
.actions {
|
2020-08-11 12:23:07 +02:00
|
|
|
padding: var(--spacing-l) var(--spacing-xl);
|
2020-08-07 17:13:57 +02:00
|
|
|
display: grid;
|
|
|
|
grid-gap: var(--spacing-xl);
|
|
|
|
}
|
|
|
|
|
|
|
|
footer {
|
|
|
|
padding: 20px 30px;
|
|
|
|
display: grid;
|
|
|
|
grid-template-columns: 1fr 1fr 1fr 1fr;
|
|
|
|
gap: 20px;
|
|
|
|
background: var(--grey-1);
|
|
|
|
border-bottom-left-radius: 0.5rem;
|
|
|
|
border-bottom-left-radius: 0.5rem;
|
|
|
|
}
|
|
|
|
|
|
|
|
.field {
|
|
|
|
margin-top: var(--spacing-xl);
|
|
|
|
margin-bottom: var(--spacing-xl);
|
|
|
|
}
|
|
|
|
|
|
|
|
.button-margin-3 {
|
|
|
|
grid-column-start: 3;
|
|
|
|
display: grid;
|
|
|
|
}
|
|
|
|
|
|
|
|
.button-margin-4 {
|
|
|
|
grid-column-start: 4;
|
|
|
|
display: grid;
|
|
|
|
}
|
|
|
|
</style>
|