forked from tsai/budibase
5 changed files with 330 additions and 309 deletions
@ -1,221 +1,219 @@ |
|||||
const LayoutTypes = { |
const BASE_LAYOUTS = [ |
||||
MAIN: "main", |
{ |
||||
UNAUTHENTICATED: "unauthenticated", |
componentLibraries: ["@budibase/standard-components"], |
||||
} |
title: "{{ name }}", |
||||
|
favicon: "./_shared/favicon.png", |
||||
const MAIN = { |
stylesheets: [], |
||||
componentLibraries: ["@budibase/standard-components"], |
name: "Main", |
||||
title: "{{ name }}", |
props: { |
||||
favicon: "./_shared/favicon.png", |
_id: "private-master-root", |
||||
stylesheets: [], |
_component: "@budibase/standard-components/container", |
||||
name: LayoutTypes.MAIN, |
_children: [ |
||||
props: { |
{ |
||||
_id: "private-master-root", |
_id: "c74f07266980c4b6eafc33e2a6caa783d", |
||||
_component: "@budibase/standard-components/container", |
_component: "@budibase/standard-components/container", |
||||
_children: [ |
_styles: { |
||||
{ |
normal: { |
||||
_id: "c74f07266980c4b6eafc33e2a6caa783d", |
display: "flex", |
||||
_component: "@budibase/standard-components/container", |
"flex-direction": "row", |
||||
_styles: { |
"justify-content": "flex-start", |
||||
normal: { |
"align-items": "flex-start", |
||||
display: "flex", |
background: "#fff", |
||||
"flex-direction": "row", |
width: "100%", |
||||
"justify-content": "flex-start", |
"box-shadow": "0 1px 2px 0 rgba(0, 0, 0, 0.05)", |
||||
"align-items": "flex-start", |
}, |
||||
background: "#fff", |
hover: {}, |
||||
width: "100%", |
active: {}, |
||||
"box-shadow": "0 1px 2px 0 rgba(0, 0, 0, 0.05)", |
selected: {}, |
||||
}, |
}, |
||||
hover: {}, |
_code: "", |
||||
active: {}, |
className: "", |
||||
selected: {}, |
onLoad: [], |
||||
}, |
type: "div", |
||||
_code: "", |
_appId: "inst_app_80b_f158d4057d2c4bedb0042d42fda8abaf", |
||||
className: "", |
_instanceName: "Header", |
||||
onLoad: [], |
_children: [ |
||||
type: "div", |
{ |
||||
_appId: "inst_app_80b_f158d4057d2c4bedb0042d42fda8abaf", |
_id: "49e0e519-9e5e-4127-885a-ee6a0a49e2c1", |
||||
_instanceName: "Header", |
_component: "@budibase/standard-components/Navigation", |
||||
_children: [ |
_styles: { |
||||
{ |
normal: { |
||||
_id: "49e0e519-9e5e-4127-885a-ee6a0a49e2c1", |
"max-width": "1400px", |
||||
_component: "@budibase/standard-components/Navigation", |
"margin-left": "auto", |
||||
_styles: { |
"margin-right": "auto", |
||||
normal: { |
padding: "20px", |
||||
"max-width": "1400px", |
color: "#757575", |
||||
"margin-left": "auto", |
"font-weight": "400", |
||||
"margin-right": "auto", |
"font-size": "16px", |
||||
padding: "20px", |
flex: "1 1 auto", |
||||
color: "#757575", |
}, |
||||
"font-weight": "400", |
hover: {}, |
||||
"font-size": "16px", |
active: {}, |
||||
flex: "1 1 auto", |
selected: {}, |
||||
}, |
}, |
||||
hover: {}, |
_code: "", |
||||
active: {}, |
logoUrl: |
||||
selected: {}, |
"https://d33wubrfki0l68.cloudfront.net/aac32159d7207b5085e74a7ef67afbb7027786c5/2b1fd/img/logo/bb-emblem.svg", |
||||
}, |
title: "", |
||||
_code: "", |
backgroundColor: "", |
||||
logoUrl: |
color: "", |
||||
"https://d33wubrfki0l68.cloudfront.net/aac32159d7207b5085e74a7ef67afbb7027786c5/2b1fd/img/logo/bb-emblem.svg", |
borderWidth: "", |
||||
title: "", |
borderColor: "", |
||||
backgroundColor: "", |
borderStyle: "", |
||||
color: "", |
_appId: "inst_cf8ace4_69efc0d72e6f443db2d4c902c14d9394", |
||||
borderWidth: "", |
_instanceName: "Navigation", |
||||
borderColor: "", |
_children: [ |
||||
borderStyle: "", |
{ |
||||
_appId: "inst_cf8ace4_69efc0d72e6f443db2d4c902c14d9394", |
_id: "48b35328-4c91-4343-a6a3-1a1fd77b3386", |
||||
_instanceName: "Navigation", |
_component: "@budibase/standard-components/link", |
||||
_children: [ |
_styles: { |
||||
{ |
normal: { |
||||
_id: "48b35328-4c91-4343-a6a3-1a1fd77b3386", |
"font-family": "Inter", |
||||
_component: "@budibase/standard-components/link", |
"font-weight": "500", |
||||
_styles: { |
color: "#000000", |
||||
normal: { |
"text-decoration-line": "none", |
||||
"font-family": "Inter", |
"font-size": "16px", |
||||
"font-weight": "500", |
}, |
||||
color: "#000000", |
hover: { |
||||
"text-decoration-line": "none", |
color: "#4285f4", |
||||
"font-size": "16px", |
}, |
||||
|
active: {}, |
||||
|
selected: {}, |
||||
}, |
}, |
||||
hover: { |
_code: "", |
||||
color: "#4285f4", |
url: "/", |
||||
}, |
openInNewTab: false, |
||||
active: {}, |
text: "Home", |
||||
selected: {}, |
color: "", |
||||
|
hoverColor: "", |
||||
|
underline: false, |
||||
|
fontSize: "", |
||||
|
fontFamily: "initial", |
||||
|
_appId: "inst_cf8ace4_69efc0d72e6f443db2d4c902c14d9394", |
||||
|
_instanceName: "Home Link", |
||||
|
_children: [], |
||||
}, |
}, |
||||
_code: "", |
], |
||||
url: "/", |
}, |
||||
openInNewTab: false, |
], |
||||
text: "Home", |
}, |
||||
color: "", |
{ |
||||
hoverColor: "", |
_id: "7fcf11e4-6f5b-4085-8e0d-9f3d44c98967", |
||||
underline: false, |
_component: "##builtin/screenslot", |
||||
fontSize: "", |
_styles: { |
||||
fontFamily: "initial", |
normal: { |
||||
_appId: "inst_cf8ace4_69efc0d72e6f443db2d4c902c14d9394", |
flex: "1 1 auto", |
||||
_instanceName: "Home Link", |
display: "flex", |
||||
_children: [], |
"flex-direction": "column", |
||||
}, |
"justify-content": "flex-start", |
||||
], |
"align-items": "stretch", |
||||
}, |
"max-width": "100%", |
||||
], |
"margin-left": "20px", |
||||
}, |
"margin-right": "20px", |
||||
{ |
width: "1400px", |
||||
_id: "7fcf11e4-6f5b-4085-8e0d-9f3d44c98967", |
padding: "20px", |
||||
_component: "##builtin/screenslot", |
}, |
||||
_styles: { |
hover: {}, |
||||
normal: { |
active: {}, |
||||
flex: "1 1 auto", |
selected: {}, |
||||
display: "flex", |
|
||||
"flex-direction": "column", |
|
||||
"justify-content": "flex-start", |
|
||||
"align-items": "stretch", |
|
||||
"max-width": "100%", |
|
||||
"margin-left": "20px", |
|
||||
"margin-right": "20px", |
|
||||
width: "1400px", |
|
||||
padding: "20px", |
|
||||
}, |
}, |
||||
hover: {}, |
_code: "", |
||||
active: {}, |
_children: [], |
||||
selected: {}, |
|
||||
}, |
}, |
||||
_code: "", |
], |
||||
_children: [], |
type: "div", |
||||
}, |
_styles: { |
||||
], |
active: {}, |
||||
type: "div", |
hover: {}, |
||||
_styles: { |
normal: { |
||||
active: {}, |
display: "flex", |
||||
hover: {}, |
"flex-direction": "column", |
||||
normal: { |
"align-items": "center", |
||||
display: "flex", |
"justify-content": "flex-start", |
||||
"flex-direction": "column", |
"margin-right": "auto", |
||||
"align-items": "center", |
"margin-left": "auto", |
||||
"justify-content": "flex-start", |
"min-height": "100%", |
||||
"margin-right": "auto", |
"background-image": |
||||
"margin-left": "auto", |
"linear-gradient(135deg, rgba(252,215,212,1) 20%, rgba(207,218,255,1) 100%);", |
||||
"min-height": "100%", |
}, |
||||
"background-image": |
selected: {}, |
||||
"linear-gradient(135deg, rgba(252,215,212,1) 20%, rgba(207,218,255,1) 100%);", |
|
||||
}, |
}, |
||||
selected: {}, |
_code: "", |
||||
|
className: "", |
||||
|
onLoad: [], |
||||
}, |
}, |
||||
_code: "", |
|
||||
className: "", |
|
||||
onLoad: [], |
|
||||
}, |
}, |
||||
} |
{ |
||||
|
componentLibraries: ["@budibase/standard-components"], |
||||
const UNAUTHENTICATED = { |
title: "{{ name }}", |
||||
componentLibraries: ["@budibase/standard-components"], |
favicon: "./_shared/favicon.png", |
||||
title: "{{ name }}", |
stylesheets: [], |
||||
favicon: "./_shared/favicon.png", |
name: "Unauthenticated", |
||||
stylesheets: [], |
props: { |
||||
name: LayoutTypes.UNAUTHENTICATED, |
_id: "public-master-root", |
||||
props: { |
_component: "@budibase/standard-components/container", |
||||
_id: "public-master-root", |
_children: [ |
||||
_component: "@budibase/standard-components/container", |
{ |
||||
_children: [ |
_id: "686c252d-dbf2-4e28-9078-414ba4719759", |
||||
{ |
_component: "@budibase/standard-components/login", |
||||
_id: "686c252d-dbf2-4e28-9078-414ba4719759", |
_styles: { |
||||
_component: "@budibase/standard-components/login", |
normal: { |
||||
_styles: { |
padding: "64px", |
||||
normal: { |
background: "rgba(255, 255, 255, 0.4)", |
||||
padding: "64px", |
"border-radius": "0.5rem", |
||||
background: "rgba(255, 255, 255, 0.4)", |
"margin-top": "0px", |
||||
"border-radius": "0.5rem", |
margin: "0px", |
||||
"margin-top": "0px", |
"line-height": "1", |
||||
margin: "0px", |
"box-shadow": |
||||
"line-height": "1", |
"0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04)", |
||||
"box-shadow": |
"font-size": "16px", |
||||
"0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04)", |
"font-family": "Inter", |
||||
"font-size": "16px", |
flex: "0 1 auto", |
||||
"font-family": "Inter", |
transform: "0", |
||||
flex: "0 1 auto", |
}, |
||||
transform: "0", |
hover: {}, |
||||
|
active: {}, |
||||
|
selected: {}, |
||||
}, |
}, |
||||
hover: {}, |
_code: "", |
||||
active: {}, |
loginRedirect: "", |
||||
selected: {}, |
usernameLabel: "Username", |
||||
|
passwordLabel: "Password", |
||||
|
loginButtonLabel: "Login", |
||||
|
buttonClass: "", |
||||
|
_instanceName: "Login", |
||||
|
inputClass: "", |
||||
|
_children: [], |
||||
|
title: "Log in to {{ name }}", |
||||
|
buttonText: "Log In", |
||||
|
logo: |
||||
|
"https://d33wubrfki0l68.cloudfront.net/aac32159d7207b5085e74a7ef67afbb7027786c5/2b1fd/img/logo/bb-emblem.svg", |
||||
}, |
}, |
||||
_code: "", |
], |
||||
loginRedirect: "", |
type: "div", |
||||
usernameLabel: "Username", |
_styles: { |
||||
passwordLabel: "Password", |
active: {}, |
||||
loginButtonLabel: "Login", |
hover: {}, |
||||
buttonClass: "", |
normal: { |
||||
_instanceName: "Login", |
display: "flex", |
||||
inputClass: "", |
"flex-direction": "column", |
||||
_children: [], |
"align-items": "center", |
||||
title: "Log in to {{ name }}", |
"justify-content": "center", |
||||
buttonText: "Log In", |
"margin-right": "auto", |
||||
logo: |
"margin-left": "auto", |
||||
"https://d33wubrfki0l68.cloudfront.net/aac32159d7207b5085e74a7ef67afbb7027786c5/2b1fd/img/logo/bb-emblem.svg", |
"min-height": "100%", |
||||
}, |
"background-image": |
||||
], |
"linear-gradient(135deg, rgba(252,215,212,1) 20%, rgba(207,218,255,1) 100%);", |
||||
type: "div", |
}, |
||||
_styles: { |
selected: {}, |
||||
active: {}, |
|
||||
hover: {}, |
|
||||
normal: { |
|
||||
display: "flex", |
|
||||
"flex-direction": "column", |
|
||||
"align-items": "center", |
|
||||
"justify-content": "center", |
|
||||
"margin-right": "auto", |
|
||||
"margin-left": "auto", |
|
||||
"min-height": "100%", |
|
||||
"background-image": |
|
||||
"linear-gradient(135deg, rgba(252,215,212,1) 20%, rgba(207,218,255,1) 100%);", |
|
||||
}, |
}, |
||||
selected: {}, |
_code: "", |
||||
|
className: "", |
||||
|
onLoad: [], |
||||
}, |
}, |
||||
_code: "", |
|
||||
className: "", |
|
||||
onLoad: [], |
|
||||
}, |
}, |
||||
} |
] |
||||
|
|
||||
module.exports = { MAIN, UNAUTHENTICATED, LayoutTypes } |
module.exports = { |
||||
|
BASE_LAYOUTS, |
||||
|
} |
||||
|
|||||
@ -0,0 +1,73 @@ |
|||||
|
const handlebars = require("handlebars") |
||||
|
|
||||
|
handlebars.registerHelper("object", value => { |
||||
|
return new handlebars.SafeString(JSON.stringify(value)) |
||||
|
}) |
||||
|
|
||||
|
/** |
||||
|
* When running mustache statements to execute on the context of the automation it possible user's may input mustache |
||||
|
* in a few different forms, some of which are invalid but are logically valid. An example of this would be the mustache |
||||
|
* statement "{{steps[0].revision}}" here it is obvious the user is attempting to access an array or object using array |
||||
|
* like operators. These are not supported by Mustache and therefore the statement will fail. This function will clean up |
||||
|
* the mustache statement so it instead reads as "{{steps.0.revision}}" which is valid and will work. It may also be expanded |
||||
|
* to include any other mustache statement cleanup that has been deemed necessary for the system. |
||||
|
* |
||||
|
* @param {string} string The string which *may* contain mustache statements, it is OK if it does not contain any. |
||||
|
* @returns {string} The string that was input with cleaned up mustache statements as required. |
||||
|
*/ |
||||
|
function cleanMustache(string) { |
||||
|
let charToReplace = { |
||||
|
"[": ".", |
||||
|
"]": "", |
||||
|
} |
||||
|
let regex = new RegExp(/{{[^}}]*}}/g) |
||||
|
let matches = string.match(regex) |
||||
|
if (matches == null) { |
||||
|
return string |
||||
|
} |
||||
|
for (let match of matches) { |
||||
|
let baseIdx = string.indexOf(match) |
||||
|
for (let key of Object.keys(charToReplace)) { |
||||
|
let idxChar = match.indexOf(key) |
||||
|
if (idxChar !== -1) { |
||||
|
string = |
||||
|
string.slice(baseIdx, baseIdx + idxChar) + |
||||
|
charToReplace[key] + |
||||
|
string.slice(baseIdx + idxChar + 1) |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
return string |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Given an input object this will recurse through all props to try and update |
||||
|
* any handlebars/mustache statements within. |
||||
|
* @param {object|array} inputs The input structure which is to be recursed, it is important to note that |
||||
|
* if the structure contains any cycles then this will fail. |
||||
|
* @param {object} context The context that handlebars should fill data from. |
||||
|
* @returns {object|array} The structure input, as fully updated as possible. |
||||
|
*/ |
||||
|
function recurseMustache(inputs, context) { |
||||
|
// JSON stringify will fail if there are any cycles, stops infinite recursion
|
||||
|
try { |
||||
|
JSON.stringify(inputs) |
||||
|
} catch (err) { |
||||
|
throw "Unable to process inputs to JSON, cannot recurse" |
||||
|
} |
||||
|
for (let key of Object.keys(inputs)) { |
||||
|
let val = inputs[key] |
||||
|
if (typeof val === "string") { |
||||
|
val = cleanMustache(inputs[key]) |
||||
|
const template = handlebars.compile(val) |
||||
|
inputs[key] = template(context) |
||||
|
} |
||||
|
// this covers objects and arrays
|
||||
|
else if (typeof val === "object") { |
||||
|
inputs[key] = recurseMustache(inputs[key], context) |
||||
|
} |
||||
|
} |
||||
|
return inputs |
||||
|
} |
||||
|
|
||||
|
exports.recurseMustache = recurseMustache |
||||
Loading…
Reference in new issue