208 lines
19 KiB
JavaScript
208 lines
19 KiB
JavaScript
|
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",
|
||
|
}
|
||
|
}
|
||
|
];
|
||
|
|
||
|
const forms = ({records, indexes}) =>
|
||
|
[...headers(),
|
||
|
...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: [
|
||
|
{
|
||
|
control: {
|
||
|
_component: "common/H1",
|
||
|
value: `Edit ${record.name}`,
|
||
|
}
|
||
|
},
|
||
|
form(record),
|
||
|
saveCancelButtons(record)
|
||
|
]
|
||
|
}
|
||
|
});
|
||
|
|
||
|
const form = record => ({
|
||
|
control: {
|
||
|
_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) => ({
|
||
|
control: {
|
||
|
_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) => ({
|
||
|
control: {
|
||
|
_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: indexes
|
||
|
.filter(i => i.parent().type === "root")
|
||
|
.map(navItem),
|
||
|
selectedItem: {
|
||
|
"##bbstate": "selectedNav",
|
||
|
"##bbstatefallback": records[0].collectionName,
|
||
|
"##bbsource":"store"
|
||
|
}
|
||
|
},
|
||
|
},
|
||
|
...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"
|
||
|
}
|
||
|
}
|
||
|
];
|
||
|
|
||
|
export { app, buttons, forms, headers, indexTables, nav };
|
||
|
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiZ2VuZXJhdG9ycy5qcyIsInNvdXJjZXMiOlsiLi4vc3JjL2dlbmVyYXRvcnMvaGVhZGVyc0dlbmVyYXRvci5qcyIsIi4uL3NyYy9nZW5lcmF0b3JzL2Zvcm1zR2VuZXJhdG9yLmpzIiwiLi4vc3JjL2dl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IH0sXHJcbiAgICB7XHJcbiAgICAgICAgbmFtZTogXCJjb21tb24vSDRcIixcclxuICAgICAgICBkZXNjcmlwdGlvbjogXCJIZWFkZXIgNFwiLFxyXG4gICAgICAgIGluaGVyaXRzOiBcIkBidWRpYmFzZS9zdGFuZGFyZC1jb21wb25lbnRzL3RleHRcIixcclxuICAgICAgICBwcm9wczoge1xyXG4gICAgICAgICAgICBmb250OiBcIjEwcHQgYm9sZFwiLFxyXG4gICAgICAgIH1cclxuICAgIH1cclxuXSIsImltcG9ydCB7aGVhZGVyc30gZnJvbSBcIi4vaGVhZGVyc0dlbmVyYXRvclwiO1xyXG5cclxuZXhwb3J0IGNvbnN0IGZvcm1zID0gKHtyZWNvcmRzLCBpbmRleGVzfSkgPT4gXHJcbiAgICBbLi4uaGVhZGVycyh7cmVjb3JkcywgaW5kZXhlc30pLFxyXG4gICAgLi4ucmVjb3Jkcy5tYXAocm9vdCldO1xyXG5cclxuY29uc3Qgcm9vdCA9IHJlY29yZCA9PiAoe1xyXG4gICAgbmFtZTogYCR7cmVjb3JkLm5hbWV9IEZvcm1gLFxyXG4gICAgZGVzY3JpcHRpb246IGBBbGwgZmllbGRzIG9uIHJlY29yZCAnJHtyZWNvcmQubm9kZUtleSgpfScgYCxcclxuICAgIGluaGVyaXRzOiBcIkBidWRpYmFzZS9zdGFuZGFyZC1jb21wb25lbnRzL3N0YWNrcGFuZWxcIixcclxuICAgIHByb3BzOiB7XHJcbiAgICAgICAgZGlyZWN0aW9uOiBcInZlcnRpY2FsXCIsXHJcbiAgICAgICAgY2hpbGRyZW46IFtcclxuICAgICAgICAgICAge1xyXG4gICAgICAgICAgICAgICAgY29udHJvbDoge1xyXG4gICAgICAgICAgICAgICAgICAgIF9jb21wb25lbnQ6IFwiY29tbW9uL0gxXCIsXHJcbiAgICAgICAgICAgICAgICAgICAgdmFsdWU6IGBFZGl0ICR7cmVjb3JkLm5hbWV9YCxcclxuICAgICAgICAgICAgICAgIH1cclxuICAgICAgICAgICAgfSxcclxuICAgICAgICAgICAgZm9ybShyZWNvcmQpLFxyXG4gICAgICAgICAgICBzYXZlQ2FuY2VsQnV0dG9ucyhyZWNvcmQpXHJcbiAgICAgICAgXVxyXG4gICAgfVxyXG59KSBcclxuXHJcbmNvbnN0IGZvcm0gPSByZWNvcmQgPT4gKHtcclxuICAgIGNvbnRyb2w6IHtcclxuICAgICAgICBfY29tcG9uZW50OiBcIkBidWRpYmFzZS9zdGFuZGFyZC1jb21wb25lbnRzL2Zvcm1cIixcclxuICAgICAgICBmb3JtQ29udHJvbHM6IFxyXG4gICAgICAgICAgICByZWNvcmQuZmllbGRzLm1hcChmID0+ICh7XHJcbiAgICAgICAgICAgICAgICBsYWJlbDogZi5sYWJlbCxcclxuICAgICAgICAgICAgICAgIGNvbnRyb2w6IHtcclxuICAgICAgICAgICAgICAgICAgICBfY29tcG9uZW50OiBcIkBidWRpYmFzZS9zdGFuZGFyZC1jb21wb25lbnRzL3RleHRib3hcIixcclxuICAgICAgICAgICAgICAgICAgICB2YWx1ZToge1xyXG4gICAgICAgICAgICAgICAgICAgICAgICBcIiMjYmJzdGF0ZVwiOmBjdXJyZW50JHtyZWNvcmQubmFtZX0uJHtmLm5hbWV9YCxcclxuICAgICAgICAgICAgICAgICAgICAgICAgXCIjI2Jic291cmNlXCI6XCJzdG9yZVwiXHJcbiAgICAgICAgICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICB9KSlcclxuICAgIH1cclxufSlcclxuXHJcbmNvbnN0IHNhdmVDYW5jZWxCdXR0b25zID0gKHJlY29yZCkgPT4gKHtcclxuICAgIGNvbnRyb2w6IHtcclxuICAgICAgICBfY29tcG9uZW50OiBcIkBidWRpYmFzZS9zdGFuZGFyZC1jb21wb25lbnRzL3N0YWNrcGFuZWxcIixcclxuICAgICAgICBkaXJlY3Rpb246IFwiaG9yaXpvbnRhbFwiLFxyXG4gICAgICAgIGNoaWxkcmVuOiBbXHJcbiAgICAgICAgICAgIHBhZGRlZFBhbmVsRm9yQnV0dG9uKHtcclxuICAgICAgICAgICAgICAgIF9jb21wb25lbnQ6IFwiY29tbW9uL1ByaW1hcnkgQnV0dG9uXCIsXHJcbiAgICAgICAgICAgICAgICBjb250ZW50VGV4dDogYFNhdmUgJHtyZWNvcmQubmFtZX1gLFxyXG4gICAgICAgICAgICAgICAgb25DbGljazogWyAgICAgICAgICAgICAgICBcclxuICAgICAgICAgICAgICAgICAgICB7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgIFwiIyNldmVudEhhbmRsZXJUeXBlXCI6IFwiU2F2ZSBSZWNvcmRcIixcclxuICAgICAgICAgICAgICAgICAgICAgICAgcGFyYW1ldGVyczo
|