backend - routing based on models

This commit is contained in:
Michael Shanks 2020-06-30 14:12:37 +01:00
parent 94c1f16aa7
commit 85fe1cdcfe
11 changed files with 72 additions and 64 deletions

View File

@ -27,9 +27,6 @@ export const getBackendUiStore = () => {
const views = await viewsResponse.json() const views = await viewsResponse.json()
store.update(state => { store.update(state => {
state.selectedDatabase = db state.selectedDatabase = db
if (models && models.length > 0) {
store.actions.models.select(models[0])
}
state.models = models state.models = models
state.views = views state.views = views
return state return state

View File

@ -109,8 +109,8 @@ const setPackage = (store, initial) => async pkg => {
initial.builtins = [getBuiltin("##builtin/screenslot")] initial.builtins = [getBuiltin("##builtin/screenslot")]
initial.appInstances = pkg.application.instances initial.appInstances = pkg.application.instances
initial.appId = pkg.application._id initial.appId = pkg.application._id
store.set(initial) store.set(initial)
await backendUiStore.actions.database.select(initial.appInstances[0])
return initial return initial
} }

View File

@ -25,7 +25,7 @@
function selectModel(model, fieldId) { function selectModel(model, fieldId) {
backendUiStore.actions.models.select(model) backendUiStore.actions.models.select(model)
$goto(`./model/${model._id}`)
if (fieldId) { if (fieldId) {
backendUiStore.update(state => { backendUiStore.update(state => {
state.selectedField = fieldId state.selectedField = fieldId

View File

@ -1,36 +0,0 @@
<script>
import { store, backendUiStore } from "builderStore"
import { goto } from "@sveltech/routify"
import { onMount } from "svelte"
$: instances = $store.appInstances
async function selectDatabase(database) {
backendUiStore.actions.database.select(database)
}
onMount(async () => {
if ($store.appInstances.length > 0) {
await selectDatabase($store.appInstances[0])
$goto(`./${$backendUiStore.selectedDatabase._id}`)
}
})
</script>
<div class="root">
<div class="node-view">
<slot />
</div>
</div>
<style>
.root {
height: 100%;
position: relative;
}
.node-view {
overflow-y: auto;
flex: 1 1 auto;
}
</style>

View File

@ -1,20 +0,0 @@
<script>
import { store, backendUiStore } from "builderStore"
import { goto } from "@sveltech/routify"
import { onMount } from "svelte"
$: instances = $store.appInstances
async function selectDatabase(database) {
backendUiStore.actions.database.select(database)
}
onMount(async () => {
if ($store.appInstances.length > 0) {
await selectDatabase($store.appInstances[0])
$goto(`../${$backendUiStore.selectedDatabase._id}`)
}
})
</script>
Please select a database

View File

@ -1,6 +1,6 @@
<script> <script>
import { goto } from "@sveltech/routify" import { goto } from "@sveltech/routify"
$goto("../database") $goto("../model")
</script> </script>
<!-- routify:options index=false --> <!-- routify:options index=false -->

View File

@ -0,0 +1,14 @@
<script>
import { params } from "@sveltech/routify"
import { backendUiStore } from "builderStore"
if ($params.selectedModel) {
const model = $backendUiStore.models.find(m => m._id === $params.selectedModel)
if (model) {
backendUiStore.actions.models.select(model)
}
}
</script>
<slot />

View File

@ -3,7 +3,7 @@
import { Button } from "@budibase/bbui" import { Button } from "@budibase/bbui"
import EmptyModel from "components/nav/ModelNavigator/EmptyModel.svelte" import EmptyModel from "components/nav/ModelNavigator/EmptyModel.svelte"
import ModelDataTable from "components/database/ModelDataTable" import ModelDataTable from "components/database/ModelDataTable"
import { store, backendUiStore } from "builderStore" import { backendUiStore } from "builderStore"
import ActionButton from "components/common/ActionButton.svelte" import ActionButton from "components/common/ActionButton.svelte"
import * as api from "components/database/ModelDataTable/api" import * as api from "components/database/ModelDataTable/api"
import { CreateEditRecordModal } from "components/database/ModelDataTable/modals" import { CreateEditRecordModal } from "components/database/ModelDataTable/modals"

View File

@ -0,0 +1,33 @@
<script>
import { backendUiStore } from "builderStore"
import { goto, leftover } from "@sveltech/routify"
import { onMount } from "svelte"
async function selectModel(model) {
backendUiStore.actions.models.select(model)
}
onMount(async () => {
if (!$leftover && $backendUiStore.models.length > 0 && (!$backendUiStore.selectedModel || !$backendUiStore.selectedModel._id)) {
$goto(`./${$backendUiStore.models[0]._id}`)
}
})
</script>
<div class="root">
<div class="node-view">
<slot />
</div>
</div>
<style>
.root {
height: 100%;
position: relative;
}
.node-view {
overflow-y: auto;
flex: 1 1 auto;
}
</style>

View File

@ -0,0 +1,21 @@
<script>
import { store, backendUiStore } from "builderStore"
import { goto, leftover } from "@sveltech/routify"
import { onMount } from "svelte"
async function selectModel(model) {
backendUiStore.actions.models.select(model)
}
onMount(async () => {
if (!$leftover && $backendUiStore.models.length > 0 && (!$backendUiStore.selectedModel || !$backendUiStore.selectedModel._id)) {
$goto(`../${$backendUiStore.models[0]._id}`)
}
})
</script>
{#if $backendUiStore.models.length === 0}
Please create a model
{:else}
Please select a model
{/if}