2019-10-18 18:32:03 +02:00
|
|
|
const buttons = () => [
|
|
|
|
{
|
|
|
|
name: "common/Primary Button",
|
|
|
|
description: "Bootstrap primary button ",
|
|
|
|
inherits: "@budibase/standard-components/button",
|
|
|
|
props: {
|
|
|
|
className: "btn btn-primary"
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "common/Default Button",
|
|
|
|
description: "Bootstrap default button",
|
|
|
|
inherits: "@budibase/standard-components/button",
|
|
|
|
props: {
|
|
|
|
className: "btn btn-light"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
];
|
2019-10-14 09:32:20 +02:00
|
|
|
|
2019-10-18 18:32:03 +02:00
|
|
|
const forms = ({records, indexes, helpers}) =>
|
|
|
|
[
|
|
|
|
...records.map(root),
|
|
|
|
...buttons()
|
|
|
|
];
|
|
|
|
|
|
|
|
const formName = record => `${record.name}/${record.name} Form`;
|
|
|
|
|
|
|
|
const root = record => ({
|
|
|
|
name: formName(record),
|
|
|
|
description: `Control for creating/updating '${record.nodeKey()}' `,
|
|
|
|
inherits: "@budibase/standard-components/div",
|
|
|
|
props: {
|
|
|
|
className:"p-1",
|
|
|
|
children: [
|
|
|
|
{
|
|
|
|
component: {
|
|
|
|
_component: "@budibase/standard-components/h3",
|
|
|
|
text: `Edit ${record.name}`,
|
|
|
|
}
|
|
|
|
},
|
|
|
|
form(record),
|
|
|
|
saveCancelButtons(record)
|
|
|
|
]
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
const form = record => ({
|
|
|
|
component: {
|
|
|
|
_component: "@budibase/standard-components/form",
|
|
|
|
formControls:
|
|
|
|
record.fields.map(f => formControl(record, f))
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
const formControl = (record, field) => {
|
|
|
|
if(field.type === "string" && field.typeOptions.values && field.typeOptions.values.length > 0) {
|
|
|
|
return ({
|
|
|
|
control: {
|
|
|
|
_component: "@budibase/standard-components/select",
|
|
|
|
options: field.typeOptions.values.map(v => ({id:v, value:v})),
|
|
|
|
value: {
|
|
|
|
"##bbstate":`${record.name}.${field.name}`,
|
|
|
|
"##bbsource":"store"
|
|
|
|
},
|
|
|
|
className: "form-control"
|
|
|
|
},
|
|
|
|
label: field.label
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
return ({
|
|
|
|
control: {
|
|
|
|
_component: "@budibase/standard-components/input",
|
|
|
|
value: {
|
|
|
|
"##bbstate":`${record.name}.${field.name}`,
|
|
|
|
"##bbsource":"store"
|
|
|
|
},
|
|
|
|
className: "form-control",
|
|
|
|
type: field.type === "string" ? "text"
|
|
|
|
: field.type === "datetime" ? "date"
|
|
|
|
: field.type === "number" ? "number"
|
|
|
|
: "text"
|
|
|
|
},
|
|
|
|
label: field.label
|
|
|
|
});
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
const saveCancelButtons = (record) => ({
|
|
|
|
component: {
|
|
|
|
_component: "@budibase/standard-components/stackpanel",
|
|
|
|
direction: "horizontal",
|
|
|
|
children: [
|
|
|
|
paddedPanelForButton({
|
|
|
|
_component: "common/Primary Button",
|
|
|
|
contentText: `Save ${record.name}`,
|
|
|
|
onClick: [
|
|
|
|
{
|
|
|
|
"##eventHandlerType": "Save Record",
|
|
|
|
parameters: {
|
|
|
|
statePath: `${record.name}`,
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"##eventHandlerType": "Set State",
|
|
|
|
parameters: {
|
|
|
|
path: `isEditing${record.name}`,
|
|
|
|
value: ""
|
|
|
|
}
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}),
|
|
|
|
paddedPanelForButton({
|
|
|
|
_component: "common/Default Button",
|
|
|
|
contentText: `Cancel`,
|
|
|
|
onClick: [
|
|
|
|
{
|
|
|
|
"##eventHandlerType": "Set State",
|
|
|
|
parameters: {
|
|
|
|
path: `isEditing${record.name}`,
|
|
|
|
value: ""
|
|
|
|
}
|
|
|
|
}
|
|
|
|
]
|
|
|
|
})
|
|
|
|
]
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
const paddedPanelForButton = (button) => ({
|
|
|
|
control: {
|
|
|
|
_component: "@budibase/standard-components/div",
|
|
|
|
className: "btn-group",
|
|
|
|
children: [
|
|
|
|
{
|
|
|
|
component: button
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
const getRecordPath = (record) => {
|
|
|
|
|
|
|
|
const parts = [];
|
|
|
|
|
|
|
|
return parts.reverse().join("/");
|
|
|
|
};
|
|
|
|
|
|
|
|
const indexTables = ({indexes, helpers}) =>
|
|
|
|
indexes.map(i => indexTable(i, helpers));
|
|
|
|
|
|
|
|
const excludedColumns = ["id", "isNew", "key", "type", "sortKey"];
|
|
|
|
|
|
|
|
const indexTableProps = (index, helpers) => ({
|
|
|
|
data: {
|
|
|
|
"##bbstate":index.nodeKey(),
|
|
|
|
"##bbsource":"store"
|
|
|
|
},
|
|
|
|
tableClass: "table table-hover",
|
|
|
|
theadClass: "thead-dark",
|
|
|
|
columns: helpers
|
|
|
|
.indexSchema(index)
|
|
|
|
.filter(c => !excludedColumns.includes(c.name))
|
|
|
|
.map(column),
|
|
|
|
onRowClick: [
|
|
|
|
{
|
|
|
|
"##eventHandlerType": "Load Record",
|
|
|
|
parameters: {
|
|
|
|
recordKey: {
|
|
|
|
"##bbstate": "key",
|
|
|
|
"##bbsource": "context"
|
|
|
|
},
|
|
|
|
statePath: {
|
|
|
|
"##bbstate": "type",
|
|
|
|
"##bbsource": "context"
|
|
|
|
}
|
|
|
|
},
|
|
|
|
"##eventHandlerType": "Set State",
|
|
|
|
parameters: {
|
|
|
|
path: "currentView",
|
|
|
|
value: {
|
|
|
|
"##bbstate": "type",
|
|
|
|
"##bbsource": "context"
|
|
|
|
}
|
|
|
|
},
|
|
|
|
}
|
|
|
|
]
|
|
|
|
});
|
|
|
|
|
|
|
|
const getIndexTableName = (index, record) => {
|
|
|
|
record = record
|
|
|
|
|| index.parent().type === "record" ? index.parent() : null;
|
|
|
|
|
|
|
|
return (record
|
|
|
|
? `${getRecordPath()}/${index.name} Table`
|
|
|
|
: `${index.name} Table`);
|
|
|
|
};
|
|
|
|
|
|
|
|
const indexTable = (index, helpers) => ({
|
|
|
|
name: getIndexTableName(index),
|
|
|
|
inherits: "@budibase/standard-components/table",
|
|
|
|
props: indexTableProps(index, helpers)
|
|
|
|
});
|
|
|
|
|
|
|
|
const column = (col) => ({
|
|
|
|
title: col.name,
|
|
|
|
value: {
|
|
|
|
"##bbstate": col.name,
|
|
|
|
"##bbsource":"context"
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
const recordHomePageComponents = ({indexes, records, helpers}) =>
|
|
|
|
[
|
|
|
|
...recordHomepages({indexes, records})
|
|
|
|
.map(component),
|
|
|
|
|
|
|
|
...recordHomepages({indexes, records})
|
|
|
|
.map(homePageButtons),
|
|
|
|
|
|
|
|
...indexTables({indexes, records, helpers}),
|
|
|
|
|
|
|
|
...buttons()
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
|
|
const findIndexForRecord = (indexes, record) => {
|
|
|
|
const forRecord = indexes.filter(i => i.allowedRecordNodeIds.includes(record.nodeId));
|
|
|
|
if(forRecord.length === 0) return;
|
|
|
|
if(forRecord.length === 1) return forRecord[0];
|
|
|
|
const noMap = forRecord.filter(i => !i.filter || !i.filter.trim());
|
|
|
|
if(noMap.length === 0) forRecord[0];
|
|
|
|
return noMap[0];
|
|
|
|
};
|
|
|
|
|
|
|
|
const recordHomepages = ({indexes, records}) =>
|
|
|
|
records.filter(r => r.parent().type === "root")
|
|
|
|
.map(r =>({
|
|
|
|
record:r,
|
|
|
|
index:findIndexForRecord(indexes, r)
|
|
|
|
}))
|
|
|
|
.filter(r => r.index);
|
|
|
|
|
|
|
|
|
|
|
|
const homepageComponentName = (record) =>
|
|
|
|
`${record.name}/${record.name} homepage`;
|
|
|
|
|
|
|
|
const component = ({record, index}) => ({
|
|
|
|
inherits: "@budibase/standard-components/div",
|
|
|
|
name: homepageComponentName(record),
|
|
|
|
props: {
|
|
|
|
className: "p-3",
|
|
|
|
children: [
|
|
|
|
{
|
|
|
|
component: {
|
|
|
|
_component: "@budibase/standard-components/h2",
|
|
|
|
text: record.collectionName
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
component: {
|
|
|
|
_component: `${record.name}/homepage buttons`,
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
component: {
|
|
|
|
_component: getIndexTableName(index)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
],
|
|
|
|
onLoad: [
|
|
|
|
{
|
|
|
|
"##eventHandlerType": "Set State",
|
|
|
|
parameters: {
|
|
|
|
path: `isEditing${record.name}`,
|
|
|
|
value: ""
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"##eventHandlerType": "List Records",
|
|
|
|
parameters: {
|
|
|
|
statePath: index.nodeKey(),
|
|
|
|
indexKey: index.nodeKey()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
const homePageButtons = ({index, record}) => ({
|
|
|
|
inherits: "@budibase/standard-components/div",
|
|
|
|
name: `${record.name}/homepage buttons`,
|
|
|
|
props: {
|
|
|
|
className: "btn-group",
|
|
|
|
children: [
|
|
|
|
{
|
|
|
|
component: {
|
|
|
|
_component: "common/Default Button",
|
|
|
|
contentText: `Create ${record.name}`,
|
|
|
|
onClick: [
|
|
|
|
{
|
|
|
|
"##eventHandlerType": "Get New Record",
|
|
|
|
parameters: {
|
|
|
|
statePath: record.name,
|
|
|
|
collectionKey: `/${record.collectionName}`,
|
|
|
|
childRecordType: record.name
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"##eventHandlerType": "Set State",
|
|
|
|
parameters: {
|
|
|
|
path: `isEditing${record.name}`,
|
|
|
|
value: "true"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
component: {
|
|
|
|
_component: "common/Default Button",
|
|
|
|
contentText: `Refresh`,
|
|
|
|
onClick: [
|
|
|
|
{
|
|
|
|
"##eventHandlerType": "List Records",
|
|
|
|
parameters: {
|
|
|
|
statePath: index.nodeKey(),
|
|
|
|
indexKey: index.nodeKey()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
const selectNavContent = ({indexes, records, helpers}) =>
|
|
|
|
[
|
|
|
|
...recordHomepages({indexes, records})
|
|
|
|
.map(component$1),
|
|
|
|
|
|
|
|
...recordHomePageComponents({indexes, records, helpers}),
|
|
|
|
|
|
|
|
...forms({indexes, records, helpers})
|
|
|
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
|
|
const navContentComponentName = record =>
|
|
|
|
`${record.name}/${record.name} Nav Content`;
|
|
|
|
|
|
|
|
const component$1 = ({record, index}) => ({
|
|
|
|
inherits: "@budibase/standard-components/if",
|
|
|
|
description: `the component that gets displayed when the ${record.collectionName} nav is selected`,
|
|
|
|
name: navContentComponentName(record),
|
|
|
|
props: {
|
|
|
|
condition: `$store.isEditing${record.name}`,
|
|
|
|
thenComponent: {
|
|
|
|
_component: formName(record)
|
|
|
|
},
|
|
|
|
elseComponent: {
|
|
|
|
_component: homepageComponentName(record)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
const app = ({records, indexes, helpers}) => [
|
|
|
|
{
|
|
|
|
name: "Application Root",
|
|
|
|
inherits: "@budibase/bootstrap-components/nav",
|
|
|
|
props: {
|
|
|
|
items: recordHomepages({indexes, records})
|
|
|
|
.map(navItem),
|
|
|
|
orientation: "horizontal",
|
|
|
|
alignment: "start",
|
|
|
|
fill: false,
|
|
|
|
pills: true,
|
|
|
|
selectedItem: {
|
|
|
|
"##bbstate":"selectedNav",
|
|
|
|
"##bbstatefallback":`${records[0].name}`,
|
|
|
|
"##bbsource": "store"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "Login",
|
|
|
|
inherits: "@budibase/standard-components/login",
|
|
|
|
props: {}
|
|
|
|
},
|
|
|
|
...selectNavContent({records, indexes, helpers})
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
|
|
const navItem = ({record}) => ({
|
|
|
|
title: record.collectionName,
|
|
|
|
component : {
|
|
|
|
_component: navContentComponentName(record)
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
export { app, forms, indexTables, recordHomePageComponents as recordHomepages };
|
|
|
|
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiZ2VuZXJhdG9ycy5qcyIsInNvdXJjZXMiOlsiLi4vc3JjL2dlbmVyYXRvcnMvYnV0dG9uR2VuZXJhdG9ycy5qcyIsIi4uL3NyYy9nZW5lcmF0b3JzL2Zvcm1zR2VuZXJhdG9yLmpzIiwiLi4vc3JjL2dlbmVyYXRvcnMvZ2V0UmVjb3JkUGF0aC5qcyIsIi4uL3NyYy9nZW5lcmF0b3JzL2luZGV4VGFibGVzR2VuZXJhdG9yLmpzIiwiLi4vc3JjL2dlbmVyYXRvcnMvcmVjb3JkSG9tZVBhZ2VHZW5lcmF0b3IuanMiLCIuLi9zcmMvZ2VuZXJhdG9ycy9zZWxlY3RlZE5hdkNvbnRlbnRHZW5lcmF0b3IuanMiLCIuLi9zcmMvZ2VuZXJhdG9ycy9hcHBHZW5lcmF0b3IuanMiXSwic291cmNlc0NvbnRlbnQiOlsiZXhwb3J0IGNvbnN0IGJ1dHRvbnMgPSAoKSA9PiBbXHJcbiAgICB7XHJcbiAgICAgICAgbmFtZTogXCJjb21tb24vUHJpbWFyeSBCdXR0b25cIixcclxuICAgICAgICBkZXNjcmlwdGlvbjogXCJCb290c3RyYXAgcHJpbWFyeSBidXR0b24gXCIsXHJcbiAgICA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b3JkLm5vZGVLZXkoKX0nIGAsXHJcbiAgICBpbmhlcml0czogXCJAYnVkaWJhc2Uvc3RhbmRhcmQtY29tcG9uZW50cy9kaXZcIixcclxuICAgIHByb3BzOiB7XHJcbiAgICAgICAgY2xhc3NOYW1lOlwicC0xXCIsXHJcbiAgICAgICAgY2hpbGRyZW46IFtcclxuICAgICAgICAgICAge1xyXG4gICAgICAgICAgICAgICAgY29tcG9uZW50OiB7XHJcbiAgICAgICAgICAgICAgICAgICAgX2NvbXBvbmVudDogXCJAYnVkaWJhc2Uvc3RhbmRhcmQtY29tcG9uZW50cy9oM1wiLFxyXG4gICAgICAgICAgICAgICAgICAgIHRleHQ6IGBFZGl0ICR7cmVjb3JkLm5hbWV9YCxcclxuICAgICAgICAgICAgICAgIH1cclxuICAgICAgICAgICAgfSxcclxuICAgICAgICAgICAgZm9ybShyZWNvcmQpLFxyXG4gICAgICAgICAgICBzYXZlQ2FuY2VsQnV0dG9ucyhyZWNvcmQpXHJcbiAgICAgICAgXVxyXG4gICAgfVxyXG59KSBcclxuXHJcbmNvbnN0IGZvcm0gPSByZWNvcmQgPT4gKHtcclxuICAgIGNvbXBvbmVudDoge1xyXG4gICAgICAgIF9jb21wb25lbnQ6IFwiQGJ1ZGliYXNlL3N0YW5kYXJkLWNvbXBvbmVudHMvZm9ybVwiLFxyXG4gICAgICAgIGZvcm1Db250cm9sczogXHJcbiAgICAgICAgICAgIHJlY29yZC5maWVsZHMubWFwKGYgPT4gZm9ybUNvbnRyb2wocmVjb3JkLCBmKSlcclxuICAgIH1cclxufSlcclxuXHJcbmNvbnN0IGZvcm1Db250cm9sID0gKHJlY29yZCwgZmllbGQpID0+IHtcclxuICAgIGlmKGZpZWxkLnR5cGUgPT09IFwic3RyaW5nXCIgJiYgZmllbGQudHlwZU9wdGlvbnMudmFsdWVzICYmIGZpZWxkLnR5cGVPcHRpb25zLnZhbHVlcy5sZW5ndGggPiAwKSB7XHJcbiAgICAgICAgcmV0dXJuICh7XHJcbiAgICAgICAgICAgIGNvbnRyb2w6IHtcclxuICAgICAgICAgICAgICAgIF9jb21wb25lbnQ6IFwiQGJ1ZGliYXNlL3N0YW5kYXJkLWNvbXBvbmVudHMvc2VsZWN0XCIsXHJcbiAgICAgICAgICAgICAgICBvcHRpb25zOiBmaWVsZC50eXBlT3B0aW9ucy52YWx1ZXMubWFwKHYgPT4gKHtpZDp2LCB2YWx1ZTp2fSkpLFxyXG4gICAgICAgICAgICAgICAgdmFsdWU6IHtcclxuICAgICAgICAgICAgICAgICAgICBcIiMjYmJzdGF0ZVwiOmAke3JlY29yZC5uYW1lfS4ke2ZpZWxkLm5hbWV9YCxcclxuICAgICAgICAgICAgICAgICAgICBcIiMjYmJzb3VyY2VcIjpcInN0b3JlXCJcclxuICAgICAgICAgICAgICAgIH0sXHJcbiAgICAgICAgICAgICAgICBjbGFzc05hbWU6IFwiZm9ybS1jb250cm9sXCJcclxuICAgICAgICAgICAgfSxcclxuICAgICAgICAgICAgbGFiZWw6IGZpZWxkLmxhYmVsXHJcbiAgICAgICAgfSk7XHJcbiAgICB9IGVsc2Uge1xyXG4gICAgICAgIHJldHVybiAoe1xyXG4gICAgICAgICAgICBjb250cm9sOiB7XHJcbiAgICAgICAgICAgICAgICBfY29tcG9uZW50OiBcIkBidWRpYmFzZS9zdGFuZGFyZC1jb21wb25lbnRzL2lucHV0XCIsXHJcbiAgICAgICAgICAgICAgICB2YWx1ZToge1xyXG4gICAgICAgICAgICAgICAgICAgIFwiIyNiYnN0YXRlXCI6YCR7cmVjb3JkLm5hbWV9LiR7ZmllbGQubmFtZX1gLFxyXG4gICAgICAgICAgICAgICAgICAgIFwiIyNiYnNvdXJjZVwiOlwic3RvcmVcIlxyXG4gICAgICAgICAgICAgICAgfSxcclxuICAgICAgICAgICAgICAgIGNsYXNzTmFtZTogXCJmb3JtLWNvbnRyb2xcIixcclxuICAgICAgICAgICAgICAgIHR5cGU6IGZpZWxkLnR5cGU
|