waibu-db 1.1.5 → 1.1.6

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.6",
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" />
@@ -29,6 +29,7 @@ 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 filter = get(this, 'component.locals.list.filter', {})
32
33
  const count = get(this, 'component.locals.list.count', 0)
33
34
  if (count === 0) {
34
35
  const alert = '<c:alert color="warning" t:content="noRecordFound" margin="top-4"/>'
@@ -45,7 +46,11 @@ async function table () {
45
46
  const qsKey = this.plugin.app.waibu.config.qsKey
46
47
  let fields = without(get(this, `component.locals._meta.query.${qsKey.fields}`, '').split(','), '')
47
48
  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}`, '')
49
+ let sort = this.params.attr.sort ? attrToArray(this.params.attr.sort) : get(this, `component.locals._meta.query.${qsKey.sort}`, '')
50
+ if (isEmpty(sort)) {
51
+ const keys = Object.keys(filter.sort)
52
+ if (keys.length > 0) sort = `${keys[0]}:${filter.sort[keys[0]]}`
53
+ }
49
54
 
50
55
  let [sortCol, sortDir] = sort.split(':')
51
56
  if (!['-1', '1'].includes(sortDir)) sortDir = '1'
@@ -63,7 +68,8 @@ async function table () {
63
68
  // head
64
69
  for (const f of schema.view.fields) {
65
70
  if (!fields.includes(f)) continue
66
- const prop = find(schema.properties, { name: f })
71
+ let prop = find(schema.properties, { name: f })
72
+ if (!prop) prop = find(schema.view.calcFields, { name: f })
67
73
  if (!prop) continue
68
74
  let head = req.t(get(schema, `view.label.${f}`, `field.${f}`))
69
75
  if (!this.params.attr.noSort && (schema.sortables ?? []).includes(f)) {
@@ -113,7 +119,8 @@ async function table () {
113
119
  }
114
120
  for (const f of schema.view.fields) {
115
121
  if (!fields.includes(f)) continue
116
- const prop = find(schema.properties, { name: f })
122
+ let prop = find(schema.properties, { name: f })
123
+ if (!prop) prop = find(schema.view.calcFields, { name: f })
117
124
  if (!prop) continue
118
125
  const opts = {}
119
126
  if (f === 'lng') opts.longitude = true
@@ -124,8 +131,14 @@ async function table () {
124
131
  ' ' + (req.t(d[f] ? 'Yes' : 'No'))
125
132
  } else value = escape(value)
126
133
  let dataValue = d[f] ?? ''
134
+ if (['datetime'].includes(prop.type)) dataValue = escape(dataValue.toISOString())
127
135
  if (['string', 'text'].includes(prop.type)) dataValue = escape(dataValue)
128
136
  if (['array', 'object'].includes(prop.type)) dataValue = escape(JSON.stringify(d[f]))
137
+ const vf = get(schema, `view.valueFormatter.${f}`)
138
+ if (vf) {
139
+ if (isFunction(vf)) dataValue = escape(await vf(d[f], d))
140
+ else dataValue = await callHandler(vf, req, d[f], d)
141
+ }
129
142
  const attr = { dataValue, dataKey: prop.name, dataType: prop.type, style: { cursor: 'pointer' } }
130
143
  const cellFormatter = get(schema, `view.cellFormatter.${f}`)
131
144
  if (cellFormatter) merge(attr, await cellFormatter(dataValue, d))
@@ -158,6 +171,7 @@ async function table () {
158
171
  const goDetails = `
159
172
  goDetails (id) {
160
173
  let url = '${this.params.attr.detailsHref ?? this.component.buildUrl({ base: 'details', prettyUrl })}'
174
+ if (url === '#') return
161
175
  if (url.indexOf('/:id') > -1) url = url.replace('/:id', '/' + id)
162
176
  else url += '&id=' + id
163
177
  window.location.href = url