Continuing the discussion from How to split the forum into two main parts (general/groups) and how to display only subcategories I can create a new post in?:
Hey everyone,
Here is a theme component that does a thing I’ve been wanting to do for a long time, but I’d like your comments on the code to improve it, or your suggestions.
I don’t believe the code is very good so I don’t want to recommend it before it has been checked by someone else.
What it does
Hide with CSS all the topics for which the user has a category permission restriction in chosen pages.
Repository
Repository link
framagit.org/oca/discourse-theme-shroud-subcategories
Motivation
I’ve got a community with a lot of groups, and I want people to peacefully ignore what is from other groups than theirs. I don’t want to restrict access to the content, I just don’t want it to be on main page. They should be able to access it by going for it, by choosing to go on this category specifically (for example, in order to know what is discussed here). Obviously, the relevant tool would be the watch/ignore function, but since the UI requires more than 2 clicks to set it up, no-one in the community uses it. Some improvement on the Category page might do the trick but they are out of my skill.
So, I use what UI is simple enough for them: the group page. On the same page are displayed all the groups they can access, freely or not, and their description. That’s perfect, they just need to click and chose them. The group page is too hidden for them (inside the hamburger) so I could put a big button link on the main page.
Now, I need to link the group membership and the display of the category posts.
How it works
The trick I used was to setup the category permission as:
- everyone: read, write
- that group: start a message, read, write
and then, for each topic in the list, check if there is a category restriction, and if yes, add a class not-in-group
to the topic element.
Then, the CSS add display:none
accordingly.
UI
The admin can chose the pages where this behaviour is effective. It should not be done on the category page because, by definition, that is where we want to access the content. On my website, all those groups are subcategories that are hidden from the latest
page, we access it through the /c/groups/
page, so that is that page which is used.
Improvements
- Being able to select parents category of the filtered categories (so any category that is not a child of this one is safe from being skipped)
- Add tags, so that if a topic has this tag, then it will not be removed.