@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,63 @@
|
|
|
1
|
+
lowdefy: 3.23.2
|
|
2
|
+
name: Generate PDF from data with Lowdefy
|
|
3
|
+
|
|
4
|
+
app:
|
|
5
|
+
html:
|
|
6
|
+
appendHead: |
|
|
7
|
+
<script type="module" src="/public/csvMake.js"></script>
|
|
8
|
+
|
|
9
|
+
pages:
|
|
10
|
+
- id: example
|
|
11
|
+
type: PageHeaderMenu
|
|
12
|
+
properties:
|
|
13
|
+
title: Example
|
|
14
|
+
areas:
|
|
15
|
+
content:
|
|
16
|
+
justify: center
|
|
17
|
+
blocks:
|
|
18
|
+
- id: generate_csv
|
|
19
|
+
type: Button
|
|
20
|
+
properties:
|
|
21
|
+
size: large
|
|
22
|
+
title: Generate a CSV
|
|
23
|
+
color: '#1890ff'
|
|
24
|
+
events:
|
|
25
|
+
onClick:
|
|
26
|
+
- id: generate_csv
|
|
27
|
+
type: JsAction
|
|
28
|
+
params:
|
|
29
|
+
name: csvMake
|
|
30
|
+
args:
|
|
31
|
+
- profiles.csv # csv filename
|
|
32
|
+
- - Username: booker12 # an array of data, usually a reference
|
|
33
|
+
Identifier: 9012
|
|
34
|
+
FirstName: Rachel
|
|
35
|
+
LastName: Booker
|
|
36
|
+
- Username: grey07
|
|
37
|
+
Identifier: 2070
|
|
38
|
+
FirstName: Laura
|
|
39
|
+
LastName: Grey
|
|
40
|
+
- Username: johnson81
|
|
41
|
+
Identifier: 4081
|
|
42
|
+
FirstName: Craig
|
|
43
|
+
LastName: Johnson
|
|
44
|
+
- Username: jenkins46
|
|
45
|
+
Identifier: 9346
|
|
46
|
+
FirstName: Mary
|
|
47
|
+
LastName: Jenkins
|
|
48
|
+
- Username: smith79
|
|
49
|
+
Identifier: 5079
|
|
50
|
+
FirstName: Jamie
|
|
51
|
+
LastName: Smith
|
|
52
|
+
- - Username # an array of field definitions
|
|
53
|
+
- Identifier
|
|
54
|
+
- FirstName
|
|
55
|
+
- LastName
|
|
56
|
+
footer:
|
|
57
|
+
blocks:
|
|
58
|
+
- id: footer
|
|
59
|
+
type: Paragraph
|
|
60
|
+
properties:
|
|
61
|
+
type: secondary
|
|
62
|
+
content: |
|
|
63
|
+
Made by a Lowdefy 🤖
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
const csvMakeFn = async (context, filename, data, fields) => {
|
|
2
|
+
if (!Array.isArray(data) || typeof data[0] !== 'object') {
|
|
3
|
+
throw new Error('csvMake data takes an array of objects');
|
|
4
|
+
}
|
|
5
|
+
if (!fields) {
|
|
6
|
+
fields = Object.keys(data[0]);
|
|
7
|
+
}
|
|
8
|
+
const arrays = [fields];
|
|
9
|
+
data.forEach((obj) => arrays.push(fields.map((field) => obj[field])));
|
|
10
|
+
const csv = arrays
|
|
11
|
+
.map((row) =>
|
|
12
|
+
row
|
|
13
|
+
.map((cell) => (typeof cell === 'undefined' || cell === null ? '' : cell))
|
|
14
|
+
.map(String)
|
|
15
|
+
.map((v) => v.replaceAll('"', '""'))
|
|
16
|
+
.map((v) => `"${v}"`)
|
|
17
|
+
.join(',')
|
|
18
|
+
)
|
|
19
|
+
.join('\r\n');
|
|
20
|
+
const blob = new Blob([csv], { type: 'text/csv;charset=utf-8;' });
|
|
21
|
+
const url = URL.createObjectURL(blob);
|
|
22
|
+
const el = document.createElement('a');
|
|
23
|
+
el.href = url;
|
|
24
|
+
el.setAttribute('download', filename);
|
|
25
|
+
el.click();
|
|
26
|
+
};
|
|
27
|
+
window.lowdefy.registerJsAction('csvMake', csvMakeFn);
|
|
@@ -0,0 +1,200 @@
|
|
|
1
|
+
- _nunjucks:
|
|
2
|
+
on:
|
|
3
|
+
_state: invoice
|
|
4
|
+
template: 'INV-{{ id }}-{{ inv_date | date("DD-MM-YYYY") }}.pdf'
|
|
5
|
+
- pageMargins: [50, 25, 50, 70]
|
|
6
|
+
defaultStyle:
|
|
7
|
+
fontSize: 10
|
|
8
|
+
images:
|
|
9
|
+
logo:
|
|
10
|
+
_string.concat:
|
|
11
|
+
- _location: origin
|
|
12
|
+
- /public/logo_example.png
|
|
13
|
+
footer:
|
|
14
|
+
_function:
|
|
15
|
+
- columns:
|
|
16
|
+
- qr:
|
|
17
|
+
_string.concat:
|
|
18
|
+
- _location: origin
|
|
19
|
+
- /invoice?id="
|
|
20
|
+
- _state: invoice.id
|
|
21
|
+
- '"'
|
|
22
|
+
margin: [50, 0, 0, 0]
|
|
23
|
+
fit: '64'
|
|
24
|
+
- alignment: 'right'
|
|
25
|
+
fontSize: 7
|
|
26
|
+
margin: [0, 0, 50, 0]
|
|
27
|
+
text:
|
|
28
|
+
__nunjucks:
|
|
29
|
+
template: 'Page {{ page }} of {{ total }}'
|
|
30
|
+
on:
|
|
31
|
+
page:
|
|
32
|
+
__args: 0
|
|
33
|
+
total:
|
|
34
|
+
__args: 1
|
|
35
|
+
content:
|
|
36
|
+
- columns:
|
|
37
|
+
- width: 'auto'
|
|
38
|
+
margin: [0, 20, 0, 0]
|
|
39
|
+
stack:
|
|
40
|
+
- fontSize: 9
|
|
41
|
+
text: |
|
|
42
|
+
|
|
43
|
+
- fontSize: 7
|
|
44
|
+
text: |
|
|
45
|
+
Example Services Ltd.
|
|
46
|
+
112 Street Name
|
|
47
|
+
City, State 12345
|
|
48
|
+
Country
|
|
49
|
+
001-AB
|
|
50
|
+
|
|
51
|
+
+00-1234-5566
|
|
52
|
+
info@example.com
|
|
53
|
+
|
|
54
|
+
Vat Number: 444 5555 0000
|
|
55
|
+
|
|
56
|
+
- width: '*'
|
|
57
|
+
text: ' '
|
|
58
|
+
- width: 110
|
|
59
|
+
stack:
|
|
60
|
+
- width: 110
|
|
61
|
+
image: logo
|
|
62
|
+
- margin: [0, 5, 0, 0]
|
|
63
|
+
alignment: right
|
|
64
|
+
fontSize: 7
|
|
65
|
+
text: |
|
|
66
|
+
Example Services Ltd.
|
|
67
|
+
Reg Number: 2001/22224/09
|
|
68
|
+
|
|
69
|
+
- margin: [0, 20, 0, 20]
|
|
70
|
+
text: Customer Invoice
|
|
71
|
+
bold: true
|
|
72
|
+
alignment: center
|
|
73
|
+
fontSize: 14
|
|
74
|
+
- columns:
|
|
75
|
+
- width: 150
|
|
76
|
+
bold: true
|
|
77
|
+
text: |
|
|
78
|
+
INVOICE NUMBER:
|
|
79
|
+
DATE ISSUED:
|
|
80
|
+
ACCOUNT NUMBER:
|
|
81
|
+
- width: '*'
|
|
82
|
+
text:
|
|
83
|
+
_nunjucks:
|
|
84
|
+
template: |
|
|
85
|
+
{{ id }}
|
|
86
|
+
{{ inv_date | date("YYYY/MM/DD") }}
|
|
87
|
+
{{ account_id }}
|
|
88
|
+
on:
|
|
89
|
+
_state: invoice
|
|
90
|
+
- width: 150
|
|
91
|
+
bold: true
|
|
92
|
+
text: |
|
|
93
|
+
CUSTOMER:
|
|
94
|
+
ADDRESS:
|
|
95
|
+
- width: '*'
|
|
96
|
+
text:
|
|
97
|
+
_nunjucks:
|
|
98
|
+
template: |
|
|
99
|
+
{{ customer.name }}
|
|
100
|
+
{{ customer.address }}
|
|
101
|
+
on:
|
|
102
|
+
_state: invoice
|
|
103
|
+
|
|
104
|
+
- layout: 'lightHorizontalLines'
|
|
105
|
+
margin: [0, 10, 0, 0]
|
|
106
|
+
table:
|
|
107
|
+
widths: [70, '*', 70, 70, 70]
|
|
108
|
+
headerRows: 1
|
|
109
|
+
body:
|
|
110
|
+
_json.parse:
|
|
111
|
+
_nunjucks:
|
|
112
|
+
on:
|
|
113
|
+
services:
|
|
114
|
+
_state: invoice.services
|
|
115
|
+
template: |
|
|
116
|
+
[
|
|
117
|
+
[
|
|
118
|
+
{ "text": "ITEM CODE", "bold": true },
|
|
119
|
+
{ "text": "SERVICE", "bold": true },
|
|
120
|
+
{ "text": "UNIT PRICE", "bold": true, "alignment": "right" },
|
|
121
|
+
{ "text": "QTY", "bold": true, "alignment": "right" },
|
|
122
|
+
{ "text": "COST", "bold": true, "alignment": "right" }
|
|
123
|
+
],
|
|
124
|
+
{% for item in services %}
|
|
125
|
+
[
|
|
126
|
+
"{{ loop.index }}: {{ item.code }}",
|
|
127
|
+
"{{ item.name | safe }}",
|
|
128
|
+
{ "text": "{{ ( item.price / item.qty ).toFixed(2) }}", "alignment": "right"},
|
|
129
|
+
{ "text": "{{ item.qty }}", "alignment": "right"},
|
|
130
|
+
{ "text": "{{ item.price.toFixed(2) }}", "alignment": "right"}
|
|
131
|
+
{% if loop.last %} ] {% else %} ], {% endif %}
|
|
132
|
+
{% endfor %}
|
|
133
|
+
]
|
|
134
|
+
- layout: 'headerLineOnly'
|
|
135
|
+
margin: [0, -5, 0, 0]
|
|
136
|
+
table:
|
|
137
|
+
widths: ['*', 70, 70, 70]
|
|
138
|
+
headerRows: 1
|
|
139
|
+
body:
|
|
140
|
+
- - ''
|
|
141
|
+
- ''
|
|
142
|
+
- ''
|
|
143
|
+
- ''
|
|
144
|
+
- - ''
|
|
145
|
+
- alignment: right
|
|
146
|
+
text: 'Subtotal:'
|
|
147
|
+
- ''
|
|
148
|
+
- alignment: right
|
|
149
|
+
text:
|
|
150
|
+
_number.toFixed:
|
|
151
|
+
- _state: invoice.subtotal
|
|
152
|
+
- 2
|
|
153
|
+
- - ''
|
|
154
|
+
- alignment: right
|
|
155
|
+
text: 'Discount (5%):'
|
|
156
|
+
- ''
|
|
157
|
+
- alignment: right
|
|
158
|
+
text:
|
|
159
|
+
_number.toFixed:
|
|
160
|
+
- _state: invoice.discount
|
|
161
|
+
- 2
|
|
162
|
+
- - ''
|
|
163
|
+
- alignment: right
|
|
164
|
+
text: 'VAT (15%):'
|
|
165
|
+
- ''
|
|
166
|
+
- alignment: right
|
|
167
|
+
text:
|
|
168
|
+
_number.toFixed:
|
|
169
|
+
- _state: invoice.vat
|
|
170
|
+
- 2
|
|
171
|
+
- - ''
|
|
172
|
+
- alignment: right
|
|
173
|
+
text: 'Total:'
|
|
174
|
+
- ''
|
|
175
|
+
- alignment: right
|
|
176
|
+
text:
|
|
177
|
+
_number.toFixed:
|
|
178
|
+
- _state: invoice.total
|
|
179
|
+
- 2
|
|
180
|
+
- layout: 'headerLineOnly'
|
|
181
|
+
margin: [0, -5, 0, 0]
|
|
182
|
+
table:
|
|
183
|
+
widths: ['*', 70, 70, 70]
|
|
184
|
+
headerRows: 1
|
|
185
|
+
body:
|
|
186
|
+
- - ''
|
|
187
|
+
- ''
|
|
188
|
+
- ''
|
|
189
|
+
- ''
|
|
190
|
+
- - ''
|
|
191
|
+
- alignment: right
|
|
192
|
+
bold: true
|
|
193
|
+
text: 'BALANCE DUE:'
|
|
194
|
+
- ''
|
|
195
|
+
- alignment: right
|
|
196
|
+
bold: true
|
|
197
|
+
text:
|
|
198
|
+
_number.toFixed:
|
|
199
|
+
- _state: invoice.balance
|
|
200
|
+
- 2
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
lowdefy: 3.23.2
|
|
2
|
+
name: Generate PDF from data with Lowdefy
|
|
3
|
+
|
|
4
|
+
app:
|
|
5
|
+
html:
|
|
6
|
+
appendHead:
|
|
7
|
+
_ref: my_header.html
|
|
8
|
+
|
|
9
|
+
pages:
|
|
10
|
+
- id: example
|
|
11
|
+
type: PageHeaderMenu
|
|
12
|
+
properties:
|
|
13
|
+
title: Example
|
|
14
|
+
events:
|
|
15
|
+
onEnter:
|
|
16
|
+
- id: init_data
|
|
17
|
+
type: SetState
|
|
18
|
+
params:
|
|
19
|
+
invoice:
|
|
20
|
+
id: '0030135'
|
|
21
|
+
account_id: 'A-11344'
|
|
22
|
+
inv_date:
|
|
23
|
+
_date: now
|
|
24
|
+
subtotal: 397.034
|
|
25
|
+
discount: -19.8517
|
|
26
|
+
vat: 59.5551
|
|
27
|
+
total: 436.7374
|
|
28
|
+
balance: 413.2330
|
|
29
|
+
customer:
|
|
30
|
+
name: Service Center
|
|
31
|
+
phone: +123-456-7890
|
|
32
|
+
vat_nmr: 12-333-4567
|
|
33
|
+
address: |
|
|
34
|
+
123 Main St.
|
|
35
|
+
Anytown
|
|
36
|
+
CA
|
|
37
|
+
US
|
|
38
|
+
9999
|
|
39
|
+
services:
|
|
40
|
+
- name: Hosting and Maintannce
|
|
41
|
+
qty: 1
|
|
42
|
+
price: 235.90
|
|
43
|
+
code: X12-33C
|
|
44
|
+
- name: Developer Hours
|
|
45
|
+
qty: 16
|
|
46
|
+
price: 60.345
|
|
47
|
+
code: X12-39A
|
|
48
|
+
- name: Designer Hours
|
|
49
|
+
qty: 4
|
|
50
|
+
price: 40.122
|
|
51
|
+
code: X12-21A
|
|
52
|
+
- name: Project Management
|
|
53
|
+
qty: 2
|
|
54
|
+
price: 60.667
|
|
55
|
+
code: X12-49A
|
|
56
|
+
areas:
|
|
57
|
+
content:
|
|
58
|
+
justify: center
|
|
59
|
+
blocks:
|
|
60
|
+
- id: content_card
|
|
61
|
+
type: Card
|
|
62
|
+
style:
|
|
63
|
+
maxWidth: 800
|
|
64
|
+
blocks:
|
|
65
|
+
- id: content
|
|
66
|
+
type: Result
|
|
67
|
+
properties:
|
|
68
|
+
title: Generate PDF from data with Lowdefy
|
|
69
|
+
subTitle: <a href="https://docs.lowdefy.com/generate-pdf-document-from-data">Read the full how to guide</a>
|
|
70
|
+
icon:
|
|
71
|
+
name: PrinterTwoTone
|
|
72
|
+
color: '#ff0000'
|
|
73
|
+
areas:
|
|
74
|
+
extra:
|
|
75
|
+
gutter: 16
|
|
76
|
+
blocks:
|
|
77
|
+
- id: customer_description
|
|
78
|
+
type: Descriptions
|
|
79
|
+
properties:
|
|
80
|
+
bordered: true
|
|
81
|
+
size: small
|
|
82
|
+
title:
|
|
83
|
+
_string.concat:
|
|
84
|
+
- 'Customer Details: '
|
|
85
|
+
- _state: invoice.account_id
|
|
86
|
+
column: 2
|
|
87
|
+
items:
|
|
88
|
+
_change_case.capitalCase:
|
|
89
|
+
options:
|
|
90
|
+
convertKeys: true
|
|
91
|
+
on:
|
|
92
|
+
_state: invoice.customer
|
|
93
|
+
|
|
94
|
+
- id: generate_pdf_button
|
|
95
|
+
type: Button
|
|
96
|
+
properties:
|
|
97
|
+
size: large
|
|
98
|
+
title: Generate Invoice
|
|
99
|
+
color: '#1890ff'
|
|
100
|
+
events:
|
|
101
|
+
onClick:
|
|
102
|
+
- id: make_pdf
|
|
103
|
+
type: JsAction
|
|
104
|
+
params:
|
|
105
|
+
name: pdfMake
|
|
106
|
+
args:
|
|
107
|
+
_ref:
|
|
108
|
+
path: inv_template.yaml
|
|
109
|
+
footer:
|
|
110
|
+
blocks:
|
|
111
|
+
- id: footer
|
|
112
|
+
type: Paragraph
|
|
113
|
+
properties:
|
|
114
|
+
type: secondary
|
|
115
|
+
content: |
|
|
116
|
+
Made by a Lowdefy 🤖
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
<script defer type="module" src="/public/modules/pdfMake.js"></script>
|
|
Binary file
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import importUmd from './importUmd.js';
|
|
2
|
+
import vfs from './vfs_fonts.js';
|
|
3
|
+
const pdfMake = await importUmd(`https://cdn.jsdelivr.net/npm/pdfmake@0.2.2/build/pdfmake.min.js`);
|
|
4
|
+
const pdfMakeFn = async (context, filename, docDefinition, tableLayouts, fonts) => {
|
|
5
|
+
await pdfMake.createPdf(docDefinition, tableLayouts, fonts, vfs).download(filename);
|
|
6
|
+
};
|
|
7
|
+
window.lowdefy.registerJsAction('pdfMake', pdfMakeFn);
|