waibu-db 1.1.10 → 1.1.11
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/bajoTemplate/partial/crud/add-handler.html +2 -3
- package/bajoTemplate/partial/crud/details-handler.html +1 -3
- package/bajoTemplate/partial/crud/edit-handler.html +2 -3
- package/lib/crud/add-handler.js +1 -1
- package/lib/crud/delete-handler.js +1 -1
- package/lib/crud/details-handler.js +1 -1
- package/lib/crud/edit-handler.js +1 -1
- package/lib/crud/export-handler.js +1 -1
- package/lib/crud/list-handler.js +1 -1
- package/package.json +1 -1
- package/plugin/method/get-schema-ext.js +17 -9
- package/waibuBootstrap/theme/component/factory/form.js +43 -0
- package/waibuBootstrap/theme/component/factory/table.js +21 -11
- package/bajoTemplate/partial/crud/_form.html +0 -12
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
<c:form>
|
|
2
|
-
<!-- include waibuDb.partial:/crud/_form.html -->
|
|
1
|
+
<c:wdb-form id="main-form" method="POST" enctype="multipart/form-data">
|
|
3
2
|
<!-- include waibuDb.partial:/crud/_add-btns.html -->
|
|
4
|
-
</c:form>
|
|
3
|
+
</c:wdb-form>
|
|
5
4
|
<!-- include waibuDb.partial:/crud/_addons.html -->
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
<c:form id="main-form">
|
|
2
|
-
<!-- include waibuDb.partial:/crud/_form.html -->
|
|
1
|
+
<c:wdb-form id="main-form" method="POST" enctype="multipart/form-data">
|
|
3
2
|
<!-- include waibuDb.partial:/crud/_edit-btns.html -->
|
|
4
|
-
</c:form>
|
|
3
|
+
</c:wdb-form>
|
|
5
4
|
<!-- include waibuDb.partial:/crud/_addons.html -->
|
package/lib/crud/add-handler.js
CHANGED
|
@@ -5,7 +5,7 @@ async function addHandler ({ req, reply, model, params = {}, template, addOnsHan
|
|
|
5
5
|
const { pick, map, merge, defaultsDeep, omit, isEmpty } = this.lib._
|
|
6
6
|
const options = {}
|
|
7
7
|
model = model ?? pascalCase(req.params.model)
|
|
8
|
-
const { schema } = await getSchemaExt(model, 'add',
|
|
8
|
+
const { schema } = await getSchemaExt(model, 'add', { params })
|
|
9
9
|
if (schema.disabled.includes('create')) return reply.view(templateDisabled, { action: 'add' })
|
|
10
10
|
// req.query.attachment = true
|
|
11
11
|
options.fields = schema.view.fields
|
|
@@ -5,7 +5,7 @@ async function deleteHandler ({ req, reply, model, params = {}, templateDisabled
|
|
|
5
5
|
const { reduce } = this.lib._
|
|
6
6
|
const options = {}
|
|
7
7
|
model = model ?? pascalCase(req.params.model)
|
|
8
|
-
const { schema } = await getSchemaExt(model, 'add',
|
|
8
|
+
const { schema } = await getSchemaExt(model, 'add', { params })
|
|
9
9
|
if (schema.disabled.includes('remove')) return reply.view(templateDisabled, { action: 'delete' })
|
|
10
10
|
options.fields = schema.view.fields
|
|
11
11
|
const ids = (req.body.ids ?? '').split(',')
|
|
@@ -4,7 +4,7 @@ async function detailsHandler ({ req, reply, model, params = {}, template, addOn
|
|
|
4
4
|
const { merge } = this.lib._
|
|
5
5
|
const options = {}
|
|
6
6
|
model = model ?? pascalCase(req.params.model)
|
|
7
|
-
const { schema } = await getSchemaExt(model, 'details',
|
|
7
|
+
const { schema } = await getSchemaExt(model, 'details', { params })
|
|
8
8
|
if (schema.disabled.includes('get')) return reply.view(templateDisabled, { action: 'details' })
|
|
9
9
|
// req.query.attachment = true
|
|
10
10
|
options.fields = schema.view.fields
|
package/lib/crud/edit-handler.js
CHANGED
|
@@ -5,7 +5,7 @@ async function editHandler ({ req, reply, model, params = {}, template, addOnsHa
|
|
|
5
5
|
const { merge, defaultsDeep } = this.lib._
|
|
6
6
|
const options = {}
|
|
7
7
|
model = model ?? pascalCase(req.params.model)
|
|
8
|
-
const { schema } = await getSchemaExt(model, 'edit', options)
|
|
8
|
+
const { schema } = await getSchemaExt(model, 'edit', options, { params })
|
|
9
9
|
if (schema.disabled.includes('update')) return reply.view(templateDisabled, { action: 'edit' })
|
|
10
10
|
// req.query.attachment = true
|
|
11
11
|
options.fields = schema.view.fields
|
|
@@ -4,7 +4,7 @@ async function exportHandler ({ req, reply, model, params = {}, templateDisabled
|
|
|
4
4
|
const { buildUrl } = this.app.waibuMpa
|
|
5
5
|
const options = {}
|
|
6
6
|
model = model ?? pascalCase(req.params.model)
|
|
7
|
-
const { schema } = await getSchemaExt(model, 'add', options)
|
|
7
|
+
const { schema } = await getSchemaExt(model, 'add', options, { params })
|
|
8
8
|
if (schema.disabled.includes('find')) return reply.view(templateDisabled, { action: 'list' })
|
|
9
9
|
options.fields = schema.view.fields
|
|
10
10
|
const url = buildUrl({ url: req.url, base: req.body.handler })
|
package/lib/crud/list-handler.js
CHANGED
|
@@ -5,7 +5,7 @@ async function listHandler ({ req, reply, model, template, params = {}, addOnsHa
|
|
|
5
5
|
const qsKey = this.app.waibu.config.qsKey
|
|
6
6
|
const options = { count: true }
|
|
7
7
|
model = model ?? pascalCase(req.params.model)
|
|
8
|
-
const { schema } = await getSchemaExt(model, 'list')
|
|
8
|
+
const { schema } = await getSchemaExt(model, 'list', { params })
|
|
9
9
|
if (schema.disabled.includes('find')) return reply.view(templateDisabled, { action: 'list' })
|
|
10
10
|
for (const key of ['sort', 'limit', 'fields']) {
|
|
11
11
|
const sessKey = `wdb${model}${upperFirst(key)}`
|
package/package.json
CHANGED
|
@@ -8,12 +8,14 @@ function getCommons (action, schema, ext, opts = {}) {
|
|
|
8
8
|
const card = get(ext, `view.${action}.card`, get(ext, 'common.card', true))
|
|
9
9
|
const hidden = get(ext, `view.${action}.hidden`, get(ext, 'common.hidden', []))
|
|
10
10
|
const disabled = get(ext, `view.${action}.disabled`, get(ext, 'common.disabled', []))
|
|
11
|
+
const x = get(ext, `view.${action}.x`, get(ext, 'common.x', {}))
|
|
11
12
|
const aggregate = get(ext, `view.${action}.stat.aggregate`, get(ext, 'common.stat.aggregate', []))
|
|
12
13
|
hidden.push(...schema.hidden, ...(opts.hidden ?? []))
|
|
13
14
|
const allFields = without(map(schema.properties, 'name'), ...hidden)
|
|
14
15
|
const forFields = get(ext, `view.${action}.fields`, get(ext, 'common.fields', allFields))
|
|
15
16
|
set(schema, 'view.stat.aggregate', aggregate)
|
|
16
17
|
set(schema, 'view.disabled', disabled)
|
|
18
|
+
set(schema, 'view.x', x)
|
|
17
19
|
if (schema.disabled.length > 0) schema.view.disabled.push(...schema.disabled)
|
|
18
20
|
let fields = []
|
|
19
21
|
for (const f of forFields) {
|
|
@@ -59,8 +61,11 @@ function customLayout ({ action, schema, ext, layout, allWidgets, readonly }) {
|
|
|
59
61
|
}
|
|
60
62
|
const widget = find(allWidgets, { name: f.name })
|
|
61
63
|
if (!widget && !f.component) continue
|
|
62
|
-
widget.attr = merge({}, widget.attr, omit(f, ['component']))
|
|
63
|
-
if (f.component && !readonly.includes(f.name) && action !== 'details')
|
|
64
|
+
widget.attr = merge({}, widget.attr, omit(f, ['component', 'componentOpts']))
|
|
65
|
+
if (f.component && !readonly.includes(f.name) && action !== 'details') {
|
|
66
|
+
widget.component = f.component
|
|
67
|
+
widget.componentOpts = f.componentOpts
|
|
68
|
+
}
|
|
64
69
|
widgets.push(widget)
|
|
65
70
|
}
|
|
66
71
|
if (widgets.length > 0) layout.push({ name: item.name, widgets })
|
|
@@ -85,7 +90,7 @@ function applyLayout (action, schema, ext) {
|
|
|
85
90
|
} else {
|
|
86
91
|
if (prop.type === 'boolean') {
|
|
87
92
|
result.component = 'form-select'
|
|
88
|
-
result.attr.options = 'false
|
|
93
|
+
result.attr.options = 'false|No true|Yes'
|
|
89
94
|
}
|
|
90
95
|
if (prop.values) {
|
|
91
96
|
result.component = 'form-select'
|
|
@@ -112,13 +117,16 @@ const handler = {
|
|
|
112
117
|
for (const f of get(schema, 'view.qs.fields', '').split(',')) {
|
|
113
118
|
if (fields.includes(f)) qsFields.push(f)
|
|
114
119
|
}
|
|
115
|
-
|
|
116
|
-
if (
|
|
117
|
-
|
|
120
|
+
const sort = get(schema, 'view.qs.sort')
|
|
121
|
+
if (sort) {
|
|
122
|
+
let [col, dir] = get(schema, 'view.qs.sort', '').split(':')
|
|
123
|
+
if (!fields.includes(col) || !col) col = 'id'
|
|
124
|
+
if (!['1', '-1'].includes(dir)) dir = '1'
|
|
125
|
+
set(schema, 'view.qs.sort', `${col}:${dir}`)
|
|
126
|
+
}
|
|
118
127
|
set(schema, 'view.label', label)
|
|
119
128
|
set(schema, 'view.fields', fields)
|
|
120
129
|
set(schema, 'view.qs.fields', qsFields.join(','))
|
|
121
|
-
set(schema, 'view.qs.sort', `${col}:${dir}`)
|
|
122
130
|
},
|
|
123
131
|
details: async function (schema, ext, opts) {
|
|
124
132
|
applyLayout.call(this, 'details', schema, ext, opts)
|
|
@@ -138,8 +146,8 @@ async function getSchemaExt (model, view, opts) {
|
|
|
138
146
|
|
|
139
147
|
let schema = getSchema(model)
|
|
140
148
|
const base = path.basename(schema.file, path.extname(schema.file))
|
|
141
|
-
let ext = await readConfig(`${schema.ns}:/waibuDb/schema/${base}.*`, { ignoreError: true })
|
|
142
|
-
const over = await readConfig(`main:/waibuDb/extend/${schema.ns}/schema/${base}.*`, { ignoreError: true })
|
|
149
|
+
let ext = await readConfig(`${schema.ns}:/waibuDb/schema/${base}.*`, { ignoreError: true, opts })
|
|
150
|
+
const over = await readConfig(`main:/waibuDb/extend/${schema.ns}/schema/${base}.*`, { ignoreError: true, opts })
|
|
143
151
|
ext = defaultsDeep(over, ext)
|
|
144
152
|
await handler[view].call(this, schema, ext, opts)
|
|
145
153
|
schema = pick(schema, ['name', 'properties', 'indexes', 'disabled', 'attachment', 'sortables', 'view'])
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import wdbBase from '../wdb-base.js'
|
|
2
|
+
|
|
3
|
+
async function form () {
|
|
4
|
+
const WdbBase = await wdbBase.call(this)
|
|
5
|
+
|
|
6
|
+
return class WdbForm extends WdbBase {
|
|
7
|
+
build = async () => {
|
|
8
|
+
const { get, find, filter, forOwn, isEmpty } = this.plugin.lib._
|
|
9
|
+
const { base64JsonEncode } = this.plugin.app.waibuMpa
|
|
10
|
+
const schema = get(this, 'component.locals.schema', {})
|
|
11
|
+
const body = []
|
|
12
|
+
const xModels = get(schema, 'view.x.model', [])
|
|
13
|
+
const xOns = get(schema, 'view.x.on', [])
|
|
14
|
+
for (const l of schema.view.layout) {
|
|
15
|
+
body.push(`<c:fieldset ${schema.view.card === false ? '' : 'card'} ${l.name[0] !== '_' ? ('t:legend="' + l.name + '"') : ''} grid-gutter="2">`)
|
|
16
|
+
for (const w of l.widgets) {
|
|
17
|
+
const prop = find(schema.properties, { name: w.name })
|
|
18
|
+
const attr = [`x-ref="${w.name}"`]
|
|
19
|
+
if (xModels.includes(w.name)) attr.push(`x-model="${w.name}"`)
|
|
20
|
+
forOwn(w.attr, (v, k) => {
|
|
21
|
+
attr.push(`${k}="${v}"`)
|
|
22
|
+
})
|
|
23
|
+
const xon = filter(xOns, { field: w.name })
|
|
24
|
+
for (const o of xon) {
|
|
25
|
+
attr.push(`@${o.bind}="${o.handler}"`)
|
|
26
|
+
}
|
|
27
|
+
if (w.componentOpts) attr.push(`c-opts="${base64JsonEncode(w.componentOpts)}"`)
|
|
28
|
+
body.push(`<c:${w.component} ${w.attr.label ? ('t:label="' + w.attr.label + '"') : ''} data-type="${prop.type}" label-floating name="${w.name}" ${attr.join(' ')} />`)
|
|
29
|
+
}
|
|
30
|
+
body.push('</c:fieldset>')
|
|
31
|
+
}
|
|
32
|
+
const html = await this.component.buildSentence(body, this.component.locals)
|
|
33
|
+
this.params.html = `${html}\n${this.params.html}`
|
|
34
|
+
const xData = get(schema, 'view.x.data', '')
|
|
35
|
+
this.params.attr['x-data'] = isEmpty(xData) ? '' : `{ ${xData} }`
|
|
36
|
+
this.params.attr['x-init'] = get(schema, 'view.x.init', '')
|
|
37
|
+
|
|
38
|
+
this.params.tag = this.params.attr.tag ?? 'form'
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export default form
|
|
@@ -171,7 +171,7 @@ async function table () {
|
|
|
171
171
|
}
|
|
172
172
|
html.push(await this.component.buildTag({ tag: 'tbody', attr: group.body, html: items.join('\n') }))
|
|
173
173
|
this.params.attr = omit(this.params.attr, ['sortUpIcon', 'sortDownIcon', 'noSort', 'selection', 'headerNowrap'])
|
|
174
|
-
|
|
174
|
+
let xData = `
|
|
175
175
|
goDetails (id) {
|
|
176
176
|
let url = '${this.params.attr.detailsHref ?? this.component.buildUrl({ base: 'details', prettyUrl })}'
|
|
177
177
|
if (url === '#') return
|
|
@@ -180,8 +180,15 @@ async function table () {
|
|
|
180
180
|
window.location.href = url
|
|
181
181
|
}
|
|
182
182
|
`
|
|
183
|
+
const xDataView = get(schema, 'view.x.data', '')
|
|
184
|
+
if (!isEmpty(xDataView)) xData += `, ${xDataView}`
|
|
185
|
+
let xInit = ''
|
|
186
|
+
const xInitView = get(schema, 'view.x.init', '')
|
|
187
|
+
if (!isEmpty(xInitView)) xInit += `${xInitView}\n`
|
|
188
|
+
|
|
183
189
|
if (selection === 'multi') {
|
|
184
|
-
|
|
190
|
+
xData = `{
|
|
191
|
+
${xData},
|
|
185
192
|
toggleAll: false,
|
|
186
193
|
selected: [],
|
|
187
194
|
toggle (id) {
|
|
@@ -189,10 +196,10 @@ async function table () {
|
|
|
189
196
|
const idx = this.selected.indexOf(id)
|
|
190
197
|
this.selected.splice(idx, 1)
|
|
191
198
|
} else this.selected.push(id)
|
|
192
|
-
}
|
|
193
|
-
${goDetails}
|
|
199
|
+
}
|
|
194
200
|
}`
|
|
195
|
-
|
|
201
|
+
xInit = `
|
|
202
|
+
${xInit}
|
|
196
203
|
$watch('toggleAll', val => {
|
|
197
204
|
if (val) {
|
|
198
205
|
const els = document.getElementsByName('_rt')
|
|
@@ -203,21 +210,24 @@ async function table () {
|
|
|
203
210
|
$watch('selected', val => $dispatch('on-selection', val))
|
|
204
211
|
`
|
|
205
212
|
} else if (selection === 'single') {
|
|
206
|
-
|
|
213
|
+
xData = `{
|
|
214
|
+
${xData},
|
|
207
215
|
selected: '',
|
|
208
216
|
toggle (id) {
|
|
209
217
|
this.selected = id
|
|
210
|
-
}
|
|
211
|
-
${goDetails}
|
|
218
|
+
}
|
|
212
219
|
}`
|
|
213
|
-
|
|
220
|
+
xInit = `
|
|
221
|
+
${xInit}
|
|
214
222
|
$watch('selected', val => $dispatch('on-selection', [val]))
|
|
215
223
|
`
|
|
216
224
|
} else {
|
|
217
|
-
|
|
218
|
-
${
|
|
225
|
+
xData = `{
|
|
226
|
+
${xData}
|
|
219
227
|
}`
|
|
220
228
|
}
|
|
229
|
+
this.params.attr['x-data'] = xData
|
|
230
|
+
this.params.attr['x-init'] = xInit
|
|
221
231
|
this.params.html = await this.component.buildTag({ tag: 'table', attr: this.params.attr, html: html.join('\n') })
|
|
222
232
|
}
|
|
223
233
|
}
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
<% for (const l of schema.view.layout) { %>
|
|
2
|
-
<c:fieldset <%= schema.view.card === false ? '' : 'card' %> <% if (l.name[0] !== '_') print('t:legend="' + l.name + '"') %> grid-gutter="2">
|
|
3
|
-
<% for (const w of l.widgets) {
|
|
4
|
-
const prop = _.find(schema.properties, { name: w.name })
|
|
5
|
-
const attr = []
|
|
6
|
-
_.forOwn(w.attr, (v, k) => {
|
|
7
|
-
attr.push(`${k}="${v}"`)
|
|
8
|
-
})
|
|
9
|
-
print(`<c:${w.component} ${w.attr.label ? ('label="' + _t(w.attr.label) + '"') : ''} data-type="${prop.type}" label-floating name="${w.name}" ${attr.join(' ')} />`)
|
|
10
|
-
} %>
|
|
11
|
-
</c:fieldset>
|
|
12
|
-
<% } %>
|