2019-08-07 10:03:49 +02:00
|
|
|
<script>
|
2020-03-31 13:16:03 +02:00
|
|
|
import { store } from "builderStore"
|
|
|
|
import { pipe } from "components/common/core"
|
2020-02-03 10:50:30 +01:00
|
|
|
import { isRootComponent } from "./pagesParsing/searchComponents"
|
|
|
|
import { splitName } from "./pagesParsing/splitRootComponentName.js"
|
2020-10-05 12:13:09 +02:00
|
|
|
import { Input, Select, Button, Spacer } from "@budibase/bbui"
|
|
|
|
import { Modal } from "components/common/Modal"
|
2020-02-03 10:50:30 +01:00
|
|
|
import { find, filter, some, map, includes } from "lodash/fp"
|
|
|
|
import { assign } from "lodash"
|
|
|
|
|
2020-10-05 12:13:09 +02:00
|
|
|
export let visible
|
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 routeError
|
2020-02-25 16:21:23 +01:00
|
|
|
|
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 = () => {
|
2020-08-18 21:59:34 +02:00
|
|
|
if (!route) {
|
2020-08-18 18:14:35 +02:00
|
|
|
routeError = "Url is required"
|
|
|
|
} else {
|
2020-08-18 21:59:34 +02:00
|
|
|
if (routeNameExists(route)) {
|
2020-08-18 18:14:35 +02:00
|
|
|
routeError = "This url is already taken"
|
|
|
|
} else {
|
|
|
|
routeError = ""
|
|
|
|
}
|
|
|
|
}
|
2020-10-05 12:13:09 +02:00
|
|
|
if (routeError) {
|
|
|
|
return false
|
|
|
|
}
|
2020-05-02 16:29:10 +02:00
|
|
|
store.createScreen(name, route, layoutComponent._component)
|
2020-08-18 21:59:34 +02:00
|
|
|
name = ""
|
|
|
|
route = ""
|
2020-02-03 10:50:30 +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-10-05 12:13:09 +02:00
|
|
|
<Modal
|
|
|
|
bind:visible
|
|
|
|
title="New Screen"
|
|
|
|
confirmText="Create Screen"
|
|
|
|
onConfirm={save}>
|
|
|
|
<Input label="Name" bind:value={name} />
|
|
|
|
<Input
|
|
|
|
label="Url"
|
|
|
|
error={routeError}
|
|
|
|
bind:value={route}
|
|
|
|
on:change={routeChanged} />
|
|
|
|
<Select label="Layout Component" bind:value={layoutComponent} secondary>
|
|
|
|
{#each layoutComponents as { _component, name }}
|
|
|
|
<option value={_component}>{name}</option>
|
|
|
|
{/each}
|
|
|
|
</Select>
|
2020-09-03 09:59:05 +02:00
|
|
|
</Modal>
|