2019-08-07 10:03:49 +02:00
|
|
|
<script>
|
2020-03-31 13:16:03 +02:00
|
|
|
import { store } from "builderStore"
|
|
|
|
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 10:50:30 +01:00
|
|
|
import UIkit from "uikit"
|
|
|
|
import { isRootComponent } from "./pagesParsing/searchComponents"
|
|
|
|
import { splitName } from "./pagesParsing/splitRootComponentName.js"
|
2020-08-18 18:14:35 +02:00
|
|
|
import { Input, Select } from "@budibase/bbui"
|
2020-02-03 10:50:30 +01:00
|
|
|
|
|
|
|
import { find, filter, some, map, includes } from "lodash/fp"
|
|
|
|
import { assign } from "lodash"
|
|
|
|
|
|
|
|
export const show = () => {
|
2020-03-05 17:14:36 +01:00
|
|
|
dialog.show()
|
2020-02-03 10:50:30 +01:00
|
|
|
}
|
|
|
|
|
2020-03-05 17:14:36 +01:00
|
|
|
let dialog
|
2020-02-03 10:50:30 +01:00
|
|
|
let layoutComponents
|
|
|
|
let layoutComponent
|
|
|
|
let screens
|
|
|
|
let name = ""
|
2020-08-18 18:14:35 +02:00
|
|
|
let nameError = ""
|
|
|
|
let routeError
|
2020-02-25 16:21:23 +01:00
|
|
|
|
2020-02-03 10:50:30 +01:00
|
|
|
let saveAttempted = false
|
|
|
|
|
2020-05-07 11:53:34 +02:00
|
|
|
$: layoutComponents = Object.values($store.components).filter(
|
|
|
|
componentDefinition => componentDefinition.container
|
|
|
|
)
|
2020-02-03 10:50:30 +01:00
|
|
|
|
2020-02-25 11:01:07 +01:00
|
|
|
$: layoutComponent = layoutComponent
|
2020-05-07 11:53:34 +02:00
|
|
|
? layoutComponents.find(
|
|
|
|
component => component._component === layoutComponent._component
|
|
|
|
)
|
2020-02-25 16:21:23 +01:00
|
|
|
: layoutComponents[0]
|
2020-02-03 10:50:30 +01:00
|
|
|
|
2020-05-02 16:29:10 +02:00
|
|
|
$: route = !route && $store.screens.length === 0 ? "*" : route
|
2020-02-03 10:50:30 +01:00
|
|
|
|
|
|
|
const save = () => {
|
|
|
|
saveAttempted = true
|
|
|
|
|
2020-08-18 18:14:35 +02:00
|
|
|
if (name.length === 0) {
|
|
|
|
nameError = "Name is required"
|
|
|
|
} else {
|
|
|
|
if (screenNameExists(name)) {
|
|
|
|
nameError = "This name is already taken"
|
|
|
|
} else {
|
|
|
|
nameError = ""
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (route.length === 0) {
|
|
|
|
routeError = "Url is required"
|
|
|
|
} else {
|
|
|
|
if (routeNameExists(name)) {
|
|
|
|
routeError = "This url is already taken"
|
|
|
|
} else {
|
|
|
|
routeError = ""
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const isValid = !routeError && !nameError
|
2020-02-03 10:50:30 +01:00
|
|
|
|
|
|
|
if (!isValid) return
|
|
|
|
|
2020-05-02 16:29:10 +02:00
|
|
|
store.createScreen(name, route, layoutComponent._component)
|
2020-03-05 17:14:36 +01:00
|
|
|
dialog.hide()
|
2020-02-03 10:50:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
const cancel = () => {
|
2020-03-05 17:14:36 +01:00
|
|
|
dialog.hide()
|
2020-02-03 10:50:30 +01:00
|
|
|
}
|
|
|
|
|
2020-02-10 16:51:09 +01:00
|
|
|
const screenNameExists = name => {
|
2020-05-07 11:53:34 +02:00
|
|
|
return $store.screens.some(
|
|
|
|
screen => screen.name.toLowerCase() === name.toLowerCase()
|
|
|
|
)
|
2020-02-10 16:51:09 +01:00
|
|
|
}
|
2020-02-25 11:01:07 +01:00
|
|
|
|
|
|
|
const routeNameExists = route => {
|
2020-05-07 11:53:34 +02:00
|
|
|
return $store.screens.some(
|
|
|
|
screen => screen.route.toLowerCase() === route.toLowerCase()
|
|
|
|
)
|
2020-02-25 11:01:07 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
const routeChanged = event => {
|
2020-05-02 16:29:10 +02:00
|
|
|
if (!event.target.value.startsWith("/")) {
|
|
|
|
route = "/" + event.target.value
|
2020-02-25 11:01:07 +01:00
|
|
|
}
|
|
|
|
}
|
2019-08-07 10:03:49 +02:00
|
|
|
</script>
|
|
|
|
|
2020-03-05 17:14:36 +01:00
|
|
|
<ConfirmDialog
|
|
|
|
bind:this={dialog}
|
|
|
|
title="New Screen"
|
|
|
|
onCancel={cancel}
|
|
|
|
onOk={save}
|
|
|
|
okText="Create Screen">
|
|
|
|
|
2020-08-18 18:14:35 +02:00
|
|
|
<div>
|
2020-03-05 17:14:36 +01:00
|
|
|
<div class="uk-margin">
|
2020-08-18 18:14:35 +02:00
|
|
|
<Input label="Name" error={nameError} bind:value={name} />
|
2020-03-05 17:14:36 +01:00
|
|
|
</div>
|
2020-02-10 16:51:09 +01:00
|
|
|
|
2020-03-05 17:14:36 +01:00
|
|
|
<div class="uk-margin">
|
2020-08-18 18:14:35 +02:00
|
|
|
<Input
|
|
|
|
label="Url"
|
|
|
|
error={routeError}
|
|
|
|
bind:value={route}
|
|
|
|
on:change={routeChanged} />
|
2020-03-05 17:14:36 +01:00
|
|
|
</div>
|
2020-02-03 10:50:30 +01:00
|
|
|
|
2020-03-05 17:14:36 +01:00
|
|
|
<div class="uk-margin">
|
2020-08-18 18:14:35 +02:00
|
|
|
<label>Layout Component</label>
|
|
|
|
<Select bind:value={layoutComponent}>
|
|
|
|
{#each layoutComponents as { _component, name }}
|
|
|
|
<option value={_component}>{name}</option>
|
|
|
|
{/each}
|
|
|
|
</Select>
|
2019-10-07 07:03:41 +02:00
|
|
|
</div>
|
2020-02-03 10:50:30 +01:00
|
|
|
</div>
|
2019-10-07 07:03:41 +02:00
|
|
|
|
2020-03-05 17:14:36 +01:00
|
|
|
</ConfirmDialog>
|
|
|
|
|
2020-03-24 11:56:48 +01:00
|
|
|
<style>
|
2020-03-27 17:58:32 +01:00
|
|
|
.uk-margin {
|
|
|
|
display: flex;
|
|
|
|
flex-direction: column;
|
|
|
|
}
|
|
|
|
</style>
|