waibu-db 2.12.0 → 2.12.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/extend/bajoTemplate/partial/crud/_list-btns.html +1 -0
- package/extend/waibuBootstrap/theme/component/widget/btn-details.js +1 -1
- package/extend/waibuBootstrap/theme/component/widget/form.js +8 -1
- package/extend/waibuBootstrap/theme/component/widget/table.js +2 -2
- package/index.js +1 -1
- package/lib/crud/add-handler.js +1 -1
- package/lib/crud/delete-handler.js +2 -2
- package/lib/crud/details-handler.js +1 -1
- package/lib/crud/edit-handler.js +1 -1
- package/lib/crud/export-handler.js +1 -1
- package/lib/crud/list-handler.js +1 -1
- package/lib/method/count-record.js +1 -1
- package/lib/method/create-aggregate.js +1 -1
- package/lib/method/create-histogram.js +1 -1
- package/lib/method/find-all-record.js +1 -1
- package/lib/method/find-one-record.js +1 -1
- package/lib/method/find-record.js +1 -1
- package/lib/method/get-record.js +1 -1
- package/lib/method/get-schema-ext.js +3 -0
- package/lib/method/remove-record.js +1 -1
- package/lib/method/update-record.js +1 -1
- package/lib/util.js +1 -2
- package/package.json +1 -1
- package/wiki/CHANGES.md +9 -0
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
<c:grid-col col="8-lg" flex="justify-content:end-lg">
|
|
6
6
|
<c:btn-group margin="end-2">
|
|
7
7
|
<c:wdb-btn-add text="nowrap"/>
|
|
8
|
+
<c:wdb-btn-details on-list text="nowrap"/>
|
|
8
9
|
<c:wdb-btn-edit on-list menu-dir="end"/>
|
|
9
10
|
</c:btn-group>
|
|
10
11
|
<c:wdb-btn-delete on-list margin="end-2" />
|
|
@@ -10,7 +10,7 @@ async function btnDetails () {
|
|
|
10
10
|
const { isEmpty, get } = this.app.lib._
|
|
11
11
|
this.params.noTag = true
|
|
12
12
|
const schema = get(this, 'component.locals.schema', {})
|
|
13
|
-
if (schema.view.disabled.includes('
|
|
13
|
+
if (schema.view.disabled.includes('get')) {
|
|
14
14
|
this.params.html = ''
|
|
15
15
|
return
|
|
16
16
|
}
|
|
@@ -7,7 +7,9 @@ async function form () {
|
|
|
7
7
|
build = async () => {
|
|
8
8
|
const { get, find, filter, forOwn, isEmpty } = this.app.lib._
|
|
9
9
|
const { base64JsonEncode } = this.app.waibu
|
|
10
|
+
const { req } = this.component
|
|
10
11
|
const schema = get(this, 'component.locals.schema', {})
|
|
12
|
+
const data = get(this, 'component.locals.form', {})
|
|
11
13
|
const body = []
|
|
12
14
|
const xModels = get(schema, 'view.x.model', [])
|
|
13
15
|
const xOns = get(schema, 'view.x.on', [])
|
|
@@ -31,7 +33,12 @@ async function form () {
|
|
|
31
33
|
attr.push(`@${o.bind}="${o.handler}"`)
|
|
32
34
|
}
|
|
33
35
|
if (w.componentOpts) attr.push(`c-opts="${base64JsonEncode(w.componentOpts)}"`)
|
|
34
|
-
|
|
36
|
+
if (schema.view.valueFormatter[f] && this.params.attr.method !== 'POST') {
|
|
37
|
+
const value = await schema.view.valueFormatter[f].call(this, data[f], data, { req })
|
|
38
|
+
body.push(`<c:${w.component} ${w.attr.label ? ('t:label="' + w.attr.label + '"') : ''} value="${value}" label-floating name="${w.name}" ${attr.join(' ')} />`)
|
|
39
|
+
} else {
|
|
40
|
+
body.push(`<c:${w.component} ${w.attr.label ? ('t:label="' + w.attr.label + '"') : ''} data-type="${prop.type}" label-floating name="${w.name}" ${attr.join(' ')} />`)
|
|
41
|
+
}
|
|
35
42
|
}
|
|
36
43
|
body.push('</c:fieldset>')
|
|
37
44
|
}
|
|
@@ -165,7 +165,7 @@ async function table () {
|
|
|
165
165
|
const attr = { dataValue, dataKey: prop.name, dataType: prop.type }
|
|
166
166
|
if (!disableds.includes('get')) attr.style = { cursor: 'pointer' }
|
|
167
167
|
const cellFormatter = get(schema, `view.cellFormatter.${f}`)
|
|
168
|
-
if (cellFormatter) merge(attr, await cellFormatter.call(this, dataValue, d))
|
|
168
|
+
if (cellFormatter) merge(attr, await cellFormatter.call(this, dataValue, d, { params: this.params, req }))
|
|
169
169
|
const noWrap = this.isNoWrap(f, schema, group.body.nowrap) ? 'nowrap' : ''
|
|
170
170
|
if (this.isRightAligned(f, schema)) attr.text = `align:end ${noWrap}`
|
|
171
171
|
else attr.text = noWrap
|
|
@@ -175,7 +175,7 @@ async function table () {
|
|
|
175
175
|
if (item) value = req.t(item[lookup.field ?? 'name'])
|
|
176
176
|
}
|
|
177
177
|
const formatter = get(schema, `view.formatter.${f}`)
|
|
178
|
-
if (formatter) value = await formatter.call(this, value, d, { params: this.params })
|
|
178
|
+
if (formatter) value = await formatter.call(this, value, d, { params: this.params, req })
|
|
179
179
|
else value = await this._defFormatter({ req, key: f, schema, value, data: d, params: this.params })
|
|
180
180
|
const line = await this.component.buildTag({ tag: 'td', attr, html: value })
|
|
181
181
|
lines.push(line)
|
package/index.js
CHANGED
|
@@ -203,7 +203,7 @@ async function factory (pkgName) {
|
|
|
203
203
|
rec[f] = format(data[f], prop.type, opts)
|
|
204
204
|
const vf = get(schema, `view.valueFormatter.${f}`)
|
|
205
205
|
if (vf) {
|
|
206
|
-
if (isFunction(vf)) rec[f] = await vf.call(this, data[f], data)
|
|
206
|
+
if (isFunction(vf)) rec[f] = await vf.call(this, data[f], data, { req })
|
|
207
207
|
else rec[f] = await callHandler(vf, { req, value: data[f], data })
|
|
208
208
|
} else if (['string', 'text'].includes(prop.type)) rec[f] = escape(rec[f])
|
|
209
209
|
}
|
package/lib/crud/add-handler.js
CHANGED
|
@@ -6,7 +6,7 @@ async function addHandler ({ req, reply, model, params = {}, template, addOnsHan
|
|
|
6
6
|
const { pick, map, merge, omit } = this.app.lib._
|
|
7
7
|
const opts = merge({}, options.modelOpts)
|
|
8
8
|
model = pascalCase(model ?? req.params.model)
|
|
9
|
-
const { schema } = await getSchemaExt(model, 'add', merge({}, { params }, options))
|
|
9
|
+
const { schema } = await getSchemaExt(model, 'add', merge({ args: [req] }, { params }, options))
|
|
10
10
|
if (schema.disabled.includes('create')) return await reply.view(templateDisabled, { action: 'add' })
|
|
11
11
|
// req.query.attachment = true
|
|
12
12
|
opts.fields = schema.view.fields
|
|
@@ -5,14 +5,14 @@ async function deleteHandler ({ req, reply, model, params = {}, templateDisabled
|
|
|
5
5
|
const { reduce, merge } = this.app.lib._
|
|
6
6
|
const opts = merge({}, options.modelOpts)
|
|
7
7
|
model = pascalCase(model ?? req.params.model)
|
|
8
|
-
const { schema } = await getSchemaExt(model, '
|
|
8
|
+
const { schema } = await getSchemaExt(model, 'delete', merge({ args: [req] }, { params }, options))
|
|
9
9
|
if (schema.disabled.includes('remove')) return await reply.view(templateDisabled, { action: 'delete' })
|
|
10
10
|
opts.fields = schema.view.fields
|
|
11
11
|
delete req.query.query
|
|
12
12
|
const ids = (req.body.ids ?? '').split(',')
|
|
13
13
|
if (ids.length > 0) {
|
|
14
14
|
const result = []
|
|
15
|
-
opts.noResult = true
|
|
15
|
+
// opts.noResult = true
|
|
16
16
|
opts.noFlash = true
|
|
17
17
|
for (const id of ids) {
|
|
18
18
|
try {
|
|
@@ -6,7 +6,7 @@ async function detailsHandler ({ req, reply, model, params = {}, id, template, a
|
|
|
6
6
|
const { merge, isEmpty } = this.app.lib._
|
|
7
7
|
const opts = merge({ refs: '*' }, options.modelOpts)
|
|
8
8
|
model = pascalCase(model ?? req.params.model)
|
|
9
|
-
const { schema } = await getSchemaExt(model, 'details', merge({}, { params }, options))
|
|
9
|
+
const { schema } = await getSchemaExt(model, 'details', merge({ args: [req] }, { params }, options))
|
|
10
10
|
if (schema.disabled.includes('get')) return await reply.view(templateDisabled, { action: 'details' })
|
|
11
11
|
// req.query.attachment = true
|
|
12
12
|
opts.fields = schema.view.fields
|
package/lib/crud/edit-handler.js
CHANGED
|
@@ -13,7 +13,7 @@ async function editHandler ({ req, reply, model, id, params = {}, template, addO
|
|
|
13
13
|
let resp
|
|
14
14
|
let form
|
|
15
15
|
model = pascalCase(model ?? req.params.model)
|
|
16
|
-
const { schema } = await getSchemaExt(model, 'edit', merge({}, { params }, options))
|
|
16
|
+
const { schema } = await getSchemaExt(model, 'edit', merge({ args: [req] }, { params }, options))
|
|
17
17
|
if (schema.disabled.includes('update')) return await reply.view(templateDisabled, { action: 'edit' })
|
|
18
18
|
// req.query.attachment = true
|
|
19
19
|
opts.fields = schema.view.fields
|
|
@@ -9,7 +9,7 @@ async function exportHandler ({ req, reply, model, params = {}, templateDisabled
|
|
|
9
9
|
const { buildUrl } = this.app.waibuMpa
|
|
10
10
|
const { pushDownload } = getPlugin('sumba')
|
|
11
11
|
model = pascalCase(model ?? req.params.model)
|
|
12
|
-
const { schema } = await getSchemaExt(model, 'add', merge({}, { params }, options))
|
|
12
|
+
const { schema } = await getSchemaExt(model, 'add', merge({ args: [req] }, { params }, options))
|
|
13
13
|
if (schema.disabled.includes('find')) return await reply.view(templateDisabled, { action: 'list' })
|
|
14
14
|
const data = await prepCrud.call(getPlugin('waibuDb'), { model, req, reply, args: ['model'] })
|
|
15
15
|
data.opts = omit(data.opts, ['req', 'reply'])
|
package/lib/crud/list-handler.js
CHANGED
|
@@ -6,7 +6,7 @@ async function listHandler ({ req, reply, model, template, params = {}, addOnsHa
|
|
|
6
6
|
|
|
7
7
|
const opts = merge({}, { count: true, refs: '*' }, options.modelOpts)
|
|
8
8
|
model = pascalCase(model ?? req.params.model)
|
|
9
|
-
const { schema } = await getSchemaExt(model, 'list', merge({}, { params }, options))
|
|
9
|
+
const { schema } = await getSchemaExt(model, 'list', merge({ args: [req] }, { params }, options))
|
|
10
10
|
if (schema.disabled.includes('find')) return await reply.view(templateDisabled, { action: 'list' })
|
|
11
11
|
for (const key of ['sort', 'limit', 'fields']) {
|
|
12
12
|
const sessKey = `wdb${model}${upperFirst(key)}`
|
|
@@ -4,7 +4,7 @@ async function countRecord ({ model, req, reply, options = {}, transaction } = {
|
|
|
4
4
|
const { model: mdl, opts, filter } = await prepCrud.call(this, { model, req, reply, options, args: ['model'], transaction })
|
|
5
5
|
|
|
6
6
|
async function handler (trx) {
|
|
7
|
-
opts.trx
|
|
7
|
+
if (opts.trx === true) opts.trx = trx
|
|
8
8
|
return await mdl.countRecord(filter, opts)
|
|
9
9
|
}
|
|
10
10
|
|
|
@@ -9,7 +9,7 @@ async function createAggregate ({ model, req, reply, options = {}, transaction }
|
|
|
9
9
|
params.aggregates = params.aggregates ?? ['count']
|
|
10
10
|
|
|
11
11
|
async function handler (trx) {
|
|
12
|
-
opts.trx
|
|
12
|
+
if (opts.trx === true) opts.trx = trx
|
|
13
13
|
return await mdl.createAggregate(filter, params, opts)
|
|
14
14
|
}
|
|
15
15
|
|
|
@@ -9,7 +9,7 @@ async function createHistogram ({ model, req, reply, options = {}, transaction }
|
|
|
9
9
|
params.aggregates = params.aggregates ?? ['count']
|
|
10
10
|
|
|
11
11
|
async function handler (trx) {
|
|
12
|
-
opts.trx
|
|
12
|
+
if (opts.trx === true) opts.trx = trx
|
|
13
13
|
return await mdl.createHistogram(filter, params, opts)
|
|
14
14
|
}
|
|
15
15
|
|
|
@@ -4,7 +4,7 @@ async function findAllRecord ({ model, req, reply, options = {}, transaction } =
|
|
|
4
4
|
const { model: mdl, opts, filter, attachment, stats, mimeType } = await prepCrud.call(this, { model, req, reply, options, args: ['model'], transaction })
|
|
5
5
|
|
|
6
6
|
async function handler (trx) {
|
|
7
|
-
opts.trx
|
|
7
|
+
if (opts.trx === true) opts.trx = trx
|
|
8
8
|
const ret = await mdl.findAllRecord(filter, opts)
|
|
9
9
|
if (attachment) {
|
|
10
10
|
for (const d of ret.data) {
|
|
@@ -4,7 +4,7 @@ async function findOneRecord ({ model, req, reply, options = {}, transaction } =
|
|
|
4
4
|
const { model: mdl, opts, filter, attachment, stats, mimeType } = await prepCrud.call(this, { model, req, reply, options, args: ['model'], transaction })
|
|
5
5
|
|
|
6
6
|
async function handler (trx) {
|
|
7
|
-
opts.trx
|
|
7
|
+
if (opts.trx === true) opts.trx = trx
|
|
8
8
|
const ret = await mdl.findOneRecord(filter, opts)
|
|
9
9
|
if (attachment) ret.data._attachment = await mdl.findAttachment(ret.data.id, { stats, mimeType })
|
|
10
10
|
return ret
|
|
@@ -4,7 +4,7 @@ async function findRecord ({ model, req, reply, options = {}, transaction } = {}
|
|
|
4
4
|
const { model: mdl, opts, filter, attachment, stats, mimeType } = await prepCrud.call(this, { model, req, reply, options, args: ['model'], transaction })
|
|
5
5
|
|
|
6
6
|
async function handler (trx) {
|
|
7
|
-
opts.trx
|
|
7
|
+
if (opts.trx === true) opts.trx = trx
|
|
8
8
|
const ret = await mdl.findRecord(filter, opts)
|
|
9
9
|
if (attachment) {
|
|
10
10
|
for (const d of ret.data) {
|
package/lib/method/get-record.js
CHANGED
|
@@ -5,7 +5,7 @@ async function getRecord ({ model, req, reply, id, options = {}, transaction } =
|
|
|
5
5
|
const me = this
|
|
6
6
|
|
|
7
7
|
async function handler (trx) {
|
|
8
|
-
opts.trx
|
|
8
|
+
if (opts.trx === true) opts.trx = trx
|
|
9
9
|
const data = await getOneRecord.call(me, mdl, recId, filter, opts)
|
|
10
10
|
if (attachment) data._attachment = await mdl.findAttachment(data.id, { stats, mimeType })
|
|
11
11
|
return data
|
|
@@ -165,6 +165,9 @@ const handler = {
|
|
|
165
165
|
},
|
|
166
166
|
edit: async function (schema, ext, options) {
|
|
167
167
|
applyLayout.call(this, 'edit', schema, ext, options)
|
|
168
|
+
},
|
|
169
|
+
delete: async function (schema, ext, options) {
|
|
170
|
+
applyLayout.call(this, 'delete', schema, ext, options)
|
|
168
171
|
}
|
|
169
172
|
}
|
|
170
173
|
|
|
@@ -5,7 +5,7 @@ async function removeRecord ({ model, req, reply, id, options = {}, transaction
|
|
|
5
5
|
const me = this
|
|
6
6
|
|
|
7
7
|
async function handler (trx) {
|
|
8
|
-
opts.trx
|
|
8
|
+
if (opts.trx === true) opts.trx = trx
|
|
9
9
|
const resp = await getOneRecord.call(me, mdl, recId, filter, opts)
|
|
10
10
|
opts._data = resp.data
|
|
11
11
|
return await mdl.removeRecord(recId, opts)
|
|
@@ -5,7 +5,7 @@ async function updateRecord ({ model, req, reply, id, body, options = {}, transa
|
|
|
5
5
|
const me = this
|
|
6
6
|
|
|
7
7
|
async function handler (trx) {
|
|
8
|
-
opts.trx
|
|
8
|
+
if (opts.trx === true) opts.trx = trx
|
|
9
9
|
const resp = await getOneRecord.call(me, mdl, recId, filter, opts)
|
|
10
10
|
opts._data = resp.data
|
|
11
11
|
const ret = await mdl.updateRecord(recId, input, opts)
|
package/lib/util.js
CHANGED
|
@@ -14,7 +14,6 @@ export async function prepCrud ({ model, body, id, req, reply, transaction, opti
|
|
|
14
14
|
if (opts.suppressError === true) opts.suppressError = actions
|
|
15
15
|
else if (isString(opts.suppressError)) opts.suppressError = [opts.suppressError]
|
|
16
16
|
else opts.suppressError = opts.suppressError ?? []
|
|
17
|
-
opts.trx = options.trx
|
|
18
17
|
const params = this.getParams(req, ...args)
|
|
19
18
|
for (const k of ['count', 'fields']) {
|
|
20
19
|
opts[k] = opts[k] ?? params[k]
|
|
@@ -23,7 +22,7 @@ export async function prepCrud ({ model, body, id, req, reply, transaction, opti
|
|
|
23
22
|
opts.dataOnly = opts.dataOnly ?? false
|
|
24
23
|
opts.req = req
|
|
25
24
|
opts.reply = reply
|
|
26
|
-
opts.trx = opts.trx
|
|
25
|
+
opts.trx = opts.trx ?? options.trx ?? transaction ?? true
|
|
27
26
|
|
|
28
27
|
let { attachment, stats, mimeType } = opts
|
|
29
28
|
attachment = attachment ?? req.query.attachment
|
package/package.json
CHANGED
package/wiki/CHANGES.md
CHANGED
|
@@ -1,5 +1,14 @@
|
|
|
1
1
|
# Changes
|
|
2
2
|
|
|
3
|
+
## 2026-03-30
|
|
4
|
+
|
|
5
|
+
- [2.12.3] Bug fix in transaction supports
|
|
6
|
+
|
|
7
|
+
## 2026-03-27
|
|
8
|
+
|
|
9
|
+
- [2.12.1] Bug fix in all ```view.formatter``` & ```view.valueFormatter```
|
|
10
|
+
- [2.12.2] Bug fix in ```wdb-form``` & ```wdb-table``` widgets, now correctly use value from formatter if provided
|
|
11
|
+
|
|
3
12
|
## 2026-03-26
|
|
4
13
|
|
|
5
14
|
- [2.11.0] Adding ```suppressError``` to model options
|