waibu-db 2.16.2 → 2.17.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.
@@ -1,3 +1,5 @@
1
+ <% if (schema && schema.attachment) { %>
1
2
  <c:fieldset <%= schema.view.card === false ? '' : 'card' %> t:legend="attachment" grid-gutter="3">
2
3
  <!-- include waibuDb.partial:/crud/_list-attachment.html|<%= JSON.stringify({ readonly: true }) %> -->
3
4
  </c:fieldset>
5
+ <% } %>
@@ -1,5 +1,5 @@
1
1
  <!-- include waibuDb.partial:/crud/_list-btns.html -->
2
- <c:wdb-table id="main-table" border body-divider strip responsive margin="top-3"/>
2
+ <c:wdb-data-table id="main-table" border body-divider strip responsive margin="top-3"/>
3
3
  <!-- include waibuDb.partial:/crud/_list-footer.html -->
4
4
  <!-- include waibuDb.partial:/crud/_addons.html -->
5
5
  <!-- include waibuDb.partial:/crud/_list-warnings.html -->
@@ -3,7 +3,7 @@ import wdbBase from '../wdb-base.js'
3
3
  async function table () {
4
4
  const WdbBase = await wdbBase.call(this)
5
5
 
6
- return class WdbTable extends WdbBase {
6
+ return class WdbDataTable extends WdbBase {
7
7
  isRightAligned = (field, schema) => {
8
8
  const { get, find } = this.app.lib._
9
9
  const prop = find(schema.properties, { name: field })
@@ -127,9 +127,9 @@ async function table () {
127
127
  if (!prop) prop = find(schema.view.calcFields, { name: f })
128
128
  if (!prop) continue
129
129
  let dataValue = d._orig[f]
130
- if (['datetime'].includes(prop.type)) dataValue = escape(dataValue.toISOString())
130
+ if (['datetime'].includes(prop.type) && dataValue) dataValue = escape(dataValue.toISOString())
131
131
  else if (['string', 'text'].includes(prop.type)) dataValue = escape(dataValue)
132
- else if (['array', 'object'].includes(prop.type)) dataValue = escape(JSON.stringify(d[f]))
132
+ else if (['array', 'object'].includes(prop.type)) dataValue = escape(JSON.stringify(dataValue))
133
133
  const refName = get(schema, `view.widget.${f}.attr.refName`)
134
134
  let value = this.getRefValue({ field: f, data: d, refName }) ?? d[f]
135
135
  const formatValue = get(schema, `view.formatValue.${f}`)
@@ -11,11 +11,11 @@ async function form () {
11
11
  static async handleRw ({ attr = {}, prop = {}, widget = {} } = {}) {
12
12
  const { get, has } = this.app.lib._
13
13
  const { stringifyAttribs } = this.app.waibuMpa
14
- if (has(attr, 'name') && !has(attr, 'value')) {
15
- attr.value = widget.component === 'form-plaintext' ? get(this, `oldData.${attr.name}`, attr.dataValue) : attr.dataValue
16
- }
17
14
  attr.dataType = prop.type
18
15
  const cmp = prop.ref ? 'wdb-lookup-select' : widget.component
16
+ if (has(attr, 'name') && !has(attr, 'value')) {
17
+ attr.value = cmp === 'form-plaintext' ? get(this, `oldData.${attr.name}`, attr.dataValue) : attr.dataValue
18
+ }
19
19
  return `<c:${cmp} ${stringifyAttribs(attr)} />`
20
20
  }
21
21
 
@@ -61,7 +61,7 @@ async function query () {
61
61
  }
62
62
  this.params.noTag = true
63
63
  const container = this.params.attr.modal ? 'modal' : 'drawer'
64
- const scanables = (this.model ? this.model.scanables : []).map(item => req.t(`field.${item}`))
64
+ const scanables = (this.schema.scanables ?? []).map(item => req.t(`field.${item}`))
65
65
  let placeholder = this.params.attr.placeholder
66
66
  if (!placeholder) placeholder = scanables.length > 0 ? req.t('queryHint%s', join(scanables, { separator: ', ', lastSeparator: 'or' })) : req.t('query')
67
67
  this.params.html = await this.component.buildSentence(`
@@ -111,7 +111,6 @@ async function query () {
111
111
  val = opv.slice(v.length).replaceAll('[', '').replaceAll('{', '').replaceAll(']', '').replaceAll('}', '').replaceAll('\\'', '')
112
112
  }
113
113
  })
114
- console.log(op, val)
115
114
  if (_.isEmpty(op)) continue
116
115
  this[f + 'Op'] = op
117
116
  if (op === 'between') {
@@ -13,11 +13,17 @@ async function addHandler ({ req, reply, model, params = {}, template, addOnsHan
13
13
  opts.fields = schema.view.fields
14
14
  delete req.query.query
15
15
  let def = {}
16
- if (req.method === 'GET' && req.query.mode === 'clone' && req.query.id) {
17
- const resp = await getRecord({ model, req, id: req.query.id, options: { fields: map(schema.properties, 'name'), ...opts } })
18
- def = omit(resp.data._orig, ['id', 'createdAt', 'updatedAt'])
16
+ if (req.method === 'GET') {
17
+ const omitted = ['id', 'createdAt', 'updatedAt']
18
+ if (req.query.mode === 'clone' && req.query.id) {
19
+ const resp = await getRecord({ model, req, id: req.query.id, options: { fields: map(schema.properties, 'name'), ...opts } })
20
+ def = omit(resp.data._orig, omitted)
21
+ } else {
22
+ const picked = map(schema.properties, 'name')
23
+ def = omit(pick(req.query, picked), omitted)
24
+ }
19
25
  }
20
- let form = defaultsDeep(req.body, def)
26
+ let form = defaultsDeep({}, req.body, def)
21
27
  let error
22
28
  let resp
23
29
  if (req.method === 'POST') {
@@ -27,7 +27,7 @@ async function editHandler ({ req, reply, model, id, params = {}, template, addO
27
27
  for (const k in def) {
28
28
  if (isArray(def[k]) || isPlainObject(def[k])) def[k] = JSON.stringify(def[k])
29
29
  }
30
- form = defaultsDeep(req.body, def)
30
+ form = defaultsDeep({}, req.body, def)
31
31
  if (req.method !== 'GET') {
32
32
  form = omit(form, ['_action', '_value'])
33
33
  try {
@@ -181,13 +181,13 @@ async function getSchemaExt (modelName, view, options = {}) {
181
181
  const { pick, isString } = this.app.lib._
182
182
 
183
183
  const model = isString(modelName) ? this.app.dobo.getModel(modelName) : modelName
184
- const schema = pick(model, ['name', 'properties', 'indexes', 'disabled', 'attachment', 'sortables', 'view', 'hidden'])
184
+ const schema = pick(model, ['name', 'properties', 'indexes', 'disabled', 'attachment', 'sortables', 'scanables', 'view', 'hidden'])
185
185
  const base = options.base ?? path.basename(model.file, path.extname(model.file))
186
186
  let ext = await readConfig(`${model.plugin.ns}:/extend/waibuDb/schema/${base}.*`, { ignoreError: true, options })
187
187
  const over = await readConfig(`main:/extend/waibuDb/extend/${model.plugin.ns}/schema/${base}.*`, { ignoreError: true, options })
188
188
  ext = defaultsDeep(options.schema ?? {}, over, ext)
189
189
  await handler[view].call(this, schema, ext, options)
190
- return { schema, ext }
190
+ return { schema, ext, model }
191
191
  }
192
192
 
193
193
  export default getSchemaExt
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "waibu-db",
3
- "version": "2.16.2",
3
+ "version": "2.17.0",
4
4
  "description": "DB Helper",
5
5
  "main": "index.js",
6
6
  "scripts": {
package/wiki/CHANGES.md CHANGED
@@ -1,5 +1,17 @@
1
1
  # Changes
2
2
 
3
+ ## 2026-04-19
4
+
5
+ - [2.12.0] Rename ```WdbTable``` to ```WdbDataTable``` widget
6
+ - [2.12.0] ```getSchemaExt()``` now include export related model too
7
+
8
+ ## 2026-04-18
9
+
10
+ - [2.16.3] Bug fix in ```WdbForm``` widget
11
+ - [2.16.3] Bug fix in ```WdbTable``` widget
12
+ - [2.16.3] Bug fix in ```add-handler.js``` module
13
+ - [2.16.3] Bug fix in ```edit-handler.js``` module
14
+
3
15
  ## 2026-04-17
4
16
 
5
17
  - [2.16.2] Bug fix in ```WdbTable``` widget
@@ -53,7 +65,7 @@
53
65
  - [2.12.5] Bug fix in ```wdb-pagination``` widget
54
66
  - [2.12.5] Bug fix in ```wdb-query``` widget
55
67
  - [2.12.5] Bug fix in ```wdb-recs-info``` widget
56
- - [2.12.5] Bug fix in ```wdb-table``` widget
68
+ - [2.12.5] Bug fix in ```wdb-data-table``` widget
57
69
  - [2.12.5] Bug fix in remove attachment
58
70
 
59
71
  ## 2026-03-30
@@ -64,7 +76,7 @@
64
76
  ## 2026-03-27
65
77
 
66
78
  - [2.12.1] Bug fix in all ```view.format``` & ```view.formatValue```
67
- - [2.12.2] Bug fix in ```wdb-form``` & ```wdb-table``` widgets, now correctly use value from format if provided
79
+ - [2.12.2] Bug fix in ```wdb-form``` & ```wdb-data-table``` widgets, now correctly use value from format if provided
68
80
 
69
81
  ## 2026-03-26
70
82
 
@@ -89,7 +101,7 @@
89
101
 
90
102
  - [2.9.0] Add ability to overwrite ```base``` through ```options```
91
103
  - [2.9.0] Bug fix in ```wdb-btn-columns``` widget
92
- - [2.9.0] Bug fix in ```wdb-table``` widget
104
+ - [2.9.0] Bug fix in ```wdb-data-table``` widget
93
105
 
94
106
  ## 2026-03-08
95
107