updates ModelView to use model instead of record
This commit is contained in:
parent
09758d7ee9
commit
17ab20fb8a
|
@ -23,8 +23,7 @@
|
||||||
import { templateApi, pipe, validate } from "components/common/core"
|
import { templateApi, pipe, validate } from "components/common/core"
|
||||||
import ErrorsBox from "components/common/ErrorsBox.svelte"
|
import ErrorsBox from "components/common/ErrorsBox.svelte"
|
||||||
|
|
||||||
let record
|
let model
|
||||||
let getIndexAllowedRecords
|
|
||||||
let editingField = false
|
let editingField = false
|
||||||
let fieldToEdit
|
let fieldToEdit
|
||||||
let isNewField = false
|
let isNewField = false
|
||||||
|
@ -34,23 +33,15 @@
|
||||||
let onFinishedFieldEdit
|
let onFinishedFieldEdit
|
||||||
let editIndex
|
let editIndex
|
||||||
|
|
||||||
$: models = $store.hierarchy.children
|
$: parent = model && model.parent()
|
||||||
$: parent = record && record.parent()
|
|
||||||
$: isChildModel = parent && parent.name !== "root"
|
$: isChildModel = parent && parent.name !== "root"
|
||||||
$: modelExistsInHierarchy =
|
$: modelExistsInHierarchy =
|
||||||
$store.currentNode && getNode($store.hierarchy, $store.currentNode.nodeId)
|
$store.currentNode && getNode($store.hierarchy, $store.currentNode.nodeId)
|
||||||
|
|
||||||
store.subscribe($store => {
|
store.subscribe($store => {
|
||||||
record = $store.currentNode
|
model = $store.currentNode
|
||||||
const flattened = hierarchy.getFlattenedHierarchy($store.hierarchy)
|
const flattened = hierarchy.getFlattenedHierarchy($store.hierarchy)
|
||||||
|
|
||||||
getIndexAllowedRecords = compose(
|
|
||||||
join(", "),
|
|
||||||
map(id => flattened.find(n => n.nodeId === id).name),
|
|
||||||
filter(id => flattened.some(n => n.nodeId === id)),
|
|
||||||
get("allowedRecordNodeIds")
|
|
||||||
)
|
|
||||||
|
|
||||||
newField = () => {
|
newField = () => {
|
||||||
isNewField = true
|
isNewField = true
|
||||||
fieldToEdit = templateApi($store.hierarchy).getNewField("string")
|
fieldToEdit = templateApi($store.hierarchy).getNewField("string")
|
||||||
|
@ -94,8 +85,8 @@
|
||||||
|
|
||||||
const nameChanged = ev => {
|
const nameChanged = ev => {
|
||||||
const pluralName = n => `${n}s`
|
const pluralName = n => `${n}s`
|
||||||
if (record.collectionName === "") {
|
if (model.collectionName === "") {
|
||||||
record.collectionName = pluralName(ev.target.value)
|
model.collectionName = pluralName(ev.target.value)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
@ -119,7 +110,7 @@
|
||||||
|
|
||||||
<form on:submit|preventDefault class="uk-form-stacked">
|
<form on:submit|preventDefault class="uk-form-stacked">
|
||||||
|
|
||||||
<Textbox label="Name" bind:text={record.name} on:change={nameChanged} />
|
<Textbox label="Name" bind:text={model.name} on:change={nameChanged} />
|
||||||
{#if isChildModel}
|
{#if isChildModel}
|
||||||
<div>
|
<div>
|
||||||
<label class="uk-form-label">Parent</label>
|
<label class="uk-form-label">Parent</label>
|
||||||
|
@ -144,7 +135,7 @@
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
{#each record ? record.fields : [] as field}
|
{#each model ? model.fields : [] as field}
|
||||||
<tr>
|
<tr>
|
||||||
<td>
|
<td>
|
||||||
<i class="ri-more-line" on:click={() => editField(field)} />
|
<i class="ri-more-line" on:click={() => editField(field)} />
|
||||||
|
@ -169,7 +160,7 @@
|
||||||
</ActionButton>
|
</ActionButton>
|
||||||
{#if modelExistsInHierarchy}
|
{#if modelExistsInHierarchy}
|
||||||
<ActionButton color="primary" on:click={store.newChildModel}>
|
<ActionButton color="primary" on:click={store.newChildModel}>
|
||||||
Create Child Model on {record.name}
|
Create Child Model on {model.name}
|
||||||
</ActionButton>
|
</ActionButton>
|
||||||
<ActionButton
|
<ActionButton
|
||||||
color="primary"
|
color="primary"
|
||||||
|
@ -178,7 +169,7 @@
|
||||||
await tick()
|
await tick()
|
||||||
store.newChildIndex()
|
store.newChildIndex()
|
||||||
}}>
|
}}>
|
||||||
Create Child View on {record.name}
|
Create Child View on {model.name}
|
||||||
</ActionButton>
|
</ActionButton>
|
||||||
<ActionButton alert on:click={store.deleteCurrentNode}>
|
<ActionButton alert on:click={store.deleteCurrentNode}>
|
||||||
Delete
|
Delete
|
||||||
|
@ -190,7 +181,7 @@
|
||||||
<FieldView
|
<FieldView
|
||||||
field={fieldToEdit}
|
field={fieldToEdit}
|
||||||
onFinished={onFinishedFieldEdit}
|
onFinished={onFinishedFieldEdit}
|
||||||
allFields={record.fields}
|
allFields={model.fields}
|
||||||
store={$store} />
|
store={$store} />
|
||||||
{/if}
|
{/if}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue