Skip to content

Commit

Permalink
implement ajax views and add urls
Browse files Browse the repository at this point in the history
  • Loading branch information
gromdimon committed Apr 25, 2024
1 parent 4819bb7 commit 6a063b4
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 1 deletion.
10 changes: 10 additions & 0 deletions projectroles/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,16 @@
view=views_ajax.ProjectStarringAjaxView.as_view(),
name='ajax_star',
),
path(
route='ajax/sidebar/<uuid:project>',
view=views_ajax.SidebarContentAjaxView.as_view(),
name='ajax_sidebar',
),
path(
route='ajax/dropdown/<uuid:project>',
view=views_ajax.UserDropdownContentAjaxView.as_view(),
name='ajax_user_dropdown',
),
path(
route='ajax/user/current',
view=views_ajax.CurrentUserRetrieveAjaxView.as_view(),
Expand Down
29 changes: 28 additions & 1 deletion projectroles/views_ajax.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
ROLE_RANKING,
)
from projectroles.plugins import get_active_plugins
from projectroles.utils import get_display_name
from projectroles.utils import get_display_name, AppLinkContent
from projectroles.views import ProjectAccessMixin, User
from projectroles.views_api import (
SODARAPIProjectPermission,
Expand Down Expand Up @@ -431,6 +431,33 @@ def post(self, request, *args, **kwargs):
return Response(1 if value else 0, status=200)


class SidebarContentAjaxView(SODARBaseProjectAjaxView):
"""Ajax view for delivering sidebar content for specific projects."""

permission_required = 'projectroles.view_project'

def get(self, request, *args, **kwargs):
project = self.get_project()
# Get the content for the sidebar
app_link_content = AppLinkContent()
# # Get the current URL for highlighting the active link
# current_url = request.GET.get('current_url')
sidebar_links = app_link_content.get_project_app_links(request, project)
return JsonResponse({'links': sidebar_links})


class UserDropdownContentAjaxView(SODARBaseAjaxView):
"""Ajax view for delivering user dropdown content for the navbar."""

permission_classes = [IsAuthenticated]

def get(self, request, *args, **kwargs):
# Get the content for the user dropdown
app_link_content = AppLinkContent()
user_dropdown_links = app_link_content.get_user_links(request)
return JsonResponse({'links': user_dropdown_links})


class CurrentUserRetrieveAjaxView(
SODARBaseAjaxMixin, CurrentUserRetrieveAPIView
):
Expand Down

0 comments on commit 6a063b4

Please sign in to comment.