knowledge-repo icon indicating copy to clipboard operation
knowledge-repo copied to clipboard

[Feature] Have a better nesting structure for /cluster view

Open NiharikaRay opened this issue 8 years ago • 7 comments

Folders within folders should be nested.

Auto-reviewers: @NiharikaRay @matthewwardrop @earthmancash @danfrankj

NiharikaRay avatar Dec 12 '16 18:12 NiharikaRay

This would be an awesome feature, is there any update on whether it's on the roadmap?

tcbegley avatar May 24 '18 10:05 tcbegley

Sounds pretty doable with a little html/css/js knowledge.

This issue isn't my highest priority (not the maintainer btw), but feel free to make some changes and create a pull request! Otherwise I might have a look at it in a few months, it does seem pretty basic right now.

dorianbrown avatar May 24 '18 13:05 dorianbrown

No worries, thanks for the clarification.

I'll take a look and create a pull request if I can figure it out.

tcbegley avatar May 24 '18 13:05 tcbegley

If you want some pointers for where to look and what to change, let me know and I can help you out. Having a little Flask and Jinja templating knowledge is probably helpful, but its really easy to learn.

dorianbrown avatar May 24 '18 14:05 dorianbrown

Sure, happy to take any pointers. My current thinking was to modify render_cluster in app/routes/index.py to create the nested structure, then also modify app/templates/index-cluster.html to recursively unpack it and generate the nested lists. I haven't figured out which bits of the css/js will need modifying yet if any. Does that seem like a reasonable starting point?

tcbegley avatar May 24 '18 14:05 tcbegley

To be honest, I think this can be done using only jinja templating. It's the first time I'm looking at this code, and I haven't done anything too fancy with Jinja, but it seems to be possible to do recursion with just jinja. That would mean you won't have to touch any javascript, and maybe just some CSS to make it look a little prettier.

Here's a bit from the documentation:

It is also possible to use loops recursively. This is useful if you are dealing with recursive data such as sitemaps or RDFa. To use loops recursively, you basically have to add the recursive modifier to the loop definition and call the loop variable with the new iterable where you want to recurse.

The following example implements a sitemap with recursive loops:

<ul class="sitemap">
{%- for item in sitemap recursive %}
    <li><a href="{{ item.href|e }}">{{ item.title }}</a>
    {%- if item.children -%}
        <ul class="submenu">{{ loop(item.children) }}</ul>
    {%- endif %}</li>
{%- endfor %}
</ul>

The loop variable always refers to the closest (innermost) loop. If we have more than one level of loops, we can rebind the variable loop by writing {% set outer_loop = loop %} after the loop that we want to use recursively. Then, we can call it using {{ outer_loop(…) }}

dorianbrown avatar May 24 '18 21:05 dorianbrown

Great, thanks for the advice. I have something basic working just using jinja and python. Needs a bit more attention to make sure the sorting and post counts work as expected. I'll try to finish it up next week and submit for review.

tcbegley avatar May 24 '18 23:05 tcbegley