1
0
Fork 0
mirror of synced 2024-09-20 11:27:56 +12:00
budibase/packages/builder/src/components/userInterface/NewScreen.svelte

160 lines
3.8 KiB
Svelte
Raw Normal View History

<script>
import { store } from "builderStore"
2020-02-03 22:50:30 +13:00
import PropsView from "./PropsView.svelte"
import Textbox from "components/common/Textbox.svelte"
import Button from "components/common/Button.svelte"
import ActionButton from "components/common/ActionButton.svelte"
import ButtonGroup from "components/common/ButtonGroup.svelte"
import ConfirmDialog from "components/common/ConfirmDialog.svelte"
import { pipe } from "components/common/core"
2020-02-03 22:50:30 +13:00
import UIkit from "uikit"
import { isRootComponent } from "./pagesParsing/searchComponents"
import { splitName } from "./pagesParsing/splitRootComponentName.js"
import { find, filter, some, map, includes } from "lodash/fp"
import { assign } from "lodash"
export const show = () => {
dialog.show()
2020-02-03 22:50:30 +13:00
}
let dialog
2020-02-03 22:50:30 +13:00
let layoutComponents
let layoutComponent
let screens
let name = ""
2020-02-26 04:21:23 +13:00
2020-02-03 22:50:30 +13:00
let saveAttempted = false
$: layoutComponents = pipe(
$store.components,
[
filter(c => c.container),
map(c => ({ name: c.name, ...splitName(c.name) })),
]
)
2020-02-03 22:50:30 +13:00
2020-02-25 23:01:07 +13:00
$: layoutComponent = layoutComponent
2020-02-26 04:21:23 +13:00
? find(c => c.name === layoutComponent.name)(layoutComponents)
: layoutComponents[0]
2020-02-03 22:50:30 +13:00
2020-02-25 23:01:07 +13:00
$: screens = $store.screens
$: route = !route && screens.length === 0 ? "*" : route
2020-02-03 22:50:30 +13:00
const save = () => {
saveAttempted = true
const isValid =
2020-02-26 04:21:23 +13:00
name.length > 0 &&
!screenNameExists(name) &&
route.length > 0 &&
!routeNameExists(route) &&
layoutComponent
2020-02-03 22:50:30 +13:00
if (!isValid) return
store.createScreen(name, route, layoutComponent.name)
dialog.hide()
2020-02-03 22:50:30 +13:00
}
const cancel = () => {
dialog.hide()
2020-02-03 22:50:30 +13:00
}
const screenNameExists = name => {
return some(s => {
return s.name.toLowerCase() === name.toLowerCase()
})(screens)
}
2020-02-25 23:01:07 +13:00
const routeNameExists = route => {
return some(s => {
return s.route.toLowerCase() === route.toLowerCase()
})(screens)
}
const routeChanged = event => {
const r = event.target.value
if (!r.startsWith("/")) {
route = "/" + r
}
}
</script>
<ConfirmDialog
bind:this={dialog}
title="New Screen"
onCancel={cancel}
onOk={save}
okText="Create Screen">
<div class="uk-form-horizontal">
<div class="uk-margin">
<label class="uk-form-label">Name</label>
<div class="uk-form-controls">
<input
class="uk-input uk-form-small"
class:uk-form-danger={saveAttempted && (name.length === 0 || screenNameExists(name))}
bind:value={name} />
</div>
</div>
<div class="uk-margin">
<label class="uk-form-label">Route (Url)</label>
<div class="uk-form-controls">
<input
class="uk-input uk-form-small"
class:uk-form-danger={saveAttempted && (route.length === 0 || routeNameExists(route))}
bind:value={route}
on:change={routeChanged} />
2020-02-03 22:50:30 +13:00
</div>
</div>
2020-02-03 22:50:30 +13:00
<div class="uk-margin">
<label class="uk-form-label">Layout Component</label>
<div class="uk-form-controls">
<select
class="uk-select uk-form-small"
bind:value={layoutComponent}
class:uk-form-danger={saveAttempted && !layoutComponent}>
{#each layoutComponents as comp}
2020-03-28 05:58:32 +13:00
<option value={comp}>{comp.componentName} - {comp.libName}</option>
{/each}
</select>
2020-02-03 22:50:30 +13:00
</div>
2019-10-07 18:03:41 +13:00
</div>
2020-02-03 22:50:30 +13:00
</div>
2019-10-07 18:03:41 +13:00
</ConfirmDialog>
2020-03-24 23:56:48 +13:00
<style>
2020-03-28 05:58:32 +13:00
.uk-margin {
display: flex;
flex-direction: column;
}
2020-03-24 23:56:48 +13:00
2020-03-28 05:58:32 +13:00
.uk-form-controls {
margin-left: 0 !important;
}
2020-03-24 23:56:48 +13:00
2020-03-28 05:58:32 +13:00
.uk-form-label {
padding-bottom: 10px;
font-weight: 500;
font-size: 16px;
color: var(--secondary80);
}
2020-03-24 23:56:48 +13:00
2020-03-28 05:58:32 +13:00
.uk-input {
height: 40px !important;
border-radius: 3px;
}
.uk-select {
height: 40px !important;
font-weight: 500px;
color: var(--secondary60);
border: 1px solid var(--slate);
border-radius: 3px;
}
</style>