budibase/packages/builder/src/components/design/NavigationPanel/NewScreenModal.svelte

171 lines
4.6 KiB
Svelte
Raw Normal View History

<script>
2021-11-09 10:33:34 +01:00
import { store, allScreens } from "builderStore"
import { tables } from "stores/backend"
2021-11-09 10:33:34 +01:00
import { ModalContent, Body, Detail, Layout, Icon } from "@budibase/bbui"
import getTemplates from "builderStore/store/screenTemplates"
2020-10-08 15:53:06 +02:00
const CONTAINER = "@budibase/standard-components/container"
2021-11-09 10:33:34 +01:00
const blankScreen = "createFromScratch"
let selectedScreens = []
let navigationSelectionModal
2020-02-03 10:50:30 +01:00
let name = ""
2020-10-08 15:53:06 +02:00
let baseComponent = CONTAINER
2020-10-09 12:58:46 +02:00
let templateIndex
let draftScreen
2021-11-09 10:33:34 +01:00
$: blankSelected = selectedScreens.includes(blankScreen)
$: autoSelected = selectedScreens.length > 0 && !blankSelected
2020-02-25 16:21:23 +01:00
$: templates = getTemplates($store, $tables.list)
$: route = !route && $allScreens.length === 0 ? "*" : route
2020-10-09 12:58:46 +02:00
$: {
if (templates && templateIndex === undefined) {
templateIndex = 0
templateChanged(0)
}
}
2021-05-04 12:32:22 +02:00
const templateChanged = newTemplateIndex => {
2020-10-09 12:58:46 +02:00
if (newTemplateIndex === undefined) return
draftScreen = templates[newTemplateIndex].create()
if (draftScreen.props._instanceName) {
name = draftScreen.props._instanceName
}
if (draftScreen.props._component) {
baseComponent = draftScreen.props._component
}
if (draftScreen.routing) {
route = draftScreen.routing.route
}
}
2021-11-09 10:33:34 +01:00
/*
const save = async () => {
if (!route) {
routeError = "URL is required"
2020-08-18 18:14:35 +02:00
} else {
if (routeExists(route, roleId)) {
routeError = "This URL is already taken for this access role"
2020-08-18 18:14:35 +02:00
} else {
routeError = ""
}
}
2020-10-08 15:53:06 +02:00
if (routeError) return false
draftScreen.props._instanceName = name
draftScreen.props._component = baseComponent
draftScreen.routing = { route, roleId }
await store.actions.screens.create(draftScreen)
if (createLink) {
await store.actions.components.links.save(route, name)
}
2020-11-20 12:41:17 +01:00
await store.actions.routing.fetch()
if (templateIndex !== undefined) {
const template = templates[templateIndex]
analytics.captureEvent(Events.SCREEN.CREATED, {
template: template.id || template.name,
})
}
2020-02-03 10:50:30 +01:00
}
2021-11-09 10:33:34 +01:00
*/
const toggleScreenSelection = template => {
if (selectedScreens.includes(template.id)) {
selectedScreens = selectedScreens.filter(screen => screen !== template.id)
} else {
selectedScreens = [template.id, ...selectedScreens]
2020-02-25 11:01:07 +01:00
}
}
</script>
2021-11-09 10:33:34 +01:00
<ModalContent
title="Add screens"
confirmText="Add Screens"
cancelText="Cancel"
onConfirm={() => navigationSelectionModal.show()}
disabled={!selectedScreens.length}
size="L"
>
<Body size="XS"
>Please select the screens you would like to add to your application.
Autogenerated screens come with CRUD functionality.</Body
>
<Layout noPadding>
<Detail size="S">Blank screen</Detail>
<div
class="item"
class:selected={selectedScreens.includes(blankScreen)}
on:click={() => toggleScreenSelection({ id: blankScreen })}
class:disabled={autoSelected}
>
<div class="content">
<Body size="S">Blank</Body>
</div>
<div style="color: var(--spectrum-global-color-green-600); float: right">
{#if selectedScreens.includes(blankScreen)}
<Icon size="S" name="CheckmarkCircleOutline" />
{/if}
</div>
</div>
<Detail size="S">Autogenerated Screens</Detail>
{#each templates.filter(x => x.id !== blankScreen) as template}
<div
class:disabled={blankSelected}
class:selected={selectedScreens.includes(template.id)}
on:click={() => toggleScreenSelection(template)}
class="item"
>
<div class="content">
{template.name}
</div>
<div
style="color: var(--spectrum-global-color-green-600); float: right"
>
{#if selectedScreens.includes(template.id)}
<Icon size="S" name="CheckmarkCircleOutline" />
{/if}
</div>
</div>
{/each}
</Layout>
2020-10-08 10:34:22 +02:00
</ModalContent>
2021-11-09 10:33:34 +01:00
<style>
.disabled {
opacity: 0.3;
pointer-events: none;
}
.content {
padding-left: 10px;
letter-spacing: 0px;
color: #2c2c2c;
}
.item {
cursor: pointer;
grid-gap: var(--spectrum-alias-grid-margin-xsmall);
padding: var(--spectrum-alias-item-padding-s);
background: var(--background);
transition: 0.3s all;
border: solid var(--spectrum-alias-border-color);
border-radius: 2px;
box-sizing: border-box;
border-width: 1px;
display: flex;
justify-content: space-between;
align-items: center;
height: 60px;
}
.item:hover,
.selected {
background: var(--spectrum-alias-background-color-tertiary);
}
</style>