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-10 16:51:09 +01:00
|
|
|
let route = ""
|
2020-02-03 10:50:30 +01:00
|
|
|
let saveAttempted = false
|
|
|
|
|
|
|
|
store.subscribe(s => {
|
2020-02-10 16:51:09 +01:00
|
|
|
layoutComponents = pipe(
|
|
|
|
s.components,
|
|
|
|
[
|
|
|
|
filter(c => c.container),
|
|
|
|
map(c => ({ name: c.name, ...splitName(c.name) })),
|
|
|
|
]
|
|
|
|
)
|
2020-02-03 10:50:30 +01:00
|
|
|
|
|
|
|
layoutComponent = layoutComponent
|
|
|
|
? find(c => c.name === layoutComponent.name)(layoutComponents)
|
|
|
|
: layoutComponents[0]
|
|
|
|
|
|
|
|
screens = s.screens
|
|
|
|
})
|
|
|
|
|
|
|
|
const save = () => {
|
|
|
|
saveAttempted = true
|
|
|
|
|
|
|
|
const isValid =
|
|
|
|
name.length > 0 && !screenNameExists(name) && layoutComponent
|
|
|
|
|
|
|
|
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)
|
|
|
|
}
|
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-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"
|
|
|
|
class:uk-form-danger={saveAttempted && route.length === 0}
|
|
|
|
bind:value={route} />
|
|
|
|
</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>
|