Closed markfinger closed 7 years ago
Can we activate it by default, please? I think it's something we'll use in every project, and would like to backport to maintained projects. And if it's used in every project, should it be a contrib?
I don't think it should do anything without a template tag to render navs, and that template tag shouldn't do anything if there's no navs defined.
I think a method on the plugin class that returns a match based on a request should work. By default, a startswith
query should work. You could get the most precise one by looking at the length of the match maybe.
I think a NavItem.objects.filter(match__iregex=request.path)
shouldn't be too outrageous as a fallback if we couldn't find any 'startswith' matches - it's executed natively by postgres.
@cogat can you take a look and merge this in, if ok?
Thanks for the feedback, Greg
No probs. Thanks for the neat solution!
re #48
@cogat I've rigged up everything except for the 'selected' state detection. I'll pick it back up on Monday, but figured you might want some input on a couple of things:
icekit.contrib.navigation
.icekit/contrib/navigation/README.md
contains the minimal settings changes necessary to activate it (installed apps + fluent plugin conf).Regarding the detection of an item's selected state:
startswith
checks should make it fairly easy to handle nested items. That being said, we're likely to end up with multiple items that intersect and have the selected state. Eg: two menu items /about/ and /about/donate/ would both be selected when /about/donate/thanks is the current path. I don't think there's an easy way around this, at least, without massively complicating the UI and relying on non-technical users to enter regexes. Also, pulling regexes out of the DB and executing them at runtime seems like it has the potential to be an issue (regardless of the superuser permission checks).We might need to just accept that there will be edge-cases we can't predict and deal with them when they emerge. If so, I could try adding an escape hatch - eg: an optional setting pointing to a callable that takes the current path, a list of navigation items, and the default determination of the selected state for each item. It could return the selected states manipulated to whatever was appropriate for the system.