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"
|
2020-02-27 16:17:27 +01:00
|
|
|
import ActionButton from "../common/ActionButton.svelte"
|
2020-02-03 10:50:30 +01:00
|
|
|
import ButtonGroup from "../common/ButtonGroup.svelte"
|
2020-03-05 17:14:36 +01:00
|
|
|
import ConfirmDialog from "../common/ConfirmDialog.svelte"
|
2020-02-03 10:50:30 +01:00
|
|
|
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 = () => {
|
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-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-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 => {
|
|
|
|
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>
|
|
|
|
|
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">
|
|
|
|
<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 || 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}>
|
|
|
|
{#each layoutComponents as comp}
|
2020-03-27 17:58:32 +01:00
|
|
|
<option value={comp}>{comp.componentName} - {comp.libName}</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>
|