@rglabs/butterfly 2.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.
- package/CLAUDE.md +201 -0
- package/README.md +371 -0
- package/dist/commands/add.d.ts +23 -0
- package/dist/commands/add.js +303 -0
- package/dist/commands/code.d.ts +11 -0
- package/dist/commands/code.js +72 -0
- package/dist/commands/create-object.d.ts +6 -0
- package/dist/commands/create-object.js +293 -0
- package/dist/commands/create-report.d.ts +6 -0
- package/dist/commands/create-report.js +154 -0
- package/dist/commands/diff.d.ts +4 -0
- package/dist/commands/diff.js +238 -0
- package/dist/commands/download.d.ts +4 -0
- package/dist/commands/download.js +374 -0
- package/dist/commands/layout.d.ts +12 -0
- package/dist/commands/layout.js +83 -0
- package/dist/commands/record.d.ts +21 -0
- package/dist/commands/record.js +483 -0
- package/dist/commands/run-poc.d.ts +3 -0
- package/dist/commands/run-poc.js +18 -0
- package/dist/commands/setup.d.ts +3 -0
- package/dist/commands/setup.js +66 -0
- package/dist/commands/start-poc.d.ts +3 -0
- package/dist/commands/start-poc.js +55 -0
- package/dist/commands/sync-docs.d.ts +3 -0
- package/dist/commands/sync-docs.js +27 -0
- package/dist/commands/translate.d.ts +13 -0
- package/dist/commands/translate.js +401 -0
- package/dist/commands/upload.d.ts +3 -0
- package/dist/commands/upload.js +150 -0
- package/dist/commands/workflow-info.d.ts +13 -0
- package/dist/commands/workflow-info.js +161 -0
- package/dist/components/ConflictResolver.d.ts +12 -0
- package/dist/components/ConflictResolver.js +77 -0
- package/dist/components/DiffView.d.ts +11 -0
- package/dist/components/DiffView.js +101 -0
- package/dist/components/DownloadProgress.d.ts +11 -0
- package/dist/components/DownloadProgress.js +29 -0
- package/dist/components/RecordPreview.d.ts +11 -0
- package/dist/components/RecordPreview.js +91 -0
- package/dist/components/SetupForm.d.ts +8 -0
- package/dist/components/SetupForm.js +56 -0
- package/dist/components/UploadProgress.d.ts +13 -0
- package/dist/components/UploadProgress.js +42 -0
- package/dist/diff/adapters/index.d.ts +8 -0
- package/dist/diff/adapters/index.js +18 -0
- package/dist/diff/adapters/objectsAdapter.d.ts +13 -0
- package/dist/diff/adapters/objectsAdapter.js +177 -0
- package/dist/diff/adapters/reportsAdapter.d.ts +14 -0
- package/dist/diff/adapters/reportsAdapter.js +212 -0
- package/dist/diff/adapters/types.d.ts +19 -0
- package/dist/diff/adapters/types.js +2 -0
- package/dist/diff/engine.d.ts +19 -0
- package/dist/diff/engine.js +57 -0
- package/dist/diff/types.d.ts +34 -0
- package/dist/diff/types.js +110 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +117 -0
- package/dist/types/index.d.ts +18 -0
- package/dist/types/index.js +2 -0
- package/dist/utils/api.d.ts +85 -0
- package/dist/utils/api.js +1031 -0
- package/dist/utils/auth.d.ts +4 -0
- package/dist/utils/auth.js +22 -0
- package/dist/utils/bfySplitter.d.ts +12 -0
- package/dist/utils/bfySplitter.js +151 -0
- package/dist/utils/docs.d.ts +16 -0
- package/dist/utils/docs.js +186 -0
- package/dist/utils/errorLogger.d.ts +6 -0
- package/dist/utils/errorLogger.js +29 -0
- package/dist/utils/files.d.ts +14 -0
- package/dist/utils/files.js +772 -0
- package/dist/utils/lockManager.d.ts +15 -0
- package/dist/utils/lockManager.js +126 -0
- package/dist/utils/resourceHandlers.d.ts +50 -0
- package/dist/utils/resourceHandlers.js +684 -0
- package/dist/utils/resourceMapping.d.ts +32 -0
- package/dist/utils/resourceMapping.js +210 -0
- package/dist/utils/singleResourceDownload.d.ts +14 -0
- package/dist/utils/singleResourceDownload.js +261 -0
- package/dist/utils/summaryGenerator.d.ts +2 -0
- package/dist/utils/summaryGenerator.js +183 -0
- package/dist/utils/uploadHandler.d.ts +31 -0
- package/dist/utils/uploadHandler.js +263 -0
- package/docs/AI_API.md +93 -0
- package/docs/CLAUDE.md +216 -0
- package/docs/PROJECT_SPECIFIC.md +1 -0
- package/docs/RECORD_COMMAND.md +262 -0
- package/docs/WORKFLOW_API.md +480 -0
- package/docs/bfy-splitting.md +126 -0
- package/docs/cli-commands.md +333 -0
- package/docs/examples/README.md +95 -0
- package/docs/examples/order-system.md +147 -0
- package/docs/examples/product-catalog.md +195 -0
- package/docs/examples/reports.md +187 -0
- package/docs/excel-export.md +216 -0
- package/docs/field-types/README.md +29 -0
- package/docs/field-types/calculated.md +147 -0
- package/docs/field-types/code-mappings.md +84 -0
- package/docs/field-types/custom.md +340 -0
- package/docs/object-specs/README.md +136 -0
- package/docs/object-specs/code-parameters.md +151 -0
- package/docs/object-specs/creating.md +203 -0
- package/docs/object-specs/js-code-examples.md +208 -0
- package/docs/object-specs/js-field-updates.md +168 -0
- package/docs/objects/README.md +89 -0
- package/docs/objects/creating.md +127 -0
- package/docs/page-layout.md +361 -0
- package/docs/permissions.md +260 -0
- package/docs/reports.md +197 -0
- package/docs/state-machines.md +544 -0
- package/docs/tasks/create-object.md +81 -0
- package/docs/translations.md +346 -0
- package/docs/twig-helpers.md +283 -0
- package/docs/webservices.md +159 -0
- package/docs/workspaces.md +176 -0
- package/package.json +59 -0
package/docs/reports.md
ADDED
|
@@ -0,0 +1,197 @@
|
|
|
1
|
+
# Reports Guide
|
|
2
|
+
|
|
3
|
+
Reports in Butterfly are created using the `cms_reports` table with queries in `cms_report_queries`.
|
|
4
|
+
|
|
5
|
+
> **Important:** Always use `cms_report_queries` for Twig query code. The `query` field in `cms_reports` is **deprecated**.
|
|
6
|
+
|
|
7
|
+
## Creating a Report
|
|
8
|
+
|
|
9
|
+
### 1. Create Report Record
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
butterfly-cli record add cms_reports --data '{
|
|
13
|
+
"title": "Sales Report",
|
|
14
|
+
"alias": "sales-report",
|
|
15
|
+
"category_id": 1
|
|
16
|
+
}'
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
### 2. Add Report Query
|
|
20
|
+
|
|
21
|
+
```bash
|
|
22
|
+
butterfly-cli record add cms_report_queries --data '{
|
|
23
|
+
"cms_report_id": <REPORT_ID>,
|
|
24
|
+
"name": "Sales Data",
|
|
25
|
+
"system_name": "sales_data",
|
|
26
|
+
"column_size": "1",
|
|
27
|
+
"query": "{% set records = db().table(\"orders\").where(\"status\", \"completed\").get() %}"
|
|
28
|
+
}'
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
## Report Query Fields
|
|
32
|
+
|
|
33
|
+
| Field | Description |
|
|
34
|
+
|-------|-------------|
|
|
35
|
+
| `cms_report_id` | Parent report ID |
|
|
36
|
+
| `name` | Display name |
|
|
37
|
+
| `system_name` | System identifier |
|
|
38
|
+
| `query` | Twig query code |
|
|
39
|
+
| `column_size` | Layout width: `1`, `1/2`, `1/3`, `2/3`, `1/4`, `3/4` |
|
|
40
|
+
| `js_code` | Optional JavaScript processing code |
|
|
41
|
+
|
|
42
|
+
## Query Code Examples
|
|
43
|
+
|
|
44
|
+
### Basic Query
|
|
45
|
+
|
|
46
|
+
```twig
|
|
47
|
+
{% set records = db()
|
|
48
|
+
.table('orders')
|
|
49
|
+
.where('status', 'completed')
|
|
50
|
+
.orderByDesc('created_at')
|
|
51
|
+
.get()
|
|
52
|
+
%}
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
### With Parameters
|
|
56
|
+
|
|
57
|
+
```twig
|
|
58
|
+
{% set startDate = getParameter('start_date') %}
|
|
59
|
+
{% set endDate = getParameter('end_date') %}
|
|
60
|
+
|
|
61
|
+
{% set records = db()
|
|
62
|
+
.table('orders')
|
|
63
|
+
.where('created_at', '>=', startDate)
|
|
64
|
+
.where('created_at', '<=', endDate)
|
|
65
|
+
.get()
|
|
66
|
+
%}
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
### With Joins
|
|
70
|
+
|
|
71
|
+
```twig
|
|
72
|
+
{% set records = db()
|
|
73
|
+
.table('orders')
|
|
74
|
+
.join('users', 'users.id', '=', 'orders.user_id')
|
|
75
|
+
.join('products', 'products.id', '=', 'orders.product_id')
|
|
76
|
+
.select(
|
|
77
|
+
'orders.*',
|
|
78
|
+
'users.name as customer_name',
|
|
79
|
+
'products.title as product_name'
|
|
80
|
+
)
|
|
81
|
+
.get()
|
|
82
|
+
%}
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
### Aggregations
|
|
86
|
+
|
|
87
|
+
```twig
|
|
88
|
+
{% set summary = db()
|
|
89
|
+
.table('orders')
|
|
90
|
+
.select(
|
|
91
|
+
'status',
|
|
92
|
+
'COUNT(*) as count',
|
|
93
|
+
'SUM(total) as total_amount'
|
|
94
|
+
)
|
|
95
|
+
.groupBy('status')
|
|
96
|
+
.get()
|
|
97
|
+
%}
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
### Current User Filter
|
|
101
|
+
|
|
102
|
+
```twig
|
|
103
|
+
{% set userId = currentUser('id') %}
|
|
104
|
+
|
|
105
|
+
{% set records = db()
|
|
106
|
+
.table('tasks')
|
|
107
|
+
.where('assigned_to', userId)
|
|
108
|
+
.get()
|
|
109
|
+
%}
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
## Report Specs
|
|
113
|
+
|
|
114
|
+
Report specs use the same field types as object specs. Add filter fields to reports:
|
|
115
|
+
|
|
116
|
+
```bash
|
|
117
|
+
butterfly-cli record add cms_report_specs --data '{
|
|
118
|
+
"cms_report_id": <REPORT_ID>,
|
|
119
|
+
"name": "Status Filter",
|
|
120
|
+
"column_name": "status_filter",
|
|
121
|
+
"type": "from_list",
|
|
122
|
+
"val_1": "all:All|pending:Pending|completed:Completed"
|
|
123
|
+
}'
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
Use in query:
|
|
127
|
+
|
|
128
|
+
```twig
|
|
129
|
+
{% set statusFilter = getParameter('status_filter') %}
|
|
130
|
+
|
|
131
|
+
{% set query = db().table('orders') %}
|
|
132
|
+
|
|
133
|
+
{% if statusFilter and statusFilter != 'all' %}
|
|
134
|
+
{% set query = query.where('status', statusFilter) %}
|
|
135
|
+
{% endif %}
|
|
136
|
+
|
|
137
|
+
{% set records = query.get() %}
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
## File Structure
|
|
141
|
+
|
|
142
|
+
Downloaded reports are stored in:
|
|
143
|
+
|
|
144
|
+
```
|
|
145
|
+
butterfly-resources/
|
|
146
|
+
└── reports/
|
|
147
|
+
└── [report-alias]/
|
|
148
|
+
├── report.json # Report definition
|
|
149
|
+
├── queries/
|
|
150
|
+
│ └── [query-name]/
|
|
151
|
+
│ ├── query.json
|
|
152
|
+
│ ├── query_code.bfy # Twig query code
|
|
153
|
+
│ └── script.js # Optional JS code
|
|
154
|
+
└── specs/
|
|
155
|
+
└── [field-name]/
|
|
156
|
+
├── spec.json
|
|
157
|
+
└── code.js # Optional JS code
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
## JavaScript Code (js_code)
|
|
161
|
+
|
|
162
|
+
Process data client-side after query execution:
|
|
163
|
+
|
|
164
|
+
```javascript
|
|
165
|
+
// Access query results
|
|
166
|
+
var data = window.reportData.sales_data;
|
|
167
|
+
|
|
168
|
+
// Process or transform data
|
|
169
|
+
data.forEach(function(row) {
|
|
170
|
+
row.formatted_total = '$' + row.total.toFixed(2);
|
|
171
|
+
});
|
|
172
|
+
```
|
|
173
|
+
|
|
174
|
+
## Best Practices
|
|
175
|
+
|
|
176
|
+
1. **Use `cms_report_queries`** - Never use the deprecated `query` field in `cms_reports`
|
|
177
|
+
2. **Add parameters** - Use `getParameter()` for user-configurable filters
|
|
178
|
+
3. **Limit results** - Use `.limit()` for large datasets
|
|
179
|
+
4. **Check errors** - Monitor `.butterfly/error_log.txt` for query errors
|
|
180
|
+
5. **Test queries** - Use `butterfly-cli code` to test before deploying
|
|
181
|
+
|
|
182
|
+
### Testing Queries
|
|
183
|
+
|
|
184
|
+
```bash
|
|
185
|
+
butterfly-cli code -c "{% set records = db().table('orders').limit(5).get() %}{{ dump(records) }}"
|
|
186
|
+
```
|
|
187
|
+
|
|
188
|
+
## Column Sizes
|
|
189
|
+
|
|
190
|
+
| Value | Width |
|
|
191
|
+
|-------|-------|
|
|
192
|
+
| `1` | Full width |
|
|
193
|
+
| `1/2` | Half width |
|
|
194
|
+
| `1/3` | One third |
|
|
195
|
+
| `2/3` | Two thirds |
|
|
196
|
+
| `1/4` | One quarter |
|
|
197
|
+
| `3/4` | Three quarters |
|