waibu-db 2.36.0 → 2.38.0
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-footer.html +2 -2
- package/extend/waibuBootstrap/theme/component/widget/form.js +2 -1
- package/extend/waibuBootstrap/theme/component/widget/pagination.js +5 -4
- package/extend/waibuBootstrap/theme/component/widget/query.js +1 -1
- package/extend/waibuBootstrap/theme/component/widget/recs-info.js +6 -5
- package/lib/crud/add-handler.js +3 -2
- package/lib/crud/details-handler.js +2 -3
- package/lib/crud/edit-handler.js +2 -3
- package/lib/crud/helper.js +9 -0
- package/lib/crud/list-handler.js +3 -2
- package/lib/method/create-record.js +1 -1
- package/lib/method/find-one-record.js +1 -1
- package/lib/method/get-record.js +1 -1
- package/lib/method/get-schema-ext.js +6 -0
- package/lib/method/update-record.js +2 -2
- package/package.json +1 -1
- package/wiki/CHANGES.md +13 -1
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
<c:grid-row gutter="3">
|
|
2
2
|
<c:grid-col col="6-lg">
|
|
3
|
-
<c:wdb-recs-info pages recs-per-page recs-per-page-values="10 15 25 50" />
|
|
3
|
+
<c:wdb-recs-info pages recs-per-page recs-per-page-values="10 15 25 50" <% if (attr.dataKey) { %> data-key="<%= attr.dataKey %>" <% } %> />
|
|
4
4
|
</c:grid-col>
|
|
5
5
|
<c:grid-col col="6-lg" flex="justify-content:end-lg">
|
|
6
|
-
<c:wdb-pagination />
|
|
6
|
+
<c:wdb-pagination <% if (attr.dataKey) { %> data-key="<%= attr.dataKey %>" <% } %> />
|
|
7
7
|
</c:grid-col>
|
|
8
8
|
</c:grid-row>
|
|
@@ -65,7 +65,8 @@ async function form () {
|
|
|
65
65
|
ao.position = ao.position ?? 'append'
|
|
66
66
|
}
|
|
67
67
|
let html
|
|
68
|
-
|
|
68
|
+
const roCmps = ['createdAt', 'updatedAt']
|
|
69
|
+
if (widget.component === 'form-plaintext' || this.params.attr.method !== 'POST' || roCmps.includes(widget.name)) {
|
|
69
70
|
html = await WdbForm.handleRo.call(this, { attr, prop, widget })
|
|
70
71
|
} else {
|
|
71
72
|
html = await WdbForm.handleRw.call(this, { attr, prop, widget })
|
|
@@ -21,20 +21,21 @@ async function pagination () {
|
|
|
21
21
|
const { attrToObject } = this.app.waibu
|
|
22
22
|
const { get, isNumber } = this.app.lib._
|
|
23
23
|
const schema = get(this, 'component.locals.schema', {})
|
|
24
|
+
const dataKey = this.params.attr.dataKey ?? 'list'
|
|
24
25
|
if (schema.view.disabled.includes('find')) {
|
|
25
26
|
this.params.html = ''
|
|
26
27
|
return
|
|
27
28
|
}
|
|
28
29
|
let { count, limit, page } = attrToObject(this.params.attr.options)
|
|
29
|
-
count = count ?? get(this,
|
|
30
|
-
const data = get(this,
|
|
30
|
+
count = count ?? get(this, `component.locals.${dataKey}.count`, 0)
|
|
31
|
+
const data = get(this, `component.locals.${dataKey}.data`, [])
|
|
31
32
|
if (count === 0 || data.length === 0) {
|
|
32
33
|
this.params.noTag = true
|
|
33
34
|
this.params.html = ''
|
|
34
35
|
return
|
|
35
36
|
}
|
|
36
|
-
limit = limit ?? get(this,
|
|
37
|
-
page = page ?? get(this,
|
|
37
|
+
limit = limit ?? get(this, `component.locals.${dataKey}.limit`, 25)
|
|
38
|
+
page = page ?? get(this, `component.locals.${dataKey}.page`, 1)
|
|
38
39
|
const pages = paginationLayout(count, limit, page) ?? []
|
|
39
40
|
this.params.noTag = true
|
|
40
41
|
const group = groupAttrs(this.params.attr, ['pagination'])
|
|
@@ -211,7 +211,7 @@ async function query () {
|
|
|
211
211
|
const params = new URLSearchParams(url.search)
|
|
212
212
|
params.set('${qsKey.page}', 1)
|
|
213
213
|
params.set('${qsKey.query}', val)
|
|
214
|
-
window.location.href = '?' + params.toString()
|
|
214
|
+
window.location.href = '${this.params.attr.href ?? ''}?' + params.toString()
|
|
215
215
|
}
|
|
216
216
|
}" x-init="
|
|
217
217
|
const url = new URL(window.location.href)
|
|
@@ -11,21 +11,22 @@ async function recsInfo () {
|
|
|
11
11
|
const { attrToObject, attrToArray } = this.app.waibu
|
|
12
12
|
const { get, isEmpty, omit, merge } = this.app.lib._
|
|
13
13
|
const schema = get(this, 'component.locals.schema', {})
|
|
14
|
+
const dataKey = this.params.attr.dataKey ?? 'list'
|
|
14
15
|
if (schema.view.disabled.includes('find')) {
|
|
15
16
|
this.params.html = ''
|
|
16
17
|
return
|
|
17
18
|
}
|
|
18
19
|
let { count, limit, page, pages } = attrToObject(this.params.attr.options)
|
|
19
|
-
count = count ?? get(this,
|
|
20
|
-
const data = get(this,
|
|
20
|
+
count = count ?? get(this, `component.locals.${dataKey}.count`, 0)
|
|
21
|
+
const data = get(this, `component.locals.${dataKey}.data`, [])
|
|
21
22
|
if (count === 0 || data.length === 0) {
|
|
22
23
|
this.params.noTag = true
|
|
23
24
|
this.params.html = ''
|
|
24
25
|
return
|
|
25
26
|
}
|
|
26
|
-
page = get(this,
|
|
27
|
-
limit = get(this,
|
|
28
|
-
pages = get(this,
|
|
27
|
+
page = get(this, `component.locals.${dataKey}.page`, page ?? 1)
|
|
28
|
+
limit = get(this, `component.locals.${dataKey}.limit`, limit ?? 25)
|
|
29
|
+
pages = get(this, `component.locals.${dataKey}.pages`, pages ?? 0)
|
|
29
30
|
|
|
30
31
|
this.params.tag = 'div'
|
|
31
32
|
this.params.attr.flex = 'justify-center:start align-items:center'
|
package/lib/crud/add-handler.js
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { getPageTemplate } from './helper.js'
|
|
2
|
+
|
|
1
3
|
/**
|
|
2
4
|
* Handler for rendering the add view of a model.
|
|
3
5
|
*
|
|
@@ -71,8 +73,7 @@ async function addHandler (opts = {}) {
|
|
|
71
73
|
}
|
|
72
74
|
const addOns = addOnsHandler ? await addOnsHandler.call(this.app[req.ns], { req, reply, params, data: resp, schema, error, options }) : undefined
|
|
73
75
|
merge(params, { form, schema, error, addOns })
|
|
74
|
-
|
|
75
|
-
if (schema.layout) params.page.layout = schema.layout
|
|
76
|
+
template = (await getPageTemplate.call(this, schema, params)) ?? template
|
|
76
77
|
return await reply.view(template, params)
|
|
77
78
|
}
|
|
78
79
|
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { attachmentHandler, notFoundTpl } from './helper.js'
|
|
1
|
+
import { attachmentHandler, notFoundTpl, getPageTemplate } from './helper.js'
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* Handler for rendering the details view of a model.
|
|
@@ -44,8 +44,7 @@ async function detailsHandler (opts = {}) {
|
|
|
44
44
|
const addOns = addOnsHandler ? await addOnsHandler.call(this.app[req.ns], { req, reply, params, data: resp, schema, options }) : undefined
|
|
45
45
|
const attachments = await attachmentHandler.call(this, { schema, id, options })
|
|
46
46
|
merge(params, { form, schema, addOns, attachments })
|
|
47
|
-
|
|
48
|
-
if (schema.layout) params.page.layout = schema.layout
|
|
47
|
+
template = (await getPageTemplate.call(this, schema, params)) ?? template
|
|
49
48
|
return await reply.view(template, params)
|
|
50
49
|
}
|
|
51
50
|
|
package/lib/crud/edit-handler.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { attachmentHandler, notFoundTpl } from './helper.js'
|
|
1
|
+
import { attachmentHandler, notFoundTpl, getPageTemplate } from './helper.js'
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* Handler for rendering the edit view of a model.
|
|
@@ -79,8 +79,7 @@ async function editHandler (opts = {}) {
|
|
|
79
79
|
const addOns = addOnsHandler ? await addOnsHandler.call(this.app[req.ns], { req, reply, params, data: resp, schema, error, options }) : undefined
|
|
80
80
|
const attachments = await attachmentHandler.call(this, { schema, id, options })
|
|
81
81
|
merge(params, { oldData: old.data, form, schema, error, addOns, attachments })
|
|
82
|
-
|
|
83
|
-
if (schema.layout) params.page.layout = schema.layout
|
|
82
|
+
template = (await getPageTemplate.call(this, schema, params)) ?? template
|
|
84
83
|
return await reply.view(template, params)
|
|
85
84
|
}
|
|
86
85
|
|
package/lib/crud/helper.js
CHANGED
|
@@ -113,3 +113,12 @@ export function buildParams (opts = {}) {
|
|
|
113
113
|
* @memberof module:CRUDHandler/Helper
|
|
114
114
|
*/
|
|
115
115
|
export const notFoundTpl = 'waibuDb.template:/crud/not-found.html'
|
|
116
|
+
|
|
117
|
+
export async function getPageTemplate (schema, params = {}) {
|
|
118
|
+
const { get } = this.app.lib._
|
|
119
|
+
const page = get(schema, 'view.page', {})
|
|
120
|
+
if (page.layout) params.page.layout = page.layout
|
|
121
|
+
params.page.features = params.page.features ?? []
|
|
122
|
+
params.page.features.push(...(page.features ?? []))
|
|
123
|
+
return page.template
|
|
124
|
+
}
|
package/lib/crud/list-handler.js
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { getPageTemplate } from './helper.js'
|
|
2
|
+
|
|
1
3
|
/**
|
|
2
4
|
* Handle the list view for a given model, rendering the appropriate template with the retrieved data.
|
|
3
5
|
*
|
|
@@ -50,8 +52,7 @@ async function listHandler (opts) {
|
|
|
50
52
|
if (!isArray(addOns)) addOns = [addOns]
|
|
51
53
|
}
|
|
52
54
|
merge(params, { list, schema, addOns })
|
|
53
|
-
|
|
54
|
-
if (schema.layout) params.page.layout = schema.layout
|
|
55
|
+
template = (await getPageTemplate.call(this, schema, params)) ?? template
|
|
55
56
|
return await reply.view(template, params)
|
|
56
57
|
}
|
|
57
58
|
|
|
@@ -6,7 +6,7 @@ async function createRecord ({ model, req, body, reply, options = {}, transactio
|
|
|
6
6
|
async function handler (trx) {
|
|
7
7
|
if (opts.trx === true) opts.trx = trx
|
|
8
8
|
const ret = await mdl.createRecord(body ?? req.body, { ...opts, dataOnly: false, partial: true, strict: true })
|
|
9
|
-
if (attachment) {
|
|
9
|
+
if (attachment && ret.data) {
|
|
10
10
|
const { params, options: attachOpts } = attachment ?? {}
|
|
11
11
|
ret.data._attachment = await mdl.findAttachment(ret.data.id, params, attachOpts)
|
|
12
12
|
}
|
|
@@ -6,7 +6,7 @@ async function findOneRecord ({ model, req, reply, options = {}, noAutoFilter, t
|
|
|
6
6
|
async function handler (trx) {
|
|
7
7
|
if (opts.trx === true) opts.trx = trx
|
|
8
8
|
const ret = await mdl.findOneRecord(filter, { ...opts, dataOnly: false })
|
|
9
|
-
if (attachment) {
|
|
9
|
+
if (attachment && ret.data) {
|
|
10
10
|
const { params, options: attachOpts } = attachment ?? {}
|
|
11
11
|
ret.data._attachment = await mdl.findAttachment(ret.data.id, params, attachOpts)
|
|
12
12
|
}
|
package/lib/method/get-record.js
CHANGED
|
@@ -7,7 +7,7 @@ async function getRecord ({ model, req, reply, id, options = {}, transaction, no
|
|
|
7
7
|
async function handler (trx) {
|
|
8
8
|
if (opts.trx === true) opts.trx = trx
|
|
9
9
|
const data = await getOneRecord.call(me, mdl, recId, filter, { ...opts, dataOnly: false })
|
|
10
|
-
if (attachment) {
|
|
10
|
+
if (attachment && data) {
|
|
11
11
|
const { params, options: attachOpts } = attachment ?? {}
|
|
12
12
|
data._attachment = await mdl.findAttachment(data.id, params, attachOpts)
|
|
13
13
|
}
|
|
@@ -5,6 +5,7 @@ const defFormatter = {}
|
|
|
5
5
|
function getCommons (action, schema, ext, options = {}) {
|
|
6
6
|
const { defaultsDeep } = this.app.lib.aneka
|
|
7
7
|
const { merge, map, get, set, without, uniq, pull } = this.app.lib._
|
|
8
|
+
const page = get(ext, `view.${action}.page`, get(ext, 'common.page', {}))
|
|
8
9
|
const forceVisible = get(ext, `view.${action}.forceVisible`, get(ext, 'common.forceVisible', []))
|
|
9
10
|
const widget = defaultsDeep(get(ext, `view.${action}.widget`), get(ext, 'common.widget', {}))
|
|
10
11
|
const noEscape = get(ext, `view.${action}.noEscape`, get(ext, 'common.noEscape', []))
|
|
@@ -16,6 +17,7 @@ function getCommons (action, schema, ext, options = {}) {
|
|
|
16
17
|
const disabled = get(ext, `view.${action}.disabled`, get(ext, 'common.disabled', []))
|
|
17
18
|
const x = defaultsDeep(get(ext, `view.${action}.x`), get(ext, 'common.x', {}))
|
|
18
19
|
const aggregate = get(ext, `view.${action}.stat.aggregate`, get(ext, 'common.stat.aggregate', []))
|
|
20
|
+
const qs = get(ext, `view.${action}.qs`, get(ext, 'common.qs', {}))
|
|
19
21
|
const hasXSite = get(options, 'args.0.req.routeOptions.config.xSite')
|
|
20
22
|
const hasSiteId = schema.model.hasProperty('siteId')
|
|
21
23
|
const hasImmutable = schema.model.hasProperty('_immutable')
|
|
@@ -36,8 +38,10 @@ function getCommons (action, schema, ext, options = {}) {
|
|
|
36
38
|
set(schema, 'view.format', merge({}, defFormatter, format))
|
|
37
39
|
set(schema, 'view.stat.aggregate', aggregate)
|
|
38
40
|
set(schema, 'view.disabled', disabled)
|
|
41
|
+
set(schema, 'view.qs', qs)
|
|
39
42
|
set(schema, 'view.control', control)
|
|
40
43
|
set(schema, 'view.x', x)
|
|
44
|
+
set(schema, 'view.page', page)
|
|
41
45
|
if (schema.disabled.length > 0) schema.view.disabled.push(...schema.disabled)
|
|
42
46
|
let fields = forFields.filter(f => allFields.includes(f))
|
|
43
47
|
fields = uniq(without(fields, ...hidden))
|
|
@@ -89,6 +93,7 @@ async function applyLayout (action, schema, ext, options) {
|
|
|
89
93
|
const { defaultsDeep } = this.app.lib.aneka
|
|
90
94
|
const { set, get, isEmpty, find } = this.app.lib._
|
|
91
95
|
const { fields, card } = getCommons.call(this, action, schema, ext, options)
|
|
96
|
+
const page = get(ext, `view.${action}.page`, get(ext, 'common.page', {}))
|
|
92
97
|
const layout = get(ext, `view.${action}.layout`, get(ext, 'common.layout', []))
|
|
93
98
|
const readonly = get(ext, `view.${action}.readonly`, get(ext, 'common.readonly', defReadonly))
|
|
94
99
|
const widget = {}
|
|
@@ -153,6 +158,7 @@ async function applyLayout (action, schema, ext, options) {
|
|
|
153
158
|
*/
|
|
154
159
|
widget[f] = result
|
|
155
160
|
}
|
|
161
|
+
set(schema, 'view.page', page)
|
|
156
162
|
set(schema, 'view.widget', widget)
|
|
157
163
|
if (isEmpty(layout)) autoLayout.call(this, { layout, schema, action, ext, options })
|
|
158
164
|
else customLayout.call(this, { layout, schema, action, ext, readonly, options })
|
|
@@ -11,9 +11,9 @@ async function updateRecord ({ model, req, reply, id, body, options = {}, transa
|
|
|
11
11
|
opts._data = resp.data
|
|
12
12
|
}
|
|
13
13
|
const ret = await mdl.updateRecord(recId, body ?? req.body, { ...opts, dataOnly: false, partial: true, strict: true })
|
|
14
|
-
if (attachment) {
|
|
14
|
+
if (attachment && ret.data) {
|
|
15
15
|
const { params, options: attachOpts } = attachment ?? {}
|
|
16
|
-
ret.data._attachment = await mdl.findAttachment(
|
|
16
|
+
ret.data._attachment = await mdl.findAttachment(ret.data.id, params, attachOpts)
|
|
17
17
|
}
|
|
18
18
|
return ret
|
|
19
19
|
}
|
package/package.json
CHANGED
package/wiki/CHANGES.md
CHANGED
|
@@ -1,11 +1,23 @@
|
|
|
1
1
|
# Changes
|
|
2
2
|
|
|
3
|
+
## 2026-11-23
|
|
4
|
+
|
|
5
|
+
- [2.38.0] Add `view.qs` to `getSchemaExt()`
|
|
6
|
+
|
|
7
|
+
## 2026-11-22
|
|
8
|
+
|
|
9
|
+
- [2.37.0] `recs-info` widget now accept `data-key` option
|
|
10
|
+
- [2.37.0] `pagination` widget now accept `data-key` option
|
|
11
|
+
- [2.37.0] Bug fix in `form` widget
|
|
12
|
+
- [2.37.0] Crud handlers now support `page` locals
|
|
13
|
+
- [2.37.0] Bug fix in crud methods when no data is returned
|
|
14
|
+
|
|
3
15
|
## 2026-11-20
|
|
4
16
|
|
|
5
17
|
- [2.35.0] `attachment` options can now accept plain object too
|
|
6
18
|
- [2.35.0] Bug fix in `attachment` handling
|
|
7
19
|
- [2.35.0] Bug fix in `dataOnly` handling
|
|
8
|
-
- [2.35.0] Submit button can be omitted in `query` widget
|
|
20
|
+
- [2.35.0] Submit button can be omitted in `query` widget
|
|
9
21
|
- [2.36.0] Refactoring everything related to attachment handling
|
|
10
22
|
|
|
11
23
|
## 2026-11-08
|