@operato/scene-grist 2.0.0-alpha.6 → 2.0.0-beta.0

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.
@@ -3,6 +3,7 @@
3
3
  *
4
4
  * grist 컴포넌트를 보조하여 grist의 각종 동작을 수행하는 컴포넌트.
5
5
  */
6
+ import 'ses'
6
7
 
7
8
  import { Component, ComponentNature, Properties, RectPath, ValueHolder } from '@hatiolab/things-scene'
8
9
  import { DataGrist } from '@operato/data-grist'
@@ -17,7 +18,8 @@ export enum ACTIONS {
17
18
  GET_DIRTY = 'getDirtyRows',
18
19
  ADD_ROW = 'addRow',
19
20
  DELETE_SELECTED_ROWS = 'deleteSelectedRowsSoftly',
20
- GET_PAGE_INFO = 'getPageInfo'
21
+ GET_PAGE_INFO = 'getPageInfo',
22
+ GET_LIST_PARAM = 'getListParam'
21
23
  }
22
24
 
23
25
  const NATURE: ComponentNature = {
@@ -46,6 +48,11 @@ const NATURE: ComponentNature = {
46
48
  display: 'Get page information',
47
49
  value: ACTIONS.GET_PAGE_INFO
48
50
  },
51
+ {
52
+ // 페이지네이션 정보 가져오기
53
+ display: 'Get ListParam',
54
+ value: ACTIONS.GET_LIST_PARAM
55
+ },
49
56
  {
50
57
  // 모든 레코드 데이터 가져오기
51
58
  display: 'Get all rows',
@@ -141,6 +148,16 @@ export default class GristAction extends ValueHolder(RectPath(Component)) {
141
148
  this.data = this.getPageInfoFrom(null, fetchedData)
142
149
  this.doDataMap()
143
150
  }
151
+ } else if (after.action == ACTIONS.GET_LIST_PARAM) {
152
+ gristComponent.beforeFetchFuncs[refid] = (fetchedData: {
153
+ page: number
154
+ limit: number
155
+ total: number
156
+ records: GristRecord[]
157
+ }) => {
158
+ this.data = this.getListParamFrom(null, fetchedData)
159
+ this.doDataMap()
160
+ }
144
161
  } else {
145
162
  delete gristComponent.beforeFetchFuncs[refid]
146
163
  }
@@ -194,10 +211,11 @@ export default class GristAction extends ValueHolder(RectPath(Component)) {
194
211
  case ACTIONS.ADD_ROW:
195
212
  {
196
213
  var records = grist.dirtyData.records || []
214
+ const c = new Compartment()
197
215
 
198
216
  let recordFormat
199
217
  try {
200
- recordFormat = eval(`(${this.state.recordFormat})`)
218
+ recordFormat = c.evaluate(`(${this.state.recordFormat})`)
201
219
  } catch (e) {
202
220
  console.log('Invalid JSON format. It will be assumed as empty object.\n', e)
203
221
  recordFormat = {}
@@ -223,6 +241,9 @@ export default class GristAction extends ValueHolder(RectPath(Component)) {
223
241
  case ACTIONS.GET_PAGE_INFO:
224
242
  data = this.getPageInfoFrom(grist)
225
243
  break
244
+ case ACTIONS.GET_LIST_PARAM:
245
+ data = this.getListParamFrom(grist)
246
+ break
226
247
  }
227
248
 
228
249
  // 이 컴포넌트의 data 값이 바뀌는 동작은 데이터 매핑까지 실행함
@@ -292,6 +313,38 @@ export default class GristAction extends ValueHolder(RectPath(Component)) {
292
313
  }
293
314
  }
294
315
 
316
+ // Grist로부터 ListParam 정보를 가져옴
317
+ getListParamFrom(grist: DataGrist | null, fetchedData?: GristData) {
318
+ var {
319
+ page = 1,
320
+ limit = 20,
321
+ sorters,
322
+ sortings,
323
+ filters = [],
324
+ inherited,
325
+ options
326
+ // @ts-ignore
327
+ } = fetchedData || (grist && grist.dataProvider) || pagination(grist!)
328
+
329
+ return {
330
+ pagination: { page, limit },
331
+ sortings: sorters || sortings,
332
+ filters,
333
+ inherited,
334
+ options
335
+ }
336
+
337
+ function pagination(grist: DataGrist) {
338
+ var config = grist && grist.config && grist.config.pagination
339
+ if (config)
340
+ return {
341
+ page: config.page,
342
+ limit: config.limit || (config.pages && config.pages[0])
343
+ }
344
+ else return {}
345
+ }
346
+ }
347
+
295
348
  // 레코드들을 서버 공통 resolver에 맞는 포맷으로 만듦
296
349
  buildPatches(patches: GristRecord[]): GristRecord[] {
297
350
  return patches.map(patch => {
@@ -345,7 +398,7 @@ export default class GristAction extends ValueHolder(RectPath(Component)) {
345
398
 
346
399
  get targetGristComponent(): SceneGrist {
347
400
  var { target } = this.state
348
- return this.root.findById(target) as SceneGrist
401
+ return target && (this.root.findById(target) as SceneGrist)
349
402
  }
350
403
 
351
404
  get targetGristElement(): DataGrist | undefined {
package/src/grist.ts CHANGED
@@ -2,10 +2,13 @@
2
2
  * Copyright © HatioLab Inc. All rights reserved.
3
3
  */
4
4
 
5
- import '@operato/data-grist'
5
+ import 'ses'
6
+ import '@operato/data-grist/ox-grist.js'
7
+ import '@operato/data-grist/ox-filters-form.js'
6
8
 
7
9
  import { Component, ComponentNature, error, HTMLOverlayElement, Properties } from '@hatiolab/things-scene'
8
10
  import { DataGrist, FetchResult } from '@operato/data-grist'
11
+ import { i18next as _i18next } from '@operato/i18n'
9
12
  import { FetchOption } from '@operato/data-grist/dist/src/types'
10
13
 
11
14
  const NATURE: ComponentNature = {
@@ -43,6 +46,11 @@ const NATURE: ComponentNature = {
43
46
  label: 'config',
44
47
  name: 'config'
45
48
  },
49
+ {
50
+ type: 'checkbox',
51
+ label: 'filterable',
52
+ name: 'filterable'
53
+ },
46
54
  {
47
55
  type: 'checkbox',
48
56
  label: 'appendable',
@@ -127,8 +135,6 @@ export default class SceneGrist extends HTMLOverlayElement {
127
135
  super.createElement()
128
136
 
129
137
  this.grist = document.createElement('ox-grist') as DataGrist
130
- this.grist.style.setProperty('--grist-padding', '0')
131
-
132
138
  this.element.appendChild(this.grist)
133
139
 
134
140
  this.rescale()
@@ -137,8 +143,18 @@ export default class SceneGrist extends HTMLOverlayElement {
137
143
 
138
144
  this.setGristConfig(grist)
139
145
 
140
- grist.fetchHandler = async ({ page, limit, sorters, options }: FetchOption): Promise<FetchResult> => {
141
- Object.values(this.beforeFetchFuncs).forEach((func: any) => func({ page, limit, sorters, options }))
146
+ grist.fetchHandler = async ({
147
+ page,
148
+ limit,
149
+ sorters,
150
+ sortings,
151
+ filters,
152
+ inherited,
153
+ options
154
+ }: FetchOption): Promise<FetchResult> => {
155
+ Object.values(this.beforeFetchFuncs).forEach((func: any) =>
156
+ func({ page, limit, sorters, sortings, filters, inherited, options })
157
+ )
142
158
  var { total = 0, records = [] } = grist.data || {}
143
159
 
144
160
  return {
@@ -198,7 +214,13 @@ export default class SceneGrist extends HTMLOverlayElement {
198
214
  onchange(after: Properties, before: Properties) {
199
215
  super.onchange(after, before)
200
216
 
201
- if ('mode' in after || 'appendable' in after || 'paginatable' in after || 'config' in after) {
217
+ if (
218
+ 'mode' in after ||
219
+ 'filterable' in after ||
220
+ 'appendable' in after ||
221
+ 'paginatable' in after ||
222
+ 'config' in after
223
+ ) {
202
224
  this.setGristConfig(this.grist)
203
225
  }
204
226
 
@@ -226,7 +248,7 @@ export default class SceneGrist extends HTMLOverlayElement {
226
248
  return
227
249
  }
228
250
 
229
- var { mode } = this.state
251
+ var { mode, filterable } = this.state
230
252
 
231
253
  if (mode != 'DEVICE') {
232
254
  grist.mode = mode
@@ -235,6 +257,16 @@ export default class SceneGrist extends HTMLOverlayElement {
235
257
  }
236
258
 
237
259
  grist.config = this.config
260
+
261
+ grist.innerHTML = filterable
262
+ ? `
263
+ <div slot="headroom">
264
+ <div style="padding: 9px 9px 0px 9px;">
265
+ <ox-filters-form autofocus></ox-filters-form>
266
+ </div>
267
+ </div>
268
+ `
269
+ : ''
238
270
  }
239
271
 
240
272
  /*
@@ -276,7 +308,12 @@ export default class SceneGrist extends HTMLOverlayElement {
276
308
 
277
309
  if (typeof config !== 'object') {
278
310
  try {
279
- config = eval(`(${config})`)
311
+ const c = new Compartment({
312
+ t: _i18next.t,
313
+ i18next: _i18next
314
+ })
315
+
316
+ config = c.evaluate(`(${config})`)
280
317
  } catch (e) {
281
318
  error(e)
282
319
  }
@@ -9,6 +9,7 @@
9
9
  "label.run-at-startup": "run at startup",
10
10
  "label.record-adder-format": "default when adding row",
11
11
  "label.appendable": "appendable",
12
+ "label.filterable": "filterable",
12
13
  "label.paginatable": "paginatable",
13
14
  "label.bound-data": "bound data"
14
15
  }
@@ -9,6 +9,7 @@
9
9
  "label.run-at-startup": "起動時に実行",
10
10
  "label.record-adder-format": "行追加時のデフォルト",
11
11
  "label.appendable": "追加可能",
12
+ "label.filterable": "フィルタ可能",
12
13
  "label.paginatable": "ページング可能",
13
14
  "label.bound-data": "バインドデータ"
14
15
  }
@@ -9,6 +9,7 @@
9
9
  "label.run-at-startup": "시작 시 실행",
10
10
  "label.record-adder-format": "행 추가 시 초기값",
11
11
  "label.appendable": "행추가 가능",
12
+ "label.filterable": "필터 가능",
12
13
  "label.paginatable": "페이지네이션",
13
14
  "label.bound-data": "연결 데이타"
14
15
  }
@@ -9,6 +9,7 @@
9
9
  "label.run-at-startup": "Jalankan ketika memulakan",
10
10
  "label.record-adder-format": "Default ketika menambah baris",
11
11
  "label.appendable": "Boleh ditambah",
12
+ "label.filterable": "boleh ditapis",
12
13
  "label.paginatable": "Boleh dipaginasi",
13
14
  "label.bound-data": "Data Terikat"
14
15
  }
@@ -9,6 +9,7 @@
9
9
  "label.run-at-startup": "启动时运行",
10
10
  "label.record-adder-format": "添加行时的默认值",
11
11
  "label.appendable": "可追加",
12
+ "label.filterable": "可过滤",
12
13
  "label.paginatable": "可分页",
13
14
  "label.bound-data": "绑定数据"
14
15
  }
package/tsconfig.json CHANGED
@@ -7,6 +7,7 @@
7
7
  "lib": ["es2019", "dom"],
8
8
  "strict": true,
9
9
  "esModuleInterop": false,
10
+ "allowJs": true,
10
11
  "allowSyntheticDefaultImports": true,
11
12
  "experimentalDecorators": true,
12
13
  "importHelpers": true,