2019-08-07 10:03:49 +02:00
|
|
|
<script>
|
2020-02-03 10:50:30 +01:00
|
|
|
import { store } from "../builderStore"
|
|
|
|
import PropsView from "./PropsView.svelte"
|
|
|
|
import Textbox from "../common/Textbox.svelte"
|
|
|
|
import Button from "../common/Button.svelte"
|
|
|
|
import ButtonGroup from "../common/ButtonGroup.svelte"
|
|
|
|
import { pipe } from "../common/core"
|
|
|
|
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 = () => {
|
|
|
|
UIkit.modal(componentSelectorModal).show()
|
|
|
|
}
|
|
|
|
|
|
|
|
let componentSelectorModal
|
|
|
|
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-02-25 16:21:23 +01:00
|
|
|
$: layoutComponents = pipe($store.components, [
|
|
|
|
filter(c => c.container),
|
|
|
|
map(c => ({ name: c.name, ...splitName(c.name) })),
|
|
|
|
])
|
2020-02-03 10:50:30 +01:00
|
|
|
|
2020-02-25 11:01:07 +01:00
|
|
|
$: layoutComponent = layoutComponent
|
2020-02-25 16:21:23 +01:00
|
|
|
? find(c => c.name === layoutComponent.name)(layoutComponents)
|
|
|
|
: layoutComponents[0]
|
2020-02-03 10:50:30 +01:00
|
|
|
|
2020-02-25 11:01:07 +01:00
|
|
|
$: screens = $store.screens
|
|
|
|
$: route = !route && 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-02-10 16:51:09 +01:00
|
|
|
store.createScreen(name, route, layoutComponent.name)
|
2020-02-03 10:50:30 +01:00
|
|
|
UIkit.modal(componentSelectorModal).hide()
|
|
|
|
}
|
|
|
|
|
|
|
|
const cancel = () => {
|
|
|
|
UIkit.modal(componentSelectorModal).hide()
|
|
|
|
}
|
|
|
|
|
2020-02-10 16:51:09 +01:00
|
|
|
const screenNameExists = name => {
|
|
|
|
return some(s => {
|
|
|
|
return s.name.toLowerCase() === name.toLowerCase()
|
|
|
|
})(screens)
|
|
|
|
}
|
2020-02-25 11:01:07 +01: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
|
|
|
|
}
|
|
|
|
}
|
2019-08-07 10:03:49 +02:00
|
|
|
</script>
|
|
|
|
|
2019-10-07 07:03:41 +02:00
|
|
|
<div bind:this={componentSelectorModal} id="new-component-modal" uk-modal>
|
2020-02-03 10:50:30 +01:00
|
|
|
<div class="uk-modal-dialog" uk-overflow-auto>
|
2019-08-14 23:11:59 +02:00
|
|
|
|
2020-02-03 10:50:30 +01:00
|
|
|
<div class="uk-modal-header">
|
|
|
|
<h1>New Screen</h1>
|
|
|
|
</div>
|
2019-08-14 23:11:59 +02:00
|
|
|
|
2020-02-03 10:50:30 +01:00
|
|
|
<div class="uk-modal-body 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>
|
2020-02-25 10:38:50 +01:00
|
|
|
</div>
|
2020-02-10 16:51:09 +01:00
|
|
|
|
2020-02-25 10:38:50 +01:00
|
|
|
<div class="uk-margin">
|
2020-02-10 16:51:09 +01:00
|
|
|
<label class="uk-form-label">Route (Url)</label>
|
|
|
|
<div class="uk-form-controls">
|
|
|
|
<input
|
|
|
|
class="uk-input uk-form-small"
|
2020-02-25 11:01:07 +01:00
|
|
|
class:uk-form-danger={saveAttempted && (route.length === 0 || routeNameExists(route))}
|
2020-02-25 16:21:23 +01:00
|
|
|
bind:value={route}
|
|
|
|
on:change={routeChanged} />
|
2020-02-10 16:51:09 +01:00
|
|
|
</div>
|
2020-02-03 10:50:30 +01:00
|
|
|
</div>
|
|
|
|
|
|
|
|
<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}
|
|
|
|
<option value={comp}>
|
|
|
|
{comp.componentName} - {comp.libName}
|
|
|
|
</option>
|
|
|
|
{/each}
|
|
|
|
</select>
|
2019-10-07 07:03:41 +02:00
|
|
|
</div>
|
2020-02-03 10:50:30 +01:00
|
|
|
</div>
|
|
|
|
|
|
|
|
<ButtonGroup style="float: right;">
|
|
|
|
<Button color="primary" grouped on:click={save}>Create Screen</Button>
|
|
|
|
<Button color="tertiary" grouped on:click={cancel}>Cancel</Button>
|
|
|
|
</ButtonGroup>
|
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
|
|
|
</div>
|
|
|
|
|
2020-01-18 00:06:42 +01:00
|
|
|
<style>
|
2020-02-03 10:50:30 +01:00
|
|
|
h1 {
|
|
|
|
font-size: 1.2em;
|
|
|
|
}
|
2020-01-22 10:41:19 +01:00
|
|
|
</style>
|