2019-08-07 10:03:49 +02:00
|
|
|
<script>
|
2020-03-31 13:16:03 +02:00
|
|
|
import { store } from "builderStore"
|
2020-02-03 10:50:30 +01:00
|
|
|
import PropsView from "./PropsView.svelte"
|
2020-03-31 13:16:03 +02:00
|
|
|
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 10:50:30 +01: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 = () => {
|
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-02-25 16:21:23 +01:00
|
|
|
|
2020-02-03 10:50:30 +01:00
|
|
|
let saveAttempted = false
|
|
|
|
|
2020-05-02 16:29:10 +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-02 16:29:10 +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
|
|
|
|
|
|
|
|
const isValid =
|
2020-02-25 16:21:23 +01:00
|
|
|
name.length > 0 &&
|
|
|
|
!screenNameExists(name) &&
|
|
|
|
route.length > 0 &&
|
|
|
|
!routeNameExists(route) &&
|
|
|
|
layoutComponent
|
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-02 16:29:10 +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-02 16:29:10 +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">
|
|
|
|
|
|
|
|
<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} />
|
2020-02-25 10:38:50 +01:00
|
|
|
</div>
|
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-05-02 16:29:10 +02:00
|
|
|
<label class="uk-form-label">Route (URL)</label>
|
2020-03-05 17:14:36 +01:00
|
|
|
<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 10:50:30 +01:00
|
|
|
</div>
|
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">
|
|
|
|
<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}>
|
2020-05-02 16:29:10 +02:00
|
|
|
{#each layoutComponents as { _component, name }}
|
|
|
|
<option value={_component}>{name}</option>
|
2020-03-05 17:14:36 +01:00
|
|
|
{/each}
|
|
|
|
</select>
|
2020-02-03 10:50:30 +01:00
|
|
|
</div>
|
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;
|
|
|
|
}
|
2020-03-24 11:56:48 +01:00
|
|
|
|
2020-03-27 17:58:32 +01:00
|
|
|
.uk-form-controls {
|
|
|
|
margin-left: 0 !important;
|
|
|
|
}
|
2020-03-24 11:56:48 +01:00
|
|
|
|
2020-03-27 17:58:32 +01:00
|
|
|
.uk-form-label {
|
|
|
|
padding-bottom: 10px;
|
|
|
|
font-weight: 500;
|
|
|
|
font-size: 16px;
|
|
|
|
color: var(--secondary80);
|
|
|
|
}
|
2020-03-24 11:56:48 +01:00
|
|
|
|
2020-03-27 17:58:32 +01: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>
|