@operato/app 1.0.0-beta.8 → 1.0.1

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.
Files changed (113) hide show
  1. package/CHANGELOG.md +378 -0
  2. package/demo/data-grist-test.html +1 -1
  3. package/dist/src/filters-form/filter-resource-select.d.ts +4 -0
  4. package/dist/src/filters-form/filter-resource-select.js +78 -0
  5. package/dist/src/filters-form/filter-resource-select.js.map +1 -0
  6. package/dist/src/{grist → filters-form}/index.d.ts +0 -0
  7. package/dist/src/filters-form/index.js +5 -0
  8. package/dist/src/filters-form/index.js.map +1 -0
  9. package/dist/src/grist-editor/index.js +1 -9
  10. package/dist/src/grist-editor/index.js.map +1 -1
  11. package/dist/src/grist-editor/ox-grist-editor-resource-object-legacy.d.ts +10 -0
  12. package/dist/src/grist-editor/ox-grist-editor-resource-object-legacy.js +99 -0
  13. package/dist/src/grist-editor/ox-grist-editor-resource-object-legacy.js.map +1 -0
  14. package/dist/src/grist-editor/ox-grist-editor-resource-object.d.ts +0 -1
  15. package/dist/src/grist-editor/ox-grist-editor-resource-object.js +7 -12
  16. package/dist/src/grist-editor/ox-grist-editor-resource-object.js.map +1 -1
  17. package/dist/src/grist-editor/ox-grist-renderer-crontab.js +3 -3
  18. package/dist/src/grist-editor/ox-grist-renderer-crontab.js.map +1 -1
  19. package/dist/src/grist-editor/ox-grist-renderer-resource-id.js +5 -2
  20. package/dist/src/grist-editor/ox-grist-renderer-resource-id.js.map +1 -1
  21. package/dist/src/grist-editor/ox-popup-code-input.js +5 -4
  22. package/dist/src/grist-editor/ox-popup-code-input.js.map +1 -1
  23. package/dist/src/grist-editor/ox-selector-resource-id.js +5 -4
  24. package/dist/src/grist-editor/ox-selector-resource-id.js.map +1 -1
  25. package/dist/src/grist-editor/ox-selector-resource-object-adv.d.ts +36 -0
  26. package/dist/src/grist-editor/ox-selector-resource-object-adv.js +270 -0
  27. package/dist/src/grist-editor/ox-selector-resource-object-adv.js.map +1 -0
  28. package/dist/src/grist-editor/ox-selector-resource-object-legacy.d.ts +39 -0
  29. package/dist/src/grist-editor/ox-selector-resource-object-legacy.js +351 -0
  30. package/dist/src/grist-editor/ox-selector-resource-object-legacy.js.map +1 -0
  31. package/dist/src/grist-editor/ox-selector-resource-object.d.ts +1 -5
  32. package/dist/src/grist-editor/ox-selector-resource-object.js +70 -146
  33. package/dist/src/grist-editor/ox-selector-resource-object.js.map +1 -1
  34. package/dist/src/input/ox-input-background-pattern.d.ts +3 -0
  35. package/dist/src/input/ox-input-background-pattern.js +35 -7
  36. package/dist/src/input/ox-input-background-pattern.js.map +1 -1
  37. package/dist/src/input/ox-input-fill-style.d.ts +4 -2
  38. package/dist/src/input/ox-input-fill-style.js +13 -7
  39. package/dist/src/input/ox-input-fill-style.js.map +1 -1
  40. package/dist/src/input/ox-input-graphql.d.ts +1 -1
  41. package/dist/src/input/ox-input-graphql.js +7 -7
  42. package/dist/src/input/ox-input-graphql.js.map +1 -1
  43. package/dist/src/property-editor/index.d.ts +2 -1
  44. package/dist/src/property-editor/index.js +5 -2
  45. package/dist/src/property-editor/index.js.map +1 -1
  46. package/dist/src/property-editor/ox-property-editor-graphql.d.ts +2 -2
  47. package/dist/src/property-editor/ox-property-editor-graphql.js +4 -4
  48. package/dist/src/property-editor/ox-property-editor-graphql.js.map +1 -1
  49. package/dist/tsconfig.tsbuildinfo +1 -1
  50. package/package.json +25 -30
  51. package/src/filters-form/filter-resource-select.ts +94 -0
  52. package/src/filters-form/index.ts +6 -0
  53. package/src/grist-editor/index.ts +1 -9
  54. package/src/grist-editor/ox-grist-editor-resource-object-legacy.ts +123 -0
  55. package/src/grist-editor/ox-grist-editor-resource-object.ts +17 -13
  56. package/src/grist-editor/ox-grist-renderer-crontab.ts +5 -4
  57. package/src/grist-editor/ox-grist-renderer-resource-id.ts +6 -2
  58. package/src/grist-editor/ox-popup-code-input.ts +5 -4
  59. package/src/grist-editor/ox-selector-resource-id.ts +5 -4
  60. package/src/grist-editor/ox-selector-resource-object-legacy.ts +360 -0
  61. package/src/grist-editor/ox-selector-resource-object.ts +71 -160
  62. package/src/input/ox-input-background-pattern.ts +37 -7
  63. package/src/input/ox-input-fill-style.ts +18 -8
  64. package/src/input/ox-input-graphql.ts +8 -8
  65. package/src/property-editor/index.ts +5 -2
  66. package/src/property-editor/ox-property-editor-graphql.ts +5 -4
  67. package/dist/src/grist/id-input.d.ts +0 -19
  68. package/dist/src/grist/id-input.js +0 -119
  69. package/dist/src/grist/id-input.js.map +0 -1
  70. package/dist/src/grist/id-renderer.d.ts +0 -2
  71. package/dist/src/grist/id-renderer.js +0 -9
  72. package/dist/src/grist/id-renderer.js.map +0 -1
  73. package/dist/src/grist/id-selector.d.ts +0 -23
  74. package/dist/src/grist/id-selector.js +0 -197
  75. package/dist/src/grist/id-selector.js.map +0 -1
  76. package/dist/src/grist/index.js +0 -7
  77. package/dist/src/grist/index.js.map +0 -1
  78. package/dist/src/grist-editor/ox-grist-editor-crontab.d.ts +0 -8
  79. package/dist/src/grist-editor/ox-grist-editor-crontab.js +0 -50
  80. package/dist/src/grist-editor/ox-grist-editor-crontab.js.map +0 -1
  81. package/dist/src/grist-editor/ox-grist-editor-parameters.d.ts +0 -12
  82. package/dist/src/grist-editor/ox-grist-editor-parameters.js +0 -84
  83. package/dist/src/grist-editor/ox-grist-editor-parameters.js.map +0 -1
  84. package/dist/src/grist-editor/ox-grist-editor-partition-keys.d.ts +0 -11
  85. package/dist/src/grist-editor/ox-grist-editor-partition-keys.js +0 -74
  86. package/dist/src/grist-editor/ox-grist-editor-partition-keys.js.map +0 -1
  87. package/dist/src/grist-editor/ox-grist-editor-value-map.d.ts +0 -11
  88. package/dist/src/grist-editor/ox-grist-editor-value-map.js +0 -74
  89. package/dist/src/grist-editor/ox-grist-editor-value-map.js.map +0 -1
  90. package/dist/src/grist-editor/ox-parameters-builder.d.ts +0 -4
  91. package/dist/src/grist-editor/ox-parameters-builder.js +0 -118
  92. package/dist/src/grist-editor/ox-parameters-builder.js.map +0 -1
  93. package/dist/src/grist-editor/ox-popup-crontab-input.d.ts +0 -11
  94. package/dist/src/grist-editor/ox-popup-crontab-input.js +0 -74
  95. package/dist/src/grist-editor/ox-popup-crontab-input.js.map +0 -1
  96. package/dist/src/grist-editor/ox-popup-parameters-builder.d.ts +0 -13
  97. package/dist/src/grist-editor/ox-popup-parameters-builder.js +0 -111
  98. package/dist/src/grist-editor/ox-popup-parameters-builder.js.map +0 -1
  99. package/dist/src/grist-editor/ox-popup-partition-keys-input.d.ts +0 -12
  100. package/dist/src/grist-editor/ox-popup-partition-keys-input.js +0 -98
  101. package/dist/src/grist-editor/ox-popup-partition-keys-input.js.map +0 -1
  102. package/dist/src/grist-editor/ox-popup-value-map-input.d.ts +0 -12
  103. package/dist/src/grist-editor/ox-popup-value-map-input.js +0 -104
  104. package/dist/src/grist-editor/ox-popup-value-map-input.js.map +0 -1
  105. package/src/grist-editor/ox-grist-editor-crontab.ts +0 -62
  106. package/src/grist-editor/ox-grist-editor-parameters.ts +0 -99
  107. package/src/grist-editor/ox-grist-editor-partition-keys.ts +0 -86
  108. package/src/grist-editor/ox-grist-editor-value-map.ts +0 -86
  109. package/src/grist-editor/ox-parameters-builder.ts +0 -128
  110. package/src/grist-editor/ox-popup-crontab-input.ts +0 -74
  111. package/src/grist-editor/ox-popup-parameters-builder.ts +0 -106
  112. package/src/grist-editor/ox-popup-partition-keys-input.ts +0 -95
  113. package/src/grist-editor/ox-popup-value-map-input.ts +0 -101
