From ec594234d86a004c7acbee46a2d3c5708da36b55 Mon Sep 17 00:00:00 2001 From: Michael Shanks Date: Mon, 6 Jul 2020 10:17:23 +0100 Subject: [PATCH 01/11] Add `title` prop to forms (hides title if none entered) --- .../userInterface/temporaryPanelStructure.js | 10 ++++++++++ packages/standard-components/components.json | 6 ++++-- packages/standard-components/src/DataForm.svelte | 7 ++++--- packages/standard-components/src/DataFormWide.svelte | 7 ++++--- 4 files changed, 22 insertions(+), 8 deletions(-) diff --git a/packages/builder/src/components/userInterface/temporaryPanelStructure.js b/packages/builder/src/components/userInterface/temporaryPanelStructure.js index 73bd9dd9b7..e3eb0b67f4 100644 --- a/packages/builder/src/components/userInterface/temporaryPanelStructure.js +++ b/packages/builder/src/components/userInterface/temporaryPanelStructure.js @@ -335,6 +335,11 @@ export default { key: "model", control: ModelSelect, }, + { + label: "Title", + key: "title", + control: Input, + }, ], }, template: { @@ -355,6 +360,11 @@ export default { key: "model", control: ModelSelect, }, + { + label: "Title", + key: "title", + control: Input, + }, ], }, }, diff --git a/packages/standard-components/components.json b/packages/standard-components/components.json index ce205cf92c..cbe2d7ff69 100644 --- a/packages/standard-components/components.json +++ b/packages/standard-components/components.json @@ -206,14 +206,16 @@ "description": "an HTML table that fetches data from a table or view and displays it.", "data": true, "props": { - "model": "models" + "model": "models", + "title": "string" } }, "dataformwide": { "description": "an HTML table that fetches data from a table or view and displays it.", "data": true, "props": { - "model": "models" + "model": "models", + "title": "string" } }, "datalist": { diff --git a/packages/standard-components/src/DataForm.svelte b/packages/standard-components/src/DataForm.svelte index 389ce0ecd2..4e59e6b911 100644 --- a/packages/standard-components/src/DataForm.svelte +++ b/packages/standard-components/src/DataForm.svelte @@ -3,6 +3,7 @@ export let _bb export let model + export let title const TYPE_MAP = { string: "text", @@ -10,8 +11,6 @@ number: "number", } - let username - let password let newModel = { modelId: model, } @@ -64,7 +63,9 @@
-

{modelDef.name} Form

+ {#if title} +

{title}

+ {/if}
{#each fields as field} diff --git a/packages/standard-components/src/DataFormWide.svelte b/packages/standard-components/src/DataFormWide.svelte index f712c787de..332e5d1672 100644 --- a/packages/standard-components/src/DataFormWide.svelte +++ b/packages/standard-components/src/DataFormWide.svelte @@ -2,6 +2,7 @@ import { onMount } from "svelte" export let _bb export let model + export let title const TYPE_MAP = { string: "text", @@ -9,8 +10,6 @@ number: "number", } - let username - let password let newModel = { modelId: model, } @@ -54,7 +53,9 @@ -

{modelDef.name} Form

+ {#if title} +

{title}

+ {/if}
{#each fields as field} From fee6985f3316697ffea259638d25880c783f9b8c Mon Sep 17 00:00:00 2001 From: Michael Shanks Date: Mon, 6 Jul 2020 11:17:54 +0100 Subject: [PATCH 02/11] bugfix: delete component sometimes breaks navigation --- .../frontend/[page]/[screen]/_layout.svelte | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/packages/builder/src/pages/[application]/frontend/[page]/[screen]/_layout.svelte b/packages/builder/src/pages/[application]/frontend/[page]/[screen]/_layout.svelte index b9bed2866a..b601251b16 100644 --- a/packages/builder/src/pages/[application]/frontend/[page]/[screen]/_layout.svelte +++ b/packages/builder/src/pages/[application]/frontend/[page]/[screen]/_layout.svelte @@ -38,15 +38,21 @@ // Loop through each ID ids.forEach(id => { - // Find ID and select it - componentToSelect = currentChildren.find(child => child._id === id) + // Find ID + const component = currentChildren.find(child => child._id === id) + + // If it does not exist, ignore (use last valid route) + if (!component) return + + componentToSelect = component // Update childrens array to selected components children currentChildren = componentToSelect._children }) // Select Component! - store.selectComponent(componentToSelect) + if (componentToSelect) + store.selectComponent(componentToSelect) } From cc1659f807fcc9c01e54d79e21c9881717140113 Mon Sep 17 00:00:00 2001 From: Michael Shanks Date: Mon, 6 Jul 2020 11:30:36 +0100 Subject: [PATCH 03/11] Login: allow edit of title & button text --- .../userInterface/temporaryPanelStructure.js | 10 ++++++++++ .../pages/unauthenticated/page.json | 3 ++- packages/standard-components/components.json | 5 +++-- packages/standard-components/src/Login.svelte | 10 ++++++---- 4 files changed, 21 insertions(+), 7 deletions(-) diff --git a/packages/builder/src/components/userInterface/temporaryPanelStructure.js b/packages/builder/src/components/userInterface/temporaryPanelStructure.js index e3eb0b67f4..69f0005659 100644 --- a/packages/builder/src/components/userInterface/temporaryPanelStructure.js +++ b/packages/builder/src/components/userInterface/temporaryPanelStructure.js @@ -303,6 +303,16 @@ export default { key: "logo", control: Input, }, + { + label: "Title", + key: "title", + control: Input, + }, + { + label: "Button Text", + key: "buttonText", + control: Input, + }, ], }, }, diff --git a/packages/server/src/utilities/appDirectoryTemplate/pages/unauthenticated/page.json b/packages/server/src/utilities/appDirectoryTemplate/pages/unauthenticated/page.json index bfe0590912..fb010023b9 100644 --- a/packages/server/src/utilities/appDirectoryTemplate/pages/unauthenticated/page.json +++ b/packages/server/src/utilities/appDirectoryTemplate/pages/unauthenticated/page.json @@ -28,7 +28,8 @@ "_instanceName": "Login", "inputClass": "", "_children": [], - "name": "{{ name }}", + "title": "Login to {{ name }}", + "buttonText": "Login", "logo": "" } ], diff --git a/packages/standard-components/components.json b/packages/standard-components/components.json index cbe2d7ff69..a46a44b06a 100644 --- a/packages/standard-components/components.json +++ b/packages/standard-components/components.json @@ -66,7 +66,7 @@ "props": { "logo": "asset", "loginRedirect": "string", - "name": "string", + "title": "string", "usernameLabel": { "type": "string", "default": "Username" @@ -80,7 +80,8 @@ "default": "Login" }, "buttonClass": "string", - "inputClass": "string" + "inputClass": "string", + "buttonText": "string" }, "tags": [ "login", diff --git a/packages/standard-components/src/Login.svelte b/packages/standard-components/src/Login.svelte index d09cd0ff2b..2b94d9e425 100644 --- a/packages/standard-components/src/Login.svelte +++ b/packages/standard-components/src/Login.svelte @@ -1,9 +1,9 @@ diff --git a/packages/standard-components/src/DataFormWide.svelte b/packages/standard-components/src/DataFormWide.svelte index 4a47ed46b9..02969a071d 100644 --- a/packages/standard-components/src/DataFormWide.svelte +++ b/packages/standard-components/src/DataFormWide.svelte @@ -13,33 +13,39 @@ number: "number", } - let newModel = { - modelId: model, - } + let record let store = _bb.store let schema = {} let modelDef = {} let saved = false let saving = false + let recordId + let isNew = true let inputElements = {} $: if (model && model.length !== 0) { fetchModel() } + $: fields = Object.keys(schema) + + $: Object.values(inputElements).length && setForm(record) + async function fetchModel() { const FETCH_MODEL_URL = `/api/models/${model}` const response = await _bb.api.get(FETCH_MODEL_URL) modelDef = await response.json() schema = modelDef.schema } + async function save() { // prevent double clicking firing multiple requests if (saving) return saving = true const SAVE_RECORD_URL = `/api/${model}/records` - const response = await _bb.api.post(SAVE_RECORD_URL, newModel) + const response = await _bb.api.post(SAVE_RECORD_URL, record) + const json = await response.json() if (response.status === 200) { @@ -48,7 +54,13 @@ return state }) - resetForm() + // wipe form, if new record, otherwise update + // model to get new _rev + if (isNew) { + resetForm() + } else { + record = json + } // set saved, and unset after 1 second // i.e. make the success notifier appear, then disappear again after time @@ -69,26 +81,58 @@ el.checked = false } } - newModel = { + record = { modelId: model } } + const setForm = rec => { + if (isNew || !rec) return + for (let fieldName in inputElements) { + if (typeof rec[fieldName] === "boolean") { + inputElements[fieldName].checked = rec[fieldName] + } else { + inputElements[fieldName].value = rec[fieldName] + } + } + } + const handleInput = field => event => { let value + if (event.target.type === "checkbox") { value = event.target.checked - newModel[field] = value + record[field] = value return } + if (event.target.type === "number") { value = parseInt(event.target.value) - newModel[field] = value + record[field] = value return } + value = event.target.value - newModel[field] = value + record[field] = value } + + onMount(() => { + const routeParams = _bb.routeParams() + recordId = Object.keys(routeParams).length > 0 && (routeParams.id || routeParams[0]) + isNew = !recordId || recordId === "new" + + if (isNew) { + record = { modelId: model } + } else { + const GET_RECORD_URL = `/api/${model}/records/${recordId}` + _bb.api.get(GET_RECORD_URL) + .then(response => response.json()) + .then(rec => { + record = rec + setForm(rec) + }) + } + }); @@ -127,7 +171,7 @@ {buttonText || "Submit Form"}
{/if} - +