@things-factory/dataset 9.1.17 → 9.1.19
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/EXPLORATION_INDEX.md +252 -0
- package/FRONTEND_ARCHITECTURE.md +732 -0
- package/QUICK_REFERENCE.md +365 -0
- package/dist-client/pages/data-set/data-item-list.js +15 -1
- package/dist-client/pages/data-set/data-item-list.js.map +1 -1
- package/dist-client/tsconfig.tsbuildinfo +1 -1
- package/dist-server/controllers/create-data-sample.js +57 -5
- package/dist-server/controllers/create-data-sample.js.map +1 -1
- package/dist-server/service/data-set/data-item-type.d.ts +259 -0
- package/dist-server/service/data-set/data-item-type.js +259 -0
- package/dist-server/service/data-set/data-item-type.js.map +1 -1
- package/dist-server/tsconfig.tsbuildinfo +1 -1
- package/dist-server/utils/index.d.ts +1 -0
- package/dist-server/utils/index.js +1 -0
- package/dist-server/utils/index.js.map +1 -1
- package/dist-server/utils/media-validation.d.ts +51 -0
- package/dist-server/utils/media-validation.js +148 -0
- package/dist-server/utils/media-validation.js.map +1 -0
- package/package.json +12 -12
|
@@ -0,0 +1,365 @@
|
|
|
1
|
+
# Quick Reference: Frontend Component Architecture
|
|
2
|
+
|
|
3
|
+
## File Locations - Quick Lookup
|
|
4
|
+
|
|
5
|
+
### Client-Side Components (Your Repo)
|
|
6
|
+
```
|
|
7
|
+
/Users/super/Documents/GitHub/things-factory/packages/dataset/client/
|
|
8
|
+
├── components/
|
|
9
|
+
│ ├── data-entry-form.ts - Form wrapper using ox-data-entry-form
|
|
10
|
+
│ └── checklist-entry-form.ts - Checklist wrapper using ox-checklist-entry-form
|
|
11
|
+
└── activities/
|
|
12
|
+
└── activity-data-collect-edit.ts - Workflow activity entry point
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
### Server-Side Types & Utils (Your Repo)
|
|
16
|
+
```
|
|
17
|
+
/Users/super/Documents/GitHub/things-factory/packages/dataset/server/
|
|
18
|
+
├── service/data-set/
|
|
19
|
+
│ └── data-item-type.ts - DataItemType enum + media options schema
|
|
20
|
+
└── utils/
|
|
21
|
+
└── media-validation.ts - Media file validation utilities
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
### Core Components (Dependency - Node Modules)
|
|
25
|
+
```
|
|
26
|
+
@operato/dataset (in node_modules)
|
|
27
|
+
├── ox-data-entry-form.js - Main form component
|
|
28
|
+
├── ox-data-entry-subgroup-form.js - Grouped items in Grist table
|
|
29
|
+
└── ox-data-input-factory.js - Type-to-component mapping factory
|
|
30
|
+
|
|
31
|
+
@operato/input (in node_modules)
|
|
32
|
+
├── ox-input-file.js - File upload component
|
|
33
|
+
├── ox-input-image.js - Image upload component
|
|
34
|
+
├── ox-input-signature.js - Digital signature component
|
|
35
|
+
└── ox-form-field.js - Base class for all input components
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
---
|
|
39
|
+
|
|
40
|
+
## How Data Entry Works - 5 Step Flow
|
|
41
|
+
|
|
42
|
+
### Step 1: User Opens Activity
|
|
43
|
+
File: `activity-data-collect-edit.ts`
|
|
44
|
+
- Gets `dataSetId` from workflow
|
|
45
|
+
- Fetches DataSet with dataItems via GraphQL
|
|
46
|
+
|
|
47
|
+
### Step 2: OxDataEntryForm Renders
|
|
48
|
+
File: `@operato/dataset/ox-data-entry-form.js`
|
|
49
|
+
- Iterates through `dataItems.filter(item => item.active)`
|
|
50
|
+
- For grouped items: renders `ox-data-entry-subgroup-form`
|
|
51
|
+
- For non-grouped: calls `OxDataInputFactory.createInputElement()`
|
|
52
|
+
|
|
53
|
+
### Step 3: OxDataInputFactory Creates Input
|
|
54
|
+
File: `@operato/dataset/ox-data-input-factory.js`
|
|
55
|
+
- Switch statement on `dataItem.type`
|
|
56
|
+
- Currently supports: text, number, boolean, date, datetime, select, radio, file, signature
|
|
57
|
+
- **MISSING:** image, video, audio
|
|
58
|
+
|
|
59
|
+
### Step 4: User Submits Form
|
|
60
|
+
- Form collects values from all inputs by `name` attribute
|
|
61
|
+
- `buildValue()` extracts values into object: `{ [tag]: any }`
|
|
62
|
+
- GraphQL mutation sends with `context: { hasUpload: true }`
|
|
63
|
+
|
|
64
|
+
### Step 5: Server Processes Files
|
|
65
|
+
File: `create-data-sample.ts`
|
|
66
|
+
- Iterates `dataItems` looking for `isFileOrMediaType()`
|
|
67
|
+
- If media type: validates with `validateMediaFile()`
|
|
68
|
+
- Creates attachments and stores file paths in data
|
|
69
|
+
|
|
70
|
+
---
|
|
71
|
+
|
|
72
|
+
## Type Mapping (OxDataInputFactory)
|
|
73
|
+
|
|
74
|
+
### Current Types
|
|
75
|
+
```
|
|
76
|
+
'select' → <select name=${tag}> with options
|
|
77
|
+
'radio' → <label><input type="radio"> with options
|
|
78
|
+
'boolean' → <input type="checkbox">
|
|
79
|
+
'number' → <input type="number">
|
|
80
|
+
'date' → <input type="date">
|
|
81
|
+
'datetime' → <input type="datetime-local">
|
|
82
|
+
'file' → <ox-input-file multiple>
|
|
83
|
+
'signature' → <ox-input-signature>
|
|
84
|
+
'text' → <input type="text"> (default)
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
### Missing Types (Need Implementation)
|
|
88
|
+
```
|
|
89
|
+
'image' → <ox-input-image> (TO BE CREATED)
|
|
90
|
+
'video' → <ox-input-video> (TO BE CREATED)
|
|
91
|
+
'audio' → <ox-input-audio> (TO BE CREATED)
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
---
|
|
95
|
+
|
|
96
|
+
## Key Functions & Classes
|
|
97
|
+
|
|
98
|
+
### OxFormField (Base Class)
|
|
99
|
+
**Properties:**
|
|
100
|
+
- `name: string` - Form field identifier
|
|
101
|
+
- `value: T` - Field value (generic)
|
|
102
|
+
- `disabled: boolean` - Disabled state
|
|
103
|
+
|
|
104
|
+
**Methods:**
|
|
105
|
+
- `connectedCallback()` - Register with parent form
|
|
106
|
+
- `appendFormData(e: FormDataEvent)` - Add to form submission
|
|
107
|
+
|
|
108
|
+
### OxDataEntryForm
|
|
109
|
+
**Key Methods:**
|
|
110
|
+
- `buildInputs()` - Generate all input elements
|
|
111
|
+
- `buildValue()` - Extract form values as object
|
|
112
|
+
- `extractValuesFromInputs()` - Query DOM by name attribute
|
|
113
|
+
|
|
114
|
+
### OxDataInputFactory
|
|
115
|
+
**Static Methods:**
|
|
116
|
+
- `createInputElement(type, tag, value, options, idx)` - Route to correct component
|
|
117
|
+
- `mapGristType(type)` - Convert to Grist column type
|
|
118
|
+
- `getGristRecordOptions(type, options)` - Grid cell configuration
|
|
119
|
+
|
|
120
|
+
### Media Validation Utils
|
|
121
|
+
**Functions:**
|
|
122
|
+
- `validateMediaFile(file, mediaType, options)` - Main validator
|
|
123
|
+
- `isValidMimeType(mediaType, mimetype)` - Check MIME type
|
|
124
|
+
- `isAcceptedFormat(filename, acceptFormats)` - Check extension
|
|
125
|
+
- `isValidFileSize(fileSize, maxSize)` - Check size
|
|
126
|
+
- `isMediaType(type)` - Check if image/video/audio
|
|
127
|
+
|
|
128
|
+
---
|
|
129
|
+
|
|
130
|
+
## Adding New Media Components - Checklist
|
|
131
|
+
|
|
132
|
+
### 1. Create Component File
|
|
133
|
+
```
|
|
134
|
+
Location: packages/dataset/client/components/ox-input-image.ts
|
|
135
|
+
Extend: OxFormField
|
|
136
|
+
Pattern: Similar to ox-input-file
|
|
137
|
+
Methods needed:
|
|
138
|
+
- render()
|
|
139
|
+
- updated()
|
|
140
|
+
- firstUpdated()
|
|
141
|
+
- _onChangeValue()
|
|
142
|
+
- _notifyChange()
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
### 2. Update OxDataInputFactory
|
|
146
|
+
File: Update @operato/dataset source (or create wrapper)
|
|
147
|
+
Add to switch:
|
|
148
|
+
```javascript
|
|
149
|
+
case 'image': return html`<ox-input-image ...>`;
|
|
150
|
+
case 'video': return html`<ox-input-video ...>`;
|
|
151
|
+
case 'audio': return html`<ox-input-audio ...>`;
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
### 3. Add to mapGristType()
|
|
155
|
+
```javascript
|
|
156
|
+
case 'image': return 'image';
|
|
157
|
+
case 'video': return 'video';
|
|
158
|
+
case 'audio': return 'audio';
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
### 4. Add to getGristRecordOptions()
|
|
162
|
+
```javascript
|
|
163
|
+
case 'image':
|
|
164
|
+
case 'video':
|
|
165
|
+
case 'audio':
|
|
166
|
+
return { multiple: options.multiple || false };
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
### 5. Import in Components
|
|
170
|
+
```typescript
|
|
171
|
+
import '@operato/dataset/ox-input-image.js'
|
|
172
|
+
import '@operato/dataset/ox-input-video.js'
|
|
173
|
+
import '@operato/dataset/ox-input-audio.js'
|
|
174
|
+
```
|
|
175
|
+
|
|
176
|
+
---
|
|
177
|
+
|
|
178
|
+
## Component Value Extraction (Important!)
|
|
179
|
+
|
|
180
|
+
### How Form Gets Values
|
|
181
|
+
```typescript
|
|
182
|
+
// In ox-data-entry-form.js, line ~89
|
|
183
|
+
const editors = Array.from(
|
|
184
|
+
this.renderRoot.querySelectorAll(`[name=${tag}]`)
|
|
185
|
+
)
|
|
186
|
+
// Extracts value from: name="product_image"
|
|
187
|
+
```
|
|
188
|
+
|
|
189
|
+
### Why Name Attribute Matters
|
|
190
|
+
- Form values keyed by `name` attribute
|
|
191
|
+
- Must match `dataItem.tag` value
|
|
192
|
+
- All OxInput* components must set name on native input
|
|
193
|
+
|
|
194
|
+
### File Upload Special Handling
|
|
195
|
+
Files passed as: `[{ file: FileUpload }, ...]`
|
|
196
|
+
Backend converts to: `[{ id, mimetype, name, fullpath }, ...]`
|
|
197
|
+
|
|
198
|
+
---
|
|
199
|
+
|
|
200
|
+
## DataItem Configuration Examples
|
|
201
|
+
|
|
202
|
+
### Image Field Config
|
|
203
|
+
```typescript
|
|
204
|
+
{
|
|
205
|
+
name: 'Product Image',
|
|
206
|
+
tag: 'product_image', // ← Used as name attribute
|
|
207
|
+
type: 'image', // ← Routes to OxInputImage
|
|
208
|
+
description: 'Upload product photo',
|
|
209
|
+
unit: 'JPG/PNG',
|
|
210
|
+
quota: 3, // Allow up to 3 images
|
|
211
|
+
options: {
|
|
212
|
+
accept: ['jpeg', 'png'],
|
|
213
|
+
maxSize: 10485760, // 10MB
|
|
214
|
+
maxWidth: 4096,
|
|
215
|
+
maxHeight: 4096,
|
|
216
|
+
multiple: true
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
```
|
|
220
|
+
|
|
221
|
+
### Video Field Config
|
|
222
|
+
```typescript
|
|
223
|
+
{
|
|
224
|
+
name: 'Demo Video',
|
|
225
|
+
tag: 'demo_video',
|
|
226
|
+
type: 'video',
|
|
227
|
+
quota: 1,
|
|
228
|
+
options: {
|
|
229
|
+
accept: ['mp4', 'webm'],
|
|
230
|
+
maxSize: 104857600, // 100MB
|
|
231
|
+
maxDuration: 300, // 5 minutes
|
|
232
|
+
multiple: false
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
```
|
|
236
|
+
|
|
237
|
+
### Audio Field Config
|
|
238
|
+
```typescript
|
|
239
|
+
{
|
|
240
|
+
name: 'Voice Note',
|
|
241
|
+
tag: 'voice_note',
|
|
242
|
+
type: 'audio',
|
|
243
|
+
quota: 1,
|
|
244
|
+
options: {
|
|
245
|
+
accept: ['mp3', 'wav'],
|
|
246
|
+
maxSize: 52428800, // 50MB
|
|
247
|
+
maxDuration: 600, // 10 minutes
|
|
248
|
+
multiple: false
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
```
|
|
252
|
+
|
|
253
|
+
---
|
|
254
|
+
|
|
255
|
+
## File Upload GraphQL Context
|
|
256
|
+
|
|
257
|
+
### Why `hasUpload: true`?
|
|
258
|
+
```typescript
|
|
259
|
+
// In data-entry-form.ts
|
|
260
|
+
context: {
|
|
261
|
+
hasUpload: true
|
|
262
|
+
}
|
|
263
|
+
```
|
|
264
|
+
This tells Apollo Client to:
|
|
265
|
+
1. Use `multipart/form-data` encoding (not JSON)
|
|
266
|
+
2. Include files in GraphQL variables
|
|
267
|
+
3. Stream files to server
|
|
268
|
+
|
|
269
|
+
### GraphQL Variable Structure
|
|
270
|
+
```typescript
|
|
271
|
+
{
|
|
272
|
+
dataSample: {
|
|
273
|
+
dataSet: { id: '...' },
|
|
274
|
+
data: {
|
|
275
|
+
product_image: [{file: FileUpload}, ...],
|
|
276
|
+
demo_video: [{file: FileUpload}],
|
|
277
|
+
...
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
```
|
|
282
|
+
|
|
283
|
+
---
|
|
284
|
+
|
|
285
|
+
## Common Gotchas
|
|
286
|
+
|
|
287
|
+
### 1. OxInputImage vs OxInputFile
|
|
288
|
+
- **File**: Generic file upload
|
|
289
|
+
- **Image**: Image-specific with preview/validation
|
|
290
|
+
- Note: OxInputImage exists in @operato/input but not used in factory
|
|
291
|
+
|
|
292
|
+
### 2. Name Attribute is Critical
|
|
293
|
+
```typescript
|
|
294
|
+
// CORRECT - matches dataItem.tag
|
|
295
|
+
<ox-input-image name="product_image" ...></ox-input-image>
|
|
296
|
+
|
|
297
|
+
// WRONG - value won't be extracted
|
|
298
|
+
<ox-input-image ...></ox-input-image>
|
|
299
|
+
```
|
|
300
|
+
|
|
301
|
+
### 3. Quota vs Multiple
|
|
302
|
+
```typescript
|
|
303
|
+
quota: 3, options: { multiple: true }
|
|
304
|
+
// Allows user to select 3 times, each time multiple files
|
|
305
|
+
|
|
306
|
+
quota: 1, options: { multiple: false }
|
|
307
|
+
// Single file selection
|
|
308
|
+
```
|
|
309
|
+
|
|
310
|
+
### 4. Group vs Subgroup
|
|
311
|
+
```typescript
|
|
312
|
+
group: 'measurements' // Groups items in table (Grist)
|
|
313
|
+
subgroup: 'length' // Secondary grouping
|
|
314
|
+
// Non-grouped items show in main form
|
|
315
|
+
```
|
|
316
|
+
|
|
317
|
+
### 5. Active vs Hidden
|
|
318
|
+
```typescript
|
|
319
|
+
active: true // Rendered in form
|
|
320
|
+
active: false // Skipped entirely
|
|
321
|
+
hidden: true // Rendered but CSS hidden (for validation specs)
|
|
322
|
+
```
|
|
323
|
+
|
|
324
|
+
---
|
|
325
|
+
|
|
326
|
+
## File Paths in Codebase
|
|
327
|
+
|
|
328
|
+
### Where to Make Changes
|
|
329
|
+
1. **New Components**: `packages/dataset/client/components/`
|
|
330
|
+
2. **Type Updates**: Update @operato/dataset OR create wrapper
|
|
331
|
+
3. **Media Options**: Already defined in `data-item-type.ts`
|
|
332
|
+
4. **Validation**: Already implemented in `media-validation.ts`
|
|
333
|
+
|
|
334
|
+
### Dependencies Already Available
|
|
335
|
+
```json
|
|
336
|
+
{
|
|
337
|
+
"@operato/input": "^9.0.0",
|
|
338
|
+
"@operato/dataset": "^9.0.0",
|
|
339
|
+
"lit": "^2.x.x"
|
|
340
|
+
}
|
|
341
|
+
```
|
|
342
|
+
|
|
343
|
+
### Key Imports for New Components
|
|
344
|
+
```typescript
|
|
345
|
+
import { css, html } from 'lit'
|
|
346
|
+
import { customElement, property, query } from 'lit/decorators.js'
|
|
347
|
+
import { OxFormField } from '@operato/input'
|
|
348
|
+
```
|
|
349
|
+
|
|
350
|
+
---
|
|
351
|
+
|
|
352
|
+
## Testing Checklist
|
|
353
|
+
|
|
354
|
+
Before deploying new media components:
|
|
355
|
+
|
|
356
|
+
- [ ] Component renders with correct icon/label
|
|
357
|
+
- [ ] File selection works (click and drag-drop)
|
|
358
|
+
- [ ] Value extracted correctly by name attribute
|
|
359
|
+
- [ ] Multiple/single file toggle works
|
|
360
|
+
- [ ] GraphQL mutation includes files
|
|
361
|
+
- [ ] Server-side validation passes
|
|
362
|
+
- [ ] Media validation errors displayed to user
|
|
363
|
+
- [ ] Attachment created in database
|
|
364
|
+
- [ ] File paths stored in DataSample.data
|
|
365
|
+
- [ ] Grist grid column type correct for subgroup items
|
|
@@ -150,7 +150,21 @@ let DataItemList = class DataItemList extends localize(i18next)(LitElement) {
|
|
|
150
150
|
name: 'type',
|
|
151
151
|
header: i18next.t('field.type'),
|
|
152
152
|
record: {
|
|
153
|
-
options: [
|
|
153
|
+
options: [
|
|
154
|
+
'',
|
|
155
|
+
'number',
|
|
156
|
+
'text',
|
|
157
|
+
'select',
|
|
158
|
+
'radio',
|
|
159
|
+
'boolean',
|
|
160
|
+
'date',
|
|
161
|
+
'datetime',
|
|
162
|
+
'file',
|
|
163
|
+
'image',
|
|
164
|
+
'video',
|
|
165
|
+
'audio',
|
|
166
|
+
'signature'
|
|
167
|
+
],
|
|
154
168
|
editable: true
|
|
155
169
|
},
|
|
156
170
|
width: 120
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"data-item-list.js","sourceRoot":"","sources":["../../../client/pages/data-set/data-item-list.ts"],"names":[],"mappings":";AAAA,OAAO,4BAA4B,CAAA;AAEnC,OAAO,GAAG,MAAM,aAAa,CAAA;AAE7B,OAAO,EAAE,GAAG,EAAE,IAAI,EAAE,UAAU,EAAE,MAAM,KAAK,CAAA;AAC3C,OAAO,EAAE,aAAa,EAAE,QAAQ,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAA;AAEzE,OAAO,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAA;AACzC,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAA;AACjD,OAAO,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAA;AAC/C,OAAO,EAAE,SAAS,EAAe,MAAM,qBAAqB,CAAA;AAC5D,OAAO,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAA;AAEpD,MAAM,aAAa,GAAG,CAAC,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,UAAU,EAAE,KAAK,EAAE,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,CAAC,CAAA;AAGpG,IAAM,YAAY,GAAlB,MAAM,YAAa,SAAQ,QAAQ,CAAC,OAAO,CAAC,CAAC,UAAU,CAAC;aAK/C,WAAM,GAAG;QACd,kBAAkB;QAClB,GAAG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gB;QACpB,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC,gBAAgB,EAAE,EAAE,CAAC,EAAE,OAAO,CAAC,CAAC,CAAC,aAAa,CAAC,EAAE,CAAC,CAAC,EAAE,CAAC;YAC3E,OAAM;QACR,CAAC;QAED,IAAI,CAAC,KAAK,CAAC,qBAAqB,CAAC,KAAK,CAAC,CAAA;IACzC,CAAC;;AAtS2B;IAA3B,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;;6CAAa;AAE/B;IAAR,KAAK,EAAE;;iDAAiB;AAkBE;IAA1B,KAAK,CAAC,UAAU,CAAC;8BAAiB,SAAS;2CAAA;AArBxC,YAAY;IADjB,aAAa,CAAC,gBAAgB,CAAC;GAC1B,YAAY,CAwSjB","sourcesContent":["import '@material/web/icon/icon.js'\n\nimport gql from 'graphql-tag'\n\nimport { css, html, LitElement } from 'lit'\nimport { customElement, property, query, state } from 'lit/decorators.js'\n\nimport { client } from '@operato/graphql'\nimport { i18next, localize } from '@operato/i18n'\nimport { isMobileDevice } from '@operato/utils'\nimport { DataGrist, FetchOption } from '@operato/data-grist'\nimport { CommonHeaderStyles } from '@operato/styles'\n\nconst DataItemStats = ['sum', 'mean', 'stddev', 'variance', 'min', 'max', 'range', 'median', 'mode']\n\n@customElement('data-item-list')\nclass DataItemList extends localize(i18next)(LitElement) {\n @property({ type: Object }) dataSet: any\n\n @state() gristConfig: any\n\n static styles = [\n CommonHeaderStyles,\n css`\n :host {\n display: flex;\n flex-direction: column;\n\n background-color: var(--md-sys-color-surface);\n }\n\n ox-grist {\n flex: 1;\n }\n `\n ]\n\n @query('ox-grist') private grist!: DataGrist\n\n render() {\n return html`\n <ox-grist\n .mode=${isMobileDevice() ? 'LIST' : 'GRID'}\n .config=${this.gristConfig}\n .fetchHandler=${this.fetchHandler.bind(this)}\n ></ox-grist>\n\n <div class=\"footer\">\n <div filler></div>\n <button danger @click=${this._deleteDataItems.bind(this)}>\n <md-icon>delete_forever</md-icon>${i18next.t('button.delete')}\n </button>\n <button @click=${this._updateDataItems.bind(this)} done>\n <md-icon>save</md-icon>${i18next.t('button.save')}\n </button>\n </div>\n `\n }\n\n async firstUpdated() {\n this.gristConfig = {\n list: { fields: ['name', 'description', 'active'] },\n columns: [\n { type: 'gutter', gutterName: 'row-selector', fixed: true, multiple: true },\n {\n type: 'gutter',\n gutterName: 'button',\n fixed: true,\n icon: 'add',\n handlers: {\n click: 'record-copy'\n }\n },\n { type: 'gutter', gutterName: 'sequence', fixed: true },\n {\n type: 'gutter',\n gutterName: 'button',\n fixed: true,\n icon: 'arrow_upward',\n handlers: {\n click: 'move-up'\n }\n },\n {\n type: 'gutter',\n gutterName: 'button',\n fixed: true,\n icon: 'arrow_downward',\n handlers: {\n click: 'move-down'\n }\n },\n {\n type: 'string',\n name: 'name',\n fixed: true,\n header: i18next.t('field.name'),\n record: {\n editable: true\n },\n width: 140\n },\n {\n type: 'string',\n name: 'description',\n header: i18next.t('field.description'),\n record: {\n editable: true\n },\n width: 180\n },\n {\n type: 'checkbox',\n name: 'active',\n label: true,\n header: i18next.t('field.active'),\n record: {\n editable: true\n },\n sortable: true,\n width: 60\n },\n {\n type: 'checkbox',\n name: 'hidden',\n label: true,\n header: i18next.t('field.hidden'),\n record: {\n editable: true\n },\n sortable: true,\n width: 60\n },\n {\n type: 'varname',\n name: 'tag',\n header: i18next.t('field.tag'),\n record: {\n editable: true\n },\n width: 180\n },\n {\n type: 'string',\n name: 'group',\n header: i18next.t('field.group'),\n record: {\n editable: true\n },\n width: 180\n },\n {\n type: 'string',\n name: 'subgroup',\n header: i18next.t('field.subgroup'),\n record: {\n editable: true\n },\n width: 180\n },\n {\n type: 'select',\n name: 'type',\n header: i18next.t('field.type'),\n record: {\n options: ['', 'number', 'text', 'select', 'radio', 'boolean', 'date', 'datetime', 'file', 'signature'],\n editable: true\n },\n width: 120\n },\n {\n type: 'parameters',\n name: 'options',\n header: i18next.t('field.options'),\n record: {\n editable: true,\n renderer: 'json5',\n options: async (value, column, record, row, field) => {\n return {\n name: record.type,\n help: '',\n spec:\n record.type === 'select' || record.type === 'radio'\n ? [\n {\n type: 'options' /* property-editor type */,\n name: 'options',\n label: 'options'\n }\n ]\n : [],\n context: this.grist,\n objectified: true\n }\n }\n },\n width: 120\n },\n {\n type: 'select',\n name: 'stat',\n header: i18next.t('field.finalizing-function'),\n record: {\n options: ['', ...DataItemStats],\n editable: true\n },\n width: 120\n },\n {\n type: 'select',\n name: 'agg',\n header: i18next.t('field.agg-function'),\n record: {\n options: ['', ...DataItemStats],\n editable: true\n },\n width: 120\n },\n {\n type: 'string',\n name: 'unit',\n header: i18next.t('field.unit'),\n record: {\n editable: true\n },\n width: 120\n },\n {\n type: 'number',\n name: 'quota',\n header: i18next.t('field.quota'),\n record: {\n editable: true\n },\n width: 60\n },\n {\n type: 'data-item-spec',\n name: 'spec',\n header: i18next.t('field.spec'),\n record: {\n editable: true,\n options: {\n name: '',\n help: '',\n objectified: true /* prevent from stringifying */\n }\n },\n width: 200\n }\n ],\n rows: {\n selectable: {\n multiple: true\n }\n },\n pagination: {\n infinite: true\n },\n sorters: []\n }\n }\n\n async fetchHandler({ filters, page, limit, sortings = [] }: FetchOption) {\n const dataItems = this.dataSet.dataItems || []\n\n return {\n total: dataItems.length,\n records: dataItems\n }\n }\n\n async _updateDataItems() {\n this.grist.commit()\n\n const response = await client.mutate({\n mutation: gql`\n mutation ($id: String!, $patch: DataSetPatch!) {\n updateDataSet(id: $id, patch: $patch) {\n name\n }\n }\n `,\n variables: {\n id: this.dataSet.id,\n patch: {\n dataItems: this.grist.data.records,\n cuFlag: 'M'\n }\n }\n })\n\n if (!response.errors) {\n await document.dispatchEvent(\n new CustomEvent('notify', {\n detail: {\n message: i18next.t('text.info_x_successfully', {\n x: i18next.t('button.save')\n })\n }\n })\n )\n }\n }\n\n async _deleteDataItems() {\n if (!confirm(i18next.t('text.sure_to_x', { x: i18next.t('text.delete') }))) {\n return\n }\n\n this.grist.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MAAM,EAAE,CAAC;;6CAAa;AAE/B;IAAR,KAAK,EAAE;;iDAAiB;AAkBE;IAA1B,KAAK,CAAC,UAAU,CAAC;8BAAiB,SAAS;2CAAA;AArBxC,YAAY;IADjB,aAAa,CAAC,gBAAgB,CAAC;GAC1B,YAAY,CAsTjB","sourcesContent":["import '@material/web/icon/icon.js'\n\nimport gql from 'graphql-tag'\n\nimport { css, html, LitElement } from 'lit'\nimport { customElement, property, query, state } from 'lit/decorators.js'\n\nimport { client } from '@operato/graphql'\nimport { i18next, localize } from '@operato/i18n'\nimport { isMobileDevice } from '@operato/utils'\nimport { DataGrist, FetchOption } from '@operato/data-grist'\nimport { CommonHeaderStyles } from '@operato/styles'\n\nconst DataItemStats = ['sum', 'mean', 'stddev', 'variance', 'min', 'max', 'range', 'median', 'mode']\n\n@customElement('data-item-list')\nclass DataItemList extends localize(i18next)(LitElement) {\n @property({ type: Object }) dataSet: any\n\n @state() gristConfig: any\n\n static styles = [\n CommonHeaderStyles,\n css`\n :host {\n display: flex;\n flex-direction: column;\n\n background-color: var(--md-sys-color-surface);\n }\n\n ox-grist {\n flex: 1;\n }\n `\n ]\n\n @query('ox-grist') private grist!: DataGrist\n\n render() {\n return html`\n <ox-grist\n .mode=${isMobileDevice() ? 'LIST' : 'GRID'}\n .config=${this.gristConfig}\n .fetchHandler=${this.fetchHandler.bind(this)}\n ></ox-grist>\n\n <div class=\"footer\">\n <div filler></div>\n <button danger @click=${this._deleteDataItems.bind(this)}>\n <md-icon>delete_forever</md-icon>${i18next.t('button.delete')}\n </button>\n <button @click=${this._updateDataItems.bind(this)} done>\n <md-icon>save</md-icon>${i18next.t('button.save')}\n </button>\n </div>\n `\n }\n\n async firstUpdated() {\n this.gristConfig = {\n list: { fields: ['name', 'description', 'active'] },\n columns: [\n { type: 'gutter', gutterName: 'row-selector', fixed: true, multiple: true },\n {\n type: 'gutter',\n gutterName: 'button',\n fixed: true,\n icon: 'add',\n handlers: {\n click: 'record-copy'\n }\n },\n { type: 'gutter', gutterName: 'sequence', fixed: true },\n {\n type: 'gutter',\n gutterName: 'button',\n fixed: true,\n icon: 'arrow_upward',\n handlers: {\n click: 'move-up'\n }\n },\n {\n type: 'gutter',\n gutterName: 'button',\n fixed: true,\n icon: 'arrow_downward',\n handlers: {\n click: 'move-down'\n }\n },\n {\n type: 'string',\n name: 'name',\n fixed: true,\n header: i18next.t('field.name'),\n record: {\n editable: true\n },\n width: 140\n },\n {\n type: 'string',\n name: 'description',\n header: i18next.t('field.description'),\n record: {\n editable: true\n },\n width: 180\n },\n {\n type: 'checkbox',\n name: 'active',\n label: true,\n header: i18next.t('field.active'),\n record: {\n editable: true\n },\n sortable: true,\n width: 60\n },\n {\n type: 'checkbox',\n name: 'hidden',\n label: true,\n header: i18next.t('field.hidden'),\n record: {\n editable: true\n },\n sortable: true,\n width: 60\n },\n {\n type: 'varname',\n name: 'tag',\n header: i18next.t('field.tag'),\n record: {\n editable: true\n },\n width: 180\n },\n {\n type: 'string',\n name: 'group',\n header: i18next.t('field.group'),\n record: {\n editable: true\n },\n width: 180\n },\n {\n type: 'string',\n name: 'subgroup',\n header: i18next.t('field.subgroup'),\n record: {\n editable: true\n },\n width: 180\n },\n {\n type: 'select',\n name: 'type',\n header: i18next.t('field.type'),\n record: {\n options: [\n '',\n 'number',\n 'text',\n 'select',\n 'radio',\n 'boolean',\n 'date',\n 'datetime',\n 'file',\n 'image',\n 'video',\n 'audio',\n 'signature'\n ],\n editable: true\n },\n width: 120\n },\n {\n type: 'parameters',\n name: 'options',\n header: i18next.t('field.options'),\n record: {\n editable: true,\n renderer: 'json5',\n options: async (value, column, record, row, field) => {\n return {\n name: record.type,\n help: '',\n spec:\n record.type === 'select' || record.type === 'radio'\n ? [\n {\n type: 'options' /* property-editor type */,\n name: 'options',\n label: 'options'\n }\n ]\n : [],\n context: this.grist,\n objectified: true\n }\n }\n },\n width: 120\n },\n {\n type: 'select',\n name: 'stat',\n header: i18next.t('field.finalizing-function'),\n record: {\n options: ['', ...DataItemStats],\n editable: true\n },\n width: 120\n },\n {\n type: 'select',\n name: 'agg',\n header: i18next.t('field.agg-function'),\n record: {\n options: ['', ...DataItemStats],\n editable: true\n },\n width: 120\n },\n {\n type: 'string',\n name: 'unit',\n header: i18next.t('field.unit'),\n record: {\n editable: true\n },\n width: 120\n },\n {\n type: 'number',\n name: 'quota',\n header: i18next.t('field.quota'),\n record: {\n editable: true\n },\n width: 60\n },\n {\n type: 'data-item-spec',\n name: 'spec',\n header: i18next.t('field.spec'),\n record: {\n editable: true,\n options: {\n name: '',\n help: '',\n objectified: true /* prevent from stringifying */\n }\n },\n width: 200\n }\n ],\n rows: {\n selectable: {\n multiple: true\n }\n },\n pagination: {\n infinite: true\n },\n sorters: []\n }\n }\n\n async fetchHandler({ filters, page, limit, sortings = [] }: FetchOption) {\n const dataItems = this.dataSet.dataItems || []\n\n return {\n total: dataItems.length,\n records: dataItems\n }\n }\n\n async _updateDataItems() {\n this.grist.commit()\n\n const response = await client.mutate({\n mutation: gql`\n mutation ($id: String!, $patch: DataSetPatch!) {\n updateDataSet(id: $id, patch: $patch) {\n name\n }\n }\n `,\n variables: {\n id: this.dataSet.id,\n patch: {\n dataItems: this.grist.data.records,\n cuFlag: 'M'\n }\n }\n })\n\n if (!response.errors) {\n await document.dispatchEvent(\n new CustomEvent('notify', {\n detail: {\n message: i18next.t('text.info_x_successfully', {\n x: i18next.t('button.save')\n })\n }\n })\n )\n }\n }\n\n async _deleteDataItems() {\n if (!confirm(i18next.t('text.sure_to_x', { x: i18next.t('text.delete') }))) {\n return\n }\n\n this.grist.deleteSelectedRecords(false)\n }\n}\n"]}
|