@@ -0,0 +1,360 @@
1
+ import '@operato/data-grist'
2
+ import '@operato/form/ox-search-form.js'
3
+
4
+ import gql from 'graphql-tag'
5
+ import { css, html, LitElement } from 'lit'
6
+ import { customElement, property, query } from 'lit/decorators.js'
7
+
8
+ import {
9
+ ColumnConfig,
10
+ DataGrist,
11
+ FetchHandler,
12
+ FetchOption,
13
+ GristData,
14
+ GristEventHandler,
15
+ GristRecord,
16
+ ZERO_DATA
17
+ } from '@operato/data-grist'
18
+ import { MultiColumnFormStyles, SearchForm } from '@operato/form'
19
+ import { buildArgs, client, gqlContext } from '@operato/graphql'
20
+ import { i18next } from '@operato/i18n'
21
+ import { closePopup } from '@operato/popup'
22
+ import { isMobileDevice } from '@operato/utils'
23
+
24
+ @customElement('ox-selector-resource-object-legacy')
25
+ export class OxSelectorResourceObjectLegacy extends LitElement {
26
+ static styles = [
27
+ MultiColumnFormStyles,
28
+ css`
29
+ :host {
30
+ display: flex;
31
+ flex-direction: column;
32
+
33
+ background-color: #fff;
34
+ }
35
+
36
+ ox-grist {
37
+ flex: 1;
38
+ }
39
+
40
+ .button-container {
41
+ display: flex;
42
+ margin-left: auto;
43
+ }
44
+
45
+ form {
46
+ position: relative;
47
+ }
48
+
49
+ [search] {
50
+ position: absolute;
51
+ right: 0;
52
+ }
53
+ `
54
+ ]
55
+
56
+ @property({ type: String }) value?: string
57
+ @property({ type: Object }) config: any
58
+ @property({ type: Object }) data: GristData = ZERO_DATA
59
+ @property({ type: String }) queryName!: string
60
+ @property({ type: Object }) basicArgs: any
61
+ @property({ type: Object }) confirmCallback?: (record?: GristRecord | null) => void
62
+ @property({ type: Array }) selectedRecords: GristRecord[] = []
63
+
64
+ @property({ type: Array }) searchFields: any
65
+ @property({ type: Array }) select: {
66
+ type: string
67
+ name: string
68
+ header: string
69
+ subFields?: string[]
70
+ hidden: boolean
71
+ ignoreCondition: boolean
72
+ queryName: string
73
+ width: number
74
+ }[] = []
75
+ @property({ type: Object }) list: any
76
+ @property({ type: String }) valueField: string | ((item: any) => any) = 'id'
77
+
78
+ @query('ox-grist') grist!: DataGrist
79
+ @query('ox-search-form') searchForm!: SearchForm
80
+
81
+ render() {
82
+ return html`
83
+ <ox-search-form
84
+ id="search-form"
85
+ @keypress=${(e: KeyboardEvent) => {
86
+ if (e.key === 'Enter') {
87
+ this.grist.fetch()
88
+ }
89
+ }}
90
+ @submit=${(e: SubmitEvent) => this.grist.fetch()}
91
+ .fields=${this.searchFields}
92
+ autofocus
93
+ ></ox-search-form>
94
+
95
+ <ox-grist
96
+ .mode=${isMobileDevice() ? 'LIST' : 'GRID'}
97
+ .config=${this.config}
98
+ .data=${this.data}
99
+ .fetchHandler=${this.fetchHandler.bind(this)}
100
+ .selectedRecords=${this.selectedRecords}
101
+ >
102
+ <div slot="headroom" id="headroom">
103
+ <div id="filters">
104
+ <ox-filters-form></ox-filters-form>
105
+ </div>
106
+ </div>
107
+ </ox-grist>
108
+
109
+ <div class="button-container">
110
+ <mwc-button @click=${this.onempty.bind(this)}>${i18next.t('button.empty')}</mwc-button>
111
+ <mwc-button @click=${this.oncancel.bind(this)}>${i18next.t('button.cancel')}</mwc-button>
112
+ <mwc-button @click=${this.onconfirm.bind(this)}>${i18next.t('button.confirm')}</mwc-button>
113
+ </div>
114
+ `
115
+ }
116
+
117
+ onempty() {
118
+ this.confirmCallback && this.confirmCallback()
119
+ closePopup(this)
120
+ }
121
+
122
+ oncancel() {
123
+ closePopup(this)
124
+ }
125
+
126
+ onconfirm() {
127
+ this.confirmCallback && this.confirmCallback(this.selected)
128
+ closePopup(this)
129
+ }
130
+
131
+ fetchHandler: FetchHandler = async ({ filters, page, limit, sorters = [] }) => {
132
+ const response = await client.query({
133
+ query: gql`
134
+ query {
135
+ fetch: ${this.queryName} (${buildArgs(await this._buildConditions({ filters, page, limit, sorters }))}) {
136
+ ${this.getSelectFields()}
137
+ }
138
+ }
139
+ `,
140
+ context: gqlContext()
141
+ })
142
+
143
+ if (!response.errors) {
144
+ const records = response.data.fetch.items.map((item: any) => {
145
+ let rowValue
146
+
147
+ if (this.valueField && typeof this.valueField === 'function') {
148
+ rowValue = this.valueField(item)
149
+ } else if (this.valueField) {
150
+ rowValue = item[this.valueField]
151
+ } else {
152
+ rowValue = item.id
153
+ }
154
+
155
+ if (this.value && this.value === rowValue) {
156
+ this.selectedRecords = [item]
157
+ item['__selected__'] = true
158
+ }
159
+
160
+ return item
161
+ })
162
+ const total = response.data.fetch.total
163
+
164
+ return {
165
+ records,
166
+ total,
167
+ limit,
168
+ page
169
+ }
170
+ }
171
+ }
172
+
173
+ async firstUpdated() {
174
+ this.config = {
175
+ columns: [
176
+ {
177
+ type: 'gutter',
178
+ gutterName: 'sequence'
179
+ },
180
+ {
181
+ type: 'gutter',
182
+ gutterName: 'row-selector',
183
+ multiple: false
184
+ }
185
+ ],
186
+ rows: {
187
+ selectable: {
188
+ multiple: false
189
+ },
190
+ handlers: {
191
+ click: 'select-row',
192
+ dblclick: ((columns, data, column, record, rowIndex, field) => {
193
+ this.onconfirm()
194
+ }) as GristEventHandler
195
+ },
196
+ appendable: false
197
+ }
198
+ }
199
+
200
+ if (this.select && this.select.length > 0) {
201
+ let _searchFields = this.select.filter(selectField => !selectField.hidden && !selectField.ignoreCondition)
202
+ if (this.list && this.list.fields && this.list.fields.length > 0) {
203
+ _searchFields = _searchFields.filter(searchField => this.list.fields.indexOf(searchField.name) >= 0)
204
+ } else {
205
+ _searchFields = _searchFields.slice(0, 4)
206
+ }
207
+
208
+ this.searchFields = _searchFields.map(selectField => {
209
+ const fieldType = (selectField.type && selectField.type.toLowerCase()) || 'string'
210
+ const numberTypes = ['integer', 'float']
211
+ return {
212
+ label: selectField.header || i18next.t(`field.${selectField.name}`),
213
+ name: selectField.name,
214
+ type:
215
+ fieldType === 'string'
216
+ ? 'text'
217
+ : numberTypes.indexOf(fieldType) >= 0
218
+ ? 'number'
219
+ : fieldType === 'boolean'
220
+ ? 'checkbox'
221
+ : fieldType,
222
+ queryName: selectField.queryName,
223
+ props:
224
+ fieldType === 'string'
225
+ ? { searchOper: 'i_like' }
226
+ : fieldType === 'object'
227
+ ? { searchOper: 'in' }
228
+ : { searchOper: 'eq' },
229
+ attrs: fieldType === 'boolean' ? ['indeterminated'] : []
230
+ }
231
+ })
232
+ this.config = {
233
+ ...this.config,
234
+ columns: [
235
+ ...this.config.columns,
236
+ ...this.select.map(selectField => {
237
+ return {
238
+ ...selectField,
239
+ type: selectField.type || 'string',
240
+ width: selectField.width || 160,
241
+ header: selectField.header || i18next.t(`field.${selectField.name}`)
242
+ }
243
+ })
244
+ ]
245
+ }
246
+ } else {
247
+ this.searchFields = [
248
+ {
249
+ label: i18next.t('field.name'),
250
+ name: 'name',
251
+ type: 'text',
252
+ props: { searchOper: 'i_like' }
253
+ },
254
+ {
255
+ label: i18next.t('field.description'),
256
+ name: 'description',
257
+ type: 'text',
258
+ props: { searchOper: 'i_like' }
259
+ }
260
+ ]
261
+
262
+ this.config = {
263
+ ...this.config,
264
+ columns: [
265
+ ...this.config.columns,
266
+ {
267
+ type: 'string',
268
+ name: 'id',
269
+ header: i18next.t('field.id'),
270
+ hidden: true
271
+ },
272
+ {
273
+ type: 'string',
274
+ name: 'name',
275
+ header: i18next.t('field.name'),
276
+ record: {
277
+ align: 'left'
278
+ },
279
+ sortable: true,
280
+ width: 160
281
+ },
282
+ {
283
+ type: 'string',
284
+ name: 'description',
285
+ header: i18next.t('field.description'),
286
+ record: {
287
+ align: 'left'
288
+ },
289
+ sortable: true,
290
+ width: 300
291
+ }
292
+ ]
293
+ }
294
+ }
295
+
296
+ this.config = {
297
+ ...this.config,
298
+ list: {
299
+ ...this.list,
300
+ fields:
301
+ this.list && this.list.fields && this.list.fields.length > 0
302
+ ? this.list.fields
303
+ : (this.config.columns as ColumnConfig[])
304
+ .filter(column => column.type !== 'gutter')
305
+ .slice(0, 3)
306
+ .map(column => column.name)
307
+ }
308
+ }
309
+
310
+ await this.updateComplete
311
+ this.grist && this.grist.focus()
312
+ }
313
+
314
+ getSelectFields() {
315
+ if (this.select && this.select.length > 0) {
316
+ return `items {
317
+ ${this.select.map(selectField => {
318
+ return selectField.type === 'object'
319
+ ? `${selectField.name} { ${
320
+ selectField.subFields && selectField.subFields.length > 0
321
+ ? selectField.subFields.join(' ')
322
+ : `id name description`
323
+ } }`
324
+ : `${selectField.name}`
325
+ })}
326
+ }
327
+ total`
328
+ } else {
329
+ return `
330
+ items {
331
+ id
332
+ name
333
+ description
334
+ }
335
+ total
336
+ `
337
+ }
338
+ }
339
+
340
+ async _buildConditions({ filters, page, limit, sorters }: FetchOption) {
341
+ const queryConditions = {
342
+ filters: [],
343
+ ...this.basicArgs
344
+ }
345
+
346
+ queryConditions.filters = [...queryConditions.filters, ...(await this.searchForm.getQueryFilters())]
347
+ queryConditions.pagination = { page, limit }
348
+ queryConditions.sortings = sorters
349
+
350
+ return queryConditions
351
+ }
352
+
353
+ get selected() {
354
+ var grist = this.renderRoot.querySelector('ox-grist') as DataGrist
355
+
356
+ var selected = grist.selected
357
+
358
+ return selected && selected.length > 0 ? selected[0] : undefined
359
+ }
360
+ }
@@ -1,53 +1,46 @@
1
1
  import '@operato/data-grist'
