|
|
|
@ -13,17 +13,33 @@ |
|
|
|
|
|
|
|
const FIELD_TYPES = ["string", "number", "boolean"] |
|
|
|
|
|
|
|
export let field = { type: "string" } |
|
|
|
export let field = { type: "string", constraints: { type: "string", presence: false } } |
|
|
|
export let schema |
|
|
|
export let goBack |
|
|
|
|
|
|
|
let errors = [] |
|
|
|
let draftField = cloneDeep(field) |
|
|
|
|
|
|
|
let type = field.type |
|
|
|
let constraints = field.constraints |
|
|
|
let required = field.constraints.presence && !field.constraints.presence.allowEmpty |
|
|
|
|
|
|
|
const save = () => { |
|
|
|
constraints.presence = required ? { allowEmpty: false } : false |
|
|
|
draftField.constraints = constraints |
|
|
|
draftField.type = type |
|
|
|
schema[field.name] = draftField |
|
|
|
goBack() |
|
|
|
} |
|
|
|
|
|
|
|
$: constraints = |
|
|
|
type === "string" ? { type: "string", length: {}, presence: false } |
|
|
|
: type === "number" ? { type: "number", presence: false, numericality: {} } |
|
|
|
: type === "boolean" ? { type: "boolean", presence: false } |
|
|
|
: type === "datetime" ? { type: "date", datetime: {}, presence: false } |
|
|
|
: type.startsWith('array') ? { type: "array", presence: false } |
|
|
|
: { type: "string", presence: false } |
|
|
|
|
|
|
|
</script> |
|
|
|
|
|
|
|
<div class="root"> |
|
|
|
@ -34,30 +50,22 @@ |
|
|
|
<Textbox label="Name" bind:text={field.name} /> |
|
|
|
<Dropdown |
|
|
|
label="Type" |
|
|
|
bind:selected={draftField.type} |
|
|
|
bind:selected={type} |
|
|
|
options={FIELD_TYPES} /> |
|
|
|
|
|
|
|
<Checkbox label="Required" bind:checked={required} /> |
|
|
|
|
|
|
|
|
|
|
|
{#if field.type === 'string'} |
|
|
|
<NumberBox label="Max Length" bind:value={draftField.maxLength} /> |
|
|
|
<ValuesList label="Categories" bind:values={draftField.values} /> |
|
|
|
{:else if field.type === 'boolean'} |
|
|
|
{#if type === 'string'} |
|
|
|
<NumberBox label="Max Length" bind:value={constraints.length.maximum} /> |
|
|
|
<ValuesList label="Categories" bind:values={constraints.inclusion} /> |
|
|
|
{:else if type === 'datetime'} |
|
|
|
<!-- TODO: revisit and fix with JSON schema --> |
|
|
|
<Checkbox label="Allow Null" bind:checked={draftField.allowNulls} /> |
|
|
|
{:else if field.format === 'datetime'} |
|
|
|
<!-- TODO: revisit and fix with JSON schema --> |
|
|
|
<DatePicker label="Min Value" bind:value={draftField.minValue} /> |
|
|
|
<DatePicker label="Max Value" bind:value={draftField.maxValue} /> |
|
|
|
{:else if field.type === 'number'} |
|
|
|
<NumberBox label="Min Value" bind:value={draftField.minimum} /> |
|
|
|
<NumberBox label="Max Value" bind:value={draftField.maximum} /> |
|
|
|
{:else if draftField.type.startsWith('array')} |
|
|
|
<!-- TODO: revisit and fix with JSON schema --> |
|
|
|
<NumberBox |
|
|
|
label="Min Length" |
|
|
|
bind:value={draftField.typeOptions.minLength} /> |
|
|
|
<NumberBox |
|
|
|
label="Max Length" |
|
|
|
bind:value={draftField.typeOptions.maxLength} /> |
|
|
|
<DatePicker label="Min Value" bind:value={constraints.datetime.earliest} /> |
|
|
|
<DatePicker label="Max Value" bind:value={constraints.datetime.latest} /> |
|
|
|
{:else if type === 'number'} |
|
|
|
<NumberBox label="Min Value" bind:value={constraints.numericality.greaterThanOrEqualTo} /> |
|
|
|
<NumberBox label="Max Value" bind:value={constraints.numericality.lessThanOrEqualTo} /> |
|
|
|
{/if} |
|
|
|
</form> |
|
|
|
</div> |
|
|
|
|