waibu-db 1.0.6 → 1.0.8
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/bajo/method/get-schema-ext.js +6 -3
- package/bajo/method/record/find-one.js +4 -8
- package/package.json +1 -1
- package/waibuBootstrap/theme/component/factory/btn-columns.js +1 -0
- package/waibuBootstrap/theme/component/factory/btn-delete.js +2 -2
- package/waibuBootstrap/theme/component/factory/query.js +0 -1
- package/waibuBootstrap/theme/component/factory/table.js +19 -12
- package/waibuMpa/partial/crud/_list-footer.html +8 -0
- package/waibuMpa/partial/crud/list-handler.html +1 -8
|
@@ -4,6 +4,7 @@ const defReadonly = ['id', 'createdAt', 'updatedAt']
|
|
|
4
4
|
|
|
5
5
|
function getCommons (action, schema, ext, opts = {}) {
|
|
6
6
|
const { map, get, set, without, uniq } = this.app.bajo.lib._
|
|
7
|
+
const label = get(ext, `view.${action}.label`, get(ext, 'common.label', {}))
|
|
7
8
|
const hidden = get(ext, `view.${action}.hidden`, get(ext, 'common.hidden', []))
|
|
8
9
|
hidden.push(...schema.hidden, ...(opts.hidden ?? []))
|
|
9
10
|
const allFields = without(map(schema.properties, 'name'), ...hidden)
|
|
@@ -17,7 +18,7 @@ function getCommons (action, schema, ext, opts = {}) {
|
|
|
17
18
|
}
|
|
18
19
|
fields = uniq(without(fields, ...hidden))
|
|
19
20
|
if (action !== 'add' && !fields.includes('id')) fields.unshift('id')
|
|
20
|
-
return { fields, allFields }
|
|
21
|
+
return { fields, allFields, label }
|
|
21
22
|
}
|
|
22
23
|
|
|
23
24
|
function autoLayout ({ action, schema, ext, layout, allWidgets }) {
|
|
@@ -58,7 +59,7 @@ function customLayout ({ action, schema, ext, layout, allWidgets, readonly }) {
|
|
|
58
59
|
|
|
59
60
|
function applyLayout (action, schema, ext) {
|
|
60
61
|
const { set, get, isEmpty, map, find } = this.app.bajo.lib._
|
|
61
|
-
const { fields } = getCommons.call(this, action, schema, ext)
|
|
62
|
+
const { fields, label } = getCommons.call(this, action, schema, ext)
|
|
62
63
|
const layout = get(ext, `view.${action}.layout`, get(ext, 'common.layout', []))
|
|
63
64
|
const readonly = get(ext, `view.${action}.readonly`, get(ext, 'common.readonly', defReadonly))
|
|
64
65
|
const allWidgets = map(fields, f => {
|
|
@@ -89,12 +90,13 @@ function applyLayout (action, schema, ext) {
|
|
|
89
90
|
else customLayout.call(this, { layout, allWidgets, schema, action, ext, readonly })
|
|
90
91
|
set(schema, 'view.layout', layout)
|
|
91
92
|
set(schema, 'view.fields', fields)
|
|
93
|
+
set(schema, 'view.label', label)
|
|
92
94
|
}
|
|
93
95
|
|
|
94
96
|
const handler = {
|
|
95
97
|
list: async function (schema, ext, opts) {
|
|
96
98
|
const { get, set } = this.app.bajo.lib._
|
|
97
|
-
const { fields } = getCommons.call(this, 'list', schema, ext, opts)
|
|
99
|
+
const { fields, label } = getCommons.call(this, 'list', schema, ext, opts)
|
|
98
100
|
const qsFields = []
|
|
99
101
|
for (const f of get(schema, 'view.qs.fields', '').split(',')) {
|
|
100
102
|
if (fields.includes(f)) qsFields.push(f)
|
|
@@ -102,6 +104,7 @@ const handler = {
|
|
|
102
104
|
let [col, dir] = get(schema, 'view.qs.sort', '').split(':')
|
|
103
105
|
if (!fields.includes(col) || !col) col = 'id'
|
|
104
106
|
if (!['1', '-1'].includes(dir)) dir = '1'
|
|
107
|
+
set(schema, 'view.label', label)
|
|
105
108
|
set(schema, 'view.fields', fields)
|
|
106
109
|
set(schema, 'view.qs.fields', qsFields.join(','))
|
|
107
110
|
set(schema, 'view.qs.sort', `${col}:${dir}`)
|
|
@@ -2,17 +2,13 @@ import prepCrud from '../../../lib/prep-crud.js'
|
|
|
2
2
|
|
|
3
3
|
async function find ({ model, req, reply, options = {} }) {
|
|
4
4
|
const { recordFindOne, attachmentFind } = this.app.dobo
|
|
5
|
-
const {
|
|
6
|
-
const { name, opts } = prepCrud.call(this, { model, req, options, args: ['model'] })
|
|
7
|
-
const cfgWeb = this.app.waibu.config
|
|
8
|
-
opts.bboxLatField = req.query[cfgWeb.qsKey.bboxLatField]
|
|
9
|
-
opts.bboxLngField = req.query[cfgWeb.qsKey.bboxLngField]
|
|
10
|
-
const filter = parseFilter(req)
|
|
5
|
+
const { name, opts, filter } = prepCrud.call(this, { model, req, options, args: ['model'] })
|
|
11
6
|
const ret = await recordFindOne(name, filter, opts)
|
|
12
|
-
ret.filter = filter
|
|
13
7
|
const { attachment, stats, mimeType } = req.query
|
|
14
8
|
if (attachment) {
|
|
15
|
-
|
|
9
|
+
for (const d of ret.data) {
|
|
10
|
+
d._attachment = await attachmentFind(name, d.id, { stats, mimeType })
|
|
11
|
+
}
|
|
16
12
|
}
|
|
17
13
|
return ret
|
|
18
14
|
}
|
package/package.json
CHANGED
|
@@ -46,6 +46,7 @@ async function btnColumns () {
|
|
|
46
46
|
html.push('</form>')
|
|
47
47
|
this.params.attr.autoClose = 'outside'
|
|
48
48
|
this.params.attr.triggerColor = this.params.attr.color
|
|
49
|
+
this.params.attr.menudir = this.params.attr.menudir ?? 'end'
|
|
49
50
|
this.params.html = await this.component.buildTag({ tag: 'dropdown', attr: this.params.attr, html: html.join('\n') })
|
|
50
51
|
this.params.noTag = true
|
|
51
52
|
}
|
|
@@ -35,14 +35,14 @@ async function btnDelete () {
|
|
|
35
35
|
this.params.attr['x-data'] = `{
|
|
36
36
|
selected: ['${req.query.id}'],
|
|
37
37
|
remove (modalId, ids) {
|
|
38
|
+
ids = JSON.parse(wmpa.fromBase64(ids)).join(',')
|
|
38
39
|
wmpa.postForm({ ids }, '${this.component.buildUrl({ base: 'delete', exclude: ['id', 'page'] })}')
|
|
39
40
|
}
|
|
40
41
|
}`
|
|
41
42
|
}
|
|
42
43
|
const msg = 'You\'re about to remove one or more records. Are you really sure to do this?'
|
|
43
44
|
this.params.attr['@click'] = `
|
|
44
|
-
|
|
45
|
-
await wbs.confirmation(\`${req.t(msg)}\`, { ok: '${this.params.attr.id}:remove', close: 'y', opts })
|
|
45
|
+
await wbs.confirmation(\`${req.t(msg)}\`, { ok: '${this.params.attr.id}:remove', close: 'y', opts: selected })
|
|
46
46
|
`
|
|
47
47
|
this.params.html = await this.component.buildTag({ tag: 'btn', attr: this.params.attr, html: this.params.html })
|
|
48
48
|
}
|
|
@@ -6,9 +6,10 @@ async function table () {
|
|
|
6
6
|
return class WdbTable extends WdbBase {
|
|
7
7
|
isRightAligned (field, schema) {
|
|
8
8
|
const { get, find } = this.plugin.app.bajo.lib._
|
|
9
|
-
const
|
|
9
|
+
const prop = find(schema.properties, { name: field })
|
|
10
|
+
if (!prop) return false
|
|
10
11
|
let value = get(schema, 'view.alignEnd', []).includes(field)
|
|
11
|
-
if (!value) value = ['smallint', 'integer', 'float', 'double'].includes(type)
|
|
12
|
+
if (!value) value = ['smallint', 'integer', 'float', 'double'].includes(prop.type)
|
|
12
13
|
return value
|
|
13
14
|
}
|
|
14
15
|
|
|
@@ -24,10 +25,12 @@ async function table () {
|
|
|
24
25
|
const { get, omit, set, find, isEmpty, without } = this.plugin.app.bajo.lib._
|
|
25
26
|
const group = groupAttrs(this.params.attr, ['body', 'head', 'foot'])
|
|
26
27
|
this.params.attr = group._
|
|
28
|
+
const prettyUrl = this.params.attr.prettyUrl
|
|
27
29
|
|
|
28
30
|
const data = get(this, 'component.locals.list.data', [])
|
|
29
31
|
const schema = get(this, 'component.locals.schema', {})
|
|
30
|
-
|
|
32
|
+
const disableds = get(schema, 'view.disabled', [])
|
|
33
|
+
if (disableds.includes('find')) {
|
|
31
34
|
this.params.html = ''
|
|
32
35
|
return
|
|
33
36
|
}
|
|
@@ -40,8 +43,8 @@ async function table () {
|
|
|
40
43
|
if (!['-1', '1'].includes(sortDir)) sortDir = '1'
|
|
41
44
|
|
|
42
45
|
let selection
|
|
43
|
-
const canDelete = !
|
|
44
|
-
const canEdit = !
|
|
46
|
+
const canDelete = !disableds.includes('remove')
|
|
47
|
+
const canEdit = !disableds.includes('update')
|
|
45
48
|
if (canEdit) selection = 'single'
|
|
46
49
|
if (canDelete) selection = 'multi'
|
|
47
50
|
if (selection) this.params.attr.hover = true
|
|
@@ -53,7 +56,8 @@ async function table () {
|
|
|
53
56
|
for (const f of schema.view.fields) {
|
|
54
57
|
if (!fields.includes(f)) continue
|
|
55
58
|
const prop = find(schema.properties, { name: f })
|
|
56
|
-
|
|
59
|
+
if (!prop) continue
|
|
60
|
+
let head = req.t(get(schema, `view.label.${f}`, `field.${f}`))
|
|
57
61
|
if (!this.params.attr.noSort && (schema.sortables ?? []).includes(f)) {
|
|
58
62
|
let sortItem = `${f}:-1`
|
|
59
63
|
let icon = this.params.attr.sortUpIcon ?? 'caretUp'
|
|
@@ -95,11 +99,14 @@ async function table () {
|
|
|
95
99
|
if (selection) {
|
|
96
100
|
const tag = selection === 'single' ? 'formRadio' : 'formCheck'
|
|
97
101
|
const attr = { 'x-model': 'selected', name: '_rt', value: d.id, noLabel: true, noWrapper: true }
|
|
98
|
-
|
|
102
|
+
const type = find(schema.properties, { name: 'id' }).type
|
|
103
|
+
const prepend = `<td data-value="${d.id}" data-key="id" data-type="${type}">`
|
|
104
|
+
lines.push(await this.component.buildTag({ tag, attr, prepend, append: '</td>' }))
|
|
99
105
|
}
|
|
100
106
|
for (const f of schema.view.fields) {
|
|
101
|
-
const prop = find(schema.properties, { name: f })
|
|
102
107
|
if (!fields.includes(f)) continue
|
|
108
|
+
const prop = find(schema.properties, { name: f })
|
|
109
|
+
if (!prop) continue
|
|
103
110
|
const opts = {}
|
|
104
111
|
if (f === 'lng') opts.longitude = true
|
|
105
112
|
else if (f === 'lat') opts.latitude = true
|
|
@@ -111,7 +118,7 @@ async function table () {
|
|
|
111
118
|
let dataValue = d[f] ?? ''
|
|
112
119
|
if (['string', 'text'].includes(prop.type)) dataValue = escape(dataValue)
|
|
113
120
|
if (['array', 'object'].includes(prop.type)) dataValue = escape(JSON.stringify(d[f]))
|
|
114
|
-
const attr = { dataValue }
|
|
121
|
+
const attr = { dataValue, dataKey: prop.name, dataType: prop.type }
|
|
115
122
|
if (!['object', 'array'].includes(prop.type)) {
|
|
116
123
|
const noWrap = this.isNoWrap(f, schema) ? 'nowrap' : ''
|
|
117
124
|
if (this.isRightAligned(f, schema)) attr.text = `align:end ${noWrap}`
|
|
@@ -123,15 +130,15 @@ async function table () {
|
|
|
123
130
|
lines.push(line)
|
|
124
131
|
}
|
|
125
132
|
const attr = {}
|
|
126
|
-
if (!
|
|
127
|
-
if (!
|
|
133
|
+
if (!disableds.includes('update') || !disableds.includes('remove')) attr['@click'] = `toggle('${d.id}')`
|
|
134
|
+
if (!disableds.includes('get')) attr['@dblclick'] = `goDetails('${d.id}')`
|
|
128
135
|
items.push(await this.component.buildTag({ tag: 'tr', attr, html: lines.join('\n') }))
|
|
129
136
|
}
|
|
130
137
|
html.push(await this.component.buildTag({ tag: 'tbody', attr: group.body, html: items.join('\n') }))
|
|
131
138
|
this.params.attr = omit(this.params.attr, ['sortUpIcon', 'sortDownIcon', 'noSort', 'selection', 'headerNowrap'])
|
|
132
139
|
const goDetails = `
|
|
133
140
|
goDetails (id) {
|
|
134
|
-
window.location.href = '${this.component.buildUrl({ base: 'details' })}&id=' + id
|
|
141
|
+
window.location.href = '${this.component.buildUrl({ base: 'details', prettyUrl })}&id=' + id
|
|
135
142
|
}
|
|
136
143
|
`
|
|
137
144
|
if (selection === 'multi') {
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
<c:grid-row gutter="3" margin="top-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" />
|
|
4
|
+
</c:grid-col>
|
|
5
|
+
<c:grid-col col="6-lg" flex="justify-content:end-lg">
|
|
6
|
+
<c:wdb-pagination />
|
|
7
|
+
</c:grid-col>
|
|
8
|
+
</c:grid-row>
|
|
@@ -15,12 +15,5 @@
|
|
|
15
15
|
</c:grid-col>
|
|
16
16
|
</c:grid-row>
|
|
17
17
|
<c:wdb-table id="main-table" border body-divider strip responsive />
|
|
18
|
-
<c:
|
|
19
|
-
<c:grid-col col="6-lg">
|
|
20
|
-
<c:wdb-recs-info pages recs-per-page recs-per-page-values="10 15 25 50" />
|
|
21
|
-
</c:grid-col>
|
|
22
|
-
<c:grid-col col="6-lg" flex="justify-content:end-lg">
|
|
23
|
-
<c:wdb-pagination />
|
|
24
|
-
</c:grid-col>
|
|
25
|
-
</c:grid-row>
|
|
18
|
+
<c:include resource="waibuDb.partial:/crud/_list-footer.html" />
|
|
26
19
|
<c:include resource="waibuDb.partial:/crud/_addons.html" />
|