2
- import '@operato/form/ox-search-form.js'
3
2
 
4
3
  import gql from 'graphql-tag'
5
4
  import { css, html, LitElement } from 'lit'
6
5
  import { customElement, property, query } from 'lit/decorators.js'
7
6
 
8
- import {
9
- ColumnConfig,
10
- DataGrist,
11
- FetchHandler,
12
- FetchOption,
13
- GristData,
14
- GristEventHandler,
15
- GristRecord,
16
- ZERO_DATA
17
- } from '@operato/data-grist'
18
- import { MultiColumnFormStyles, SearchForm } from '@operato/form'
19
- import { buildArgs, client, gqlContext } from '@operato/graphql'
7
+ import { DataGrist, FetchHandler, GristData, GristEventHandler, GristRecord, ZERO_DATA } from '@operato/data-grist'
8
+ import { client, gqlContext } from '@operato/graphql'
20
9
  import { i18next } from '@operato/i18n'
21
- import { isMobileDevice } from '@operato/utils'
10
+ import { closePopup } from '@operato/popup'
11
+ import { adjustFilters, isMobileDevice } from '@operato/utils'
22
12
 
23
13
  @customElement('ox-selector-resource-object')
24
14
  export class OxSelectorResourceObject extends LitElement {
25
15
  static styles = [
26
- MultiColumnFormStyles,
27
16
  css`
28
17
  :host {
29
18
  display: flex;
30
19
  flex-direction: column;
31
20
 
32
21
  background-color: #fff;
22
+
23
+ width: var(--overlay-center-normal-width, 50%);
24
+ height: var(--overlay-center-normal-height, 50%);
33
25
  }
34
26
 
35
27
  ox-grist {
36
28
  flex: 1;
37
29
  }
38
30
 
39
- .button-container {
31
+ #filters {
40
32
  display: flex;
41
- margin-left: auto;
33
+ flex-direction: row;
34
+ justify-content: space-between;
42
35
  }
43
36
 
44
- form {
45
- position: relative;
37
+ #filters > * {
38
+ padding: var(--padding-default) var(--padding-wide);
46
39
  }
47
40
 
48
- [search] {
49
- position: absolute;
50
- right: 0;
41
+ .button-container {
42
+ display: flex;
43
+ margin-left: auto;
51
44
  }
52
45
  `
53
46
  ]
@@ -75,28 +68,20 @@ export class OxSelectorResourceObject extends LitElement {
75
68
  @property({ type: String }) valueField: string | ((item: any) => any) = 'id'
76
69
 
77
70
  @query('ox-grist') grist!: DataGrist
78
- @query('ox-search-form') searchForm!: SearchForm
79
71
 
80
72
  render() {
81
73
  return html`
82
- <ox-search-form
83
- id="search-form"
84
- @keypress=${(e: KeyboardEvent) => {
85
- if (e.key === 'Enter') {
86
- this.grist.fetch()
87
- }
88
- }}
89
- @submit=${(e: SubmitEvent) => this.grist.fetch()}
90
- .fields=${this.searchFields}
91
- ></ox-search-form>
92
-
93
74
  <ox-grist
94
75
  .mode=${isMobileDevice() ? 'LIST' : 'GRID'}
95
76
  .config=${this.config}
96
77
  .data=${this.data}
97
78
  .fetchHandler=${this.fetchHandler.bind(this)}
98
79
  .selectedRecords=${this.selectedRecords}
99
- ></ox-grist>
80
+ >
81
+ <div id="filters" slot="headroom">
82
+ <ox-filters-form autofocus></ox-filters-form>
83
+ </div>
84
+ </ox-grist>
100
85
 
101
86
  <div class="button-container">
102
87
  <mwc-button @click=${this.onempty.bind(this)}>${i18next.t('button.empty')}</mwc-button>
@@ -108,27 +93,33 @@ export class OxSelectorResourceObject extends LitElement {
108
93
 
109
94
  onempty() {
110
95
  this.confirmCallback && this.confirmCallback()
111
- history.back()
96
+ closePopup(this)
112
97
  }
113
98
 
114
99
  oncancel() {
115
- history.back()
100
+ closePopup(this)
116
101
  }
117
102
 
118
103
  onconfirm() {
119
104
  this.confirmCallback && this.confirmCallback(this.selected)
120
- history.back()
105
+ closePopup(this)
121
106
  }
122
107
 
123
- fetchHandler: FetchHandler = async ({ filters, page, limit, sorters = [] }) => {
108
+ fetchHandler: FetchHandler = async ({ filters = [], page, limit, sortings = [] }) => {
109
+ if (this.basicArgs) {
110
+ filters = adjustFilters(filters, this.basicArgs)
111
+ }
112
+ const pagination = { page, limit }
113
+
124
114
  const response = await client.query({
125
115
  query: gql`
126
- query {
127
- fetch: ${this.queryName} (${buildArgs(await this._buildConditions({ filters, page, limit, sorters }))}) {
116
+ query($filters: [Filter!], $pagination: Pagination, $sortings: [Sorting!]) {
117
+ fetch: ${this.queryName} (filters: $filters, pagination: $pagination, sortings: $sortings) {
128
118
  ${this.getSelectFields()}
129
119
  }
130
120
  }
131
121
  `,
122
+ variables: { filters, pagination, sortings },
132
123
  context: gqlContext()
133
124
  })
134
125
 
@@ -189,118 +180,51 @@ export class OxSelectorResourceObject extends LitElement {
189
180
  }
190
181
  }
191
182
 
192
- if (this.select && this.select.length > 0) {
193
- let _searchFields = this.select.filter(selectField => !selectField.hidden && !selectField.ignoreCondition)
194
- if (this.list && this.list.fields && this.list.fields.length > 0) {
195
- _searchFields = _searchFields.filter(searchField => this.list.fields.indexOf(searchField.name) >= 0)
196
- } else {
197
- _searchFields = _searchFields.slice(0, 4)
198
- }
199
-
200
- this.searchFields = _searchFields.map(selectField => {
201
- const fieldType = (selectField.type && selectField.type.toLowerCase()) || 'string'
202
- const numberTypes = ['integer', 'float']
203
- return {
204
- label: selectField.header || i18next.t(`field.${selectField.name}`),
205
- name: selectField.name,
206
- type:
207
- fieldType === 'string'
208
- ? 'text'
209
- : numberTypes.indexOf(fieldType) >= 0
210
- ? 'number'
211
- : fieldType === 'boolean'
212
- ? 'checkbox'
213
- : fieldType,
214
- queryName: selectField.queryName,
215
- props:
216
- fieldType === 'string'
217
- ? { searchOper: 'i_like' }
218
- : fieldType === 'object'
219
- ? { searchOper: 'in' }
220
- : { searchOper: 'eq' },
221
- attrs: fieldType === 'boolean' ? ['indeterminated'] : []
222
- }
223
- })
224
- this.config = {
225
- ...this.config,
226
- columns: [
227
- ...this.config.columns,
228
- ...this.select.map(selectField => {
229
- return {
230
- ...selectField,
231
- type: selectField.type || 'string',
232
- width: selectField.width || 160,
233
- header: selectField.header || i18next.t(`field.${selectField.name}`)
234
- }
235
- })
236
- ]
237
- }
238
- } else {
239
- this.searchFields = [
240
- {
241
- label: i18next.t('field.name'),
242
- name: 'name',
243
- type: 'text',
244
- props: { searchOper: 'i_like' }
183
+ const select = this.select || [
184
+ {
185
+ type: 'string',
186
+ name: 'id',
187
+ header: i18next.t('field.id'),
188
+ hidden: true
189
+ },
190
+ {
191
+ type: 'string',
192
+ name: 'name',
193
+ header: i18next.t('field.name'),
194
+ record: {
195
+ align: 'left'
245
196
  },
246
- {
247
- label: i18next.t('field.description'),
248
- name: 'description',
249
- type: 'text',
250
- props: { searchOper: 'i_like' }
251
- }
252
- ]
253
-
254
- this.config = {
255
- ...this.config,
256
- columns: [
257
- ...this.config.columns,
258
- {
259
- type: 'string',
260
- name: 'id',
261
- header: i18next.t('field.id'),
262
- hidden: true
263
- },
264
- {
265
- type: 'string',
266
- name: 'name',
267
- header: i18next.t('field.name'),
268
- record: {
269
- align: 'left'
270
- },
271
- sortable: true,
272
- width: 160
273
- },
274
- {
275
- type: 'string',
276
- name: 'description',
277
- header: i18next.t('field.description'),
278
- record: {
279
- align: 'left'
280
- },
281
- sortable: true,
282
- width: 300
283
- }
284
- ]
197
+ sortable: true,
198
+ filter: 'search',
199
+ width: 160
200
+ },
201
+ {
202
+ type: 'string',
203
+ name: 'description',
204
+ header: i18next.t('field.description'),
205
+ record: {
206
+ align: 'left'
207
+ },
208
+ sortable: true,
209
+ filter: 'search',
210
+ width: 300
285
211
  }
286
- }
212
+ ]
287
213
 
288
214
  this.config = {
289
215
  ...this.config,
290
- list: {
291
- ...this.list,
292
- fields:
293
- this.list && this.list.fields && this.list.fields.length > 0
294
- ? this.list.fields
295
- : (this.config.columns as ColumnConfig[])
296
- .filter(column => column.type !== 'gutter')
297
- .slice(0, 3)
298
- .map(column => column.name)
299
- }
216
+ columns: [
217
+ ...this.config.columns,
218
+ ...select.map(selectField => {
219
+ return {
220
+ ...selectField,
221
+ type: selectField.type || 'string',
222
+ width: selectField.width || 160,
223
+ header: selectField.header || i18next.t(`field.${selectField.name}`)
224
+ }
225
+ })
226
+ ]
300
227
  }
301
-
302
- await this.updateComplete
303
- this.grist && this.grist.focus()
304
228
  }
305
229
 
306
230
  getSelectFields() {
@@ -329,19 +253,6 @@ export class OxSelectorResourceObject extends LitElement {
329
253
  }
330
254
  }
331
255
 
332
- async _buildConditions({ filters, page, limit, sorters }: FetchOption) {
333
- const queryConditions = {
334
- filters: [],
335
- ...this.basicArgs
336
- }
337
-
338
- queryConditions.filters = [...queryConditions.filters, ...(await this.searchForm.getQueryFilters())]
339
- queryConditions.pagination = { page, limit }
340
- queryConditions.sortings = sorters
341
-
342
- return queryConditions
343
- }
344
-
345
256
  get selected() {
346
257
  var grist = this.renderRoot.querySelector('ox-grist') as DataGrist
347
258