Move main menu data into python#1849
Conversation
Previously, main menu data was in javascript and was slightly hard to modify from other plugins. Now, other plugins can just append whatever they want to c.MENU, and there is logic in there to merge submenu sections intelligently. This also opens up the future possibility of driving the main menu from some type of reflection process, like the sitemap currently does.
|
Although I know the menu needs refactoring and it's clear that you put a bunch of work into this, I have some concerns about adding Yet Another Custom Class that people making plugins will have to memorize in order to use. I don't actually see that much gain in simplicity from "pushing to a dict" to "calling a custom function (in order to push to a dict)" - it's about the same except that the latter requires knowledge of custom syntax. Was the problem that it was difficult to append to an existing submenu rather than adding a new one? |
|
Couple of issues:
I chose to go the custom class route instead of just a simple dict for a few reasons:
So while I do see that this is Yet Another Class, I feel like it's simple enough that it's not overburdening our plugin authors, it's pretty easy to look at what the main menu is doing in the main uber plugin and figure out what's needed to append menu items with minimal effort. I think it's a worthwhile tradeoff. |
|
I'm not super-attached to this btw, though, I think it's an improvement on what we were doing before in terms of making it easier for plugin authors to add more stuff to the menus. This is sorely needed in particular with the band and analytics plugins. I'm fine with later changing it to something more simple if we feel like that's the right call. I also was thinking, after talking to Chaney today, that it might be a good idea for styling purposes for this to not use javascript to render itself and move it all back to template logic - that's now a possibility because the data now lives on the backend instead of purely on the frontend. |
|
hey FYI, I have a newer version of this (checked into a different branch) in which I was able to completely remove all menu processing from javascript and just do it with django templates, which is way cleaner and more friendly for re-styling later. I need to clean that up a little bit more before it's ready, but, it looks like this on the template side: ubersystem/uber/templates/base.html Line 153 in fe9767a It also means the JSON stuff would be totally unnnecessary as I could just pass the raw python object, though I need to rewrite the filtering now to not go through JSON. easy stuff, just more work. Would appreciate if we could come to definitive answer on this as some upcoming UI rewrites that @cybersenshi and I would be working on would heavily depend on some of this menu stuff going through. |
|
This PR is now osboleted by #1857 which is functional, but needs a bit more cleanup before it's ready to go, let's redirect discussion there. |

Previously, main menu data was in javascript and was slightly hard to modify from other plugins.
Now, other plugins can just append whatever they want to c.MENU, and there is logic in there to merge submenu sections intelligently.
We render this into JSON data via c.MENU_JSON (I am using a custom encoder so couldn't just
|jsonit in the template)This also opens up the future possibility of driving the main menu from some type of reflection process, like the sitemap currently does.