waibu-db 1.0.11 → 1.0.13

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,13 @@
1
+ async function getLookupData ({ model, req, data, id = 'id', field, query }) {
2
+ const { set, map } = this.app.bajo.lib._
3
+ const $in = map(data, id)
4
+ const q = query ?? set({}, field, { $in })
5
+ const options = {
6
+ dataOnly: true,
7
+ limit: -1,
8
+ query: q
9
+ }
10
+ return await this.recordFind({ model, req, options })
11
+ }
12
+
13
+ export default getLookupData
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "waibu-db",
3
- "version": "1.0.11",
3
+ "version": "1.0.13",
4
4
  "description": "DB Helper",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -10,6 +10,8 @@ async function btnColumns () {
10
10
  const { req } = this.component
11
11
  const qsKey = this.plugin.app.waibu.config.qsKey
12
12
  const schema = get(this, 'component.locals.schema', {})
13
+ const count = get(this, 'component.locals.list.count', 0)
14
+ if (count === 0) this.params.attr.triggerDisabled = true
13
15
  if (schema.view.disabled.includes('find')) {
14
16
  this.params.html = ''
15
17
  return
@@ -9,12 +9,14 @@ async function btnExport () {
9
9
  const { req } = this.component
10
10
  this.params.noTag = true
11
11
  const schema = get(this, 'component.locals.schema', {})
12
+ const count = get(this, 'component.locals.list.count', 0)
13
+ if (count === 0 && this.params.attr.handler === 'list') this.params.attr.triggerDisabled = true
12
14
  if (schema.view.disabled.includes('find')) {
13
15
  this.params.html = ''
14
16
  return
15
17
  }
16
- if (isEmpty(this.params.attr.launch)) this.params.attr.launch = req.t('Export')
17
- this.params.attr.launchColor = this.params.attr.launchColor ?? 'secondary-outline'
18
+ if (isEmpty(this.params.attr.trigger)) this.params.attr.trigger = req.t('Export')
19
+ this.params.attr.triggerColor = this.params.attr.triggerColor ?? 'secondary-outline'
18
20
  this.params.attr.title = req.t('Data Export')
19
21
  const html = await this.component.buildSentence(`
20
22
  <c:div x-data="{
@@ -26,6 +26,11 @@ async function pagination () {
26
26
  }
27
27
  let { count, limit, page } = attrToObject(this.params.attr.options)
28
28
  count = count ?? get(this, 'component.locals.list.count', 0)
29
+ if (count === 0) {
30
+ this.params.noTag = true
31
+ this.params.html = ''
32
+ return
33
+ }
29
34
  limit = limit ?? get(this, 'component.locals.list.limit', 25)
30
35
  page = page ?? get(this, 'component.locals.list.page', 1)
31
36
  const pages = paginationLayout(count, limit, page) ?? []
@@ -10,6 +10,7 @@ async function query () {
10
10
  const { find, get, without, isEmpty, filter, upperFirst } = this.plugin.app.bajo.lib._
11
11
  const qsKey = this.plugin.app.waibu.config.qsKey
12
12
  const schema = get(this, 'component.locals.schema', {})
13
+ const count = get(this, 'component.locals.list.count', 0)
13
14
  if (schema.view.disabled.includes('find')) {
14
15
  this.params.html = ''
15
16
  return
@@ -50,12 +51,12 @@ async function query () {
50
51
  this.params.noTag = true
51
52
  const container = this.params.attr.modal ? 'modal' : 'drawer'
52
53
  this.params.html = await this.component.buildSentence(`
53
- <c:form-input type="search" t:placeholder="Query" id="${id}" x-data="{ query: '' }" x-init="
54
+ <c:form-input ${count === 0 ? 'disabled' : ''} type="search" t:placeholder="Query" id="${id}" x-data="{ query: '' }" x-init="
54
55
  const url = new URL(window.location.href)
55
56
  query = url.searchParams.get('${qsKey.query}') ?? ''
56
57
  " x-model="query" @on-query.window="query = $event.detail ?? ''" @keyup.enter="$dispatch('on-submit')">
57
58
  <c:form-input-addon>
58
- <c:${container} launch-icon="${this.params.attr.icon ?? 'dotsThree'}" launch-on-end t:title="Query Builder" x-ref="query" x-data="{
59
+ <c:${container} ${count === 0 ? 'trigger-disabled' : ''} trigger-icon="${this.params.attr.icon ?? 'dotsThree'}" trigger-on-end t:title="Query Builder" x-ref="query" x-data="{
59
60
  fields: ${jsonStringify(fields, true)},
60
61
  builder: '',
61
62
  selected: [],
@@ -157,7 +158,7 @@ async function query () {
157
158
  </c:${container}>
158
159
  </c:form-input-addon>
159
160
  <c:form-input-addon>
160
- <c:btn t:content="Submit" x-data="{
161
+ <c:btn ${count === 0 ? 'disabled' : ''} t:content="Submit" x-data="{
161
162
  submit () {
162
163
  const val = document.getElementById('${id}').value ?? ''
163
164
  const url = new URL(window.location.href)
@@ -16,16 +16,17 @@ async function recsInfo () {
16
16
  }
17
17
  let { count, limit, page, pages } = attrToObject(this.params.attr.options)
18
18
  count = count ?? get(this, 'component.locals.list.count', 0)
19
+ if (count === 0) {
20
+ this.params.noTag = true
21
+ this.params.html = ''
22
+ return
23
+ }
19
24
  page = page ?? get(this, 'component.locals.list.page', 1)
20
25
  limit = limit ?? get(this, 'component.locals.list.limit', 25)
21
26
  pages = pages ?? get(this, 'component.locals.list.pages', 0)
22
27
 
23
28
  this.params.tag = 'div'
24
29
  this.params.attr.flex = 'justify-center:start align-items:center'
25
- if (count === 0) {
26
- this.params.html = req.t('No record found')
27
- return
28
- }
29
30
  if (!this.params.attr.dropdown) this.params.attr.dropdown = true
30
31
  const group = groupAttrs(this.params.attr, ['dropdown'])
31
32
  const html = []
@@ -29,6 +29,13 @@ async function table () {
29
29
  const prettyUrl = this.params.attr.prettyUrl
30
30
 
31
31
  const data = get(this, 'component.locals.list.data', [])
32
+ const count = get(this, 'component.locals.list.count', 0)
33
+ if (count === 0) {
34
+ const alert = '<c:alert color="warning" t:content="No record found" margin="top-4"/>'
35
+ this.params.noTag = true
36
+ this.params.html = await this.component.buildSentence(alert)
37
+ return
38
+ }
32
39
  const schema = get(this, 'component.locals.schema', {})
33
40
  const disableds = get(schema, 'view.disabled', [])
34
41
  if (disableds.includes('find')) {
@@ -119,13 +126,18 @@ async function table () {
119
126
  let dataValue = d[f] ?? ''
120
127
  if (['string', 'text'].includes(prop.type)) dataValue = escape(dataValue)
121
128
  if (['array', 'object'].includes(prop.type)) dataValue = escape(JSON.stringify(d[f]))
122
- const attr = { dataValue, dataKey: prop.name, dataType: prop.type }
129
+ const attr = { dataValue, dataKey: prop.name, dataType: prop.type, style: { cursor: 'pointer' } }
123
130
  if (!['object', 'array'].includes(prop.type)) {
124
131
  const noWrap = this.isNoWrap(f, schema) ? 'nowrap' : ''
125
132
  if (this.isRightAligned(f, schema)) attr.text = `align:end ${noWrap}`
126
133
  else attr.text = noWrap
127
134
  }
128
- const formatter = get(schema, `formatter.${f}`)
135
+ const lookup = get(schema, `view.lookup.${f}`)
136
+ if (lookup) {
137
+ const item = find(lookup.values, set({}, lookup.id ?? 'id', value))
138
+ if (item) value = req.t(item[lookup.field ?? 'name'])
139
+ }
140
+ const formatter = get(schema, `view.formatter.${f}`)
129
141
  if (formatter) {
130
142
  if (isFunction(formatter)) value = await formatter(dataValue, d)
131
143
  else value = await callHandler(formatter, req, dataValue, d)
File without changes
File without changes