waibu-db 1.0.4 → 1.0.6
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.
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import prepCrud from '../../../lib/prep-crud.js'
|
|
2
|
+
|
|
3
|
+
async function count ({ model, req, reply, options = {} }) {
|
|
4
|
+
const { recordCount } = this.app.dobo
|
|
5
|
+
const { name, opts, filter } = prepCrud.call(this, { model, req, options, args: ['model'] })
|
|
6
|
+
const ret = await recordCount(name, filter, opts)
|
|
7
|
+
return ret
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export default count
|
|
@@ -2,17 +2,7 @@ import prepCrud from '../../../lib/prep-crud.js'
|
|
|
2
2
|
|
|
3
3
|
async function find ({ model, req, reply, options = {} }) {
|
|
4
4
|
const { recordFind, attachmentFind } = this.app.dobo
|
|
5
|
-
const {
|
|
6
|
-
const { name, opts } = prepCrud.call(this, { model, req, options, args: ['model'] })
|
|
7
|
-
const { parseFilter } = this.app.waibu
|
|
8
|
-
const cfgWeb = this.app.waibu.config
|
|
9
|
-
opts.bboxLatField = req.query[cfgWeb.qsKey.bboxLatField]
|
|
10
|
-
opts.bboxLngField = req.query[cfgWeb.qsKey.bboxLngField]
|
|
11
|
-
const filter = parseFilter(req)
|
|
12
|
-
if (options.query) {
|
|
13
|
-
filter.query = cloneDeep(options.query)
|
|
14
|
-
delete options.query
|
|
15
|
-
}
|
|
5
|
+
const { name, opts, filter } = prepCrud.call(this, { model, req, options, args: ['model'] })
|
|
16
6
|
const ret = await recordFind(name, filter, opts)
|
|
17
7
|
const { attachment, stats, mimeType } = req.query
|
|
18
8
|
if (attachment) {
|
package/lib/prep-crud.js
CHANGED
|
@@ -1,17 +1,26 @@
|
|
|
1
1
|
function prepCrud ({ model, body, id, req, options, args }) {
|
|
2
|
+
const { parseFilter } = this.app.waibu
|
|
2
3
|
const { pascalCase } = this.app.bajo
|
|
3
|
-
const { cloneDeep } = this.app.bajo.lib._
|
|
4
|
+
const { cloneDeep, has } = this.app.bajo.lib._
|
|
5
|
+
const cfgWeb = this.app.waibu.config
|
|
4
6
|
const opts = cloneDeep(options)
|
|
5
7
|
const params = this.getParams(req, ...args)
|
|
6
8
|
for (const k of ['count', 'fields']) {
|
|
7
9
|
opts[k] = opts[k] ?? params[k]
|
|
8
10
|
}
|
|
9
|
-
opts.
|
|
11
|
+
if (has(options, 'count')) opts.count = options.count
|
|
12
|
+
opts.dataOnly = opts.dataOnly ?? false
|
|
10
13
|
opts.req = req
|
|
11
14
|
const recId = id ?? params.id ?? req.query.id
|
|
12
15
|
const name = pascalCase(model ?? params.model)
|
|
13
16
|
const input = body ?? params.body
|
|
14
|
-
|
|
17
|
+
opts.bboxLatField = req.query[cfgWeb.qsKey.bboxLatField]
|
|
18
|
+
opts.bboxLngField = req.query[cfgWeb.qsKey.bboxLngField]
|
|
19
|
+
const filter = parseFilter(req)
|
|
20
|
+
if (options.query) filter.query = cloneDeep(options.query)
|
|
21
|
+
if (options.limit) filter.limit = options.limit
|
|
22
|
+
if (options.sort) filter.sort = options.sort
|
|
23
|
+
return { name, recId, input, opts, filter }
|
|
15
24
|
}
|
|
16
25
|
|
|
17
26
|
export default prepCrud
|
package/package.json
CHANGED
|
@@ -10,7 +10,7 @@ async function btnDelete () {
|
|
|
10
10
|
const { isEmpty, get } = this.plugin.app.bajo.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('delete')) {
|
|
14
14
|
this.params.html = ''
|
|
15
15
|
return
|
|
16
16
|
}
|
|
@@ -4,8 +4,17 @@ async function table () {
|
|
|
4
4
|
const WdbBase = await wdbBase.call(this)
|
|
5
5
|
|
|
6
6
|
return class WdbTable extends WdbBase {
|
|
7
|
-
isRightAligned (
|
|
8
|
-
|
|
7
|
+
isRightAligned (field, schema) {
|
|
8
|
+
const { get, find } = this.plugin.app.bajo.lib._
|
|
9
|
+
const type = find(schema.properties, { name: field }).type
|
|
10
|
+
let value = get(schema, 'view.alignEnd', []).includes(field)
|
|
11
|
+
if (!value) value = ['smallint', 'integer', 'float', 'double'].includes(type)
|
|
12
|
+
return value
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
isNoWrap (field, schema) {
|
|
16
|
+
const { get } = this.plugin.app.bajo.lib._
|
|
17
|
+
return get(schema, 'view.noWrap', []).includes(field)
|
|
9
18
|
}
|
|
10
19
|
|
|
11
20
|
async build () {
|
|
@@ -54,7 +63,7 @@ async function table () {
|
|
|
54
63
|
}
|
|
55
64
|
const item = set({ page: 1 }, qsKey.sort, sortItem)
|
|
56
65
|
const href = this.component.buildUrl({ params: item })
|
|
57
|
-
const attr = this.isRightAligned(
|
|
66
|
+
const attr = this.isRightAligned(f, schema) ? { text: 'align:end' } : {}
|
|
58
67
|
const content = [
|
|
59
68
|
await this.component.buildTag({ tag: 'div', attr, html: req.t(`field.${f}`) }),
|
|
60
69
|
await this.component.buildTag({ tag: 'a', attr: { icon, href }, prepend: '<div class="ms-1">', append: '</div>' })
|
|
@@ -62,7 +71,7 @@ async function table () {
|
|
|
62
71
|
head = await this.component.buildTag({ tag: 'div', attr: { flex: 'justify-content:between align-items:end' }, html: content.join('\n') })
|
|
63
72
|
}
|
|
64
73
|
let text = this.params.attr.headerNowrap ? '' : 'nowrap'
|
|
65
|
-
if (this.isRightAligned(
|
|
74
|
+
if (this.isRightAligned(f, schema)) text += ' align:end'
|
|
66
75
|
const attr = { dataKey: f, dataType: prop.type, text }
|
|
67
76
|
items.push(await this.component.buildTag({ tag: 'th', attr, html: head }))
|
|
68
77
|
}
|
|
@@ -104,9 +113,12 @@ async function table () {
|
|
|
104
113
|
if (['array', 'object'].includes(prop.type)) dataValue = escape(JSON.stringify(d[f]))
|
|
105
114
|
const attr = { dataValue }
|
|
106
115
|
if (!['object', 'array'].includes(prop.type)) {
|
|
107
|
-
|
|
108
|
-
|
|
116
|
+
const noWrap = this.isNoWrap(f, schema) ? 'nowrap' : ''
|
|
117
|
+
if (this.isRightAligned(f, schema)) attr.text = `align:end ${noWrap}`
|
|
118
|
+
else attr.text = noWrap
|
|
109
119
|
}
|
|
120
|
+
const formatter = get(schema, `formatter.${f}`)
|
|
121
|
+
if (formatter) value = await this.component.buildSentence(formatter(value, d))
|
|
110
122
|
const line = await this.component.buildTag({ tag: 'td', attr, html: value })
|
|
111
123
|
lines.push(line)
|
|
112
124
|
}
|