193 lines
18 KiB
JavaScript
193 lines
18 KiB
JavaScript
|
const forms = ({records}) =>
|
||
|
records.map(root);
|
||
|
|
||
|
const root = record => ({
|
||
|
name: `${record.name} Form`,
|
||
|
description: `All fields on record '${record.nodeKey()}' `,
|
||
|
inherits: "@budibase/standard-components/stackpanel",
|
||
|
props: {
|
||
|
direction: "vertical",
|
||
|
children: [
|
||
|
{
|
||
|
_component: "common/Header 1",
|
||
|
value: `Edit ${record.name}`,
|
||
|
},
|
||
|
form(record),
|
||
|
saveCancelButtons(record)
|
||
|
]
|
||
|
}
|
||
|
});
|
||
|
|
||
|
const form = record => ({
|
||
|
_component: "@budibase/standard-components/form",
|
||
|
formControls: [
|
||
|
record.fields.map(f => ({
|
||
|
label: f.label,
|
||
|
control: {
|
||
|
_component: "@budibase/standard-components/textbox",
|
||
|
value: {
|
||
|
"##bbstate":`current${record.name}.${f.name}`,
|
||
|
"##bbsource":"store"
|
||
|
}
|
||
|
}
|
||
|
}))
|
||
|
]
|
||
|
});
|
||
|
|
||
|
const saveCancelButtons = (record) => ({
|
||
|
_component: "@budibase/standard-components/stackpanel",
|
||
|
direction: "horizontal",
|
||
|
children: [
|
||
|
paddedPanelForButton({
|
||
|
_component: "common/Primary Button",
|
||
|
contentText: `Save ${record.name}`,
|
||
|
onClick: [
|
||
|
{
|
||
|
"##eventHandlerType": "Save Record",
|
||
|
parameters: {
|
||
|
statePath: `current${record.name}`,
|
||
|
}
|
||
|
}
|
||
|
]
|
||
|
}),
|
||
|
paddedPanelForButton({
|
||
|
_component: "common/Secondary Button",
|
||
|
contentText: `Cancel`,
|
||
|
onClick: [
|
||
|
{
|
||
|
"##eventHandlerType": "Save Record",
|
||
|
parameters: {
|
||
|
statePath: `current${record.name}`,
|
||
|
}
|
||
|
}
|
||
|
]
|
||
|
})
|
||
|
]
|
||
|
});
|
||
|
|
||
|
const paddedPanelForButton = (button) => ({
|
||
|
_component: "@budibase/standard-components/panel",
|
||
|
padding: "20px",
|
||
|
component: button
|
||
|
});
|
||
|
|
||
|
const indexTables = ({indexes, helpers}) =>
|
||
|
indexes.filter(i => i.parent().type === "root")
|
||
|
.map(i => indexTable(i, helpers));
|
||
|
|
||
|
const indexTableProps = (index, helpers) => ({
|
||
|
data: {
|
||
|
"##bbstate":index.nodeKey(),
|
||
|
"##bbsource":"store"
|
||
|
},
|
||
|
columns: helpers.indexSchema(index).map(column)
|
||
|
});
|
||
|
|
||
|
const indexTable = (index, helpers) => ({
|
||
|
name: `tables/${index.name} Table`,
|
||
|
inherits: "@budibase/standard-components/table",
|
||
|
props: indexTableProps(index, helpers)
|
||
|
});
|
||
|
|
||
|
const column = (col) => ({
|
||
|
title: col.name,
|
||
|
value: {
|
||
|
"##bbstate": col.name,
|
||
|
"##bbsource":"context"
|
||
|
}
|
||
|
});
|
||
|
|
||
|
const nav = ({records, indexes, helpers}) => [
|
||
|
{
|
||
|
name: "Application Root",
|
||
|
inherits: "@budibase/standard-components/nav",
|
||
|
props: {
|
||
|
items: index.map(navItem)
|
||
|
}
|
||
|
},
|
||
|
...indexTables({records, indexes, helpers})
|
||
|
];
|
||
|
|
||
|
|
||
|
const navItem = (index) => ({
|
||
|
title: index.name,
|
||
|
component : {
|
||
|
_component: `tables/${index.name} Table`
|
||
|
}
|
||
|
});
|
||
|
|
||
|
const app = (params) => {
|
||
|
|
||
|
return [
|
||
|
...nav(params),
|
||
|
...forms(params)
|
||
|
];
|
||
|
};
|
||
|
|
||
|
const buttons = () => [
|
||
|
{
|
||
|
name: "common/Primary Button",
|
||
|
description: "a styled button",
|
||
|
inherits: "@budibase/standard-components/button",
|
||
|
props: {
|
||
|
padding: "5px 7px",
|
||
|
border: "1px solid #EEE",
|
||
|
color: "#5F6368",
|
||
|
background: "##f2f2f2",
|
||
|
hoverColor: "black",
|
||
|
hoverBackground: "#cccccc"
|
||
|
}
|
||
|
},
|
||
|
{
|
||
|
name: "common/Secondary Button",
|
||
|
description: "a styled button",
|
||
|
inherits: "@budibase/standard-components/button",
|
||
|
props: {
|
||
|
padding: "5px 7px",
|
||
|
border: "1px solid #EEE",
|
||
|
color: "#5F6368",
|
||
|
background: "##f2f2f2",
|
||
|
hoverColor: "black",
|
||
|
hoverBackground: "#cccccc"
|
||
|
}
|
||
|
}
|
||
|
];
|
||
|
|
||
|
const headers = () => [
|
||
|
{
|
||
|
name: "common/H1",
|
||
|
description: "Header 1",
|
||
|
inherits: "@budibase/standard-components/text",
|
||
|
props: {
|
||
|
font: "20pt",
|
||
|
}
|
||
|
},
|
||
|
{
|
||
|
name: "common/H2",
|
||
|
description: "Header 2",
|
||
|
inherits: "@budibase/standard-components/text",
|
||
|
props: {
|
||
|
font: "15pt",
|
||
|
}
|
||
|
},
|
||
|
{
|
||
|
name: "common/H3",
|
||
|
description: "Header 3",
|
||
|
inherits: "@budibase/standard-components/text",
|
||
|
props: {
|
||
|
font: "12pt bold",
|
||
|
}
|
||
|
},
|
||
|
{
|
||
|
name: "common/H4",
|
||
|
description: "Header 4",
|
||
|
inherits: "@budibase/standard-components/text",
|
||
|
props: {
|
||
|
font: "10pt bold",
|
||
|
}
|
||
|
}
|
||
|
];
|
||
|
|
||
|
export { app, buttons, forms, headers, indexTables, nav };
|
||
|
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiZ2VuZXJhdG9ycy5qcyIsInNvdXJjZXMiOlsiLi4vc3JjL2dlbmVyYXRvcnMvZm9ybXNHZW5lcmF0b3IuanMiLCIuLi9zcmMvZ2VuZXJhdG9ycy9pbmRleFRhYmxlc0dlbmVyYXRvci5qcyIsIi4uL3NyYy9nZW5lcmF0b3JzL25hdkdlbmVyYXRvci5qcyIsIi4uL3NyYy9nZW5lcmF0b3JzL2FwcEdlbmVyYXRvci5qcyIsIi4uL3NyYy9nZW5lcmF0b3JzL2J1dHRvbnNHZW5lcmF0b3IuanMiLCIuLi9zcmMvZ2VuZXJhdG9ycy9oZWFkZXJzR2VuZXJhdG9yLmpzIl0sInNvdXJj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hcmQtY29tcG9uZW50cy90ZXh0Ym94XCIsXHJcbiAgICAgICAgICAgICAgICB2YWx1ZToge1xyXG4gICAgICAgICAgICAgICAgICAgIFwiIyNiYnN0YXRlXCI6YGN1cnJlbnQke3JlY29yZC5uYW1lfS4ke2YubmFtZX1gLFxyXG4gICAgICAgICAgICAgICAgICAgIFwiIyNiYnNvdXJjZVwiOlwic3RvcmVcIlxyXG4gICAgICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICB9XHJcbiAgICAgICAgfSkpXHJcbiAgICBdXHJcbn0pXHJcblxyXG5jb25zdCBzYXZlQ2FuY2VsQnV0dG9ucyA9IChyZWNvcmQpID0+ICh7XHJcbiAgICBfY29tcG9uZW50OiBcIkBidWRpYmFzZS9zdGFuZGFyZC1jb21wb25lbnRzL3N0YWNrcGFuZWxcIixcclxuICAgIGRpcmVjdGlvbjogXCJob3Jpem9udGFsXCIsXHJcbiAgICBjaGlsZHJlbjogW1xyXG4gICAgICAgIHBhZGRlZFBhbmVsRm9yQnV0dG9uKHtcclxuICAgICAgICAgICAgX2NvbXBvbmVudDogXCJjb21tb24vUHJpbWFyeSBCdXR0b25cIixcclxuICAgICAgICAgICAgY29udGVudFRleHQ6IGBTYXZlICR7cmVjb3JkLm5hbWV9YCxcclxuICAgICAgICAgICAgb25DbGljazogWyAgICAgICAgICAgICAgICBcclxuICAgICAgICAgICAgICAgIHtcclxuICAgICAgICAgICAgICAgICAgICBcIiMjZXZlbnRIYW5kbGVyVHlwZVwiOiBcIlNhdmUgUmVjb3JkXCIsXHJcbiAgICAgICAgICAgICAgICAgICAgcGFyYW1ldGVyczoge1xyXG4gICAgICAgICAgICAgICAgICAgICAgICBzdGF0ZVBhdGg6IGBjdXJyZW50JHtyZWNvcmQubmFtZX1gLFxyXG4gICAgICAgICAgICAgICAgICAgIH1cclxuICAgICAgICAgICAgICAgIH1cclxuICAgICAgICAgICAgXVxyXG4gICAgICAgIH0pLFxyXG4gICAgICAgIHBhZGRlZFBhbmVsRm9yQnV0dG9uKHtcclxuICAgICAgICAgICAgX2NvbXBvbmVudDogXCJjb21tb24vU2Vjb25kYXJ5IEJ1dHRvblwiLFxyXG4gICAgICAgICAgICBjb250ZW50VGV4dDogYENhbmNlbGAsXHJcbiAgICAgICAgICAgIG9uQ2xpY2s6IFtcclxuICAgICAgICAgICAgICAgIHtcclxuICAgICAgICAgICAgICAgICAgICBcIiMjZXZlbnRIYW5kbGVyVHlwZVwiOiBcIlNhdmUgUmVjb3JkXCIsXHJcbiAgICAgICAgICAgICAgICAgICAgcGFyYW1ldGVyczoge1xyXG4gICAgICAgICAgICAgICAgICAgICAgICBzdGF0ZVBhdGg6IGBjdXJyZW50JHtyZWNvcmQubmFtZX1gLFxyXG4gICAgICAgICAgICAgICAgICAgIH1cclxuICAgICAgICAgICAgICAgIH1cclxuICAgICAgICAgICAgXVxyXG4gICAgICAgIH0pXHJcbiAgICBdXHJcbn0pXHJcblxyXG5jb25zdCBwYWRkZWRQYW5lbEZvckJ1dHRvbiA9IChidXR0b24pID0+ICh7XHJcbiAgICBfY29tcG9uZW50OiBcIkBidWRpYmFzZS9zdGFuZGFyZC1jb21wb25lbnRzL3BhbmVsXCIsXHJcbiAgICBwYWRkaW5nOiBcIjIwcHhcIixcclxuICAgIGNvbXBvbmVudDogYnV0dG9uXHJcbn0pO1xyXG5cclxuIiwiZXhwb3J0IGNvbnN0IGluZGV4VGFibGVzID0gKHtpbmRleGVzLCBoZWxwZXJzfSkgPT4gXHJcbiAgICBpbmRleGVzLmZpbHRlcihpID0+IGkucGFyZW50KCkudHlwZSA9PT0gXCJyb290XCIpXHJcbiAgICAgICAgICAgLm1hcChpID0+IGluZGV4VGFibGUoaSwgaGVscGVycykpO1xyXG5cclxuZXhwb3J0IGNvbnN0IGluZGV4VGFibGVQcm9wcyA9IChpbmRleCwgaGVscGVycykgPT4gKHtcclxuICAgIGRhdGE6IHtcclxuICAgICAgICBcIiMjYmJzdGF0ZVwiOmluZGV4Lm5vZGVLZXkoKSxcclxuICAgICAgICBcIiMjYmJzb3VyY2VcIjpcInN0b3JlXCJcclxuICAgIH0sXHJcbiAgICBjb2x1bW5zOiBoZWxwZXJzLmluZGV4U2NoZW1hKGluZGV4KS5tYXAoY29sdW1uKVxyXG59KTtcclxuXHJcbmNvbnN0IGluZGV4VGFibGUgPSAoaW5kZXgsIGhlbHBlcnMpID0+ICh
|