waibu-db 1.1.8 → 1.1.10

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,15 @@
1
+ <c:grid-row gutter="2">
2
+ <c:grid-col col="6-md">
3
+ <c:wdb-btn-back />
4
+ </c:grid-col>
5
+ <c:grid-col col="6-md">
6
+ <c:div flex="justify-content:end-md align-items:center">
7
+ <c:btn type="reset" color="secondary" t:content="reset" />
8
+ <c:btn type="submit" color="primary" t:content="submit" margin="start-2"/>
9
+ </c:div>
10
+ </c:grid-col>
11
+ <c:grid-col col="12" margin="top-4">
12
+ <c:form-switch name="_addmore" t:label="addMoreAfterSubmit"/>
13
+ <c:form-switch name="_cloneprev" t:label="clonePrevious"/>
14
+ </c:grid-col>
15
+ </c:grid-row>
@@ -0,0 +1,17 @@
1
+ <c:grid-row gutter="2">
2
+ <c:grid-col col="6-lg">
3
+ <c:wdb-btn-back />
4
+ <% if (schema.disabled.includes('remove') && schema.disabled.includes('update')) { %>
5
+ <c:wdb-btn-export selector="#main-form" handler="details" launch-margin="start-1"/>
6
+ <% } else { %>
7
+ <c:btn-group margin="start-1">
8
+ <c:wdb-btn-edit />
9
+ <c:wdb-btn-clone />
10
+ <c:wdb-btn-export selector="#main-form" handler="details" launch-on-end/>
11
+ </c:btn-group>
12
+ <% } %>
13
+ </c:grid-col>
14
+ <c:grid-col col="6-lg" flex="justify-content:end-lg align-items:center">
15
+ <c:wdb-btn-delete/>
16
+ </c:grid-col>
17
+ </c:grid-row>
@@ -0,0 +1,15 @@
1
+ <c:grid-row gutter="2">
2
+ <c:grid-col col="6-lg">
3
+ <c:wdb-btn-back />
4
+ <c:btn-group margin="start-1">
5
+ <c:wdb-btn-details />
6
+ <c:wdb-btn-clone/>
7
+ <c:wdb-btn-export selector="#main-form" handler="edit" launch-on-end/>
8
+ </c:btn-group>
9
+ </c:grid-col>
10
+ <c:grid-col col="6-lg" flex="justify-content:end-lg align-items:center">
11
+ <c:wdb-btn-delete/>
12
+ <c:btn type="reset" color="secondary" t:content="reset" margin="start-2"/>
13
+ <c:btn type="submit" color="primary" t:content="submit" margin="start-2"/>
14
+ </c:grid-col>
15
+ </c:grid-row>
@@ -1,5 +1,5 @@
1
1
  <% for (const l of schema.view.layout) { %>
2
- <c:fieldset card <% if (l.name[0] !== '_') print('t:legend="' + l.name + '"') %> grid-gutter="2">
2
+ <c:fieldset <%= schema.view.card === false ? '' : 'card' %> <% if (l.name[0] !== '_') print('t:legend="' + l.name + '"') %> grid-gutter="2">
3
3
  <% for (const w of l.widgets) {
4
4
  const prop = _.find(schema.properties, { name: w.name })
5
5
  const attr = []
@@ -0,0 +1,16 @@
1
+ <c:grid-row gutter="3">
2
+ <c:grid-col col="4-lg">
3
+ <c:wdb-query />
4
+ </c:grid-col>
5
+ <c:grid-col col="8-lg" flex="justify-content:end-lg">
6
+ <c:btn-group margin="end-2">
7
+ <c:wdb-btn-add text="nowrap"/>
8
+ <c:wdb-btn-edit on-list menu="end"/>
9
+ </c:btn-group>
10
+ <c:wdb-btn-delete on-list margin="end-2" />
11
+ <c:btn-group>
12
+ <c:wdb-btn-export selector="#main-table" handler="list"/>
13
+ <c:wdb-btn-columns menu="end"/>
14
+ </c:btn-group>
15
+ </c:grid-col>
16
+ </c:grid-row>
@@ -1,19 +1,5 @@
1
1
  <c:form>
2
2
  <!-- include waibuDb.partial:/crud/_form.html -->
3
- <c:grid-row gutter="2" margin="top-2">
4
- <c:grid-col col="6-md">
5
- <c:wdb-btn-back />
6
- </c:grid-col>
7
- <c:grid-col col="6-md">
8
- <c:div flex="justify-content:end-md align-items:center">
9
- <c:btn type="reset" color="secondary" t:content="reset" />
10
- <c:btn type="submit" color="primary" t:content="submit" margin="start-2"/>
11
- </c:div>
12
- </c:grid-col>
13
- <c:grid-col col="12" margin="top-4">
14
- <c:form-switch name="_addmore" t:label="addMoreAfterSubmit"/>
15
- <c:form-switch name="_cloneprev" t:label="clonePrevious"/>
16
- </c:grid-col>
17
- </c:grid-row>
3
+ <!-- include waibuDb.partial:/crud/_add-btns.html -->
18
4
  </c:form>
19
5
  <!-- include waibuDb.partial:/crud/_addons.html -->
@@ -1,21 +1,5 @@
1
1
  <c:div id="main-form">
2
2
  <!-- include waibuDb.partial:/crud/_form.html -->
3
3
  </c:div>
4
- <c:grid-row gutter="2" margin="top-2">
5
- <c:grid-col col="6-lg">
6
- <c:wdb-btn-back />
7
- <% if (schema.disabled.includes('remove') && schema.disabled.includes('update')) { %>
8
- <c:wdb-btn-export selector="#main-form" handler="details" launch-margin="start-1"/>
9
- <% } else { %>
10
- <c:btn-group margin="start-1">
11
- <c:wdb-btn-edit />
12
- <c:wdb-btn-clone />
13
- <c:wdb-btn-export selector="#main-form" handler="details" launch-on-end/>
14
- </c:btn-group>
15
- <% } %>
16
- </c:grid-col>
17
- <c:grid-col col="6-lg" flex="justify-content:end-lg align-items:center">
18
- <c:wdb-btn-delete/>
19
- </c:grid-col>
20
- </c:grid-row>
4
+ <!-- include waibuDb.partial:/crud/_details-btns.html -->
21
5
  <!-- include waibuDb.partial:/crud/_addons.html -->
@@ -1,19 +1,5 @@
1
1
  <c:form id="main-form">
2
2
  <!-- include waibuDb.partial:/crud/_form.html -->
3
- <c:grid-row gutter="2" margin="top-2">
4
- <c:grid-col col="6-lg">
5
- <c:wdb-btn-back />
6
- <c:btn-group margin="start-1">
7
- <c:wdb-btn-details />
8
- <c:wdb-btn-clone/>
9
- <c:wdb-btn-export selector="#main-form" handler="edit" launch-on-end/>
10
- </c:btn-group>
11
- </c:grid-col>
12
- <c:grid-col col="6-lg" flex="justify-content:end-lg align-items:center">
13
- <c:wdb-btn-delete/>
14
- <c:btn type="reset" color="secondary" t:content="reset" margin="start-2"/>
15
- <c:btn type="submit" color="primary" t:content="submit" margin="start-2"/>
16
- </c:grid-col>
17
- </c:grid-row>
3
+ <!-- include waibuDb.partial:/crud/_edit-btns.html -->
18
4
  </c:form>
19
5
  <!-- include waibuDb.partial:/crud/_addons.html -->
@@ -1,19 +1,4 @@
1
- <c:grid-row gutter="3" margin="bottom-3">
2
- <c:grid-col col="4-lg">
3
- <c:wdb-query />
4
- </c:grid-col>
5
- <c:grid-col col="8-lg" flex="justify-content:end-lg">
6
- <c:btn-group margin="end-2">
7
- <c:wdb-btn-add text="nowrap"/>
8
- <c:wdb-btn-edit on-list menu="end"/>
9
- </c:btn-group>
10
- <c:wdb-btn-delete on-list margin="end-2" />
11
- <c:btn-group>
12
- <c:wdb-btn-export selector="#main-table" handler="list"/>
13
- <c:wdb-btn-columns menu="end"/>
14
- </c:btn-group>
15
- </c:grid-col>
16
- </c:grid-row>
1
+ <!-- include waibuDb.partial:/crud/_list-btns.html -->
17
2
  <c:wdb-table id="main-table" border body-divider strip responsive />
18
3
  <!-- include waibuDb.partial:/crud/_list-footer.html -->
19
4
  <!-- include waibuDb.partial:/crud/_addons.html -->
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "waibu-db",
3
- "version": "1.1.8",
3
+ "version": "1.1.10",
4
4
  "description": "DB Helper",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -5,12 +5,15 @@ const defReadonly = ['id', 'createdAt', 'updatedAt']
5
5
  function getCommons (action, schema, ext, opts = {}) {
6
6
  const { map, get, set, without, uniq } = this.lib._
7
7
  const label = get(ext, `view.${action}.label`, get(ext, 'common.label', {}))
8
+ const card = get(ext, `view.${action}.card`, get(ext, 'common.card', true))
8
9
  const hidden = get(ext, `view.${action}.hidden`, get(ext, 'common.hidden', []))
10
+ const disabled = get(ext, `view.${action}.disabled`, get(ext, 'common.disabled', []))
11
+ const aggregate = get(ext, `view.${action}.stat.aggregate`, get(ext, 'common.stat.aggregate', []))
9
12
  hidden.push(...schema.hidden, ...(opts.hidden ?? []))
10
13
  const allFields = without(map(schema.properties, 'name'), ...hidden)
11
14
  const forFields = get(ext, `view.${action}.fields`, get(ext, 'common.fields', allFields))
12
- set(schema, 'view.stat.aggregate', get(ext, `view.${action}.stat.aggregate`, get(ext, 'common.stat.aggregate', [])))
13
- set(schema, 'view.disabled', get(ext, 'disabled', []))
15
+ set(schema, 'view.stat.aggregate', aggregate)
16
+ set(schema, 'view.disabled', disabled)
14
17
  if (schema.disabled.length > 0) schema.view.disabled.push(...schema.disabled)
15
18
  let fields = []
16
19
  for (const f of forFields) {
@@ -18,7 +21,11 @@ function getCommons (action, schema, ext, opts = {}) {
18
21
  }
19
22
  fields = uniq(without(fields, ...hidden))
20
23
  if (action !== 'add' && !fields.includes('id')) fields.unshift('id')
21
- return { fields, allFields, label }
24
+ let noWrap = get(ext, `view.${action}.noWrap`, get(ext, 'common.noWrap', true))
25
+ if (noWrap === true) noWrap = fields
26
+ else if (noWrap === false) noWrap = []
27
+ set(schema, 'view.noWrap', noWrap)
28
+ return { fields, allFields, label, card }
22
29
  }
23
30
 
24
31
  function autoLayout ({ action, schema, ext, layout, allWidgets }) {
@@ -37,15 +44,18 @@ function autoLayout ({ action, schema, ext, layout, allWidgets }) {
37
44
  }
38
45
 
39
46
  function customLayout ({ action, schema, ext, layout, allWidgets, readonly }) {
40
- const { find, omit, merge, isString } = this.lib._
47
+ const { find, omit, merge, isString, isEmpty } = this.lib._
41
48
  const items = [...layout]
42
49
  layout.splice(0, layout.length)
43
50
  for (const item of items) {
44
51
  const widgets = []
45
52
  for (let f of item.fields) {
46
53
  if (isString(f)) {
47
- const [name, col, label] = f.split(':')
48
- f = { name, col, label }
54
+ const [name, col, label, component] = f.split(':')
55
+ f = { name }
56
+ f.label = isEmpty(label) ? `field.${name}` : label
57
+ if (!isEmpty(col)) f.col = col
58
+ if (!isEmpty(component)) f.component = component
49
59
  }
50
60
  const widget = find(allWidgets, { name: f.name })
51
61
  if (!widget && !f.component) continue
@@ -59,7 +69,7 @@ function customLayout ({ action, schema, ext, layout, allWidgets, readonly }) {
59
69
 
60
70
  function applyLayout (action, schema, ext) {
61
71
  const { set, get, isEmpty, map, find } = this.lib._
62
- const { fields, label } = getCommons.call(this, action, schema, ext)
72
+ const { fields, label, card } = getCommons.call(this, action, schema, ext)
63
73
  const layout = get(ext, `view.${action}.layout`, get(ext, 'common.layout', []))
64
74
  const readonly = get(ext, `view.${action}.readonly`, get(ext, 'common.readonly', defReadonly))
65
75
  const allWidgets = map(fields, f => {
@@ -91,6 +101,7 @@ function applyLayout (action, schema, ext) {
91
101
  set(schema, 'view.layout', layout)
92
102
  set(schema, 'view.fields', fields)
93
103
  set(schema, 'view.label', label)
104
+ set(schema, 'view.card', card)
94
105
  }
95
106
 
96
107
  const handler = {
@@ -121,13 +132,15 @@ const handler = {
121
132
  }
122
133
 
123
134
  async function getSchemaExt (model, view, opts) {
124
- const { readConfig } = this.app.bajo
135
+ const { readConfig, defaultsDeep } = this.app.bajo
125
136
  const { getSchema } = this.app.dobo
126
137
  const { pick } = this.lib._
127
138
 
128
139
  let schema = getSchema(model)
129
140
  const base = path.basename(schema.file, path.extname(schema.file))
130
- const ext = await readConfig(`${schema.ns}:/waibuDb/schema/${base}.*`, { ignoreError: true })
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 })
143
+ ext = defaultsDeep(over, ext)
131
144
  await handler[view].call(this, schema, ext, opts)
132
145
  schema = pick(schema, ['name', 'properties', 'indexes', 'disabled', 'attachment', 'sortables', 'view'])
133
146
  return { schema, ext }
@@ -2,8 +2,8 @@ import prepCrud from '../../../lib/prep-crud.js'
2
2
 
3
3
  async function get ({ model, req, reply, id, options = {} }) {
4
4
  const { recordFindOne } = this.app.dobo
5
- const { name, filter, opts } = prepCrud.call(this, { model, req, reply, id, options, args: ['model', 'id'] })
6
- filter.query = { $and: [filter.query ?? {}, { id: id ?? req.params.id }] }
5
+ const { name, recId, filter, opts } = prepCrud.call(this, { model, req, reply, id, options, args: ['model', 'id'] })
6
+ filter.query = { $and: [filter.query ?? {}, { id: recId }] }
7
7
  const ret = await recordFindOne(name, filter, opts)
8
8
  return ret
9
9
  }
@@ -10,7 +10,7 @@ async function btnDelete () {
10
10
  const { isEmpty, get } = this.plugin.app.bajo.lib._
11
11
  this.params.noTag = true
12
12
  const schema = get(this, 'component.locals.schema', {})
13
- if (schema.view.disabled.includes('delete')) {
13
+ if (schema.view.disabled.includes('remove')) {
14
14
  this.params.html = ''
15
15
  return
16
16
  }
@@ -18,12 +18,13 @@ async function echarts () {
18
18
  right: 0
19
19
  }
20
20
  }
21
+ this.params.tag = 'div'
21
22
  }
22
23
 
23
24
  build = async () => {
24
- const { defaultsDeep, generateId } = this.plugin.app.bajo
25
+ const { generateId } = this.plugin.app.bajo
25
26
  const { base64JsonDecode, jsonStringify } = this.plugin.app.waibuMpa
26
- const { cloneDeep } = this.plugin.app.bajo.lib._
27
+ const { merge, cloneDeep } = this.plugin.app.bajo.lib._
27
28
  this.params.attr.id = generateId('alpha')
28
29
  this.params.attr['x-data'] = `chart${this.params.attr.id}`
29
30
  this.params.attr['@resize.window.debounce.500ms'] = `
@@ -33,7 +34,7 @@ async function echarts () {
33
34
  `
34
35
  let option = cloneDeep(this.defOption)
35
36
  if (this.params.attr.option === true) this.params.attr.option = 'e30='
36
- if (this.params.attr.option) option = defaultsDeep(base64JsonDecode(this.params.attr.option), this.defOption)
37
+ if (this.params.attr.option) option = merge(option, base64JsonDecode(this.params.attr.option))
37
38
  this.params.attr['x-init'] = `
38
39
  $watch('option', val => {
39
40
  if (chart) chart.setOption(val)
@@ -91,6 +91,7 @@ async function table () {
91
91
  head = await this.component.buildTag({ tag: 'div', attr: { flex: 'justify-content:between align-items:end' }, html: content.join('\n') })
92
92
  }
93
93
  let text = this.params.attr.headerNowrap ? '' : 'nowrap'
94
+ if (text === '' && this.isNoWrap(f, schema, group.body.nowrap)) text = 'nowrap'
94
95
  if (this.isRightAligned(f, schema)) text += ' align:end'
95
96
  const attr = { dataKey: f, dataType: prop.type, text }
96
97
  items.push(await this.component.buildTag({ tag: 'th', attr, html: head }))
@@ -146,11 +147,9 @@ async function table () {
146
147
  if (!disableds.includes('get')) attr.style = { cursor: 'pointer' }
147
148
  const cellFormatter = get(schema, `view.cellFormatter.${f}`)
148
149
  if (cellFormatter) merge(attr, await cellFormatter(dataValue, d))
149
- if (!['object', 'array'].includes(prop.type)) {
150
- const noWrap = this.isNoWrap(f, schema, group.body.nowrap) ? 'nowrap' : ''
151
- if (this.isRightAligned(f, schema)) attr.text = `align:end ${noWrap}`
152
- else attr.text = noWrap
153
- }
150
+ const noWrap = this.isNoWrap(f, schema, group.body.nowrap) ? 'nowrap' : ''
151
+ if (this.isRightAligned(f, schema)) attr.text = `align:end ${noWrap}`
152
+ else attr.text = noWrap
154
153
  const lookup = get(schema, `view.lookup.${f}`)
155
154
  if (lookup) {
156
155
  const item = find(lookup.values, set({}, lookup.id ?? 'id', value))