waibu-bootstrap 1.2.8 → 1.2.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.
package/package.json
CHANGED
|
@@ -45,9 +45,12 @@ async function formSelectExt () {
|
|
|
45
45
|
|
|
46
46
|
build = async () => {
|
|
47
47
|
const { generateId } = this.plugin.app.bajo
|
|
48
|
-
const { omit, merge } = this.plugin.lib._
|
|
48
|
+
const { omit, merge, has } = this.plugin.lib._
|
|
49
49
|
const { routePath } = this.plugin.app.waibu
|
|
50
50
|
const { jsonStringify, base64JsonDecode, groupAttrs } = this.plugin.app.waibuMpa
|
|
51
|
+
const { req } = this.component
|
|
52
|
+
let apiKey = ''
|
|
53
|
+
if (req.user && this.plugin.app.sumba) apiKey = await this.plugin.app.sumba.getApiKeyFromUserId(req.user.id)
|
|
51
54
|
const xref = this.params.attr['x-ref'] ?? 'select'
|
|
52
55
|
this.params.attr.id = this.params.attr.id ?? generateId('alpha')
|
|
53
56
|
this.params.attr['x-ref'] = xref
|
|
@@ -80,17 +83,22 @@ async function formSelectExt () {
|
|
|
80
83
|
if (!cOpts.optsText) opts = jsonStringify(merge(opts, cOpts), true)
|
|
81
84
|
else opts = cOpts.optsText
|
|
82
85
|
const group = groupAttrs(this.params.attr, ['remote'])
|
|
86
|
+
const fetchOpts = { headers: {} }
|
|
83
87
|
if (group.remote) {
|
|
84
88
|
group.remote.url = routePath(group.remote.url)
|
|
85
89
|
group.remote.searchField = group.remote.searchField ?? 'id'
|
|
86
90
|
group.remote.labelField = group.remote.labelField ?? 'id'
|
|
87
91
|
group.remote.valueField = group.remote.valueField ?? 'id'
|
|
92
|
+
if (has(group.remote, 'apiKey')) {
|
|
93
|
+
if (group.remote.apiKey === true) fetchOpts.headers.Authorization = `Bearer ${apiKey}` // TODO: get it from wmpa
|
|
94
|
+
else fetchOpts.headers.Authorization = `Bearer ${group.remote.apiKey}`
|
|
95
|
+
}
|
|
88
96
|
opts = `{
|
|
89
97
|
searchField: '${group.remote.searchField}',
|
|
90
98
|
labelField: '${group.remote.labelField}',
|
|
91
99
|
valueField: '${group.remote.valueField}',
|
|
92
100
|
load: (query, callback) => {
|
|
93
|
-
fetch('${group.remote.url}?query=${group.remote.searchField}:~\\'' + query + '\\'')
|
|
101
|
+
fetch('${group.remote.url}?query=${group.remote.searchField}:~\\'' + query + '\\'', ${jsonStringify(fetchOpts, true)})
|
|
94
102
|
.then(resp => resp.json())
|
|
95
103
|
.then(json => {
|
|
96
104
|
callback(json.data)
|
|
@@ -115,7 +123,7 @@ async function formSelectExt () {
|
|
|
115
123
|
const opts = ${opts}
|
|
116
124
|
instance = new TomSelect($refs.${xref}, opts)
|
|
117
125
|
`
|
|
118
|
-
this.params.attr = omit(this.params.attr, ['noDropdownInput', 'removeBtn', 'clearBtn', 'c-opts', 'remoteUrl'])
|
|
126
|
+
this.params.attr = omit(this.params.attr, ['noDropdownInput', 'removeBtn', 'clearBtn', 'c-opts', 'remoteUrl', 'remoteSearchField', 'remoteLabelField', 'remoteValueField'])
|
|
119
127
|
await build.call(this, buildFormSelect, this.params)
|
|
120
128
|
}
|
|
121
129
|
}
|