Merge branch 'master' into bugfixes
This commit is contained in:
commit
cf696f109d
|
@ -37,7 +37,7 @@
|
||||||
<div class="heading">
|
<div class="heading">
|
||||||
{#if !showFieldView}
|
{#if !showFieldView}
|
||||||
<i class="ri-list-settings-line button--toggled" />
|
<i class="ri-list-settings-line button--toggled" />
|
||||||
<h3 class="budibase__title--3">Create / Edit Model</h3>
|
<h3 class="budibase__title--3">Create / Edit Table</h3>
|
||||||
{:else}
|
{:else}
|
||||||
<i class="ri-file-list-line button--toggled" />
|
<i class="ri-file-list-line button--toggled" />
|
||||||
<h3 class="budibase__title--3">Create / Edit Field</h3>
|
<h3 class="budibase__title--3">Create / Edit Field</h3>
|
||||||
|
|
|
@ -19,19 +19,19 @@
|
||||||
...rest,
|
...rest,
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
notifier.success(`${model.name} model created.`)
|
notifier.success(`${model.name} table created.`)
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<section transition:fade>
|
<section transition:fade>
|
||||||
<header>
|
<header>
|
||||||
<h2>Create New Model</h2>
|
<h2>Create New Table</h2>
|
||||||
<p>Before you can view your model, you need to set it up.</p>
|
<p>Before you can view your table, you need to set it up.</p>
|
||||||
</header>
|
</header>
|
||||||
|
|
||||||
<div class="block-row">
|
<div class="block-row">
|
||||||
<span class="block-row-title">Fields</span>
|
<span class="block-row-title">Fields</span>
|
||||||
<p>Blocks are pre-made fields and help you build your model quicker.</p>
|
<p>Blocks are pre-made fields and help you build your table quicker.</p>
|
||||||
<div class="blocks">
|
<div class="blocks">
|
||||||
{#each Object.values(FIELDS) as field}
|
{#each Object.values(FIELDS) as field}
|
||||||
<Block
|
<Block
|
||||||
|
@ -45,7 +45,7 @@
|
||||||
|
|
||||||
<div class="block-row">
|
<div class="block-row">
|
||||||
<span class="block-row-title">Blocks</span>
|
<span class="block-row-title">Blocks</span>
|
||||||
<p>Blocks are pre-made fields and help you build your model quicker.</p>
|
<p>Blocks are pre-made fields and help you build your table quicker.</p>
|
||||||
<div class="blocks">
|
<div class="blocks">
|
||||||
{#each Object.values(BLOCKS) as field}
|
{#each Object.values(BLOCKS) as field}
|
||||||
<Block
|
<Block
|
||||||
|
@ -58,8 +58,8 @@
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="block-row">
|
<div class="block-row">
|
||||||
<span class="block-row-title">Models</span>
|
<span class="block-row-title">Tables</span>
|
||||||
<p>Blocks are pre-made fields and help you build your model quicker.</p>
|
<p>Blocks are pre-made fields and help you build your table quicker.</p>
|
||||||
<div class="blocks">
|
<div class="blocks">
|
||||||
{#each Object.values(MODELS) as model}
|
{#each Object.values(MODELS) as model}
|
||||||
<Block
|
<Block
|
||||||
|
|
|
@ -53,7 +53,7 @@
|
||||||
bind:value={$backendUiStore.tabs.NAVIGATION_PANEL}>
|
bind:value={$backendUiStore.tabs.NAVIGATION_PANEL}>
|
||||||
{#if selectedTab === 'NAVIGATE'}
|
{#if selectedTab === 'NAVIGATE'}
|
||||||
<Button purple wide on:click={setupForNewModel}>
|
<Button purple wide on:click={setupForNewModel}>
|
||||||
Create New Model
|
Create New Table
|
||||||
</Button>
|
</Button>
|
||||||
<div class="hierarchy-items-container">
|
<div class="hierarchy-items-container">
|
||||||
{#each $backendUiStore.models as model}
|
{#each $backendUiStore.models as model}
|
||||||
|
|
|
@ -52,7 +52,35 @@
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function validate() {
|
||||||
|
let errors = []
|
||||||
|
for (let field of Object.values($backendUiStore.draftModel.schema)) {
|
||||||
|
const restrictedFieldNames = ["type", "modelId"]
|
||||||
|
if (field.name.startsWith("_")) {
|
||||||
|
errors.push(`field '${field.name}' - name cannot begin with '_''`)
|
||||||
|
} else if (restrictedFieldNames.includes(field.name)) {
|
||||||
|
errors.push(`field '${field.name}' - is a restricted name, please rename`)
|
||||||
|
} else if (!field.name || !field.name.trim()) {
|
||||||
|
errors.push("field name cannot be blank")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!$backendUiStore.draftModel.name) {
|
||||||
|
errors.push("Table name cannot be blank")
|
||||||
|
}
|
||||||
|
|
||||||
|
return errors
|
||||||
|
}
|
||||||
|
|
||||||
async function saveModel() {
|
async function saveModel() {
|
||||||
|
const errors = validate()
|
||||||
|
if (errors.length > 0) {
|
||||||
|
notifier.danger(
|
||||||
|
errors.join("/n")
|
||||||
|
)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
await backendUiStore.actions.models.save({
|
await backendUiStore.actions.models.save({
|
||||||
model: $backendUiStore.draftModel,
|
model: $backendUiStore.draftModel,
|
||||||
})
|
})
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
<script>
|
<script>
|
||||||
import {buildStyle} from "../helpers.js"
|
import { buildStyle } from "../helpers.js"
|
||||||
import { fade } from "svelte/transition"
|
import { fade } from "svelte/transition"
|
||||||
|
|
||||||
export let backgroundSize = "10px"
|
export let backgroundSize = "10px"
|
||||||
|
@ -20,5 +20,7 @@
|
||||||
background-image: url('data:image/svg+xml;utf8, <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 2 2"><path fill="white" d="M1,0H2V1H1V0ZM0,1H1V2H0V1Z"/><path fill="gray" d="M0,0H1V1H0V0ZM1,1H2V2H1V1Z"/></svg>');
|
background-image: url('data:image/svg+xml;utf8, <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 2 2"><path fill="white" d="M1,0H2V1H1V0ZM0,1H1V2H0V1Z"/><path fill="gray" d="M0,0H1V1H0V0ZM1,1H2V2H1V1Z"/></svg>');
|
||||||
height: fit-content;
|
height: fit-content;
|
||||||
width: fit-content;
|
width: fit-content;
|
||||||
|
width: -moz-fit-content;
|
||||||
|
height: -moz-fit-content;
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|
|
@ -1,267 +1,184 @@
|
||||||
<script>
|
<script>
|
||||||
import { onMount, createEventDispatcher } from "svelte"
|
import { onMount, createEventDispatcher } from "svelte";
|
||||||
import { fade } from "svelte/transition"
|
import { fade } from "svelte/transition";
|
||||||
import Swatch from "./Swatch.svelte"
|
import Swatch from "./Swatch.svelte";
|
||||||
import CheckedBackground from "./CheckedBackground.svelte"
|
import CheckedBackground from "./CheckedBackground.svelte";
|
||||||
import { buildStyle } from "../helpers.js"
|
import { buildStyle } from "../helpers.js";
|
||||||
import {
|
import {
|
||||||
getColorFormat,
|
getColorFormat,
|
||||||
convertToHSVA,
|
convertToHSVA,
|
||||||
convertHsvaToFormat,
|
convertHsvaToFormat
|
||||||
} from "../utils.js"
|
} from "../utils.js";
|
||||||
import Slider from "./Slider.svelte"
|
import Slider from "./Slider.svelte";
|
||||||
import Palette from "./Palette.svelte"
|
import Palette from "./Palette.svelte";
|
||||||
import ButtonGroup from "./ButtonGroup.svelte"
|
import ButtonGroup from "./ButtonGroup.svelte";
|
||||||
import Input from "./Input.svelte"
|
import Input from "./Input.svelte";
|
||||||
import Portal from "./Portal.svelte"
|
import Portal from "./Portal.svelte";
|
||||||
import { keyevents } from "../actions"
|
import { keyevents } from "../actions";
|
||||||
|
|
||||||
export let value = "#3ec1d3ff"
|
export let value = "#3ec1d3ff";
|
||||||
export let open = false
|
export let open = false;
|
||||||
export let swatches = []
|
export let swatches = [];
|
||||||
|
|
||||||
export let disableSwatches = false
|
export let disableSwatches = false;
|
||||||
export let format = "hexa"
|
export let format = "hexa";
|
||||||
export let style = ""
|
export let style = "";
|
||||||
export let pickerHeight = 0
|
export let pickerHeight = 0;
|
||||||
export let pickerWidth = 0
|
export let pickerWidth = 0;
|
||||||
|
|
||||||
let colorPicker = null
|
let colorPicker = null;
|
||||||
let adder = null
|
let adder = null;
|
||||||
let swatchesSetFromLocalStore = false
|
let swatchesSetFromLocalStore = false;
|
||||||
|
|
||||||
let h = 0
|
let h = 0;
|
||||||
let s = 0
|
let s = 0;
|
||||||
let v = 0
|
let v = 0;
|
||||||
let a = 0
|
let a = 0;
|
||||||
|
|
||||||
const dispatch = createEventDispatcher()
|
const dispatch = createEventDispatcher();
|
||||||
|
|
||||||
onMount(() => {
|
onMount(() => {
|
||||||
if (!swatches.length > 0) {
|
if (!swatches.length > 0) {
|
||||||
//Don't use locally stored recent colors if swatches have been passed as props
|
//Don't use locally stored recent colors if swatches have been passed as props
|
||||||
swatchesSetFromLocalStore = true
|
swatchesSetFromLocalStore = true;
|
||||||
swatches = getRecentColors() || []
|
swatches = getRecentColors() || [];
|
||||||
}
|
}
|
||||||
|
|
||||||
if (swatches.length > 12) {
|
if (swatches.length > 12) {
|
||||||
console.warn(
|
console.warn(
|
||||||
`Colorpicker - ${swatches.length} swatches were provided. Only the first 12 swatches will be displayed.`
|
`Colorpicker - ${swatches.length} swatches were provided. Only the first 12 swatches will be displayed.`
|
||||||
)
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (colorPicker) {
|
if (colorPicker) {
|
||||||
colorPicker.focus()
|
colorPicker.focus();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (format) {
|
if (format) {
|
||||||
convertAndSetHSVA()
|
convertAndSetHSVA();
|
||||||
}
|
}
|
||||||
})
|
});
|
||||||
|
|
||||||
function getRecentColors() {
|
function getRecentColors() {
|
||||||
let colorStore = localStorage.getItem("cp:recent-colors")
|
let colorStore = localStorage.getItem("cp:recent-colors");
|
||||||
if (colorStore) {
|
if (colorStore) {
|
||||||
return JSON.parse(colorStore)
|
return JSON.parse(colorStore);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function handleEscape() {
|
function handleEscape() {
|
||||||
if (open) {
|
if (open) {
|
||||||
open = false
|
open = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function setRecentColors(color) {
|
function setRecentColors(color) {
|
||||||
const s = swatchesSetFromLocalStore
|
const s = swatchesSetFromLocalStore
|
||||||
? swatches
|
? swatches
|
||||||
: [...getRecentColors(), color]
|
: [...getRecentColors(), color];
|
||||||
localStorage.setItem("cp:recent-colors", JSON.stringify(s))
|
localStorage.setItem("cp:recent-colors", JSON.stringify(s));
|
||||||
}
|
}
|
||||||
|
|
||||||
function convertAndSetHSVA() {
|
function convertAndSetHSVA() {
|
||||||
let hsva = convertToHSVA(value, format)
|
let hsva = convertToHSVA(value, format);
|
||||||
setHSVA(hsva)
|
setHSVA(hsva);
|
||||||
}
|
}
|
||||||
|
|
||||||
function setHSVA([hue, sat, val, alpha]) {
|
function setHSVA([hue, sat, val, alpha]) {
|
||||||
h = hue
|
h = hue;
|
||||||
s = sat
|
s = sat;
|
||||||
v = val
|
v = val;
|
||||||
a = alpha
|
a = alpha;
|
||||||
}
|
}
|
||||||
|
|
||||||
//fired by choosing a color from the palette
|
//fired by choosing a color from the palette
|
||||||
function setSaturationAndValue({ detail }) {
|
function setSaturationAndValue({ detail }) {
|
||||||
s = detail.s
|
s = detail.s;
|
||||||
v = detail.v
|
v = detail.v;
|
||||||
value = convertHsvaToFormat([h, s, v, a], format)
|
value = convertHsvaToFormat([h, s, v, a], format);
|
||||||
dispatchValue()
|
dispatchValue();
|
||||||
}
|
}
|
||||||
|
|
||||||
function setHue({ color, isDrag }) {
|
function setHue({ color, isDrag }) {
|
||||||
h = color
|
h = color;
|
||||||
value = convertHsvaToFormat([h, s, v, a], format)
|
value = convertHsvaToFormat([h, s, v, a], format);
|
||||||
if (!isDrag) {
|
if (!isDrag) {
|
||||||
dispatchValue()
|
dispatchValue();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function setAlpha({ color, isDrag }) {
|
function setAlpha({ color, isDrag }) {
|
||||||
a = color === "1.00" ? "1" : color
|
a = color === "1.00" ? "1" : color;
|
||||||
value = convertHsvaToFormat([h, s, v, a], format)
|
value = convertHsvaToFormat([h, s, v, a], format);
|
||||||
if (!isDrag) {
|
if (!isDrag) {
|
||||||
dispatchValue()
|
dispatchValue();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function dispatchValue() {
|
function dispatchValue() {
|
||||||
dispatch("change", value)
|
dispatch("change", value);
|
||||||
}
|
}
|
||||||
|
|
||||||
function changeFormatAndConvert(f) {
|
function changeFormatAndConvert(f) {
|
||||||
format = f
|
format = f;
|
||||||
value = convertHsvaToFormat([h, s, v, a], format)
|
value = convertHsvaToFormat([h, s, v, a], format);
|
||||||
}
|
}
|
||||||
|
|
||||||
function handleColorInput(text) {
|
function handleColorInput(text) {
|
||||||
let format = getColorFormat(text)
|
let format = getColorFormat(text);
|
||||||
if (format) {
|
if (format) {
|
||||||
value = text
|
value = text;
|
||||||
convertAndSetHSVA()
|
convertAndSetHSVA();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function dispatchInputChange() {
|
function dispatchInputChange() {
|
||||||
if (format) {
|
if (format) {
|
||||||
dispatchValue()
|
dispatchValue();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function addSwatch() {
|
function addSwatch() {
|
||||||
if (format) {
|
if (format) {
|
||||||
if (swatches.length === 12) {
|
if (swatches.length === 12) {
|
||||||
swatches.splice(0, 1)
|
swatches.splice(0, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!swatches.includes(value)) {
|
if (!swatches.includes(value)) {
|
||||||
swatches = [...swatches, value]
|
swatches = [...swatches, value];
|
||||||
setRecentColors(value)
|
setRecentColors(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
dispatch("addswatch", value)
|
dispatch("addswatch", value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function removeSwatch(idx) {
|
function removeSwatch(idx) {
|
||||||
let removedSwatch = swatches.splice(idx, 1)
|
let removedSwatch = swatches.splice(idx, 1);
|
||||||
swatches = swatches
|
swatches = swatches;
|
||||||
dispatch("removeswatch", removedSwatch)
|
dispatch("removeswatch", removedSwatch);
|
||||||
if (swatchesSetFromLocalStore) {
|
if (swatchesSetFromLocalStore) {
|
||||||
//as could be a swatch not present in local storage
|
//as could be a swatch not present in local storage
|
||||||
setRecentColors()
|
setRecentColors();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function applySwatch(color) {
|
function applySwatch(color) {
|
||||||
if (value !== color) {
|
if (value !== color) {
|
||||||
format = getColorFormat(color)
|
format = getColorFormat(color);
|
||||||
if (format) {
|
if (format) {
|
||||||
value = color
|
value = color;
|
||||||
convertAndSetHSVA()
|
convertAndSetHSVA();
|
||||||
dispatchValue()
|
dispatchValue();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$: border = v > 90 && s < 5 ? "1px dashed #dedada" : ""
|
$: border = v > 90 && s < 5 ? "1px dashed #dedada" : "";
|
||||||
$: selectedColorStyle = buildStyle({ background: value, border })
|
$: selectedColorStyle = buildStyle({ background: value, border });
|
||||||
$: hasSwatches = swatches.length > 0
|
$: hasSwatches = swatches.length > 0;
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<Portal>
|
|
||||||
<div
|
|
||||||
class="colorpicker-container"
|
|
||||||
use:keyevents={{ Escape: handleEscape }}
|
|
||||||
transition:fade
|
|
||||||
bind:this={colorPicker}
|
|
||||||
{style}
|
|
||||||
tabindex="0"
|
|
||||||
bind:clientHeight={pickerHeight}
|
|
||||||
bind:clientWidth={pickerWidth}>
|
|
||||||
|
|
||||||
<div class="palette-panel">
|
|
||||||
<Palette on:change={setSaturationAndValue} {h} {s} {v} {a} />
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="control-panel">
|
|
||||||
<div class="alpha-hue-panel">
|
|
||||||
<div>
|
|
||||||
<CheckedBackground borderRadius="50%" backgroundSize="8px">
|
|
||||||
<div
|
|
||||||
class="selected-color"
|
|
||||||
title={value}
|
|
||||||
style={selectedColorStyle} />
|
|
||||||
</CheckedBackground>
|
|
||||||
</div>
|
|
||||||
<div>
|
|
||||||
<Slider
|
|
||||||
type="hue"
|
|
||||||
value={h}
|
|
||||||
on:change={hue => setHue(hue.detail)}
|
|
||||||
on:dragend={dispatchValue} />
|
|
||||||
|
|
||||||
<CheckedBackground borderRadius="10px" backgroundSize="7px">
|
|
||||||
<Slider
|
|
||||||
type="alpha"
|
|
||||||
value={a}
|
|
||||||
on:change={(alpha, isDrag) => setAlpha(alpha.detail, isDrag)}
|
|
||||||
on:dragend={dispatchValue} />
|
|
||||||
</CheckedBackground>
|
|
||||||
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
{#if !disableSwatches}
|
|
||||||
<div transition:fade class="swatch-panel">
|
|
||||||
{#if hasSwatches}
|
|
||||||
{#each swatches as color, idx}
|
|
||||||
{#if idx < 12}
|
|
||||||
<Swatch
|
|
||||||
{color}
|
|
||||||
on:click={() => applySwatch(color)}
|
|
||||||
on:removeswatch={() => removeSwatch(idx)} />
|
|
||||||
{/if}
|
|
||||||
{/each}
|
|
||||||
{/if}
|
|
||||||
{#if swatches.length < 12}
|
|
||||||
<div
|
|
||||||
tabindex="0"
|
|
||||||
use:keyevents={{ Enter: addSwatch }}
|
|
||||||
bind:this={adder}
|
|
||||||
transition:fade
|
|
||||||
class="adder"
|
|
||||||
class:shrink={hasSwatches}
|
|
||||||
on:click={addSwatch}>
|
|
||||||
<span>+</span>
|
|
||||||
</div>
|
|
||||||
{/if}
|
|
||||||
</div>
|
|
||||||
{/if}
|
|
||||||
|
|
||||||
<div class="format-input-panel">
|
|
||||||
<ButtonGroup {format} onclick={changeFormatAndConvert} />
|
|
||||||
<Input
|
|
||||||
{value}
|
|
||||||
on:input={event => handleColorInput(event.target.value)}
|
|
||||||
on:change={dispatchInputChange} />
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
</div>
|
|
||||||
</Portal>
|
|
||||||
|
|
||||||
<style>
|
<style>
|
||||||
.colorpicker-container {
|
.colorpicker-container {
|
||||||
position: absolute;
|
position: absolute;
|
||||||
|
@ -347,3 +264,86 @@
|
||||||
padding-top: 3px;
|
padding-top: 3px;
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|
||||||
|
<Portal>
|
||||||
|
<div
|
||||||
|
class="colorpicker-container"
|
||||||
|
use:keyevents={{ Escape: handleEscape }}
|
||||||
|
transition:fade
|
||||||
|
bind:this={colorPicker}
|
||||||
|
{style}
|
||||||
|
tabindex="0"
|
||||||
|
bind:clientHeight={pickerHeight}
|
||||||
|
bind:clientWidth={pickerWidth}>
|
||||||
|
|
||||||
|
<div class="palette-panel">
|
||||||
|
<Palette on:change={setSaturationAndValue} {h} {s} {v} {a} />
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="control-panel">
|
||||||
|
<div class="alpha-hue-panel">
|
||||||
|
<div>
|
||||||
|
<CheckedBackground borderRadius="50%" backgroundSize="8px">
|
||||||
|
<div
|
||||||
|
class="selected-color"
|
||||||
|
title={value}
|
||||||
|
style={selectedColorStyle} />
|
||||||
|
</CheckedBackground>
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<Slider
|
||||||
|
type="hue"
|
||||||
|
value={h}
|
||||||
|
on:change={hue => setHue(hue.detail)}
|
||||||
|
on:dragend={dispatchValue} />
|
||||||
|
|
||||||
|
<CheckedBackground borderRadius="10px" backgroundSize="7px">
|
||||||
|
<Slider
|
||||||
|
type="alpha"
|
||||||
|
value={a}
|
||||||
|
on:change={(alpha, isDrag) => setAlpha(alpha.detail, isDrag)}
|
||||||
|
on:dragend={dispatchValue} />
|
||||||
|
</CheckedBackground>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{#if !disableSwatches}
|
||||||
|
<div transition:fade class="swatch-panel">
|
||||||
|
{#if hasSwatches}
|
||||||
|
{#each swatches as color, idx}
|
||||||
|
{#if idx < 12}
|
||||||
|
<Swatch
|
||||||
|
{color}
|
||||||
|
on:click={() => applySwatch(color)}
|
||||||
|
on:removeswatch={() => removeSwatch(idx)} />
|
||||||
|
{/if}
|
||||||
|
{/each}
|
||||||
|
{/if}
|
||||||
|
{#if swatches.length < 12}
|
||||||
|
<div
|
||||||
|
tabindex="0"
|
||||||
|
title="Add Swatch"
|
||||||
|
use:keyevents={{ Enter: addSwatch }}
|
||||||
|
bind:this={adder}
|
||||||
|
transition:fade
|
||||||
|
class="adder"
|
||||||
|
class:shrink={hasSwatches}
|
||||||
|
on:click={addSwatch}>
|
||||||
|
<span>+</span>
|
||||||
|
</div>
|
||||||
|
{/if}
|
||||||
|
</div>
|
||||||
|
{/if}
|
||||||
|
|
||||||
|
<div class="format-input-panel">
|
||||||
|
<ButtonGroup {format} onclick={changeFormatAndConvert} />
|
||||||
|
<Input
|
||||||
|
{value}
|
||||||
|
on:input={event => handleColorInput(event.target.value)}
|
||||||
|
on:change={dispatchInputChange} />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
</Portal>
|
||||||
|
|
|
@ -1,93 +1,141 @@
|
||||||
<script>
|
<script>
|
||||||
import Colorpicker from "./Colorpicker.svelte"
|
import Colorpicker from "./Colorpicker.svelte";
|
||||||
import CheckedBackground from "./CheckedBackground.svelte"
|
import CheckedBackground from "./CheckedBackground.svelte";
|
||||||
import { createEventDispatcher, beforeUpdate, onMount } from "svelte"
|
import { createEventDispatcher, beforeUpdate, onMount } from "svelte";
|
||||||
|
|
||||||
import { buildStyle, debounce } from "../helpers.js"
|
import { buildStyle, debounce } from "../helpers.js";
|
||||||
import { fade } from "svelte/transition"
|
import { fade } from "svelte/transition";
|
||||||
import { getColorFormat } from "../utils.js"
|
import { getColorFormat } from "../utils.js";
|
||||||
|
|
||||||
export let value = "#3ec1d3ff"
|
export let value = "#3ec1d3ff";
|
||||||
export let swatches = []
|
export let swatches = [];
|
||||||
export let disableSwatches = false
|
export let disableSwatches = false;
|
||||||
export let open = false
|
export let open = false;
|
||||||
export let width = "25px"
|
export let width = "25px";
|
||||||
export let height = "25px"
|
export let height = "25px";
|
||||||
|
|
||||||
let format = "hexa"
|
let format = "hexa";
|
||||||
let dimensions = { top: 0, bottom: 0, right: 0, left: 0 }
|
let dimensions = { top: 0, bottom: 0, right: 0, left: 0 };
|
||||||
let positionSide = "top"
|
let positionY = "top";
|
||||||
let colorPreview = null
|
let positionX = "left";
|
||||||
|
let colorPreview = null;
|
||||||
|
|
||||||
let previewHeight = null
|
let previewHeight = null;
|
||||||
let previewWidth = null
|
let previewWidth = null;
|
||||||
let pickerWidth = 0
|
let pickerWidth = 0;
|
||||||
let pickerHeight = 0
|
let pickerHeight = 0;
|
||||||
|
|
||||||
let errorMsg = null
|
let errorMsg = null;
|
||||||
|
|
||||||
const dispatch = createEventDispatcher()
|
const dispatch = createEventDispatcher();
|
||||||
|
|
||||||
beforeUpdate(() => {
|
beforeUpdate(() => {
|
||||||
format = getColorFormat(value)
|
format = getColorFormat(value);
|
||||||
if (!format) {
|
if (!format) {
|
||||||
errorMsg = `Colorpicker - ${value} is an unknown color format. Please use a hex, rgb or hsl value`
|
errorMsg = `Colorpicker - ${value} is an unknown color format. Please use a hex, rgb or hsl value`;
|
||||||
console.error(errorMsg)
|
console.error(errorMsg);
|
||||||
} else {
|
} else {
|
||||||
errorMsg = null
|
errorMsg = null;
|
||||||
}
|
}
|
||||||
})
|
});
|
||||||
|
|
||||||
function openColorpicker(event) {
|
function openColorpicker(event) {
|
||||||
if (colorPreview) {
|
if (colorPreview) {
|
||||||
open = true
|
open = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function onColorChange(color) {
|
function onColorChange(color) {
|
||||||
value = color.detail
|
value = color.detail;
|
||||||
dispatch("change", color.detail)
|
dispatch("change", color.detail);
|
||||||
}
|
}
|
||||||
|
|
||||||
function calculateDimensions() {
|
function calculateDimensions() {
|
||||||
|
if (open) {
|
||||||
const {
|
const {
|
||||||
top: spaceAbove,
|
top: spaceAbove,
|
||||||
width,
|
width,
|
||||||
bottom,
|
bottom,
|
||||||
right,
|
right,
|
||||||
left,
|
left
|
||||||
} = colorPreview.getBoundingClientRect()
|
} = colorPreview.getBoundingClientRect();
|
||||||
|
|
||||||
const spaceBelow = window.innerHeight - bottom
|
const spaceBelow = window.innerHeight - bottom;
|
||||||
const previewCenter = previewWidth / 2
|
const previewCenter = previewWidth / 2;
|
||||||
|
|
||||||
let y, x
|
let y, x;
|
||||||
|
|
||||||
if (spaceAbove > spaceBelow) {
|
if (spaceAbove > spaceBelow) {
|
||||||
positionSide = "bottom"
|
positionY = "bottom";
|
||||||
y = window.innerHeight - spaceAbove
|
y = window.innerHeight - spaceAbove;
|
||||||
} else {
|
} else {
|
||||||
positionSide = "top"
|
positionY = "top";
|
||||||
y = bottom
|
y = bottom;
|
||||||
}
|
}
|
||||||
|
|
||||||
x = left + previewCenter - 220 / 2
|
// Centre picker by default
|
||||||
|
x = left + previewCenter - 220 / 2;
|
||||||
|
|
||||||
dimensions = { [positionSide]: y.toFixed(1), left: x.toFixed(1) }
|
const spaceRight = window.innerWidth - right;
|
||||||
|
|
||||||
|
//Position picker left or right if space not available for centering
|
||||||
|
if (left < 110 && spaceRight > 220) {
|
||||||
|
positionX = "left";
|
||||||
|
x = right;
|
||||||
|
} else if (spaceRight < 100 && left > 220) {
|
||||||
|
positionX = "right";
|
||||||
|
x = document.body.clientWidth - left;
|
||||||
|
}
|
||||||
|
|
||||||
|
dimensions = { [positionY]: y.toFixed(1), [positionX]: x.toFixed(1) };
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$: if (open && colorPreview) {
|
$: if (open && colorPreview) {
|
||||||
calculateDimensions()
|
calculateDimensions();
|
||||||
}
|
}
|
||||||
|
|
||||||
$: previewStyle = buildStyle({ width, height, background: value })
|
$: previewStyle = buildStyle({ width, height, background: value });
|
||||||
$: errorPreviewStyle = buildStyle({ width, height })
|
$: errorPreviewStyle = buildStyle({ width, height });
|
||||||
$: pickerStyle = buildStyle({
|
$: pickerStyle = buildStyle({
|
||||||
[positionSide]: `${dimensions[positionSide]}px`,
|
[positionY]: `${dimensions[positionY]}px`,
|
||||||
left: `${dimensions.left}px`,
|
[positionX]: `${dimensions[positionX]}px`
|
||||||
})
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
<style>
|
||||||
|
.color-preview-container {
|
||||||
|
display: flex;
|
||||||
|
flex-flow: row nowrap;
|
||||||
|
height: fit-content;
|
||||||
|
}
|
||||||
|
|
||||||
|
.color-preview {
|
||||||
|
cursor: pointer;
|
||||||
|
border-radius: 3px;
|
||||||
|
border: 1px solid #dedada;
|
||||||
|
position: absolute;
|
||||||
|
left: 110px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.preview-error {
|
||||||
|
background: #cccccc;
|
||||||
|
color: #808080;
|
||||||
|
text-align: center;
|
||||||
|
font-size: 18px;
|
||||||
|
cursor: not-allowed;
|
||||||
|
}
|
||||||
|
|
||||||
|
.overlay {
|
||||||
|
position: fixed;
|
||||||
|
top: 0;
|
||||||
|
bottom: 0;
|
||||||
|
left: 0;
|
||||||
|
right: 0;
|
||||||
|
z-index: 2;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
|
||||||
<svelte:window on:resize={debounce(calculateDimensions, 200)} />
|
<svelte:window on:resize={debounce(calculateDimensions, 200)} />
|
||||||
|
|
||||||
<div class="color-preview-container">
|
<div class="color-preview-container">
|
||||||
|
@ -127,41 +175,3 @@
|
||||||
</div>
|
</div>
|
||||||
{/if}
|
{/if}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<style>
|
|
||||||
.color-preview-container {
|
|
||||||
display: flex;
|
|
||||||
flex-flow: row nowrap;
|
|
||||||
height: fit-content;
|
|
||||||
}
|
|
||||||
|
|
||||||
.color-preview {
|
|
||||||
cursor: pointer;
|
|
||||||
border-radius: 3px;
|
|
||||||
border: 1px solid #dedada;
|
|
||||||
}
|
|
||||||
|
|
||||||
.preview-error {
|
|
||||||
background: #cccccc;
|
|
||||||
color: #808080;
|
|
||||||
text-align: center;
|
|
||||||
font-size: 18px;
|
|
||||||
cursor: not-allowed;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* .picker-container {
|
|
||||||
position: absolute;
|
|
||||||
z-index: 3;
|
|
||||||
width: fit-content;
|
|
||||||
height: fit-content;
|
|
||||||
} */
|
|
||||||
|
|
||||||
.overlay {
|
|
||||||
position: fixed;
|
|
||||||
top: 0;
|
|
||||||
bottom: 0;
|
|
||||||
left: 0;
|
|
||||||
right: 0;
|
|
||||||
z-index: 2;
|
|
||||||
}
|
|
||||||
</style>
|
|
||||||
|
|
|
@ -313,7 +313,7 @@ export default {
|
||||||
icon: "ri-archive-drawer-fill",
|
icon: "ri-archive-drawer-fill",
|
||||||
properties: {
|
properties: {
|
||||||
design: { ...all },
|
design: { ...all },
|
||||||
settings: [{ label: "Model", key: "model", control: ModelSelect }],
|
settings: [{ label: "Table", key: "model", control: ModelSelect }],
|
||||||
},
|
},
|
||||||
children: [],
|
children: [],
|
||||||
},
|
},
|
||||||
|
@ -331,7 +331,7 @@ export default {
|
||||||
design: { ...all },
|
design: { ...all },
|
||||||
settings: [
|
settings: [
|
||||||
{
|
{
|
||||||
label: "Model",
|
label: "Table",
|
||||||
key: "model",
|
key: "model",
|
||||||
control: ModelSelect,
|
control: ModelSelect,
|
||||||
},
|
},
|
||||||
|
@ -351,7 +351,7 @@ export default {
|
||||||
design: { ...all },
|
design: { ...all },
|
||||||
settings: [
|
settings: [
|
||||||
{
|
{
|
||||||
label: "Model",
|
label: "Table",
|
||||||
key: "model",
|
key: "model",
|
||||||
control: ModelSelect,
|
control: ModelSelect,
|
||||||
},
|
},
|
||||||
|
@ -368,7 +368,7 @@ export default {
|
||||||
properties: {
|
properties: {
|
||||||
design: { ...all },
|
design: { ...all },
|
||||||
settings: [
|
settings: [
|
||||||
{ label: "Model", key: "model", control: ModelSelect },
|
{ label: "Table", key: "model", control: ModelSelect },
|
||||||
{
|
{
|
||||||
label: "Chart Type",
|
label: "Chart Type",
|
||||||
key: "type",
|
key: "type",
|
||||||
|
@ -399,18 +399,18 @@ export default {
|
||||||
icon: "ri-file-list-fill",
|
icon: "ri-file-list-fill",
|
||||||
properties: {
|
properties: {
|
||||||
design: { ...all },
|
design: { ...all },
|
||||||
settings: [{ label: "Model", key: "model", control: ModelSelect }],
|
settings: [{ label: "Table", key: "model", control: ModelSelect }],
|
||||||
},
|
},
|
||||||
children: [],
|
children: [],
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "List",
|
name: "List",
|
||||||
_component: "@budibase/standard-components/list",
|
_component: "@budibase/standard-components/list",
|
||||||
description: "Renders all children once per record, of a given model",
|
description: "Renders all children once per record, of a given table",
|
||||||
icon: "ri-file-list-fill",
|
icon: "ri-file-list-fill",
|
||||||
properties: {
|
properties: {
|
||||||
design: { ...all },
|
design: { ...all },
|
||||||
settings: [{ label: "Model", key: "model", control: ModelSelect }],
|
settings: [{ label: "Table", key: "model", control: ModelSelect }],
|
||||||
},
|
},
|
||||||
children: [],
|
children: [],
|
||||||
},
|
},
|
||||||
|
@ -422,7 +422,7 @@ export default {
|
||||||
icon: "ri-profile-line",
|
icon: "ri-profile-line",
|
||||||
properties: {
|
properties: {
|
||||||
design: { ...all },
|
design: { ...all },
|
||||||
settings: [{ label: "Model", key: "model", control: ModelSelect }],
|
settings: [{ label: "Table", key: "model", control: ModelSelect }],
|
||||||
},
|
},
|
||||||
children: [],
|
children: [],
|
||||||
},
|
},
|
||||||
|
|
|
@ -28,7 +28,7 @@
|
||||||
{:else if $backendUiStore.selectedDatabase._id && selectedModel.name}
|
{:else if $backendUiStore.selectedDatabase._id && selectedModel.name}
|
||||||
<ModelDataTable />
|
<ModelDataTable />
|
||||||
{:else}
|
{:else}
|
||||||
<i style="color: var(--grey-4)">create your first model to start building</i>
|
<i style="color: var(--grey-4)">create your first table to start building</i>
|
||||||
{/if}
|
{/if}
|
||||||
|
|
||||||
<style>
|
<style>
|
||||||
|
|
|
@ -22,5 +22,5 @@
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
{#if $backendUiStore.models.length === 0}
|
{#if $backendUiStore.models.length === 0}
|
||||||
Please create a model
|
Please create a table
|
||||||
{:else}Please select a model{/if}
|
{:else}Please select a table{/if}
|
||||||
|
|
|
@ -1,88 +1,7 @@
|
||||||
const inquirer = require("inquirer")
|
const { xPlatHomeDir } = require("../../common")
|
||||||
const { exists, readFile, writeFile, ensureDir } = require("fs-extra")
|
const initialiseBudibase = require("@budibase/server/src/utilities/initialiseBudibase")
|
||||||
const chalk = require("chalk")
|
|
||||||
const { serverFileName, xPlatHomeDir } = require("../../common")
|
|
||||||
const { join } = require("path")
|
|
||||||
const Sqrl = require("squirrelly")
|
|
||||||
const uuid = require("uuid")
|
|
||||||
|
|
||||||
module.exports = opts => {
|
module.exports = opts => {
|
||||||
return run(opts)
|
|
||||||
}
|
|
||||||
|
|
||||||
const run = async opts => {
|
|
||||||
try {
|
|
||||||
await ensureAppDir(opts)
|
|
||||||
await setEnvironmentVariables(opts)
|
|
||||||
await createClientDatabase(opts)
|
|
||||||
await createDevEnvFile(opts)
|
|
||||||
console.log(chalk.green("Budibase successfully initialised."))
|
|
||||||
} catch (error) {
|
|
||||||
console.error(`Error initialising Budibase: ${error.message}`)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const setEnvironmentVariables = async opts => {
|
|
||||||
if (opts.couchDbUrl) {
|
|
||||||
process.env.COUCH_DB_URL = opts.couchDbUrl
|
|
||||||
} else {
|
|
||||||
const dataDir = join(opts.dir, ".data")
|
|
||||||
await ensureDir(dataDir)
|
|
||||||
process.env.COUCH_DB_URL =
|
|
||||||
dataDir + (dataDir.endsWith("/") || dataDir.endsWith("\\") ? "" : "/")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const ensureAppDir = async opts => {
|
|
||||||
opts.dir = xPlatHomeDir(opts.dir)
|
opts.dir = xPlatHomeDir(opts.dir)
|
||||||
await ensureDir(opts.dir)
|
return initialiseBudibase(opts)
|
||||||
}
|
|
||||||
|
|
||||||
const createClientDatabase = async opts => {
|
|
||||||
// cannot be a top level require as it
|
|
||||||
// will cause environment module to be loaded prematurely
|
|
||||||
const clientDb = require("@budibase/server/src/db/clientDb")
|
|
||||||
|
|
||||||
if (opts.clientId === "new") {
|
|
||||||
// cannot be a top level require as it
|
|
||||||
// will cause environment module to be loaded prematurely
|
|
||||||
const CouchDB = require("@budibase/server/src/db/client")
|
|
||||||
const existing = await CouchDB.allDbs()
|
|
||||||
|
|
||||||
let i = 0
|
|
||||||
let isExisting = true
|
|
||||||
while (isExisting) {
|
|
||||||
i += 1
|
|
||||||
opts.clientId = i.toString()
|
|
||||||
isExisting = existing.includes(clientDb.name(opts.clientId))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
await clientDb.create(opts.clientId)
|
|
||||||
}
|
|
||||||
|
|
||||||
const createDevEnvFile = async opts => {
|
|
||||||
const destConfigFile = join(opts.dir, "./.env")
|
|
||||||
let createConfig = !(await exists(destConfigFile)) || opts.quiet
|
|
||||||
if (!createConfig) {
|
|
||||||
const answers = await inquirer.prompt([
|
|
||||||
{
|
|
||||||
type: "input",
|
|
||||||
name: "overwrite",
|
|
||||||
message: ".env already exists - overwrite? (N/y)",
|
|
||||||
},
|
|
||||||
])
|
|
||||||
createConfig = ["Y", "y", "yes"].includes(answers.overwrite)
|
|
||||||
}
|
|
||||||
|
|
||||||
if (createConfig) {
|
|
||||||
const template = await readFile(serverFileName(".env.template"), {
|
|
||||||
encoding: "utf8",
|
|
||||||
})
|
|
||||||
opts.adminSecret = uuid.v4()
|
|
||||||
opts.cookieKey1 = uuid.v4()
|
|
||||||
opts.cookieKey2 = uuid.v4()
|
|
||||||
const config = Sqrl.Render(template, opts)
|
|
||||||
await writeFile(destConfigFile, config, { flag: "w+" })
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,7 +26,7 @@
|
||||||
"test": "jest routes --runInBand",
|
"test": "jest routes --runInBand",
|
||||||
"test:integration": "jest workflow --runInBand",
|
"test:integration": "jest workflow --runInBand",
|
||||||
"test:watch": "jest --watch",
|
"test:watch": "jest --watch",
|
||||||
"initialise": "node ../cli/bin/budi init -b local -q",
|
"initialise": "node ../cli/bin/budi init -q",
|
||||||
"run:docker": "node src/index",
|
"run:docker": "node src/index",
|
||||||
"budi": "node ../cli/bin/budi",
|
"budi": "node ../cli/bin/budi",
|
||||||
"dev:builder": "nodemon ../cli/bin/budi run",
|
"dev:builder": "nodemon ../cli/bin/budi run",
|
||||||
|
|
|
@ -1,29 +1,46 @@
|
||||||
const { app, BrowserWindow, shell } = require("electron")
|
const { app, BrowserWindow, shell } = require("electron")
|
||||||
const { join } = require("path")
|
const { join } = require("path")
|
||||||
const { homedir } = require("os")
|
|
||||||
const isDev = require("electron-is-dev")
|
const isDev = require("electron-is-dev")
|
||||||
const { autoUpdater } = require("electron-updater")
|
const { autoUpdater } = require("electron-updater")
|
||||||
const unhandled = require("electron-unhandled")
|
const unhandled = require("electron-unhandled")
|
||||||
|
const { existsSync } = require("fs-extra")
|
||||||
|
const initialiseBudibase = require("./utilities/initialiseBudibase")
|
||||||
|
const { budibaseAppsDir } = require("./utilities/budibaseDir")
|
||||||
|
|
||||||
require("dotenv").config({ path: join(homedir(), ".budibase", ".env") })
|
const budibaseDir = budibaseAppsDir()
|
||||||
|
const envFile = join(budibaseDir, ".env")
|
||||||
|
|
||||||
if (isDev) {
|
if (!existsSync(envFile)) {
|
||||||
|
// assume not initialised
|
||||||
|
initialiseBudibase({ dir: budibaseDir }).then(() => {
|
||||||
|
startApp()
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
startApp()
|
||||||
|
}
|
||||||
|
|
||||||
|
function startApp() {
|
||||||
|
// evict environment from cache, so it reloads when next asked
|
||||||
|
delete require.cache[require.resolve("./environment")]
|
||||||
|
require("dotenv").config({ path: envFile })
|
||||||
|
|
||||||
|
if (isDev) {
|
||||||
unhandled({
|
unhandled({
|
||||||
showDialog: true,
|
showDialog: true,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
const APP_URL = "http://localhost:4001/_builder"
|
const APP_URL = "http://localhost:4001/_builder"
|
||||||
const APP_TITLE = "Budibase Builder"
|
const APP_TITLE = "Budibase Builder"
|
||||||
|
|
||||||
let win
|
let win
|
||||||
|
|
||||||
function handleRedirect(e, url) {
|
function handleRedirect(e, url) {
|
||||||
e.preventDefault()
|
e.preventDefault()
|
||||||
shell.openExternal(url)
|
shell.openExternal(url)
|
||||||
}
|
}
|
||||||
|
|
||||||
async function createWindow() {
|
async function createWindow() {
|
||||||
app.server = await require("./app")()
|
app.server = await require("./app")()
|
||||||
win = new BrowserWindow({ width: 1920, height: 1080 })
|
win = new BrowserWindow({ width: 1920, height: 1080 })
|
||||||
win.setTitle(APP_TITLE)
|
win.setTitle(APP_TITLE)
|
||||||
|
@ -37,19 +54,20 @@ async function createWindow() {
|
||||||
// open _blank in default browser
|
// open _blank in default browser
|
||||||
win.webContents.on("new-window", handleRedirect)
|
win.webContents.on("new-window", handleRedirect)
|
||||||
win.webContents.on("will-navigate", handleRedirect)
|
win.webContents.on("will-navigate", handleRedirect)
|
||||||
}
|
}
|
||||||
|
|
||||||
app.whenReady().then(createWindow)
|
app.whenReady().then(createWindow)
|
||||||
|
|
||||||
// Quit when all windows are closed.
|
// Quit when all windows are closed.
|
||||||
app.on("window-all-closed", () => {
|
app.on("window-all-closed", () => {
|
||||||
// On macOS it is common for applications and their menu bar
|
// On macOS it is common for applications and their menu bar
|
||||||
// to stay active until the user quits explicitly with Cmd + Q
|
// to stay active until the user quits explicitly with Cmd + Q
|
||||||
if (process.platform !== "darwin") app.quit()
|
if (process.platform !== "darwin") app.quit()
|
||||||
})
|
})
|
||||||
|
|
||||||
app.on("activate", () => {
|
app.on("activate", () => {
|
||||||
// On macOS it's common to re-create a window in the app when the
|
// On macOS it's common to re-create a window in the app when the
|
||||||
// dock icon is clicked and there are no other windows open.
|
// dock icon is clicked and there are no other windows open.
|
||||||
if (win === null) createWindow()
|
if (win === null) createWindow()
|
||||||
})
|
})
|
||||||
|
}
|
||||||
|
|
|
@ -0,0 +1,66 @@
|
||||||
|
const { exists, readFile, writeFile, ensureDir } = require("fs-extra")
|
||||||
|
const { join, resolve } = require("path")
|
||||||
|
const Sqrl = require("squirrelly")
|
||||||
|
const uuid = require("uuid")
|
||||||
|
|
||||||
|
module.exports = async opts => {
|
||||||
|
await ensureDir(opts.dir)
|
||||||
|
await setCouchDbUrl(opts)
|
||||||
|
|
||||||
|
// need an env file to create the client database
|
||||||
|
await createDevEnvFile(opts)
|
||||||
|
await createClientDatabase(opts)
|
||||||
|
|
||||||
|
// need to recreate the env file, as we only now have a client id
|
||||||
|
// quiet flag will force overwrite of config
|
||||||
|
opts.quiet = true
|
||||||
|
await createDevEnvFile(opts)
|
||||||
|
}
|
||||||
|
|
||||||
|
const setCouchDbUrl = async opts => {
|
||||||
|
if (!opts.couchDbUrl) {
|
||||||
|
const dataDir = join(opts.dir, ".data")
|
||||||
|
await ensureDir(dataDir)
|
||||||
|
opts.couchDbUrl =
|
||||||
|
dataDir + (dataDir.endsWith("/") || dataDir.endsWith("\\") ? "" : "/")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const createDevEnvFile = async opts => {
|
||||||
|
const destConfigFile = join(opts.dir, "./.env")
|
||||||
|
let createConfig = !(await exists(destConfigFile)) || opts.quiet
|
||||||
|
if (createConfig) {
|
||||||
|
const template = await readFile(
|
||||||
|
resolve(__dirname, "..", "..", ".env.template"),
|
||||||
|
{
|
||||||
|
encoding: "utf8",
|
||||||
|
}
|
||||||
|
)
|
||||||
|
opts.cookieKey1 = opts.cookieKey1 || uuid.v4()
|
||||||
|
const config = Sqrl.Render(template, opts)
|
||||||
|
await writeFile(destConfigFile, config, { flag: "w+" })
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const createClientDatabase = async opts => {
|
||||||
|
// cannot be a top level require as it
|
||||||
|
// will cause environment module to be loaded prematurely
|
||||||
|
const clientDb = require("../db/clientDb")
|
||||||
|
|
||||||
|
if (!opts.clientId || opts.clientId === "new") {
|
||||||
|
// cannot be a top level require as it
|
||||||
|
// will cause environment module to be loaded prematurely
|
||||||
|
const CouchDB = require("../db/client")
|
||||||
|
const existing = await CouchDB.allDbs()
|
||||||
|
|
||||||
|
let i = 0
|
||||||
|
let isExisting = true
|
||||||
|
while (isExisting) {
|
||||||
|
i += 1
|
||||||
|
opts.clientId = i.toString()
|
||||||
|
isExisting = existing.includes(clientDb.name(opts.clientId))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
await clientDb.create(opts.clientId)
|
||||||
|
}
|
|
@ -196,21 +196,21 @@
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"datatable": {
|
"datatable": {
|
||||||
"description": "an HTML table that fetches data from a model or view and displays it.",
|
"description": "an HTML table that fetches data from a table or view and displays it.",
|
||||||
"data": true,
|
"data": true,
|
||||||
"props": {
|
"props": {
|
||||||
"model": "models"
|
"model": "models"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"dataform": {
|
"dataform": {
|
||||||
"description": "an HTML table that fetches data from a model or view and displays it.",
|
"description": "an HTML table that fetches data from a table or view and displays it.",
|
||||||
"data": true,
|
"data": true,
|
||||||
"props": {
|
"props": {
|
||||||
"model": "models"
|
"model": "models"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"dataformwide": {
|
"dataformwide": {
|
||||||
"description": "an HTML table that fetches data from a model or view and displays it.",
|
"description": "an HTML table that fetches data from a table or view and displays it.",
|
||||||
"data": true,
|
"data": true,
|
||||||
"props": {
|
"props": {
|
||||||
"model": "models"
|
"model": "models"
|
||||||
|
|
Loading…
Reference in New Issue