You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: CHANGELOG.md
+10Lines changed: 10 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -21,6 +21,16 @@
21
21
- datagrids are now slightly more compact, with less padding and less space taken by each item.
22
22
- fix a bug in the [card](https://sql.ophir.dev/documentation.sql?component=card#component) component where the icon would sometimes overflow the card's text content.
23
23
- new `image` property in the [button](https://sql.ophir.dev/documentation.sql?component=button#component) component to display a small image inside a button.
24
+
- In the `shell` component
25
+
- allow easily creating complex menus even in SQLite:
26
+
```sql
27
+
select'shell'as component, 'My Website'as title, '{"title":"About","submenu":[{"link":"/x.sql","title":"X"},{"link":"/y.sql","title":"Y"}]}') as menu_item;
28
+
```
29
+
- allow easily creating optional menu items that are only displayed in some conditions:
30
+
```sql
31
+
select 'shell' as component, 'My Website' as title, CASE WHEN $role = 'admin' THEN 'Admin' END as menu_item;
{"link": "//github.com/lovasoa/SQLpage/blob/main/examples/", "title": "All examples & demos"}
821
821
]},
822
822
{"title": "Community", "submenu": [
@@ -899,46 +899,36 @@ FROM my_menu_items
899
899
900
900
(check your database documentation for the exact syntax of the `json_group_array` function).
901
901
902
-
Another "dynamic" aspect is when menu items are adjusted based on the environment. For example,
903
-
Logout/UserProfile buttons may be presented to an authenticated user and Login/SignUp, otherwise
904
-
(such an example will presented in a separate demo). The following simple example demonstrates
905
-
the concept by hiding one arbitrary menu when the page is loaded. Then you can select from a
906
-
dropdown menu, which menu to hide. To hide a menu item, return NULL or empty JSON object ''{}''
907
-
as demonstrated below.
902
+
Another case when dynamic menus are useful is when you want to show some
903
+
menu items only in certain conditions.
904
+
905
+
For instance, you could show an "Admin panel" menu item only to users with the "admin" role,
906
+
a "Profile" menu item only to authenticated users,
907
+
and a "Login" menu item only to unauthenticated users:
908
908
909
909
```sql
910
-
SET $dummy = ifnull(:menu, abs(random()) % 5);
910
+
SET $role = (
911
+
SELECT role FROM users
912
+
INNER JOIN sessions ON users.id = sessions.user_id
913
+
WHERE sessions.session_id = sqlpage.cookie(''session_id'')
914
+
); -- Read more about how to handle user sessions in the "authentication" component documentation
911
915
912
916
SELECT
913
-
''shell'' AS component,
914
-
''SQLPage'' AS title,
915
-
''database'' AS icon,
916
-
''/'' AS link,
917
-
iif($dummy = 1, NULL, ''{"title":"About","submenu":[{"link":"/safety.sql","title":"Security"},{"link":"/performance.sql","title":"Performance"}]}'') AS menu_item,
918
-
iif($dummy = 2, ''{}'', ''{"title":"Examples","submenu":[{"link":"/examples/tabs.sql","title":"Tabs"},{"link":"/examples/layouts.sql","title":"Layouts"}]}'') AS menu_item,
919
-
iif($dummy = 3, NULL, ''{"title":"Community","submenu":[{"link":"blog.sql","title":"Blog"},{"link":"//github.com/lovasoa/sqlpage/issues","title":"Report a bug"}]}'') AS menu_item,
920
-
iif($dummy = 4, ''{}'', ''{"title":"Documentation","submenu":[{"link":"/your-first-sql-website","title":"Getting started"},{"link":"/components.sql","title":"All Components"}]}'') AS menu_item,
921
-
''Official [SQLPage](https://sql.ophir.dev) documentation'' as footer;
917
+
''shell'' AS component,
918
+
''My authenticated website'' AS title,
922
919
920
+
-- Add an admin panel link if the user is an admin
921
+
CASE WHEN $role = ''admin'' THEN ''{"link": "admin.sql", "title": "Admin panel"}'' END AS menu_item,
923
922
924
-
SELECT
925
-
''form'' AS component,
926
-
''Hide Menu'' AS validate,
927
-
sqlpage.path() AS action;
928
-
SELECT
929
-
''select'' AS type,
930
-
''menu'' AS name,
931
-
''Hide Menu'' AS label,
932
-
2 AS width,
933
-
CAST($dummy AS INT) AS value,
934
-
''[{"label": "None", "value": 0},
935
-
{"label": "About", "value": 1},
936
-
{"label": "Examples", "value": 2},
937
-
{"label": "Community", "value": 3},
938
-
{"label": "Documentation", "value": 4}]'' AS options;
923
+
-- Add a profile page if the user is authenticated
924
+
CASE WHEN $role IS NOT NULL THEN ''{"link": "profile.sql", "title": "My profile"}'' END AS menu_item,
925
+
926
+
-- Add a login link if the user is not authenticated
927
+
CASE WHEN $role IS NULL THEN ''login'' END AS menu_item
928
+
;
939
929
```
940
930
941
-
Follow [this link](examples/dynamic_menu.sql) to try this code.
931
+
More about how to handle user sessions in the [authentication component documentation](?component=authentication#component).
0 commit comments