waibu-db 2.33.0 → 2.33.2
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/.github/FUNDING.yml +0 -0
- package/.github/workflows/repo-lockdown.yml +0 -0
- package/.jsdoc.conf.json +0 -0
- package/LICENSE +0 -0
- package/README.md +0 -0
- package/docs/WaibuDb.html +0 -0
- package/docs/data/search.json +0 -0
- package/docs/external-DoboModel.html +0 -0
- package/docs/external-TFilter.html +0 -0
- package/docs/external-TOptions.html +0 -0
- package/docs/fonts/Inconsolata-Regular.ttf +0 -0
- package/docs/fonts/OpenSans-Regular.ttf +0 -0
- package/docs/fonts/WorkSans-Bold.ttf +0 -0
- package/docs/global.html +0 -0
- package/docs/index.html +0 -0
- package/docs/index.js.html +0 -0
- package/docs/lib_config.js.html +0 -0
- package/docs/lib_crud_add-handler.js.html +0 -0
- package/docs/lib_crud_all-handler.js.html +0 -0
- package/docs/lib_crud_delete-handler.js.html +0 -0
- package/docs/lib_crud_details-handler.js.html +0 -0
- package/docs/lib_crud_edit-handler.js.html +0 -0
- package/docs/lib_crud_export-handler.js.html +0 -0
- package/docs/lib_crud_helper.js.html +0 -0
- package/docs/lib_crud_list-handler.js.html +0 -0
- package/docs/lib_util.js.html +0 -0
- package/docs/module-CRUDHandler.html +0 -0
- package/docs/module-CRUDHandler_Helper.html +0 -0
- package/docs/module-Helper.html +0 -0
- package/docs/module-Helper_CRUDHandler.html +0 -0
- package/docs/scripts/core.js +0 -0
- package/docs/scripts/core.min.js +0 -0
- package/docs/scripts/resize.js +0 -0
- package/docs/scripts/search.js +0 -0
- package/docs/scripts/search.min.js +5 -5
- package/docs/scripts/third-party/Apache-License-2.0.txt +0 -0
- package/docs/scripts/third-party/fuse.js +0 -0
- package/docs/scripts/third-party/hljs-line-num-original.js +0 -0
- package/docs/scripts/third-party/hljs-line-num.js +0 -0
- package/docs/scripts/third-party/hljs-original.js +0 -0
- package/docs/scripts/third-party/hljs.js +0 -0
- package/docs/scripts/third-party/popper.js +0 -0
- package/docs/scripts/third-party/tippy.js +0 -0
- package/docs/scripts/third-party/tocbot.js +0 -0
- package/docs/scripts/third-party/tocbot.min.js +0 -0
- package/docs/static/bitcoin.jpeg +0 -0
- package/docs/static/home.md +0 -0
- package/docs/static/logo-ecosystem.png +0 -0
- package/docs/static/logo.png +0 -0
- package/docs/styles/clean-jsdoc-theme-base.css +0 -0
- package/docs/styles/clean-jsdoc-theme-dark.css +0 -0
- package/docs/styles/clean-jsdoc-theme-light.css +0 -0
- package/docs/styles/clean-jsdoc-theme-scrollbar.css +0 -0
- package/docs/styles/clean-jsdoc-theme-without-scrollbar.min.css +0 -0
- package/docs/styles/clean-jsdoc-theme.min.css +0 -0
- package/extend/bajo/hook/waibu-rest-api@after-init.js +0 -0
- package/extend/bajo/intl/en-US.json +0 -0
- package/extend/bajo/intl/id.json +0 -0
- package/extend/bajoTemplate/partial/crud/_add-attachment.html +0 -0
- package/extend/bajoTemplate/partial/crud/_add-btns.html +0 -0
- package/extend/bajoTemplate/partial/crud/_addons.html +0 -0
- package/extend/bajoTemplate/partial/crud/_details-attachment.html +0 -0
- package/extend/bajoTemplate/partial/crud/_details-btns.html +0 -0
- package/extend/bajoTemplate/partial/crud/_edit-attachment.html +0 -0
- package/extend/bajoTemplate/partial/crud/_edit-btns.html +0 -0
- package/extend/bajoTemplate/partial/crud/_list-attachment.html +0 -0
- package/extend/bajoTemplate/partial/crud/_list-btns.html +0 -0
- package/extend/bajoTemplate/partial/crud/_list-footer.html +0 -0
- package/extend/bajoTemplate/partial/crud/_list-warnings.html +9 -9
- package/extend/bajoTemplate/partial/crud/add-handler.html +0 -0
- package/extend/bajoTemplate/partial/crud/details-handler.html +0 -0
- package/extend/bajoTemplate/partial/crud/edit-handler.html +0 -0
- package/extend/bajoTemplate/partial/crud/list-handler.html +0 -0
- package/extend/bajoTemplate/partial/crud/not-found.html +0 -0
- package/extend/bajoTemplate/partial/crud/~echarts-window.html +0 -0
- package/extend/bajoTemplate/template/crud/add.html +0 -0
- package/extend/bajoTemplate/template/crud/details.html +0 -0
- package/extend/bajoTemplate/template/crud/edit.html +0 -0
- package/extend/bajoTemplate/template/crud/list.html +0 -0
- package/extend/bajoTemplate/template/crud/not-found.html +0 -0
- package/extend/bajoTemplate/template/disabled.html +0 -0
- package/extend/sumba/route/secure.json +3 -3
- package/extend/waibuBootstrap/theme/component/wdb-base.js +0 -0
- package/extend/waibuBootstrap/theme/component/widget/btn-add.js +0 -0
- package/extend/waibuBootstrap/theme/component/widget/btn-back.js +0 -0
- package/extend/waibuBootstrap/theme/component/widget/btn-clone.js +0 -0
- package/extend/waibuBootstrap/theme/component/widget/btn-columns.js +0 -0
- package/extend/waibuBootstrap/theme/component/widget/btn-delete.js +0 -0
- package/extend/waibuBootstrap/theme/component/widget/btn-details.js +0 -0
- package/extend/waibuBootstrap/theme/component/widget/btn-edit.js +0 -0
- package/extend/waibuBootstrap/theme/component/widget/btn-export.js +1 -1
- package/extend/waibuBootstrap/theme/component/widget/data-table.js +0 -0
- package/extend/waibuBootstrap/theme/component/widget/echarts-bar.js +0 -0
- package/extend/waibuBootstrap/theme/component/widget/echarts-pie.js +0 -0
- package/extend/waibuBootstrap/theme/component/widget/echarts.js +0 -0
- package/extend/waibuBootstrap/theme/component/widget/form.js +0 -0
- package/extend/waibuBootstrap/theme/component/widget/lookup-select.js +40 -40
- package/extend/waibuBootstrap/theme/component/widget/pagination.js +0 -0
- package/extend/waibuBootstrap/theme/component/widget/query.js +0 -0
- package/extend/waibuBootstrap/theme/component/widget/recs-info.js +0 -0
- package/extend/waibuMpa/extend/waibuAdmin/route/@model/@action.js +0 -0
- package/extend/waibuMpa/extend/waibuAdmin/route/index.js +11 -11
- package/extend/waibuRestApi/route/@model/@id/get.js +0 -0
- package/extend/waibuRestApi/route/@model/@id/remove.js +0 -0
- package/extend/waibuRestApi/route/@model/@id/update.js +0 -0
- package/extend/waibuRestApi/route/@model/create.js +0 -0
- package/extend/waibuRestApi/route/@model/find.js +0 -0
- package/extend/waibuRestApi/route/@model/stat/@stat/find.js +0 -0
- package/extend/waibuRestApi/route/lookup/@model/model-builder.json +0 -0
- package/index.js +0 -0
- package/lib/config.js +45 -45
- package/lib/crud/add-handler.js +0 -0
- package/lib/crud/all-handler.js +0 -0
- package/lib/crud/delete-handler.js +0 -0
- package/lib/crud/details-handler.js +0 -0
- package/lib/crud/edit-handler.js +0 -0
- package/lib/crud/export-handler.js +1 -1
- package/lib/crud/helper.js +115 -115
- package/lib/crud/list-handler.js +0 -0
- package/lib/method/aggregate.js +0 -0
- package/lib/method/count-record.js +0 -0
- package/lib/method/create-record.js +0 -0
- package/lib/method/find-all-record.js +0 -0
- package/lib/method/find-one-record.js +0 -0
- package/lib/method/find-record.js +0 -0
- package/lib/method/get-record.js +0 -0
- package/lib/method/get-schema-ext.js +1 -1
- package/lib/method/histogram.js +0 -0
- package/lib/method/remove-record.js +0 -0
- package/lib/method/update-record.js +0 -0
- package/lib/util.js +1 -1
- package/package.json +1 -1
- package/wiki/CHANGES.md +357 -347
- package/wiki/CONFIG.md +0 -0
- package/wiki/CONTRIBUTING.md +0 -0
package/lib/crud/helper.js
CHANGED
|
@@ -1,115 +1,115 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @module CRUDHandler/Helper
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Add-ons handler for generating chart options based on the schema's aggregate settings.
|
|
7
|
-
*
|
|
8
|
-
* This function retrieves the aggregate settings from the schema and generates chart options for each setting.
|
|
9
|
-
* The generated chart options are encoded in base64 and returned as an array of add-ons.
|
|
10
|
-
*
|
|
11
|
-
* @async
|
|
12
|
-
* @memberof module:CRUDHandler/Helper
|
|
13
|
-
* @method
|
|
14
|
-
* @name addOnsHandler
|
|
15
|
-
* @param {object} opts - Options object
|
|
16
|
-
* @param {object} opts.req - Request object
|
|
17
|
-
* @param {object} opts.reply - Reply object
|
|
18
|
-
* @param {object} opts.schema - Schema object
|
|
19
|
-
* @returns {Promise<Array>} Array of add-ons with chart options
|
|
20
|
-
*/
|
|
21
|
-
export async function addOnsHandler (opts = {}) {
|
|
22
|
-
const { req, reply, schema } = opts
|
|
23
|
-
const { escape } = this.app.waibu
|
|
24
|
-
const { base64JsonEncode } = this.app.waibu
|
|
25
|
-
const { aggregate } = this.app.waibuDb
|
|
26
|
-
const { get, map, pick, pullAt } = this.app.lib._
|
|
27
|
-
const _opts = map(get(schema, 'view.stat.aggregate', []), item => {
|
|
28
|
-
const dbOpts = pick(item, ['fields', 'group', 'aggregate'])
|
|
29
|
-
const name = item.name ?? `field.${item.fields[0]}`
|
|
30
|
-
return { name, dbOpts }
|
|
31
|
-
})
|
|
32
|
-
if (_opts.length === 0) return []
|
|
33
|
-
const dropped = []
|
|
34
|
-
for (const idx in _opts) {
|
|
35
|
-
const o = _opts[idx]
|
|
36
|
-
try {
|
|
37
|
-
const resp = await aggregate({ model: schema.name, req, reply, options: o.dbOpts })
|
|
38
|
-
const data = []
|
|
39
|
-
for (const d of resp.data) {
|
|
40
|
-
const key = o.dbOpts.fields[0]
|
|
41
|
-
data.push({
|
|
42
|
-
name: escape(d[key]),
|
|
43
|
-
value: d[key + 'Count']
|
|
44
|
-
})
|
|
45
|
-
}
|
|
46
|
-
_opts[idx].chartOpts = base64JsonEncode({
|
|
47
|
-
tooltip: {
|
|
48
|
-
trigger: 'item'
|
|
49
|
-
},
|
|
50
|
-
series: [{
|
|
51
|
-
type: 'pie',
|
|
52
|
-
data
|
|
53
|
-
}]
|
|
54
|
-
})
|
|
55
|
-
} catch (err) {
|
|
56
|
-
dropped.push(idx)
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
if (dropped.length > 0) pullAt(_opts, dropped)
|
|
60
|
-
return map(_opts, o => {
|
|
61
|
-
return {
|
|
62
|
-
data: { setting: o.chartOpts, name: o.name },
|
|
63
|
-
resource: 'waibuDb.partial:/crud/~echarts-window.html'
|
|
64
|
-
}
|
|
65
|
-
})
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
/**
|
|
69
|
-
* Handles attachments for a given schema and ID.
|
|
70
|
-
* @async
|
|
71
|
-
* @memberof module:CRUDHandler/Helper
|
|
72
|
-
* @method
|
|
73
|
-
* @name attachmentHandler
|
|
74
|
-
* @param {object} opts - Options object
|
|
75
|
-
* @param {object} opts.schema - Schema object
|
|
76
|
-
* @param {string|number} opts.id - ID of the record
|
|
77
|
-
* @returns {Promise<Array>} Array of attachments
|
|
78
|
-
*/
|
|
79
|
-
export async function attachmentHandler (opts = {}) {
|
|
80
|
-
const { schema, id } = opts
|
|
81
|
-
if (!schema.view.attachment) return []
|
|
82
|
-
const model = this.app.dobo.getModel(schema.name)
|
|
83
|
-
return await model.listAttachment({ id })
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
/**
|
|
87
|
-
* Builds parameters for a given model and request.
|
|
88
|
-
*
|
|
89
|
-
* @param {object} opts - Options object
|
|
90
|
-
* @param {string} opts.model - Model name
|
|
91
|
-
* @param {object} opts.req - Request object
|
|
92
|
-
* @returns {object} Parameters including page information
|
|
93
|
-
*/
|
|
94
|
-
export function buildParams (opts = {}) {
|
|
95
|
-
const { model, req } = opts
|
|
96
|
-
const { camelCase, kebabCase, map, upperFirst, get } = this.app.lib._
|
|
97
|
-
const [, ...names] = map(kebabCase(model).split('-'), n => upperFirst(n))
|
|
98
|
-
const mdl = this.app.dobo.getModel(model)
|
|
99
|
-
const prefix = this.app.waibuMpa ? this.app.waibuMpa.getPluginTitle(mdl.plugin.ns, req) : mdl.plugin.ns
|
|
100
|
-
const modelTitle = req.t(prefix) + ': ' + req.t(camelCase(names.join(' ')))
|
|
101
|
-
const page = {
|
|
102
|
-
title: req.t(get(req, 'routeOptions.config.title', this.app[mdl.plugin.ns].title)),
|
|
103
|
-
modelTitle
|
|
104
|
-
}
|
|
105
|
-
return { page }
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
/**
|
|
109
|
-
* Template path for the "not found" page.
|
|
110
|
-
* @name notFoundTpl
|
|
111
|
-
* @constant {string}
|
|
112
|
-
* @default 'waibuDb.template:/crud/not-found.html'
|
|
113
|
-
* @memberof module:CRUDHandler/Helper
|
|
114
|
-
*/
|
|
115
|
-
export const notFoundTpl = 'waibuDb.template:/crud/not-found.html'
|
|
1
|
+
/**
|
|
2
|
+
* @module CRUDHandler/Helper
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Add-ons handler for generating chart options based on the schema's aggregate settings.
|
|
7
|
+
*
|
|
8
|
+
* This function retrieves the aggregate settings from the schema and generates chart options for each setting.
|
|
9
|
+
* The generated chart options are encoded in base64 and returned as an array of add-ons.
|
|
10
|
+
*
|
|
11
|
+
* @async
|
|
12
|
+
* @memberof module:CRUDHandler/Helper
|
|
13
|
+
* @method
|
|
14
|
+
* @name addOnsHandler
|
|
15
|
+
* @param {object} opts - Options object
|
|
16
|
+
* @param {object} opts.req - Request object
|
|
17
|
+
* @param {object} opts.reply - Reply object
|
|
18
|
+
* @param {object} opts.schema - Schema object
|
|
19
|
+
* @returns {Promise<Array>} Array of add-ons with chart options
|
|
20
|
+
*/
|
|
21
|
+
export async function addOnsHandler (opts = {}) {
|
|
22
|
+
const { req, reply, schema } = opts
|
|
23
|
+
const { escape } = this.app.waibu
|
|
24
|
+
const { base64JsonEncode } = this.app.waibu
|
|
25
|
+
const { aggregate } = this.app.waibuDb
|
|
26
|
+
const { get, map, pick, pullAt } = this.app.lib._
|
|
27
|
+
const _opts = map(get(schema, 'view.stat.aggregate', []), item => {
|
|
28
|
+
const dbOpts = pick(item, ['fields', 'group', 'aggregate'])
|
|
29
|
+
const name = item.name ?? `field.${item.fields[0]}`
|
|
30
|
+
return { name, dbOpts }
|
|
31
|
+
})
|
|
32
|
+
if (_opts.length === 0) return []
|
|
33
|
+
const dropped = []
|
|
34
|
+
for (const idx in _opts) {
|
|
35
|
+
const o = _opts[idx]
|
|
36
|
+
try {
|
|
37
|
+
const resp = await aggregate({ model: schema.name, req, reply, options: o.dbOpts })
|
|
38
|
+
const data = []
|
|
39
|
+
for (const d of resp.data) {
|
|
40
|
+
const key = o.dbOpts.fields[0]
|
|
41
|
+
data.push({
|
|
42
|
+
name: escape(d[key]),
|
|
43
|
+
value: d[key + 'Count']
|
|
44
|
+
})
|
|
45
|
+
}
|
|
46
|
+
_opts[idx].chartOpts = base64JsonEncode({
|
|
47
|
+
tooltip: {
|
|
48
|
+
trigger: 'item'
|
|
49
|
+
},
|
|
50
|
+
series: [{
|
|
51
|
+
type: 'pie',
|
|
52
|
+
data
|
|
53
|
+
}]
|
|
54
|
+
})
|
|
55
|
+
} catch (err) {
|
|
56
|
+
dropped.push(idx)
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
if (dropped.length > 0) pullAt(_opts, dropped)
|
|
60
|
+
return map(_opts, o => {
|
|
61
|
+
return {
|
|
62
|
+
data: { setting: o.chartOpts, name: o.name },
|
|
63
|
+
resource: 'waibuDb.partial:/crud/~echarts-window.html'
|
|
64
|
+
}
|
|
65
|
+
})
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* Handles attachments for a given schema and ID.
|
|
70
|
+
* @async
|
|
71
|
+
* @memberof module:CRUDHandler/Helper
|
|
72
|
+
* @method
|
|
73
|
+
* @name attachmentHandler
|
|
74
|
+
* @param {object} opts - Options object
|
|
75
|
+
* @param {object} opts.schema - Schema object
|
|
76
|
+
* @param {string|number} opts.id - ID of the record
|
|
77
|
+
* @returns {Promise<Array>} Array of attachments
|
|
78
|
+
*/
|
|
79
|
+
export async function attachmentHandler (opts = {}) {
|
|
80
|
+
const { schema, id } = opts
|
|
81
|
+
if (!schema.view.attachment) return []
|
|
82
|
+
const model = this.app.dobo.getModel(schema.name)
|
|
83
|
+
return await model.listAttachment({ id })
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* Builds parameters for a given model and request.
|
|
88
|
+
*
|
|
89
|
+
* @param {object} opts - Options object
|
|
90
|
+
* @param {string} opts.model - Model name
|
|
91
|
+
* @param {object} opts.req - Request object
|
|
92
|
+
* @returns {object} Parameters including page information
|
|
93
|
+
*/
|
|
94
|
+
export function buildParams (opts = {}) {
|
|
95
|
+
const { model, req } = opts
|
|
96
|
+
const { camelCase, kebabCase, map, upperFirst, get } = this.app.lib._
|
|
97
|
+
const [, ...names] = map(kebabCase(model).split('-'), n => upperFirst(n))
|
|
98
|
+
const mdl = this.app.dobo.getModel(model)
|
|
99
|
+
const prefix = this.app.waibuMpa ? this.app.waibuMpa.getPluginTitle(mdl.plugin.ns, req) : mdl.plugin.ns
|
|
100
|
+
const modelTitle = req.t(prefix) + ': ' + req.t(camelCase(names.join(' ')))
|
|
101
|
+
const page = {
|
|
102
|
+
title: req.t(get(req, 'routeOptions.config.title', this.app[mdl.plugin.ns].title)),
|
|
103
|
+
modelTitle
|
|
104
|
+
}
|
|
105
|
+
return { page }
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* Template path for the "not found" page.
|
|
110
|
+
* @name notFoundTpl
|
|
111
|
+
* @constant {string}
|
|
112
|
+
* @default 'waibuDb.template:/crud/not-found.html'
|
|
113
|
+
* @memberof module:CRUDHandler/Helper
|
|
114
|
+
*/
|
|
115
|
+
export const notFoundTpl = 'waibuDb.template:/crud/not-found.html'
|
package/lib/crud/list-handler.js
CHANGED
|
File without changes
|
package/lib/method/aggregate.js
CHANGED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
package/lib/method/get-record.js
CHANGED
|
File without changes
|
|
@@ -105,7 +105,7 @@ async function applyLayout (action, schema, ext, options) {
|
|
|
105
105
|
if (!prop.ref && ['object', 'text'].includes(prop.type)) {
|
|
106
106
|
result.attr.col = '12'
|
|
107
107
|
result.component = 'form-textarea'
|
|
108
|
-
result.attr.rows = '3'
|
|
108
|
+
result.attr.rows = result.attr.rows ?? '3'
|
|
109
109
|
}
|
|
110
110
|
if (action === 'details') {
|
|
111
111
|
result.component = 'form-plaintext'
|
package/lib/method/histogram.js
CHANGED
|
File without changes
|
|
File without changes
|
|
File without changes
|
package/lib/util.js
CHANGED
|
@@ -147,7 +147,7 @@ export async function processHandler (opts = {}) {
|
|
|
147
147
|
if (!(req.method === 'POST' && req.body._action === 'export' && options.allowExport)) return
|
|
148
148
|
const { importModule } = this.app.bajo
|
|
149
149
|
const exportHandler = await importModule('waibuDb:/lib/crud/export-handler.js')
|
|
150
|
-
await exportHandler.call(this, { model: model.name, req, reply })
|
|
150
|
+
await exportHandler.call(this, { model: model.name, req, reply, options })
|
|
151
151
|
}
|
|
152
152
|
|
|
153
153
|
function suppressedReturn (err) {
|