@lowdefy/docs 3.22.0 → 3.23.2
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/CHANGELOG.md +53 -0
- package/actions/JsAction.yaml +2 -2
- package/blocks/display/DangerousHtml.yaml +11 -12
- package/blocks/display/DangerousMarkdown.yaml +8 -8
- package/blocks/input/MultipleSelector.yaml +80 -0
- package/blocks/input/Selector.yaml +62 -0
- package/concepts/custom-blocks.yaml +2 -2
- package/concepts/custom-code.yaml +3 -3
- package/concepts/lowdefy-schema.yaml +16 -0
- package/connections/AxiosHttp.yaml +1 -1
- package/deployment/aws-lambda.yaml +2 -2
- package/deployment/docker.yaml +2 -2
- package/head.html +2 -0
- package/howto/generate-csv.yaml.njk +251 -0
- package/howto/generate-pdf.yaml.njk +651 -0
- package/howto/generateCsv/lowdefy.yaml +63 -0
- package/howto/generateCsv/public/csvMake.js +27 -0
- package/howto/generatePdf/inv_template.yaml +200 -0
- package/howto/generatePdf/lowdefy.yaml +116 -0
- package/howto/generatePdf/my_header.html +1 -0
- package/howto/generatePdf/public/logo_example.png +0 -0
- package/howto/generatePdf/public/modules/importUmd.js +7 -0
- package/howto/generatePdf/public/modules/pdfMake.js +7 -0
- package/howto/generatePdf/public/modules/vfs_fonts.js +12 -0
- package/lowdefy.yaml +1 -1
- package/menus.yaml +25 -1
- package/operators/_actions.yaml +1 -1
- package/operators/_change_case.yaml +4 -4
- package/operators/_js.yaml +2 -2
- package/operators/_ref.yaml +16 -8
- package/operators/_switch.yaml +51 -0
- package/package.json +2 -2
- package/pages.yaml +12 -0
- package/public/images/authors/gervwyk.jpeg +0 -0
- package/public/images/authors/sandile.jpeg +0 -0
- package/public/images/howto/header_generate_csv.jpg +0 -0
- package/public/images/howto/header_generate_pdf.jpg +0 -0
- package/public/logo_example.png +0 -0
- package/public/modules/csvMake.js +27 -0
- package/public/modules/importUmd.js +7 -0
- package/public/modules/pdfMake.js +7 -0
- package/public/modules/vfs_fonts.js +12 -0
- package/public/sitemap.xml +216 -201
- package/templates/blocks/exampleTransformer.js +1 -1
- package/templates/blog.yaml.njk +221 -0
- package/templates/footer.yaml.njk +2 -2
- package/tutorial/tutorial-create-page.yaml +1 -1
- package/tutorial/tutorial-start.yaml +1 -1
- package/users/login-and-logout.yaml +2 -2
- package/users/openid-connect.yaml +1 -0
- package/users/protected-pages.yaml +2 -2
- package/users/roles.yaml +2 -2
- package/users/users-introduction.yaml +1 -1
- package/version.yaml +1 -1
|
@@ -0,0 +1,251 @@
|
|
|
1
|
+
# Copyright 2020-2021 Lowdefy, Inc
|
|
2
|
+
|
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
# you may not use this file except in compliance with the License.
|
|
5
|
+
# You may obtain a copy of the License at
|
|
6
|
+
|
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
|
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
# See the License for the specific language governing permissions and
|
|
13
|
+
# limitations under the License.
|
|
14
|
+
|
|
15
|
+
_ref:
|
|
16
|
+
path: templates/blog.yaml.njk
|
|
17
|
+
vars:
|
|
18
|
+
pageId: generate-csv-files-from-data
|
|
19
|
+
pageTitle: How to generate CSVs using Lowdefy
|
|
20
|
+
section: How To
|
|
21
|
+
filePath: howto/generate-csv.yaml
|
|
22
|
+
pageImage: /public/images/howto/header_generate_csv.jpg
|
|
23
|
+
discussionsLink: https://github.com/lowdefy/lowdefy/discussions/891
|
|
24
|
+
authorProfile: /public/images/authors/sandile.jpeg
|
|
25
|
+
authorName: |
|
|
26
|
+
<div>Sandile Memela</div>
|
|
27
|
+
<a href="https://github.com/sah-memela">Follow @sah-memela on Github</a>
|
|
28
|
+
articleLinks:
|
|
29
|
+
- title: Generate PDFs from data in Lowdefy
|
|
30
|
+
pageId: generate-pdf-document-from-data
|
|
31
|
+
content:
|
|
32
|
+
- id: md1
|
|
33
|
+
type: MarkdownWithCode
|
|
34
|
+
properties:
|
|
35
|
+
style:
|
|
36
|
+
text-align: left
|
|
37
|
+
content: |
|
|
38
|
+
Adding the functionality to generate a CSV file in Lowdefy can be accomplished by using a [JsAction](/JsAction). This action can be triggered by any in app event, such as clicking a button. This action evokes a JavaScript function that generates and downloads a CSV file.
|
|
39
|
+
|
|
40
|
+
Click the button below to see this in action:
|
|
41
|
+
|
|
42
|
+
- id: generate_csv
|
|
43
|
+
type: Button
|
|
44
|
+
properties:
|
|
45
|
+
size: large
|
|
46
|
+
title: Generate a CSV
|
|
47
|
+
color: '#1890ff'
|
|
48
|
+
events:
|
|
49
|
+
onClick:
|
|
50
|
+
- id: generate_csv
|
|
51
|
+
type: JsAction
|
|
52
|
+
params:
|
|
53
|
+
name: csvMake
|
|
54
|
+
args:
|
|
55
|
+
- profiles.csv # csv filename
|
|
56
|
+
- - Username: booker12 # an array of data, usually a reference
|
|
57
|
+
Identifier: 9012
|
|
58
|
+
FirstName: Rachel
|
|
59
|
+
LastName: Booker
|
|
60
|
+
- Username: grey07
|
|
61
|
+
Identifier: 2070
|
|
62
|
+
FirstName: Laura
|
|
63
|
+
LastName: Grey
|
|
64
|
+
- Username: johnson81
|
|
65
|
+
Identifier: 4081
|
|
66
|
+
FirstName: Craig
|
|
67
|
+
LastName: Johnson
|
|
68
|
+
- Username: jenkins46
|
|
69
|
+
Identifier: 9346
|
|
70
|
+
FirstName: Mary
|
|
71
|
+
LastName: Jenkins
|
|
72
|
+
- Username: smith79
|
|
73
|
+
Identifier: 5079
|
|
74
|
+
FirstName: Jamie
|
|
75
|
+
LastName: Smith
|
|
76
|
+
- - Username # an array of field definitions
|
|
77
|
+
- Identifier
|
|
78
|
+
- FirstName
|
|
79
|
+
- LastName
|
|
80
|
+
|
|
81
|
+
- id: md2
|
|
82
|
+
type: MarkdownWithCode
|
|
83
|
+
properties:
|
|
84
|
+
content: |
|
|
85
|
+
The full project folder for this how-to is available at:
|
|
86
|
+
https://github.com/lowdefy/lowdefy/tree/main/packages/docs/howto/generateCsv
|
|
87
|
+
|
|
88
|
+
> This how-to assumes that you are already running a Lowdefy app locally in dev mode. If not:
|
|
89
|
+
> 1) Create a empty folder.
|
|
90
|
+
> 2) Open your terminal or cmd and `cd` to your empty folder.
|
|
91
|
+
> 3) Run `npx lowdefy@latest init && npx lowdefy@latest dev` to initialize and start your Lowdefy app development server.
|
|
92
|
+
|
|
93
|
+
## Generate CSV files TLDR;
|
|
94
|
+
|
|
95
|
+
1. Add the CSV JavaScript function to the app and register the [JsAction](/JsAction) method.
|
|
96
|
+
2. Load the custom JavaScript using a script tag.
|
|
97
|
+
3. Add a JsAction to a button's onClick event with parameters populated.
|
|
98
|
+
- id: md_vid
|
|
99
|
+
type: DangerousMarkdown
|
|
100
|
+
properties:
|
|
101
|
+
DOMPurifyOptions:
|
|
102
|
+
ADD_TAGS:
|
|
103
|
+
- iframe
|
|
104
|
+
content: |
|
|
105
|
+
<div style="position: relative; padding-bottom: 62.5%; height: 0;"><iframe src="https://www.loom.com/embed/b12dad89d2b54c5aad84bd92593bb7cd" frameborder="0" webkitallowfullscreen mozallowfullscreen allowfullscreen style="position: absolute; top: 0; left: 0; width: 100%; height: 100%;"></iframe></div>
|
|
106
|
+
- id: md2_1
|
|
107
|
+
type: MarkdownWithCode
|
|
108
|
+
properties:
|
|
109
|
+
content: |
|
|
110
|
+
## 1. Add the CSV JavaScript function to the app and register the JsAction method
|
|
111
|
+
|
|
112
|
+
Custom JavaScript code can be added to a Lowdefy app to allow it to accomplish things that extend the functionality of Lowdefy. Let's create a custom action which will generate a CSV based on a JavaScript function called `csvMakeFn`.
|
|
113
|
+
|
|
114
|
+
1) Create a `public` folder inside your Lowdefy working directory.
|
|
115
|
+
2) Since all content in the `public` folder is served by the Lowdefy server, simply create a `csvMake.js` file inside the `public` folder.
|
|
116
|
+
3) Add this script to the file and save.
|
|
117
|
+
|
|
118
|
+
###### /public/csvMake.js
|
|
119
|
+
```js
|
|
120
|
+
const csvMakeFn = async (
|
|
121
|
+
context,
|
|
122
|
+
filename,
|
|
123
|
+
data,
|
|
124
|
+
fields,
|
|
125
|
+
) => {
|
|
126
|
+
if (!Array.isArray(data) || typeof data[0] !== 'object') {
|
|
127
|
+
throw new Error('csvMake data takes an array of objects');
|
|
128
|
+
}
|
|
129
|
+
if (!fields) {
|
|
130
|
+
fields = Object.keys(data[0]);
|
|
131
|
+
}
|
|
132
|
+
const arrays = [fields];
|
|
133
|
+
data.forEach(obj => arrays.push(fields.map(field => obj[field])));
|
|
134
|
+
const csv = arrays.map(row =>
|
|
135
|
+
row
|
|
136
|
+
.map(cell => typeof cell === 'undefined' || cell === null ? '' : cell)
|
|
137
|
+
.map(String)
|
|
138
|
+
.map(v => v.replaceAll('"', '""'))
|
|
139
|
+
.map(v => `"${v}"`)
|
|
140
|
+
.join(',')
|
|
141
|
+
).join('\r\n');
|
|
142
|
+
const blob = new Blob([csv], { type: 'text/csv;charset=utf-8;' });
|
|
143
|
+
const url = URL.createObjectURL(blob);
|
|
144
|
+
const el = document.createElement('a');
|
|
145
|
+
el.href = url;
|
|
146
|
+
el.setAttribute('download', filename);
|
|
147
|
+
el.click();
|
|
148
|
+
};
|
|
149
|
+
window.lowdefy.registerJsAction('csvMake', csvMakeFn);
|
|
150
|
+
```
|
|
151
|
+
This script gets a few things done, firstly a csvMake function is defined and it checks if an array of data has been provided and whether the CSV fields have been populated. It then creates an array with fields and adds the provided data to the array according to the field definition. Finally, a file is downloaded using this data string.
|
|
152
|
+
|
|
153
|
+
It is important to note that to call this function from within your Lowdefy app, it needs to be registered as a [JsAction](/JsAction). This is done by calling the `window.registerAction` function, which takes two arguments - the action name and the action function. Once this is done, the action can be triggered by any event that calls this function along with parameters.
|
|
154
|
+
|
|
155
|
+
## 2. Load the custom JavaScript using a script tag
|
|
156
|
+
|
|
157
|
+
To load the external JavaScript file we use the `app.html.appendHead` property in the `lowdefy.yaml` file to add a script tag that loads the module:
|
|
158
|
+
|
|
159
|
+
###### /lowdefy.yaml
|
|
160
|
+
```yaml
|
|
161
|
+
name: Generate a CSV
|
|
162
|
+
lowdefy: {{ version }}
|
|
163
|
+
app:
|
|
164
|
+
html:
|
|
165
|
+
appendHead: |
|
|
166
|
+
<script type="module" src="/public/csvMake.js"></script>
|
|
167
|
+
pages:
|
|
168
|
+
# ...
|
|
169
|
+
```
|
|
170
|
+
|
|
171
|
+
This instructs the browser to fetch and execute our JavaScript file, which registers the action function so it can be used in the app.
|
|
172
|
+
|
|
173
|
+
## 3. Add a JsAction to a button's onClick event with parameters populated
|
|
174
|
+
|
|
175
|
+
Lowdefy actions are triggered by events, like `onClick` when a user clicks a button, or `onEnter` when the page loads. Lowdefy comes with a list of predefined actions, however, sometimes custom code is just what you need.
|
|
176
|
+
|
|
177
|
+
By default Lowdefy builds apps with a set of pre-configured, default block types to make it easier to build apps, for example using [`Button`](/Button), [`TextInput`](/TextInput), [`Box`](/Box), etc. All the blocks documented in the Lowdefy docs are default types.
|
|
178
|
+
|
|
179
|
+
We will be using a [`Button`](/Button) with an `onClick` event to trigger the JsAction that will generate and download the CSV from the provided data.
|
|
180
|
+
|
|
181
|
+
We will need to pass an array with the arguments for the csvMake function (csv filename, data, field definitions) to the custom JsAction.
|
|
182
|
+
|
|
183
|
+
Edit the `docs_button` in the Welcome page to include the JsAction as shown below:
|
|
184
|
+
|
|
185
|
+
###### /lowdefy.yaml
|
|
186
|
+
```yaml
|
|
187
|
+
lowdefy: 3.23.2
|
|
188
|
+
name: Generate PDF from data with Lowdefy
|
|
189
|
+
|
|
190
|
+
app:
|
|
191
|
+
html:
|
|
192
|
+
appendHead: |
|
|
193
|
+
<script type="module" src="/public/csvMake.js"></script>
|
|
194
|
+
|
|
195
|
+
pages:
|
|
196
|
+
- id: example
|
|
197
|
+
type: PageHeaderMenu
|
|
198
|
+
properties:
|
|
199
|
+
title: Example
|
|
200
|
+
areas:
|
|
201
|
+
content:
|
|
202
|
+
justify: center
|
|
203
|
+
blocks:
|
|
204
|
+
- id: generate_csv
|
|
205
|
+
type: Button
|
|
206
|
+
properties:
|
|
207
|
+
size: large
|
|
208
|
+
title: Generate a CSV
|
|
209
|
+
color: '#1890ff'
|
|
210
|
+
events:
|
|
211
|
+
onClick:
|
|
212
|
+
- id: generate_csv
|
|
213
|
+
type: JsAction
|
|
214
|
+
params:
|
|
215
|
+
name: csvMake
|
|
216
|
+
args:
|
|
217
|
+
- profiles.csv # csv filename
|
|
218
|
+
- - Username: booker12 # an array of data, usually a reference
|
|
219
|
+
Identifier: 9012
|
|
220
|
+
FirstName: Rachel
|
|
221
|
+
LastName: Booker
|
|
222
|
+
- Username: grey07
|
|
223
|
+
Identifier: 2070
|
|
224
|
+
FirstName: Laura
|
|
225
|
+
LastName: Grey
|
|
226
|
+
- Username: johnson81
|
|
227
|
+
Identifier: 4081
|
|
228
|
+
FirstName: Craig
|
|
229
|
+
LastName: Johnson
|
|
230
|
+
- Username: jenkins46
|
|
231
|
+
Identifier: 9346
|
|
232
|
+
FirstName: Mary
|
|
233
|
+
LastName: Jenkins
|
|
234
|
+
- Username: smith79
|
|
235
|
+
Identifier: 5079
|
|
236
|
+
FirstName: Jamie
|
|
237
|
+
LastName: Smith
|
|
238
|
+
- - Username # an array of field definitions
|
|
239
|
+
- Identifier
|
|
240
|
+
- FirstName
|
|
241
|
+
- LastName
|
|
242
|
+
```
|
|
243
|
+
|
|
244
|
+
## Conclusion
|
|
245
|
+
|
|
246
|
+
Congratulations 🏆 your custom JsAction is now available in your Lowdefy app and ready to use to generate a CSV with the click of a button.
|
|
247
|
+
|
|
248
|
+
Check out the project folder for this how-to and why not give it a try:
|
|
249
|
+
https://github.com/lowdefy/lowdefy/tree/main/packages/docs/howto/generateCsv
|
|
250
|
+
|
|
251
|
+
Next, try fetching data from a data source and generate a CSV from the returned data.
|