waibu-db 1.1.5 → 1.1.7

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.
@@ -1,4 +1,4 @@
1
- <c:grid-row gutter="3" margin="bottom-4">
1
+ <c:grid-row gutter="3">
2
2
  <c:grid-col col="6-lg">
3
3
  <c:wdb-recs-info pages recs-per-page recs-per-page-values="10 15 25 50" />
4
4
  </c:grid-col>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "waibu-db",
3
- "version": "1.1.5",
3
+ "version": "1.1.7",
4
4
  "description": "DB Helper",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -1,12 +1,12 @@
1
1
  import prepCrud from '../../../lib/prep-crud.js'
2
2
 
3
3
  async function get ({ model, req, reply, id, options = {} }) {
4
- const { recordGet, attachmentFind } = this.app.dobo
5
- const { parseFilter } = this.app.waibu
6
- const { name, recId, opts, attachment, stats, mimeType } = prepCrud.call(this, { model, req, reply, id, options, args: ['model', 'id'] })
7
- opts.filter = parseFilter(req)
8
- const ret = await recordGet(name, recId, opts)
9
- if (attachment) ret.data._attachment = await attachmentFind(name, id, { stats, mimeType })
4
+ const { recordFindOne, attachmentFind } = this.app.dobo
5
+ const { name, filter, opts, attachment, stats, mimeType } = prepCrud.call(this, { model, req, reply, id, options, args: ['model', 'id'] })
6
+ filter.query = { $and: [filter.query ?? {}, { id: id ?? req.params.id }] }
7
+ opts.dataOnly = true
8
+ const ret = await recordFindOne(name, filter, opts)
9
+ if (attachment) ret.data._attachment = await attachmentFind(name, ret.id, { stats, mimeType })
10
10
  return ret
11
11
  }
12
12
 
