waibu-db 2.20.0 → 2.21.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.
@@ -5,11 +5,12 @@ async function btnColumns () {
5
5
 
6
6
  return class WdbBtnColumns extends WdbBase {
7
7
  build = async () => {
8
- const { find, get, isEmpty, without } = this.app.lib._
8
+ const { find, get, isEmpty, without, intersection } = this.app.lib._
9
9
  const { jsonStringify } = this.app.waibuMpa
10
10
  const { req } = this.component
11
11
  const qsKey = this.app.waibu.config.qsKey
12
12
  const schema = get(this, 'component.locals.schema', {})
13
+ const data = get(this, 'component.locals.list.data', [])
13
14
  const count = get(this, 'component.locals.list.count', 0)
14
15
  if (count === 0) this.params.attr.triggerDisabled = true
15
16
  if (schema.view.disabled.includes('find')) {
@@ -18,12 +19,13 @@ async function btnColumns () {
18
19
  }
19
20
  let fields = without(get(this, `component.locals._meta.query.${qsKey.fields}`, '').split(','), '')
20
21
  if (isEmpty(fields)) fields = without(schema.view.fields, 'id')
22
+ const allFields = data.length > 0 ? intersection(schema.view.fields, Object.keys(data[0])) : []
21
23
  const items = []
22
24
  this.params.attr.color = this.params.attr.color ?? 'secondary-outline'
23
25
  if (isEmpty(this.params.attr.content)) this.params.attr.content = req.t('columns')
24
26
  for (const f of schema.view.fields) {
25
- let prop = find(schema.properties, { name: f })
26
- if (!prop) prop = find(schema.view.calcFields, { name: f })
27
+ if (allFields.length > 0 && !allFields.includes(f)) continue
28
+ const prop = find(schema.properties, { name: f })
27
29
  if (!prop) continue
28
30
  const attr = { 'x-model': 'selected', label: req.t(get(schema, `view.label.${f}`, `field.${f}`)), value: f, labelText: 'nowrap' }
29
31
  if (fields.includes(f)) attr.checked = true
@@ -46,9 +46,7 @@ async function btnDelete () {
46
46
  await wbs.confirmation(\`${req.t(msg)}\`, {
47
47
  ok: '${this.params.attr.id}:remove',
48
48
  close: 'y',
49
- opts: selected,
50
- theme: '${get(this, 'component.theme.name', 'default')}',
51
- iconset: '${get(this, 'component.iconset.name', 'default')}'
49
+ opts: selected
52
50
  })
53
51
  `
54
52
  this.params.html = await this.component.buildTag({ tag: 'btn', attr: this.params.attr, html: this.params.html })
@@ -24,7 +24,8 @@ async function table () {
24
24
  const { escape, attrToArray } = this.app.waibu
25
25
  const { groupAttrs } = this.app.waibuMpa
26
26
  const { isHtmlLink } = this.app.bajoExtra
27
- const { get, omit, set, find, isEmpty, without, merge } = this.app.lib._
27
+ const { getTruncated } = this.app.bajoTemplate
28
+ const { get, omit, set, find, isEmpty, without, merge, intersection } = this.app.lib._
28
29
  const { isSet } = this.app.lib.aneka
29
30
  const group = groupAttrs(this.params.attr, ['body', 'head', 'foot'])
30
31
  this.params.attr = group._
@@ -48,6 +49,9 @@ async function table () {
48
49
  const qsKey = this.app.waibu.config.qsKey
49
50
  let fields = without(get(this, `component.locals._meta.query.${qsKey.fields}`, '').split(','), '')
50
51
  if (isEmpty(fields)) fields = without(schema.view.fields, 'id')
52
+ if (data.length > 0) {
53
+ fields = intersection(fields, Object.keys(data[0]))
54
+ }
51
55
  let sort = this.params.attr.sort ? attrToArray(this.params.attr.sort) : get(this, `component.locals._meta.query.${qsKey.sort}`, '')
52
56
  if (isEmpty(sort) && filter.sort) {
53
57
  const keys = Object.keys(filter.sort)
@@ -143,6 +147,7 @@ async function table () {
143
147
  if (d._immutable) attr.text += ' color:body-tertiary'
144
148
  const format = get(schema, `view.format.${f}`)
145
149
  if (format) value = await format.call(this, value, d, { params: this.params, req })
150
+ if (['object', 'array'].includes(prop.type) && !isHtmlLink(value)) value = getTruncated(value, 20) // TODO: should be handle by css instead
146
151
  if (!get(schema, 'view.noEscape', []).includes(f) && !isHtmlLink(value)) value = escape(value)
147
152
  const line = await this.component.buildTag({ tag: 'td', attr, html: value })
148
153
  lines.push(line)
@@ -4,8 +4,8 @@ async function form () {
4
4
  const WdbBase = await wdbBase.call(this)
5
5
 
6
6
  return class WdbForm extends WdbBase {
7
- static async handleRo ({ attr = {}, prop = {} } = {}) {
8
- return await this.component.buildTag({ tag: 'formPlaintext', attr, selfCosing: true, noEscape: true })
7
+ static async handleRo ({ attr = {}, prop = {}, widget = {} } = {}) {
8
+ return await this.component.buildTag({ tag: 'formPlaintext', attr, selfCosing: true, noEscape: true }, { prop, widget })
9
9
  }
10
10
 
11
11
  static async handleRw ({ attr = {}, prop = {}, widget = {} } = {}) {
@@ -44,6 +44,7 @@ async function form () {
44
44
  if (v === true) attr[k] = true
45
45
  else attr[k] = v
46
46
  })
47
+ if (['array', 'object'].includes(prop.type)) attr.col = '12-md'
47
48
  attr.label = this.component.req.t(attr.label)
48
49
  const xon = filter(xOns, { field: widget.name })
49
50
  for (const o of xon) {
package/index.js CHANGED
@@ -129,9 +129,14 @@ async function factory (pkgName) {
129
129
  menu.push({
130
130
  title: req.t(k),
131
131
  children: map(items, item => {
132
+ const params = {
133
+ model: kebabCase(item.name),
134
+ action: 'list'
135
+ }
132
136
  return {
133
137
  title: camelCase(item.name.slice(plugin.alias.length)),
134
- href: `waibuAdmin:/${prefix}/${kebabCase(item.name)}/list`
138
+ href: `waibuAdmin:/${prefix}/:model/:action`,
139
+ params
135
140
  }
136
141
  })
137
142
  })
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "waibu-db",
3
- "version": "2.20.0",
3
+ "version": "2.21.0",
4
4
  "description": "DB Helper",
5
5
  "main": "index.js",
6
6
  "scripts": {
package/wiki/CHANGES.md CHANGED
@@ -1,5 +1,16 @@
1
1
  # Changes
2
2
 
3
+ ## 2026-05-25
4
+
5
+ - [2.21.0] Auto detect theme & iconset
6
+
7
+ ## 2026-05-22
8
+
9
+ - [2.20.1] Bug fix in admin menu
10
+ - [2.20.1] Bug fix in ```wdb-btn-columns``` widget
11
+ - [2.20.1] Bug fix in ```wdb-data-table``` widget
12
+ - [2.20.1] Bug fix in ```wdb-form``` widget
13
+
3
14
  ## 2026-05-16
4
15
 
5
16
  - [2.20.0] Change to ```wdb-data-table``` widget to handle immutable rows