-
Notifications
You must be signed in to change notification settings - Fork 69
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
customization: instructions for changing menus
- Loading branch information
1 parent
2d132a9
commit 1c495bf
Showing
3 changed files
with
110 additions
and
0 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
# Change Menus | ||
|
||
For navigation, InvenioRDM uses *menu*s. For example, one such menu is at the | ||
top of the dashboard shown to users on their personal page (with submenus | ||
*Uploads*, *Communities*, and *Requests*): | ||
 | ||
Menus are configurable in the following ways: | ||
|
||
- which tabs to show | ||
- what title-text to show in those tabs | ||
- which endpoint to request when clicking them | ||
- how to dynamically show/hide them (e.g. depending on currently logged-in user) | ||
|
||
## Step-by-step | ||
|
||
**Step 0** - Structure of Configuration | ||
|
||
The user-dashboard menu pictured above is internally named `"dashboard"`. | ||
The part of the menu-configuration particular to the `"dashboard"`-menu | ||
might look something like this: | ||
|
||
```python | ||
FLASK_MENU = { | ||
"dashboard": { | ||
"uploads": { | ||
"endpoint": "invenio_app_rdm_users.uploads", | ||
"text": _("Uploads"), | ||
"order": 1, | ||
}, | ||
"communities": { | ||
"endpoint": "invenio_app_rdm_users.communities", | ||
"text": _("Communities"), | ||
"order": 2, | ||
}, | ||
"requests": { | ||
"endpoint": "invenio_app_rdm_users.requests", | ||
"text": _("Requests"), | ||
"order": 3, | ||
}, | ||
}, | ||
... # configuration for other menus | ||
} | ||
``` | ||
Here, | ||
|
||
- `"endpoint"` is the flask-endpoint requested when clicking the tab | ||
- `"text"` is the title-text in the tab | ||
- `"order"` determines order of tabs left-to-right | ||
|
||
**Step 1** - Modify menus via your `invenio.cfg` | ||
|
||
The relevant config-variable is `FLASK_MENU`. | ||
It will be populated with defaults when python-imports run. | ||
You can overwrite these defaults by adding to your `invenio.cfg` file: | ||
|
||
- overwrite the whole menu: | ||
```python | ||
# invenio.cfg file | ||
|
||
from flask_menu.config import FLASK_MENU | ||
|
||
FLASK_MENU["dashboard"] = { | ||
"uploads": { | ||
"endpoint": "my_user_endpoints.uploads", | ||
"text": _("UPLOADS IN ALLCAPS"), | ||
"order": 0, | ||
}, | ||
# other tabs in default-configuration will be cut out | ||
} | ||
``` | ||
|
||
- overwrite only a specific field of one submenu: | ||
```python | ||
# invenio.cfg file | ||
|
||
from flask_menu.config import FLASK_MENU | ||
|
||
FLASK_MENU["dashboard"]["communities"]["order"] = 4 | ||
``` | ||
|
||
**Step 2** - Re-run the server | ||
|
||
```shell | ||
<CTRL+C> | ||
invenio-cli run | ||
``` | ||
|
||
## Advanced Configuration | ||
|
||
You can add to the configuration any kwarg that | ||
`flask_menu.menu:MenuNode.register` understands. | ||
|
||
### Configuring visibility | ||
|
||
`visible_when` can be any function that can be called with no arguments and | ||
returns a boolean. | ||
|
||
```python | ||
# invenio.cfg file | ||
|
||
from flask_menu import FLASK_MENU | ||
from invenio_config_my_institution import current_user_may_upload | ||
|
||
FLASK_MENU["dashboard"]["uploads"]["visible_when"] = current_user_may_upload | ||
``` | ||
|
||
## Currently Configurable Menus | ||
|
||
- `"dashboard"`: dashboard on users' personal page |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters