@things-factory/setting-ui 4.3.131 → 4.3.142
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/client/pages/partner-setting-list.js +9 -7
- package/client/pages/setting-list.js +172 -42
- package/package.json +10 -10
|
@@ -93,12 +93,7 @@ export class PartnerSettingList extends connect(store)(localize(i18next)(PageVie
|
|
|
93
93
|
}
|
|
94
94
|
|
|
95
95
|
pageInitialized() {
|
|
96
|
-
this.searchFields = [
|
|
97
|
-
{ name: 'name', label: i18next.t('field.name'), type: 'text', props: { searchOper: 'i_like' } },
|
|
98
|
-
{ name: 'description', label: i18next.t('field.description'), type: 'text', props: { searchOper: 'i_like' } },
|
|
99
|
-
{ name: 'category', label: i18next.t('field.category'), type: 'text', props: { searchOper: 'i_like' } }
|
|
100
|
-
]
|
|
101
|
-
|
|
96
|
+
this.searchFields = []
|
|
102
97
|
this.config = {
|
|
103
98
|
list: {
|
|
104
99
|
fields: ['name', 'description', 'value']
|
|
@@ -250,7 +245,14 @@ export class PartnerSettingList extends connect(store)(localize(i18next)(PageVie
|
|
|
250
245
|
context: gqlContext()
|
|
251
246
|
})
|
|
252
247
|
|
|
253
|
-
|
|
248
|
+
let res = response.data.partnerSettings.items.map(data => {
|
|
249
|
+
return {
|
|
250
|
+
...data,
|
|
251
|
+
category: data.setting.category,
|
|
252
|
+
description: data.setting.description
|
|
253
|
+
}
|
|
254
|
+
})
|
|
255
|
+
return { records: res || [], total: response.data.partnerSettings.total || 0 }
|
|
254
256
|
}
|
|
255
257
|
|
|
256
258
|
async save() {
|
|
@@ -8,6 +8,9 @@ import gql from 'graphql-tag'
|
|
|
8
8
|
import { css, html } from 'lit'
|
|
9
9
|
import { connect } from 'pwa-helpers/connect-mixin'
|
|
10
10
|
import { CommonButtonStyles } from '../../../styles/src'
|
|
11
|
+
import { openImportPopUp } from '@things-factory/import-ui'
|
|
12
|
+
import _ from 'lodash'
|
|
13
|
+
import isEmpty from 'lodash-es/isEmpty'
|
|
11
14
|
|
|
12
15
|
export class SettingList extends connect(store)(localize(i18next)(PageView)) {
|
|
13
16
|
static get styles() {
|
|
@@ -62,7 +65,7 @@ export class SettingList extends connect(store)(localize(i18next)(PageView)) {
|
|
|
62
65
|
actions: [
|
|
63
66
|
{
|
|
64
67
|
title: i18next.t('button.save'),
|
|
65
|
-
action: this._saveSettings.
|
|
68
|
+
action: () => this._saveSettings(this.dataGrist.exportPatchList({ flagName: 'cuFlag' })),
|
|
66
69
|
...CommonButtonStyles.save
|
|
67
70
|
},
|
|
68
71
|
{
|
|
@@ -76,7 +79,26 @@ export class SettingList extends connect(store)(localize(i18next)(PageView)) {
|
|
|
76
79
|
data: this._exportableData.bind(this)
|
|
77
80
|
},
|
|
78
81
|
importable: {
|
|
79
|
-
handler:
|
|
82
|
+
handler: records => {
|
|
83
|
+
const config = {
|
|
84
|
+
rows: this.config.rows,
|
|
85
|
+
columns: [...this.config.columns.filter(column => column.imex !== undefined)]
|
|
86
|
+
}
|
|
87
|
+
openImportPopUp(records, config, async patches => {
|
|
88
|
+
try {
|
|
89
|
+
patches = patches.map(patch => {
|
|
90
|
+
if (!patch?.id) delete patch.id
|
|
91
|
+
|
|
92
|
+
return patch
|
|
93
|
+
})
|
|
94
|
+
this._validateImport(patches)
|
|
95
|
+
await this._saveSettings(patches)
|
|
96
|
+
history.back()
|
|
97
|
+
} catch (e) {
|
|
98
|
+
this.showToast(e.message)
|
|
99
|
+
}
|
|
100
|
+
})
|
|
101
|
+
}
|
|
80
102
|
}
|
|
81
103
|
}
|
|
82
104
|
}
|
|
@@ -121,7 +143,13 @@ export class SettingList extends connect(store)(localize(i18next)(PageView)) {
|
|
|
121
143
|
header: i18next.t('field.name'),
|
|
122
144
|
record: { editable: true, align: 'left' },
|
|
123
145
|
sortable: true,
|
|
124
|
-
width: 100
|
|
146
|
+
width: 100,
|
|
147
|
+
imex: {
|
|
148
|
+
header: i18next.t('field.name'),
|
|
149
|
+
key: 'name',
|
|
150
|
+
width: 50,
|
|
151
|
+
type: 'string'
|
|
152
|
+
}
|
|
125
153
|
},
|
|
126
154
|
{
|
|
127
155
|
type: 'string',
|
|
@@ -129,7 +157,13 @@ export class SettingList extends connect(store)(localize(i18next)(PageView)) {
|
|
|
129
157
|
header: i18next.t('field.description'),
|
|
130
158
|
record: { editable: true, align: 'left' },
|
|
131
159
|
sortable: true,
|
|
132
|
-
width: 200
|
|
160
|
+
width: 200,
|
|
161
|
+
imex: {
|
|
162
|
+
header: i18next.t('field.description'),
|
|
163
|
+
key: 'description',
|
|
164
|
+
width: 50,
|
|
165
|
+
type: 'string'
|
|
166
|
+
}
|
|
133
167
|
},
|
|
134
168
|
{
|
|
135
169
|
type: 'code',
|
|
@@ -137,7 +171,13 @@ export class SettingList extends connect(store)(localize(i18next)(PageView)) {
|
|
|
137
171
|
header: i18next.t('field.category'),
|
|
138
172
|
record: { editable: true, codeName: 'SETTING_CATEGORIES' },
|
|
139
173
|
sortable: true,
|
|
140
|
-
width: 150
|
|
174
|
+
width: 150,
|
|
175
|
+
imex: {
|
|
176
|
+
header: i18next.t('field.category'),
|
|
177
|
+
key: 'category',
|
|
178
|
+
width: 30,
|
|
179
|
+
type: 'code'
|
|
180
|
+
}
|
|
141
181
|
},
|
|
142
182
|
{
|
|
143
183
|
type: 'string',
|
|
@@ -153,15 +193,28 @@ export class SettingList extends connect(store)(localize(i18next)(PageView)) {
|
|
|
153
193
|
editable: true
|
|
154
194
|
},
|
|
155
195
|
sortable: true,
|
|
156
|
-
width: 180
|
|
196
|
+
width: 180,
|
|
197
|
+
imex: {
|
|
198
|
+
header: i18next.t('field.value'),
|
|
199
|
+
key: 'value',
|
|
200
|
+
width: 40,
|
|
201
|
+
type: 'string'
|
|
202
|
+
}
|
|
157
203
|
},
|
|
158
204
|
{
|
|
159
|
-
type: '
|
|
205
|
+
type: 'date',
|
|
160
206
|
name: 'updatedAt',
|
|
161
207
|
header: i18next.t('field.updated_at'),
|
|
162
208
|
record: { editable: false, align: 'left' },
|
|
163
209
|
sortable: true,
|
|
164
210
|
width: 150
|
|
211
|
+
// imex:
|
|
212
|
+
// {
|
|
213
|
+
// header: i18next.t('field.updated_at'),
|
|
214
|
+
// key: 'updatedAt',
|
|
215
|
+
// width: 20,
|
|
216
|
+
// type: 'date'
|
|
217
|
+
// }
|
|
165
218
|
},
|
|
166
219
|
{
|
|
167
220
|
type: 'object',
|
|
@@ -170,6 +223,13 @@ export class SettingList extends connect(store)(localize(i18next)(PageView)) {
|
|
|
170
223
|
record: { editable: false, align: 'left' },
|
|
171
224
|
sortable: true,
|
|
172
225
|
width: 150
|
|
226
|
+
// imex:
|
|
227
|
+
// {
|
|
228
|
+
// header: i18next.t('field.updater'),
|
|
229
|
+
// key: 'updater.name',
|
|
230
|
+
// width: 30,
|
|
231
|
+
// type: 'object'
|
|
232
|
+
// }
|
|
173
233
|
}
|
|
174
234
|
]
|
|
175
235
|
}
|
|
@@ -220,47 +280,55 @@ export class SettingList extends connect(store)(localize(i18next)(PageView)) {
|
|
|
220
280
|
}
|
|
221
281
|
}
|
|
222
282
|
|
|
223
|
-
async _saveSettings() {
|
|
224
|
-
|
|
283
|
+
async _saveSettings(patches) {
|
|
284
|
+
try {
|
|
285
|
+
if (!patches?.length) {
|
|
286
|
+
return this.showToast(i18next.t('text.nothing_changed'))
|
|
287
|
+
}
|
|
225
288
|
|
|
226
|
-
|
|
227
|
-
return this.showToast(i18next.t('text.nothing_changed'))
|
|
228
|
-
}
|
|
289
|
+
this._validate()
|
|
229
290
|
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
291
|
+
const response = await client.mutate({
|
|
292
|
+
mutation: gql`
|
|
293
|
+
mutation updateMultipleSetting($patches: [SettingPatch!]!) {
|
|
294
|
+
updateMultipleSetting(patches: $patches) {
|
|
295
|
+
name
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
`,
|
|
299
|
+
variables: { patches },
|
|
300
|
+
context: gqlContext()
|
|
301
|
+
})
|
|
237
302
|
|
|
238
|
-
|
|
239
|
-
|
|
303
|
+
if (!response.errors) {
|
|
304
|
+
this.showToast(i18next.t('text.data_updated_successfully'))
|
|
305
|
+
this.dataGrist.fetch()
|
|
306
|
+
}
|
|
307
|
+
} catch (error) {
|
|
308
|
+
this.showToast(error.message)
|
|
309
|
+
}
|
|
310
|
+
}
|
|
240
311
|
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
if (patch.cuFlag === '+' && (!patch.name || !patch.category)) return (checkValidation = false)
|
|
244
|
-
})
|
|
312
|
+
_validate() {
|
|
313
|
+
let errors = []
|
|
245
314
|
|
|
246
|
-
|
|
315
|
+
let data = this.dataGrist._data.records.map(itm => {
|
|
316
|
+
itm.error = false
|
|
247
317
|
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
}
|
|
254
|
-
}
|
|
255
|
-
`,
|
|
256
|
-
variables: { patches },
|
|
257
|
-
context: gqlContext()
|
|
318
|
+
if (isEmpty(itm.name) || '') {
|
|
319
|
+
itm.error = true
|
|
320
|
+
if (!errors.find(err => err.type == 'name')) errors.push({ type: 'name', value: 'Name is required' })
|
|
321
|
+
}
|
|
322
|
+
return itm
|
|
258
323
|
})
|
|
259
324
|
|
|
260
|
-
if (
|
|
261
|
-
this.
|
|
262
|
-
|
|
263
|
-
|
|
325
|
+
if (errors.length > 0) {
|
|
326
|
+
this._data = {
|
|
327
|
+
...this.dataGrist.dirtyData,
|
|
328
|
+
records: data
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
throw new Error(errors.map(itm => itm.value).join(', '))
|
|
264
332
|
}
|
|
265
333
|
}
|
|
266
334
|
|
|
@@ -306,8 +374,70 @@ export class SettingList extends connect(store)(localize(i18next)(PageView)) {
|
|
|
306
374
|
this.refreshHandlers.forEach(refreshHandler => refreshHandler())
|
|
307
375
|
}
|
|
308
376
|
|
|
309
|
-
_exportableData() {
|
|
310
|
-
|
|
377
|
+
async _exportableData() {
|
|
378
|
+
let records = []
|
|
379
|
+
if (this.dataGrist.selected && this.dataGrist.selected.length > 0) {
|
|
380
|
+
records = this.dataGrist.selected
|
|
381
|
+
} else {
|
|
382
|
+
records = (await this.fetchHandler({ page: 0, limit: 999999 })).records || []
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
var headerSetting = this.dataGrist._config.columns
|
|
386
|
+
.filter(column => column.type !== 'gutter' && column.record !== undefined && column.imex !== undefined)
|
|
387
|
+
.map(column => {
|
|
388
|
+
return column.imex
|
|
389
|
+
})
|
|
390
|
+
|
|
391
|
+
var data = records.map(item => {
|
|
392
|
+
return {
|
|
393
|
+
id: item.id,
|
|
394
|
+
...this.config.columns
|
|
395
|
+
.filter(column => column.type !== 'gutter' && column.record !== undefined && column.imex !== undefined)
|
|
396
|
+
.reduce((record, column) => {
|
|
397
|
+
record[column.imex.key] = column.imex.key
|
|
398
|
+
.split('.')
|
|
399
|
+
.reduce((obj, key) => (obj && obj[key] !== 'undefined' ? obj[key] : undefined), item)
|
|
400
|
+
return record
|
|
401
|
+
}, {})
|
|
402
|
+
}
|
|
403
|
+
})
|
|
404
|
+
return { header: headerSetting, data: data }
|
|
405
|
+
}
|
|
406
|
+
|
|
407
|
+
_validateImport(data) {
|
|
408
|
+
let errors = []
|
|
409
|
+
|
|
410
|
+
data = data.map(item => {
|
|
411
|
+
if (_.isEmpty(item.name) || '') {
|
|
412
|
+
if (!errors.find(error => error.type == 'name')) {
|
|
413
|
+
errors.push({ type: 'name', value: 'Name is required' })
|
|
414
|
+
}
|
|
415
|
+
}
|
|
416
|
+
|
|
417
|
+
if (_.isEmpty(item.description) || '') {
|
|
418
|
+
if (!errors.find(error => error.type == 'description')) {
|
|
419
|
+
errors.push({ type: 'description', value: 'Description is required' })
|
|
420
|
+
}
|
|
421
|
+
}
|
|
422
|
+
|
|
423
|
+
if (_.isEmpty(item.category) || '') {
|
|
424
|
+
if (!errors.find(error => error.type == 'category')) {
|
|
425
|
+
errors.push({ type: 'category', value: 'Category is required' })
|
|
426
|
+
}
|
|
427
|
+
}
|
|
428
|
+
|
|
429
|
+
if (_.isEmpty(item.value) || '') {
|
|
430
|
+
if (!errors.find(error => error.type == 'value')) {
|
|
431
|
+
errors.push({ type: 'value', value: 'Value is required' })
|
|
432
|
+
}
|
|
433
|
+
}
|
|
434
|
+
|
|
435
|
+
return item
|
|
436
|
+
})
|
|
437
|
+
|
|
438
|
+
if (errors.length > 0) {
|
|
439
|
+
throw new Error(`${errors.map(item => item.value).join(', ')}`)
|
|
440
|
+
}
|
|
311
441
|
}
|
|
312
442
|
|
|
313
443
|
stateChanged(state) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@things-factory/setting-ui",
|
|
3
|
-
"version": "4.3.
|
|
3
|
+
"version": "4.3.142",
|
|
4
4
|
"main": "dist-server/index.js",
|
|
5
5
|
"browser": "client/index.js",
|
|
6
6
|
"things-factory": true,
|
|
@@ -24,14 +24,14 @@
|
|
|
24
24
|
},
|
|
25
25
|
"dependencies": {
|
|
26
26
|
"@material/mwc-button": "^0.25.3",
|
|
27
|
-
"@things-factory/form-ui": "^4.3.
|
|
28
|
-
"@things-factory/grist-ui": "^4.3.
|
|
29
|
-
"@things-factory/i18n-base": "^4.3.
|
|
30
|
-
"@things-factory/layout-base": "^4.3.
|
|
31
|
-
"@things-factory/more-base": "^4.3.
|
|
32
|
-
"@things-factory/setting-base": "^4.3.
|
|
33
|
-
"@things-factory/styles": "^4.3.
|
|
34
|
-
"@things-factory/utils": "^4.3.
|
|
27
|
+
"@things-factory/form-ui": "^4.3.142",
|
|
28
|
+
"@things-factory/grist-ui": "^4.3.142",
|
|
29
|
+
"@things-factory/i18n-base": "^4.3.142",
|
|
30
|
+
"@things-factory/layout-base": "^4.3.142",
|
|
31
|
+
"@things-factory/more-base": "^4.3.142",
|
|
32
|
+
"@things-factory/setting-base": "^4.3.142",
|
|
33
|
+
"@things-factory/styles": "^4.3.142",
|
|
34
|
+
"@things-factory/utils": "^4.3.142"
|
|
35
35
|
},
|
|
36
|
-
"gitHead": "
|
|
36
|
+
"gitHead": "1698c58d948310a02ad506564f90e71d776943f4"
|
|
37
37
|
}
|