@operato/app 1.0.0 → 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.
@@ -1,54 +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
10
  import { closePopup } from '@operato/popup'
22
- import { isMobileDevice } from '@operato/utils'
11
+ import { adjustFilters, isMobileDevice } from '@operato/utils'
23
12
 
24
13
  @customElement('ox-selector-resource-object')
25
14
  export class OxSelectorResourceObject extends LitElement {
26
15
  static styles = [
27
- MultiColumnFormStyles,
28
16
  css`
29
17
  :host {
30
18
  display: flex;
31
19
  flex-direction: column;
32
20
 
33
21
  background-color: #fff;
22
+
23
+ width: var(--overlay-center-normal-width, 50%);
24
+ height: var(--overlay-center-normal-height, 50%);
34
25
  }
35
26
 
36
27
  ox-grist {
37
28
  flex: 1;
38
29
  }
39
30
 
40
- .button-container {
31
+ #filters {
41
32
  display: flex;
42
- margin-left: auto;
33
+ flex-direction: row;
34
+ justify-content: space-between;
43
35
  }
44
36
 
45
- form {
46
- position: relative;
37
+ #filters > * {
38
+ padding: var(--padding-default) var(--padding-wide);
47
39
  }
48
40
 
49
- [search] {
50
- position: absolute;
51
- right: 0;
41
+ .button-container {
42
+ display: flex;
43
+ margin-left: auto;
52
44
  }
53
45
  `
54
46
  ]
@@ -76,29 +68,20 @@ export class OxSelectorResourceObject extends LitElement {
76
68
  @property({ type: String }) valueField: string | ((item: any) => any) = 'id'
77
69
 
78
70
  @query('ox-grist') grist!: DataGrist
79
- @query('ox-search-form') searchForm!: SearchForm
80
71
 
81
72
  render() {
82
73
  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
74
  <ox-grist
96
75
  .mode=${isMobileDevice() ? 'LIST' : 'GRID'}
97
76
  .config=${this.config}
98
77
  .data=${this.data}
99
78
  .fetchHandler=${this.fetchHandler.bind(this)}
100
79
  .selectedRecords=${this.selectedRecords}
101
- ></ox-grist>
80
+ >
81
+ <div id="filters" slot="headroom">
82
+ <ox-filters-form autofocus></ox-filters-form>
83
+ </div>
84
+ </ox-grist>
102
85
 
103
86
  <div class="button-container">
104
87
  <mwc-button @click=${this.onempty.bind(this)}>${i18next.t('button.empty')}</mwc-button>
@@ -122,15 +105,21 @@ export class OxSelectorResourceObject extends LitElement {
122
105
  closePopup(this)
123
106
  }
124
107
 
125
- 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
+
126
114
  const response = await client.query({
127
115
  query: gql`
128
- query {
129
- 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) {
130
118
  ${this.getSelectFields()}
131
119
  }
132
120
  }
133
121
  `,
122
+ variables: { filters, pagination, sortings },
134
123
  context: gqlContext()
135
124
  })
136
125
 
@@ -191,118 +180,51 @@ export class OxSelectorResourceObject extends LitElement {
191
180
  }
192
181
  }
193
182
 
194
- if (this.select && this.select.length > 0) {
195
- let _searchFields = this.select.filter(selectField => !selectField.hidden && !selectField.ignoreCondition)
196
- if (this.list && this.list.fields && this.list.fields.length > 0) {
197
- _searchFields = _searchFields.filter(searchField => this.list.fields.indexOf(searchField.name) >= 0)
198
- } else {
199
- _searchFields = _searchFields.slice(0, 4)
200
- }
201
-
202
- this.searchFields = _searchFields.map(selectField => {
203
- const fieldType = (selectField.type && selectField.type.toLowerCase()) || 'string'
204
- const numberTypes = ['integer', 'float']
205
- return {
206
- label: selectField.header || i18next.t(`field.${selectField.name}`),
207
- name: selectField.name,
208
- type:
209
- fieldType === 'string'
210
- ? 'text'
211
- : numberTypes.indexOf(fieldType) >= 0
212
- ? 'number'
213
- : fieldType === 'boolean'
214
- ? 'checkbox'
215
- : fieldType,
216
- queryName: selectField.queryName,
217
- props:
218
- fieldType === 'string'
219
- ? { searchOper: 'i_like' }
220
- : fieldType === 'object'
221
- ? { searchOper: 'in' }
222
- : { searchOper: 'eq' },
223
- attrs: fieldType === 'boolean' ? ['indeterminated'] : []
224
- }
225
- })
226
- this.config = {
227
- ...this.config,
228
- columns: [
229
- ...this.config.columns,
230
- ...this.select.map(selectField => {
231
- return {
232
- ...selectField,
233
- type: selectField.type || 'string',
234
- width: selectField.width || 160,
235
- header: selectField.header || i18next.t(`field.${selectField.name}`)
236
- }
237
- })
238
- ]
239
- }
240
- } else {
241
- this.searchFields = [
242
- {
243
- label: i18next.t('field.name'),
244
- name: 'name',
245
- type: 'text',
246
- 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'
247
196
  },
248
- {
249
- label: i18next.t('field.description'),
250
- name: 'description',
251
- type: 'text',
252
- props: { searchOper: 'i_like' }
253
- }
254
- ]
255
-
256
- this.config = {
257
- ...this.config,
258
- columns: [
259
- ...this.config.columns,
260
- {
261
- type: 'string',
262
- name: 'id',
263
- header: i18next.t('field.id'),
264
- hidden: true
265
- },
266
- {
267
- type: 'string',
268
- name: 'name',
269
- header: i18next.t('field.name'),
270
- record: {
271
- align: 'left'
272
- },
273
- sortable: true,
274
- width: 160
275
- },
276
- {
277
- type: 'string',
278
- name: 'description',
279
- header: i18next.t('field.description'),
280
- record: {
281
- align: 'left'
282
- },
283
- sortable: true,
284
- width: 300
285
- }
286
- ]
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
287
211
  }
288
- }
212
+ ]
289
213
 
290
214
  this.config = {
291
215
  ...this.config,
292
- list: {
293
- ...this.list,
294
- fields:
295
- this.list && this.list.fields && this.list.fields.length > 0
296
- ? this.list.fields
297
- : (this.config.columns as ColumnConfig[])
298
- .filter(column => column.type !== 'gutter')
299
- .slice(0, 3)
300
- .map(column => column.name)
301
- }
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
+ ]
302
227
  }
303
-
304
- await this.updateComplete
305
- this.grist && this.grist.focus()
306
228
  }
307
229
 
308
230
  getSelectFields() {
@@ -331,19 +253,6 @@ export class OxSelectorResourceObject extends LitElement {
331
253
  }
332
254
  }
333
255
 
334
- async _buildConditions({ filters, page, limit, sorters }: FetchOption) {
335
- const queryConditions = {
336
- filters: [],
337
- ...this.basicArgs
338
- }
339
-
340
- queryConditions.filters = [...queryConditions.filters, ...(await this.searchForm.getQueryFilters())]
341
- queryConditions.pagination = { page, limit }
342
- queryConditions.sortings = sorters
343
-
344
- return queryConditions
345
- }
346
-
347
256
  get selected() {
348
257
  var grist = this.renderRoot.querySelector('ox-grist') as DataGrist
349
258