lint fixes
This commit is contained in:
parent
28caf55ac4
commit
1e1662d265
|
@ -316,7 +316,8 @@ export default {
|
||||||
{
|
{
|
||||||
name: "Grid",
|
name: "Grid",
|
||||||
_component: "@budibase/standard-components/datagrid",
|
_component: "@budibase/standard-components/datagrid",
|
||||||
description: "a datagrid component with functionality to add, remove and edit rows.",
|
description:
|
||||||
|
"a datagrid component with functionality to add, remove and edit rows.",
|
||||||
icon: "ri-file-list-line",
|
icon: "ri-file-list-line",
|
||||||
properties: {
|
properties: {
|
||||||
design: { ...all },
|
design: { ...all },
|
||||||
|
@ -336,7 +337,13 @@ export default {
|
||||||
label: "Theme",
|
label: "Theme",
|
||||||
key: "theme",
|
key: "theme",
|
||||||
control: OptionSelect,
|
control: OptionSelect,
|
||||||
options: ["alpine", "alpine-dark", "balham", "balham-dark", "material"],
|
options: [
|
||||||
|
"alpine",
|
||||||
|
"alpine-dark",
|
||||||
|
"balham",
|
||||||
|
"balham-dark",
|
||||||
|
"material",
|
||||||
|
],
|
||||||
placeholder: "alpine",
|
placeholder: "alpine",
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
|
|
|
@ -68,7 +68,7 @@ exports.patch = async function(ctx) {
|
||||||
}
|
}
|
||||||
|
|
||||||
exports.save = async function(ctx) {
|
exports.save = async function(ctx) {
|
||||||
if (ctx.request.body.type === 'delete') {
|
if (ctx.request.body.type === "delete") {
|
||||||
await bulkDelete(ctx)
|
await bulkDelete(ctx)
|
||||||
} else {
|
} else {
|
||||||
await saveRecord(ctx)
|
await saveRecord(ctx)
|
||||||
|
@ -298,20 +298,26 @@ const TYPE_TRANSFORM_MAP = {
|
||||||
}
|
}
|
||||||
|
|
||||||
async function bulkDelete(ctx) {
|
async function bulkDelete(ctx) {
|
||||||
|
const instanceId = ctx.user.instanceId
|
||||||
const { records } = ctx.request.body
|
const { records } = ctx.request.body
|
||||||
const db = new CouchDB(ctx.user.instanceId)
|
const db = new CouchDB(ctx.user.instanceId)
|
||||||
|
|
||||||
await db.bulkDocs(
|
await db.bulkDocs(
|
||||||
records.map(record => ({ ...record, _deleted: true }), (err, res) => {
|
records.map(
|
||||||
if (err) {
|
record => ({ ...record, _deleted: true }),
|
||||||
ctx.status = 500
|
err => {
|
||||||
} else {
|
if (err) {
|
||||||
records.forEach(record => {
|
ctx.status = 500
|
||||||
emitEvent(`record:delete`, ctx, record)
|
} else {
|
||||||
})
|
records.forEach(record => {
|
||||||
ctx.status = 200
|
ctx.eventEmitter &&
|
||||||
|
ctx.eventEmitter.emitRecord(`record:delete`, instanceId, record)
|
||||||
|
})
|
||||||
|
ctx.status = 200
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}))
|
)
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
async function saveRecord(ctx) {
|
async function saveRecord(ctx) {
|
||||||
|
@ -373,4 +379,4 @@ async function saveRecord(ctx) {
|
||||||
ctx.body = record
|
ctx.body = record
|
||||||
ctx.status = 200
|
ctx.status = 200
|
||||||
ctx.message = `${model.name} created successfully`
|
ctx.message = `${model.name} created successfully`
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,7 +2,7 @@ import svelte from "rollup-plugin-svelte"
|
||||||
import resolve from "rollup-plugin-node-resolve"
|
import resolve from "rollup-plugin-node-resolve"
|
||||||
import commonjs from "@rollup/plugin-commonjs"
|
import commonjs from "@rollup/plugin-commonjs"
|
||||||
import postcss from "rollup-plugin-postcss"
|
import postcss from "rollup-plugin-postcss"
|
||||||
import { terser } from "rollup-plugin-terser";
|
import { terser } from "rollup-plugin-terser"
|
||||||
|
|
||||||
const lodash_fp_exports = ["isEmpty"]
|
const lodash_fp_exports = ["isEmpty"]
|
||||||
|
|
||||||
|
|
|
@ -39,7 +39,6 @@
|
||||||
const jsonModel = await _bb.api.get(`/api/models/${datasource.modelId}`)
|
const jsonModel = await _bb.api.get(`/api/models/${datasource.modelId}`)
|
||||||
model = await jsonModel.json()
|
model = await jsonModel.json()
|
||||||
const { schema } = model
|
const { schema } = model
|
||||||
console.log(schema)
|
|
||||||
if (!isEmpty(datasource)) {
|
if (!isEmpty(datasource)) {
|
||||||
data = await fetchData(datasource)
|
data = await fetchData(datasource)
|
||||||
columnDefs = Object.keys(schema).map((key, i) => {
|
columnDefs = Object.keys(schema).map((key, i) => {
|
||||||
|
|
|
@ -1,116 +1,117 @@
|
||||||
// Custom renderers to handle special types
|
// Custom renderers to handle special types
|
||||||
// https://www.ag-grid.com/javascript-grid-cell-rendering-components/
|
// https://www.ag-grid.com/javascript-grid-cell-rendering-components/
|
||||||
|
|
||||||
import AttachmentCell from './AttachmentCell/Button.svelte'
|
import AttachmentCell from "./AttachmentCell/Button.svelte"
|
||||||
import Select from './Select/Wrapper.svelte'
|
import Select from "./Select/Wrapper.svelte"
|
||||||
import DatePicker from "./DateTime/Wrapper.svelte"
|
import DatePicker from "./DateTime/Wrapper.svelte"
|
||||||
|
|
||||||
const renderers = new Map([
|
const renderers = new Map([
|
||||||
["boolean", booleanRenderer],
|
["boolean", booleanRenderer],
|
||||||
["attachment", attachmentRenderer],
|
["attachment", attachmentRenderer],
|
||||||
["options", optionsRenderer],
|
["options", optionsRenderer],
|
||||||
["link", linkedRecordRenderer],
|
["link", linkedRecordRenderer],
|
||||||
])
|
])
|
||||||
|
|
||||||
|
|
||||||
export function getRenderer({ type, constraints }, editable) {
|
export function getRenderer({ type, constraints }, editable) {
|
||||||
if (renderers.get(type)) {
|
if (renderers.get(type)) {
|
||||||
return renderers.get(type)(constraints, editable)
|
return renderers.get(type)(constraints, editable)
|
||||||
} else {
|
} else {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* eslint-disable no-unused-vars */
|
||||||
function booleanRenderer(constraints, editable) {
|
function booleanRenderer(constraints, editable) {
|
||||||
return params => {
|
return params => {
|
||||||
const toggle = (e) => {
|
const toggle = e => {
|
||||||
params.value = !params.value
|
params.value = !params.value
|
||||||
params.setValue(e.currentTarget.checked)
|
params.setValue(e.currentTarget.checked)
|
||||||
}
|
|
||||||
let input = document.createElement("input")
|
|
||||||
input.style.display = "grid";
|
|
||||||
input.style.placeItems = "center";
|
|
||||||
input.style.height = "100%";
|
|
||||||
input.type = "checkbox"
|
|
||||||
input.checked = params.value
|
|
||||||
if (editable) {
|
|
||||||
input.addEventListener("click", toggle)
|
|
||||||
} else {
|
|
||||||
input.disabled = true
|
|
||||||
}
|
|
||||||
|
|
||||||
return input
|
|
||||||
}
|
}
|
||||||
}
|
let input = document.createElement("input")
|
||||||
function attachmentRenderer(constraints, editable ) {
|
input.style.display = "grid"
|
||||||
return params => {
|
input.style.placeItems = "center"
|
||||||
const container = document.createElement("div")
|
input.style.height = "100%"
|
||||||
|
input.type = "checkbox"
|
||||||
const attachmentInstance = new AttachmentCell({
|
input.checked = params.value
|
||||||
target: container,
|
if (editable) {
|
||||||
props: {
|
input.addEventListener("click", toggle)
|
||||||
files: params.value || [],
|
} else {
|
||||||
}
|
input.disabled = true
|
||||||
});
|
|
||||||
|
|
||||||
return container
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return input
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
/* eslint-disable no-unused-vars */
|
||||||
|
function attachmentRenderer(constraints, editable) {
|
||||||
|
return params => {
|
||||||
|
const container = document.createElement("div")
|
||||||
|
|
||||||
|
const attachmentInstance = new AttachmentCell({
|
||||||
|
target: container,
|
||||||
|
props: {
|
||||||
|
files: params.value || [],
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
return container
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/* eslint-disable no-unused-vars */
|
||||||
function dateRenderer(constraints, editable) {
|
function dateRenderer(constraints, editable) {
|
||||||
return function (params) {
|
return function(params) {
|
||||||
const container = document.createElement("div")
|
const container = document.createElement("div")
|
||||||
const toggle = (e) => {
|
const toggle = e => {
|
||||||
params.setValue(e.detail[0][0])
|
params.setValue(e.detail[0][0])
|
||||||
}
|
|
||||||
|
|
||||||
// Options need to be passed in with minTime and maxTime! Needs bbui update.
|
|
||||||
|
|
||||||
const datePickerInstance = new DatePicker({
|
|
||||||
target: container,
|
|
||||||
props: {
|
|
||||||
value: params.value,
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
return container
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
|
// Options need to be passed in with minTime and maxTime! Needs bbui update.
|
||||||
|
|
||||||
|
const datePickerInstance = new DatePicker({
|
||||||
|
target: container,
|
||||||
|
props: {
|
||||||
|
value: params.value,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
return container
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function optionsRenderer({ inclusion }, editable) {
|
function optionsRenderer({ inclusion }, editable) {
|
||||||
return params => {
|
return params => {
|
||||||
if (!editable) return params.value
|
if (!editable) return params.value
|
||||||
const container = document.createElement("div")
|
const container = document.createElement("div")
|
||||||
container.style.display = "grid";
|
container.style.display = "grid"
|
||||||
container.style.placeItems = "center";
|
container.style.placeItems = "center"
|
||||||
container.style.height = "100%";
|
container.style.height = "100%"
|
||||||
const change = (e) => {
|
const change = e => {
|
||||||
params.setValue(e.detail)
|
params.setValue(e.detail)
|
||||||
}
|
|
||||||
|
|
||||||
const selectInstance = new Select({
|
|
||||||
target: container,
|
|
||||||
props: {
|
|
||||||
value: params.value,
|
|
||||||
options: inclusion
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
selectInstance.$on('change', change)
|
|
||||||
|
|
||||||
return container
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const selectInstance = new Select({
|
||||||
|
target: container,
|
||||||
|
props: {
|
||||||
|
value: params.value,
|
||||||
|
options: inclusion,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
selectInstance.$on("change", change)
|
||||||
|
|
||||||
|
return container
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
/* eslint-disable no-unused-vars */
|
||||||
function linkedRecordRenderer(constraints, editable) {
|
function linkedRecordRenderer(constraints, editable) {
|
||||||
return params => {
|
return params => {
|
||||||
console.log(params.value)
|
let container = document.createElement("div")
|
||||||
let container = document.createElement("div")
|
container.style.display = "grid"
|
||||||
container.style.display = "grid";
|
container.style.placeItems = "center"
|
||||||
container.style.placeItems = "center";
|
container.style.height = "100%"
|
||||||
container.style.height = "100%";
|
|
||||||
|
|
||||||
container.innerText = params.value.length || 0
|
container.innerText = params.value.length || 0
|
||||||
|
|
||||||
return container
|
return container
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
// https://www.ag-grid.com/javascript-grid-value-setters/
|
// https://www.ag-grid.com/javascript-grid-value-setters/
|
||||||
// These handles values and makes sure they adhere to the data type provided by the model
|
// These handles values and makes sure they adhere to the data type provided by the model
|
||||||
export const number = (params) => {
|
export const number = params => {
|
||||||
params.data[params.colDef.field] = parseFloat(params.newValue);
|
params.data[params.colDef.field] = parseFloat(params.newValue)
|
||||||
return true;
|
return true
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue