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-09-04 23:40:25 +02:00
|
|
|
import { Input, Select, Modal, Button, Spacer } 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 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-08-18 21:59:34 +02:00
|
|
|
if (routeError) return false
|
2020-02-03 10:50:30 +01:00
|
|
|
|
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-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-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-09-04 23:40:25 +02:00
|
|
|
<Modal bind:this={dialog} minWidth="500px">
|
2020-09-03 09:59:05 +02:00
|
|
|
<h2>New Screen</h2>
|
2020-09-04 23:40:25 +02:00
|
|
|
<Spacer extraLarge />
|
2020-09-03 09:59:05 +02:00
|
|
|
|
2020-09-04 23:40:25 +02:00
|
|
|
<div data-cy="new-screen-dialog">
|
|
|
|
<div class="bb-margin-xl">
|
|
|
|
<Input label="Name" bind:value={name} />
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<div class="bb-margin-xl">
|
|
|
|
<Input
|
|
|
|
label="Url"
|
|
|
|
error={routeError}
|
|
|
|
bind:value={route}
|
|
|
|
on:change={routeChanged} />
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<div class="bb-margin-xl">
|
|
|
|
<label>Layout Component</label>
|
|
|
|
<Select bind:value={layoutComponent} secondary>
|
|
|
|
{#each layoutComponents as { _component, name }}
|
|
|
|
<option value={_component}>{name}</option>
|
|
|
|
{/each}
|
|
|
|
</Select>
|
2020-03-05 17:14:36 +01:00
|
|
|
</div>
|
2020-09-03 09:59:05 +02:00
|
|
|
</div>
|
2020-02-10 16:51:09 +01:00
|
|
|
|
2020-09-04 23:40:25 +02:00
|
|
|
<Spacer extraLarge />
|
2020-02-03 10:50:30 +01:00
|
|
|
|
2020-09-05 01:03:08 +02:00
|
|
|
<div data-cy="create-screen-footer" class="modal-footer">
|
2020-09-04 23:40:25 +02:00
|
|
|
<Button secondary medium on:click={cancel}>Cancel</Button>
|
|
|
|
<Button blue medium on:click={save}>Create Screen</Button>
|
|
|
|
</div>
|
2020-09-03 09:59:05 +02:00
|
|
|
</Modal>
|
|
|
|
|
|
|
|
<style>
|
|
|
|
h2 {
|
|
|
|
font-size: var(--font-size-xl);
|
|
|
|
margin: 0;
|
|
|
|
font-family: var(--font-sans);
|
|
|
|
font-weight: 600;
|
|
|
|
}
|
2019-10-07 07:03:41 +02:00
|
|
|
|
2020-09-04 23:40:25 +02:00
|
|
|
.modal-footer {
|
|
|
|
display: flex;
|
|
|
|
justify-content: space-between;
|
2020-09-03 09:59:05 +02:00
|
|
|
}
|
|
|
|
</style>
|