-
Notifications
You must be signed in to change notification settings - Fork 39
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add dropdowns to navigation and access nav items via file #3679
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
d4a0b05
Add dropdowns to navigation and access nav items via file
sandeepsajan0 a7b3364
Make menu items managable via env settings
sandeepsajan0 0a6224e
Redirect submissions overview and project overview pages to their res…
sandeepsajan0 2ef69a0
Add dropdown triangle, remove unnecessary urls, add focus visible to …
sandeepsajan0 9668b93
Put Nav dropdown on the top of filters by updating filters z-index
sandeepsajan0 5cc483a
Use new drop down menu on front and round page as well.
frjo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
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
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
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
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
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
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,68 @@ | ||
from django.conf import settings | ||
|
||
nav_items = [ | ||
{ | ||
"title": "My Dashboard", | ||
"url": "dashboard:dashboard", | ||
"permission_method": "has_dashboard_access", | ||
}, | ||
{ | ||
"title": "Submissions", | ||
"url": "apply:submissions:overview", # kind of basic url to figure out active tab | ||
"permission_method": "is_apply_staff_or_reviewer_required", | ||
"sub_items": [ | ||
{ | ||
"title": "All Submissions", | ||
"url": "apply:submissions:list", | ||
"permission_method": "is_apply_staff_or_reviewer_required", | ||
}, | ||
{ | ||
"title": "Staff Assignments", | ||
"url": "apply:submissions:staff_assignments", | ||
"permission_method": "is_apply_staff", | ||
}, | ||
{ | ||
"title": "Reviews", | ||
"url": "apply:submissions:reviewer_leaderboard", | ||
"permission_method": "is_apply_staff", | ||
}, | ||
{ | ||
"title": "Results", | ||
"url": "apply:submissions:result", | ||
"permission_method": "is_apply_staff", | ||
}, | ||
], | ||
}, | ||
{ | ||
"title": "Projects", | ||
"url": "apply:projects:overview", # kind of basic url to figure out active tab | ||
"permission_method": "is_apply_staff_or_finance_or_contracting", | ||
"sub_items": [ | ||
{ | ||
"title": "All Projects", | ||
"url": "apply:projects:all", | ||
"permission_method": "is_apply_staff_or_finance_or_contracting", | ||
}, | ||
{ | ||
"title": "Invoices", | ||
"url": "apply:projects:invoices", | ||
"permission_method": "is_apply_staff_or_finance", | ||
}, | ||
{ | ||
"title": "Reports", | ||
"url": "apply:projects:reports:all", | ||
"permission_method": "is_apply_staff_or_finance", | ||
}, | ||
], | ||
}, | ||
] | ||
|
||
|
||
if settings.APPLY_NAV_MENU_ITEMS: | ||
nav_items = settings.APPLY_NAV_MENU_ITEMS | ||
|
||
if settings.APPLY_NAV_SUBMISSIONS_ITEMS: | ||
nav_items[1]["sub_items"] = settings.APPLY_NAV_SUBMISSIONS_ITEMS | ||
|
||
if settings.APPLY_NAV_PROJECTS_ITEMS: | ||
nav_items[2]["sub_items"] = settings.APPLY_NAV_PROJECTS_ITEMS |
38 changes: 38 additions & 0 deletions
38
hypha/core/templates/core/navigation/primarynav-apply.html
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,38 @@ | ||
{% load i18n applynav_tags heroicons %} | ||
{% if request.user.is_authenticated %} | ||
<nav role="navigation" aria-label="Primary" class="w-full"> | ||
<ul class="nav nav--primary" role="menubar"> | ||
{% apply_nav_items request.user as nav_items %} | ||
{% for item in nav_items %} | ||
{% url item.url as target_url%} | ||
<li class="nav__item" role="presentation"> | ||
{% if item.sub_items %} | ||
<div class="relative inline-block" x-data="{open: false}"> | ||
<a class="nav__link {% if target_url in request.path %}nav__link--active{% endif %}" | ||
href="{% url item.url %}" | ||
aria-label="{% trans "Menu Item" %}" | ||
aria-haspopup="menu" | ||
aria-expanded="false" | ||
role="menuitem" | ||
@click.prevent="open = ! open"> | ||
{{ item.title }} | ||
{% heroicon_outline "chevron-down" aria_hidden="true" size=16 stroke_width=3 class="inline align-baseline mr-1" %} | ||
</a> | ||
<div x-cloak x-trap="open" x-on:keydown.escape="open = false" x-show="open" x-transition @click.outside="open = false" class="absolute block bg-white min-w-max shadow-lg z-1 mt-7 "> | ||
{% for sub_item in item.sub_items %} | ||
<a class="text-black px-4 py-3 block font-normal hover:bg-mid-grey focus-visible:ring-2" href="{% url sub_item.url %}"> | ||
{{ sub_item.title }} | ||
</a> | ||
{% endfor %} | ||
</div> | ||
</div> | ||
{% else %} | ||
<a class="nav__link {% if target_url in request.path %}nav__link--active{% endif %}" href="{{ target_url }}" role="menuitem"> | ||
{{ item.title }} | ||
</a> | ||
{% endif %} | ||
</li> | ||
{% endfor %} | ||
</ul> | ||
</nav> | ||
{% endif %} |
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,40 @@ | ||
import copy | ||
|
||
from django import template | ||
from django.core.exceptions import PermissionDenied | ||
|
||
from hypha.apply.users import decorators | ||
|
||
from ..navigation import nav_items | ||
|
||
register = template.Library() | ||
|
||
|
||
def has_permission(user, method): | ||
try: | ||
if getattr(decorators, method)(user): | ||
return True | ||
return False | ||
except PermissionDenied: | ||
return False | ||
except Exception: | ||
# just to handle unknown exceptions | ||
return False | ||
|
||
|
||
@register.simple_tag | ||
def apply_nav_items(user): | ||
temp_nav = copy.deepcopy(nav_items) | ||
item_count = 0 | ||
for item in nav_items: | ||
item_count = +1 | ||
removed = False | ||
if not has_permission(user, item["permission_method"]): | ||
temp_nav.remove(item) | ||
removed = True | ||
item_count = -1 | ||
if not removed and "sub_items" in item.keys(): | ||
for sub_item in item["sub_items"]: | ||
if not has_permission(user, sub_item["permission_method"]): | ||
temp_nav[item_count]["sub_items"].remove(sub_item) | ||
return temp_nav |
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
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 |
---|---|---|
|
@@ -7,7 +7,7 @@ | |
right: 0; | ||
bottom: 0; | ||
left: 0; | ||
z-index: 20; | ||
z-index: 9; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @frjo I have fixed the nav dropdown stacking issue here but just not sure if it is messing with any other UI component. |
||
display: block; | ||
width: 100%; | ||
height: 100vh; | ||
|
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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we here check if there is a setting that overrides the "categories" for submissions and project menu items?
Something like:
Or are there better solutions? I want it to be easy for a developer to add/change/maintain the menu subitems.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@frjo Now it can be easily managed via settings. We just have to pass a compact JSON in the env variable.
Like:
APPLY_NAV_SUBMISSIONS_ITEMS='[{"title":"All Submissions","url":"apply:submissions:list","permission_method":"is_apply_staff_or_reviewer_required"},{"title":"Staff Assignments","url":"apply:submissions:staff_assignments","permission_method":"is_apply_staff"},{"title":"Reviews","url":"apply:submissions:reviewer_leaderboard","permission_method":"is_apply_staff"},{"title":"Results","url":"apply:submissions:result","permission_method":"is_apply_staff"}]'