@@ -4,6 +4,10 @@ async function btnExport () {
4
4
  const WdbBase = await wdbBase.call(this)
5
5
 
6
6
  return class WdbBtnExport extends WdbBase {
7
+ static scripts = [...super.scripts,
8
+ 'waibuMpa.virtual:/json2csv/json2csv.js'
9
+ ]
10
+
7
11
  build = async () => {
8
12
  const { isEmpty, get } = this.plugin.app.bajo.lib._
9
13
  const { req } = this.component
@@ -71,8 +75,15 @@ async function btnExport () {
71
75
  for (const el of els) {
72
76
  let data = []
73
77
  _.each(el.children, (v, i) => {
74
- if ((i + '') === '0' && checker) return undefined
75
- data.push(this.options.includes('fvalue') ? v.innerText : wmpa.parseValue(v.dataset.value, types[parseInt(i - 1)]))
78
+ i = i + ''
79
+ if (i === '0' && checker) return undefined
80
+ if (this.options.includes('fvalue')) data.push(v.innerText)
81
+ else {
82
+ const type = types[parseInt(i)]
83
+ let val = wmpa.parseValue(v.dataset.value, type)
84
+ if (['datetime', 'date', 'time'].includes(type)) val = val.toISOString()
85
+ data.push(val)
86
+ }
76
87
  })
77
88
  const item = {}
78
89
  for (const i in keys) {
@@ -107,7 +118,7 @@ async function btnExport () {
107
118
  <c:grid-col col="6-md">
108
119
  <c:fieldset t:legend="delivery" legend-type="6">
109
120
  <c:form-radio x-model="delivery" value="file" t:label="saveAsFile" />
110
- <c:form-radio x-model="delivery" value="clipboard" t:label="copyToClipboard" />
121
+ <c:form-radio x-model="delivery" value="clipboard" t:label="copyClipboard" />
111
122
  </c:fieldset>
112
123
  <c:fieldset t:legend="options" legend-type="6" margin="top-2">
113
124
  <c:form-check x-ref="fkey" x-model="options" value="fkey" t:label="formattedField" />
@@ -13,7 +13,8 @@ async function table () {
13
13
  return value
14
14
  }
15
15
 
16
- isNoWrap = (field, schema) => {
16
+ isNoWrap = (field, schema, bodyNowrap) => {
17
+ if (bodyNowrap) return true
17
18
  const { get } = this.plugin.app.bajo.lib._
18
19
  return get(schema, 'view.noWrap', []).includes(field)
19
20
  }
@@ -29,6 +30,7 @@ async function table () {
29
30
  const prettyUrl = this.params.attr.prettyUrl
30
31
 
31
32
  const data = get(this, 'component.locals.list.data', [])
33
+ const filter = get(this, 'component.locals.list.filter', {})
32
34
  const count = get(this, 'component.locals.list.count', 0)
33
35
  if (count === 0) {
34
36
  const alert = '<c:alert color="warning" t:content="noRecordFound" margin="top-4"/>'
@@ -45,7 +47,12 @@ async function table () {
45
47
  const qsKey = this.plugin.app.waibu.config.qsKey
46
48
  let fields = without(get(this, `component.locals._meta.query.${qsKey.fields}`, '').split(','), '')
47
49
  if (isEmpty(fields)) fields = schema.view.fields
48
- const sort = this.params.attr.sort ? attrToArray(this.params.attr.sort) : get(this, `component.locals._meta.query.${qsKey.sort}`, '')
50
+ if (!isEmpty(schema.view.hidden)) fields = without(fields, ...schema.view.hidden)
51
+ let sort = this.params.attr.sort ? attrToArray(this.params.attr.sort) : get(this, `component.locals._meta.query.${qsKey.sort}`, '')
52
+ if (isEmpty(sort)) {
53
+ const keys = Object.keys(filter.sort)
54
+ if (keys.length > 0) sort = `${keys[0]}:${filter.sort[keys[0]]}`
55
+ }
49
56
 
50
57
  let [sortCol, sortDir] = sort.split(':')
51
58
  if (!['-1', '1'].includes(sortDir)) sortDir = '1'
@@ -63,7 +70,8 @@ async function table () {
63
70
  // head
64
71
  for (const f of schema.view.fields) {
65
72
  if (!fields.includes(f)) continue
66
- const prop = find(schema.properties, { name: f })
73
+ let prop = find(schema.properties, { name: f })
74
+ if (!prop) prop = find(schema.view.calcFields, { name: f })
67
75
  if (!prop) continue
68
76
  let head = req.t(get(schema, `view.label.${f}`, `field.${f}`))
69
77
  if (!this.params.attr.noSort && (schema.sortables ?? []).includes(f)) {
@@ -93,7 +101,8 @@ async function table () {
93
101
  const attr = { 'x-model': 'toggleAll', name: '_rtm', noWrapper: true, noLabel: true }
94
102
  item = await this.component.buildTag({ tag: 'formCheck', attr, prepend: '<th>', append: '</th>' })
95
103
  } else {
96
- const attr = { name: 'remove', '@click': 'selected = \'\'', style: { cursor: 'pointer' } }
104
+ const attr = { name: 'remove', '@click': 'selected = \'\'' }
105
+ if (!disableds.includes('get')) attr.style = { cursor: 'pointer' }
97
106
  item = await this.component.buildTag({ tag: 'icon', attr, prepend: '<th>', append: '</th>' })
98
107
  }
99
108
  items.unshift(item)
@@ -113,7 +122,8 @@ async function table () {
113
122
  }
114
123
  for (const f of schema.view.fields) {
115
124
  if (!fields.includes(f)) continue
116
- const prop = find(schema.properties, { name: f })
125
+ let prop = find(schema.properties, { name: f })
126
+ if (!prop) prop = find(schema.view.calcFields, { name: f })
117
127
  if (!prop) continue
118
128
  const opts = {}
119
129
  if (f === 'lng') opts.longitude = true
@@ -124,13 +134,20 @@ async function table () {
124
134
  ' ' + (req.t(d[f] ? 'Yes' : 'No'))
125
135
  } else value = escape(value)
126
136
  let dataValue = d[f] ?? ''
137
+ if (['datetime'].includes(prop.type)) dataValue = escape(dataValue.toISOString())
127
138
  if (['string', 'text'].includes(prop.type)) dataValue = escape(dataValue)
128
139
  if (['array', 'object'].includes(prop.type)) dataValue = escape(JSON.stringify(d[f]))
129
- const attr = { dataValue, dataKey: prop.name, dataType: prop.type, style: { cursor: 'pointer' } }
140
+ const vf = get(schema, `view.valueFormatter.${f}`)
141
+ if (vf) {
142
+ if (isFunction(vf)) dataValue = escape(await vf(d[f], d))
143
+ else dataValue = await callHandler(vf, req, d[f], d)
144
+ }
145
+ const attr = { dataValue, dataKey: prop.name, dataType: prop.type }
146
+ if (!disableds.includes('get')) attr.style = { cursor: 'pointer' }
130
147
  const cellFormatter = get(schema, `view.cellFormatter.${f}`)
131
148
  if (cellFormatter) merge(attr, await cellFormatter(dataValue, d))
132
149
  if (!['object', 'array'].includes(prop.type)) {
133
- const noWrap = this.isNoWrap(f, schema) ? 'nowrap' : ''
150
+ const noWrap = this.isNoWrap(f, schema, group.body.nowrap) ? 'nowrap' : ''
134
151
  if (this.isRightAligned(f, schema)) attr.text = `align:end ${noWrap}`
135
152
  else attr.text = noWrap
136
153
  }
@@ -158,6 +175,7 @@ async function table () {
158
175
  const goDetails = `
159
176
  goDetails (id) {
160
177
  let url = '${this.params.attr.detailsHref ?? this.component.buildUrl({ base: 'details', prettyUrl })}'
178
+ if (url === '#') return
161
179
  if (url.indexOf('/:id') > -1) url = url.replace('/:id', '/' + id)
162
180
  else url += '&id=' + id
163
181
  window.location.href = url