make it easy for users to create children
This commit is contained in:
parent
33183ff1e9
commit
f0a584a20a
|
@ -49,6 +49,10 @@ export const getBackendUiStore = () => {
|
||||||
state.breadcrumbs = [state.selectedDatabase.name, record.id]
|
state.breadcrumbs = [state.selectedDatabase.name, record.id]
|
||||||
return state
|
return state
|
||||||
}),
|
}),
|
||||||
|
select: record => store.update(state => {
|
||||||
|
state.selectedRecord = record
|
||||||
|
return state
|
||||||
|
})
|
||||||
},
|
},
|
||||||
views: {
|
views: {
|
||||||
select: view => store.update(state => {
|
select: view => store.update(state => {
|
||||||
|
@ -59,6 +63,13 @@ export const getBackendUiStore = () => {
|
||||||
modals: {
|
modals: {
|
||||||
show: modal => store.update(state => ({ ...state, visibleModal: modal })),
|
show: modal => store.update(state => ({ ...state, visibleModal: modal })),
|
||||||
hide: () => store.update(state => ({ ...state, visibleModal: null }))
|
hide: () => store.update(state => ({ ...state, visibleModal: null }))
|
||||||
|
},
|
||||||
|
users: {
|
||||||
|
create: user => store.update(state => {
|
||||||
|
state.users.push(user)
|
||||||
|
state.users = state.users
|
||||||
|
return state
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -29,6 +29,8 @@
|
||||||
<ActionButton color="secondary" on:click={store.saveCurrentNode}>
|
<ActionButton color="secondary" on:click={store.saveCurrentNode}>
|
||||||
Save
|
Save
|
||||||
</ActionButton>
|
</ActionButton>
|
||||||
|
|
||||||
|
<slot />
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -21,7 +21,9 @@
|
||||||
const indexableRecordsFromIndex = compose(
|
const indexableRecordsFromIndex = compose(
|
||||||
map(node => ({
|
map(node => ({
|
||||||
node,
|
node,
|
||||||
isallowed: index.allowedRecordNodeIds.some(id => node.nodeId === id),
|
isallowed:
|
||||||
|
index.allowedRecordNodeIds &&
|
||||||
|
index.allowedRecordNodeIds.some(id => node.nodeId === id),
|
||||||
})),
|
})),
|
||||||
filter(hierarchyFunctions.isRecord),
|
filter(hierarchyFunctions.isRecord),
|
||||||
filter(hierarchyFunctions.isDecendant($store.currentNode.parent())),
|
filter(hierarchyFunctions.isDecendant($store.currentNode.parent())),
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
<script>
|
<script>
|
||||||
import { onMount } from "svelte"
|
import { onMount } from "svelte"
|
||||||
import { store, backendUiStore } from "../../../builderStore"
|
import { store, backendUiStore } from "../../../builderStore"
|
||||||
import { findIndex } from "lodash/fp"
|
import { compose, map, get, flatten } from "lodash/fp"
|
||||||
import Modal from "../../../common/Modal.svelte"
|
import Modal from "../../../common/Modal.svelte"
|
||||||
import ActionButton from "../../../common/ActionButton.svelte"
|
import ActionButton from "../../../common/ActionButton.svelte"
|
||||||
import Select from "../../../common/Select.svelte"
|
import Select from "../../../common/Select.svelte"
|
||||||
|
@ -13,12 +13,20 @@
|
||||||
|
|
||||||
let selectedModel
|
let selectedModel
|
||||||
|
|
||||||
|
const childModelsForModel = compose(
|
||||||
|
flatten,
|
||||||
|
map("children"),
|
||||||
|
get("children")
|
||||||
|
)
|
||||||
|
|
||||||
$: currentAppInfo = {
|
$: currentAppInfo = {
|
||||||
appname: $store.appname,
|
appname: $store.appname,
|
||||||
instanceId: $backendUiStore.selectedDatabase.id,
|
instanceId: $backendUiStore.selectedDatabase.id,
|
||||||
}
|
}
|
||||||
$: recordFields = record ? Object.keys(record) : []
|
$: recordFields = record ? Object.keys(record) : []
|
||||||
$: models = $store.hierarchy.children
|
$: models = $backendUiStore.selectedRecord
|
||||||
|
? childModelsForModel($store.hierarchy)
|
||||||
|
: $store.hierarchy.children
|
||||||
$: modelFields = selectedModel
|
$: modelFields = selectedModel
|
||||||
? selectedModel.fields.map(({ name }) => name)
|
? selectedModel.fields.map(({ name }) => name)
|
||||||
: []
|
: []
|
||||||
|
@ -77,10 +85,7 @@
|
||||||
</form>
|
</form>
|
||||||
<footer>
|
<footer>
|
||||||
<ActionButton alert on:click={onClosed}>Cancel</ActionButton>
|
<ActionButton alert on:click={onClosed}>Cancel</ActionButton>
|
||||||
<ActionButton
|
<ActionButton on:click={saveRecord}>Save</ActionButton>
|
||||||
on:click={saveRecord}>
|
|
||||||
Save
|
|
||||||
</ActionButton>
|
|
||||||
</footer>
|
</footer>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -17,16 +17,18 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
async function createUser() {
|
async function createUser() {
|
||||||
const response = await api.createUser(
|
const user = {
|
||||||
password,
|
name: username,
|
||||||
{
|
|
||||||
name:username,
|
|
||||||
accessLevels,
|
accessLevels,
|
||||||
enabled: true,
|
enabled: true,
|
||||||
temporaryAccessId: ""
|
temporaryAccessId: "",
|
||||||
},
|
}
|
||||||
|
const response = await api.createUser(
|
||||||
|
password,
|
||||||
|
user,
|
||||||
currentAppInfo
|
currentAppInfo
|
||||||
)
|
)
|
||||||
|
backendUiStore.actions.users.save(user)
|
||||||
onClosed()
|
onClosed()
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
|
@ -2,12 +2,14 @@
|
||||||
import Textbox from "../common/Textbox.svelte"
|
import Textbox from "../common/Textbox.svelte"
|
||||||
import Button from "../common/Button.svelte"
|
import Button from "../common/Button.svelte"
|
||||||
import Select from "../common/Select.svelte"
|
import Select from "../common/Select.svelte"
|
||||||
|
import ActionButton from "../common/ActionButton.svelte"
|
||||||
import getIcon from "../common/icon"
|
import getIcon from "../common/icon"
|
||||||
import FieldView from "./FieldView.svelte"
|
import FieldView from "./FieldView.svelte"
|
||||||
import Modal from "../common/Modal.svelte"
|
import Modal from "../common/Modal.svelte"
|
||||||
import { map, join, filter, some, find, keys, isDate } from "lodash/fp"
|
import { map, join, filter, some, find, keys, isDate } from "lodash/fp"
|
||||||
import { store } from "../builderStore"
|
import { store } from "../builderStore"
|
||||||
import { common, hierarchy } from "../../../core/src"
|
import { common, hierarchy } from "../../../core/src"
|
||||||
|
import { getNode } from "../common/core"
|
||||||
import { templateApi, pipe, validate } from "../common/core"
|
import { templateApi, pipe, validate } from "../common/core"
|
||||||
import ActionsHeader from "./ActionsHeader.svelte"
|
import ActionsHeader from "./ActionsHeader.svelte"
|
||||||
import ErrorsBox from "../common/ErrorsBox.svelte"
|
import ErrorsBox from "../common/ErrorsBox.svelte"
|
||||||
|
@ -22,9 +24,11 @@
|
||||||
let deleteField
|
let deleteField
|
||||||
let onFinishedFieldEdit
|
let onFinishedFieldEdit
|
||||||
let editIndex
|
let editIndex
|
||||||
let parentRecord
|
|
||||||
|
|
||||||
$: models = $store.hierarchy.children
|
$: models = $store.hierarchy.children
|
||||||
|
$: parent = record && record.parent()
|
||||||
|
$: isChildModel = parent.name !== "root"
|
||||||
|
$: modelExistsInHierarchy = getNode($store.hierarchy, $store.currentNode.nodeId)
|
||||||
|
|
||||||
store.subscribe($store => {
|
store.subscribe($store => {
|
||||||
record = $store.currentNode
|
record = $store.currentNode
|
||||||
|
@ -107,23 +111,13 @@
|
||||||
|
|
||||||
<form class="uk-form-stacked">
|
<form class="uk-form-stacked">
|
||||||
|
|
||||||
<div class="horizontal-stack">
|
|
||||||
<Textbox label="Name" bind:text={record.name} on:change={nameChanged} />
|
<Textbox label="Name" bind:text={record.name} on:change={nameChanged} />
|
||||||
|
{#if isChildModel}
|
||||||
<div>
|
<div>
|
||||||
<label class="uk-form-label">Parent</label>
|
<label class="uk-form-label">Parent</label>
|
||||||
<div class="uk-form-controls">
|
<div class="uk-form-controls parent-name">{parent.name}</div>
|
||||||
<Select
|
|
||||||
value={parentRecord}
|
|
||||||
on:change={e => {
|
|
||||||
store.selectExistingNode(record)
|
|
||||||
store.newChildRecord()
|
|
||||||
}}>
|
|
||||||
{#each models as model}
|
|
||||||
<option value={model}>{model.name}</option>
|
|
||||||
{/each}
|
|
||||||
</Select>
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
|
{/if}
|
||||||
</form>
|
</form>
|
||||||
|
|
||||||
<div class="table-controls">
|
<div class="table-controls">
|
||||||
|
@ -155,7 +149,13 @@
|
||||||
{/each}
|
{/each}
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
<ActionsHeader />
|
<ActionsHeader>
|
||||||
|
{#if modelExistsInHierarchy}
|
||||||
|
<ActionButton color="primary" on:click={store.newChildRecord}>
|
||||||
|
Create Child Model on {record.name}
|
||||||
|
</ActionButton>
|
||||||
|
{/if}
|
||||||
|
</ActionsHeader>
|
||||||
{:else}
|
{:else}
|
||||||
<FieldView
|
<FieldView
|
||||||
field={fieldToEdit}
|
field={fieldToEdit}
|
||||||
|
@ -170,11 +170,6 @@
|
||||||
height: 100%;
|
height: 100%;
|
||||||
}
|
}
|
||||||
|
|
||||||
.horizontal-stack {
|
|
||||||
display: flex;
|
|
||||||
justify-content: space-between
|
|
||||||
}
|
|
||||||
|
|
||||||
.new-field {
|
.new-field {
|
||||||
font-size: 16px;
|
font-size: 16px;
|
||||||
font-weight: bold;
|
font-weight: bold;
|
||||||
|
@ -208,4 +203,8 @@
|
||||||
h3 {
|
h3 {
|
||||||
margin: 0 0 0 10px;
|
margin: 0 0 0 10px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.parent-name {
|
||||||
|
font-weight: bold;
|
||||||
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|
|
@ -7,6 +7,7 @@
|
||||||
|
|
||||||
function selectDatabase(database) {
|
function selectDatabase(database) {
|
||||||
backendUiStore.actions.database.select(database)
|
backendUiStore.actions.database.select(database)
|
||||||
|
backendUiStore.actions.records.select(null)
|
||||||
backendUiStore.actions.navigate("DATABASE")
|
backendUiStore.actions.navigate("DATABASE")
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
|
@ -21,6 +21,10 @@
|
||||||
const FETCH_USERS_URL = `/_builder/instance/${currentAppInfo.appname}/${currentAppInfo.instanceId}/api/users`
|
const FETCH_USERS_URL = `/_builder/instance/${currentAppInfo.appname}/${currentAppInfo.instanceId}/api/users`
|
||||||
const response = await api.get(FETCH_USERS_URL);
|
const response = await api.get(FETCH_USERS_URL);
|
||||||
users = await response.json()
|
users = await response.json()
|
||||||
|
backendUiStore.update(state => {
|
||||||
|
state.users = users
|
||||||
|
return state
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
onMount(fetchUsers)
|
onMount(fetchUsers)
|
||||||
|
|
Loading…
Reference in New Issue