Refactor sidebar logic into reusable component #1380
Labels
app: projectroles
Issue in the projectroles app
internal
Changes invisible to the user or APIs (e.g. refactoring and optimization)
Milestone
In #1366, we have a use case for providing sidebar content via an Ajax view to e.g. client-side single page apps. This enables them to display the sidebar content as they choose, without requiring the use of base SODAR Core templates.
Right now, the logic for building the sidebar is completely contained in the
_project_sidebar.html
template and associated template tags. We should move the logic away from the template and provide the necessary data as a reusable helper component. That enables us to both render the list in the server-side template in SODAR Core, as well as provide it to client-side SPAs via the Ajax view.Where to place the new helper turned out to be a somewhat complex issue. Having this as a context processor would not be optimal, as retrieving e.g. the project context there would be tricky. Also, this would create a very spagetti-ish processor method. My next idea was to extend
ProjectContextMixin
, but this would not correctly build the sidebar for site app views or the home view. The only 100% common factor between these views is the sidebar template, so we should still retrieve the list data via a template tag. But of course a template tag should not be used to add data into an Ajax view.In the end, the following solution seems to make the most sense:
Spec
AppLinkContent
class toprojectroles.utils
get_sidebar_links()
request
(HTTPRequest
object)project=None
(Project
object orNone
)url
: URL for the linklabel
: Text label to be displayedicon
: Icon to be used in format ofnamespace:id
, e.g.mdi:home
active
: Boolean for whether the link should be currently highlighted as activeget_sidebar_links()
(and potential internal helper methods in the new class)projectroles_tags
to retrieve sidebar listproject
from view context to parameter (will either be an object or None)sidebar_processor.py
TestProjectSidebar
_project_menu_btn.html
similarlyTasks
sidebar_processor
The text was updated successfully, but these errors were encountered: