Skip to content

Commit cfc0ce3

Browse files
committed
download buttons
fixes #388
1 parent 231216a commit cfc0ce3

File tree

3 files changed

+19
-1
lines changed

3 files changed

+19
-1
lines changed

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@
1111
- [Updated SQL parser](https://github.com/sqlparser-rs/sqlparser-rs/blob/main/CHANGELOG.md#0470-2024-06-01). Fixes support for `AT TIME ZONE` in postgres. Fixes `GROUP_CONCAT()` in MySQL.
1212
- Add a new warning message in the logs when trying to use `SET $x = ` when there is already a form field named `x`.
1313
- **Empty Uploaded files**: when a form contains an optional file upload field, and the user does not upload a file, the field used to still be accessible to SQLPage file-related functions such as `sqlpage.uploaded_file_path` and `sqlpage.uploaded_file_mime_type`. This is now fixed, and these functions will return `NULL` when the user does not upload a file. `sqlpage.persist_uploaded_file` will not create an empty file in the target directory when the user does not upload a file, instead it will do nothing and return `NULL`.
14-
- In the [map](https://sql.ophir.dev/documentation.sql?component=map#component) component, when top-level latitude and longitude attributes are omitted, the map will now center on its markers. This makes it easier to create zoomed maps with a single marker.
14+
- In the [map](https://sql.ophir.dev/documentation.sql?component=map#component) component, when top-level latitude and longitude properties are omitted, the map will now center on its markers. This makes it easier to create zoomed maps with a single marker.
15+
- In the [button](https://sql.ophir.dev/documentation.sql?component=button#component) component, add a `download` property to make the button download a file when clicked, a `target` property to open the link in a new tab, and a `rel` property to prevent search engines from following the link.
1516

1617
## 0.22.0 (2024-05-29)
1718
- **Important Security Fix:** The behavior of `SET $x` has been modified to match `SELECT $x`.

examples/official-site/sqlpage/migrations/18_button.sql

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ INSERT INTO parameter(component, name, description, type, top_level, optional) S
2121
('icon_after', 'Name of an icon to display after the text in the button', 'ICON', FALSE, TRUE),
2222
('icon', 'Name of an icon to be displayed on the left side of the button.', 'ICON', FALSE, TRUE),
2323
('form', 'Identifier (id) of the form to which the button should submit.', 'TEXT', FALSE, TRUE),
24+
('rel', '"nofollow" when the contents of the target link are not endorsed, "noopener" when the target is not trusted, and "noreferrer" to hide where the user came from when they open the link.', 'TEXT', FALSE, TRUE),
25+
('target', '"_blank" to open the link in a new tab, "_self" to open it in the same tab, "_parent" to open it in the parent frame, or "_top" to open it in the full body of the window.', 'TEXT', FALSE, TRUE),
26+
('download', 'If defined, the link will download the target instead of navigating to it. Set the value to the desired name of the downloaded file.', 'TEXT', FALSE, TRUE),
2427
('id', 'HTML Identifier to add to the button element.', 'TEXT', FALSE, TRUE)
2528
) x;
2629

@@ -77,4 +80,15 @@ In the target page, we could then use the GET variable `$action` to determine wh
7780
{"component":"button"},
7881
{"link":"?action=save", "form":"poem", "color":"primary", "title":"Save" },
7982
{"link":"?action=preview", "form":"poem", "outline":"yellow", "title":"Preview" }]')
83+
);
84+
85+
INSERT INTO example(component, description, properties) VALUES
86+
('button', 'A button that downloads a file when clicked, and prevents search engines from following the link.',
87+
json('[{"component":"button"},
88+
{"link":"/sqlpage_introduction_video.webm",
89+
"title":"Download Video",
90+
"icon":"download",
91+
"download":"Introduction Video.webm",
92+
"rel":"nofollow"
93+
}]')
8094
);

sqlpage/templates/button.handlebars

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@
1212
{{~#if ../shape}} btn-{{../shape}}{{/if}}
1313
{{~#if space_after}} me-auto{{/if}}"
1414
{{~#if id}} id="{{id}}"{{/if}}
15+
{{~#if target}} target="{{target}}"{{/if}}
16+
{{~#if download}} download="{{download}}"{{/if}}
17+
{{~#if rel}} rel="{{rel}}"{{/if}}
1518
{{~#if tooltip}} data-bs-toggle="tooltip" data-bs-placement="top" title="{{tooltip}}"{{/if}}
1619
role="button">
1720
{{~#if icon~}}

0 commit comments

Comments
 (0)