budibase/packages/builder/src/userInterface/PageView.svelte

71 lines
1.8 KiB
Svelte
Raw Normal View History

2019-08-27 08:32:56 +02:00
<script>
import Textbox from "../common/Textbox.svelte";
import Dropdown from "../common/Dropdown.svelte";
import Button from "../common/Button.svelte";
import { store } from "../builderStore";
import { isRootComponent } from "./pagesParsing/searchComponents";
2019-09-12 07:10:50 +02:00
import { pipe } from "../common/core";
2019-09-03 13:12:24 +02:00
import {
2019-09-12 07:10:50 +02:00
filter, find, concat
2019-09-03 13:12:24 +02:00
} from "lodash/fp";
2019-08-27 08:32:56 +02:00
let entryComponent;
let title = "";
let components = [];
let page={};
2019-09-12 07:10:50 +02:00
const notSeletedComponent = {name:"(none selected)"};
2019-08-27 08:32:56 +02:00
store.subscribe(s => {
page = s.pages[s.currentPageName];
if(!page) return;
title = page.index.title;
components = pipe(s.components, [
2019-09-12 07:10:50 +02:00
filter(s => !isRootComponent(s)),
concat([notSeletedComponent])
]);
entryComponent = find(c => c.name === page.appBody)(components);
2019-09-12 07:10:50 +02:00
if(!entryComponent) entryComponent = notSeletedComponent;
2019-08-27 08:32:56 +02:00
});
const save = () => {
2019-09-12 07:10:50 +02:00
if(!title || !entryComponent || entryComponent === notSeletedComponent) return;
2019-08-27 08:32:56 +02:00
const page = {
2019-09-03 13:12:24 +02:00
index: {
title
},
appBody: entryComponent.name,
2019-08-27 08:32:56 +02:00
}
store.savePage(page);
}
</script>
2019-09-03 13:12:24 +02:00
<div class="root">
2019-08-27 08:32:56 +02:00
2019-09-03 13:12:24 +02:00
<h3>{$store.currentPageName}</h3>
2019-08-27 08:32:56 +02:00
2019-09-03 13:12:24 +02:00
<form class="uk-form-horizontal">
2019-09-12 07:10:50 +02:00
<Textbox bind:text={title} label="Title" hasError={!title}/>
2019-09-03 13:12:24 +02:00
<div class="help-text">The title of your page, displayed in the bowser tab</div>
<Dropdown label="App Entry Component"
options={components}
bind:selected={entryComponent}
textMember={(v) => v.name} />
2019-08-27 08:32:56 +02:00
2019-09-03 13:12:24 +02:00
<div class="help-text">The component that will be loaded into the body of the page</div>
<div style="margin-top: 20px"></div>
<Button on:click={save}>Save</Button>
</form>
</div>
2019-08-27 08:32:56 +02:00
2019-09-03 13:12:24 +02:00
<style>
.root {
padding: 15px;
}
.help-text {
color: var(--slate);
font-size: 10pt;
}
2019-08-27 08:32:56 +02:00
</style>