Sort by Solved/Unsolved Questions in Category


(Jonathan Juan) #1

I wanted to know if there was a way to enable a sort feature for forums that have the solved plugin enabled to sort by Unsolved/Solved questions? The same way that we can sort on a Category by “Latest”, “New”, “Top”, “Unread” by clicking the link at the top.

I understand that this was sort of asked before, but I’m not sure exactly how to add a new sort “option” that has a link to reorganize the topics by those query params.


Query for Unsolved Topics
(Daniela) #2

You can do something like that under Theme > Common (or Desktop, or Mobile, it’s your choise) > Body

<script>
  Discourse.ExternalNavItem = Discourse.NavItem.extend({
    href : function() {
      return this.get('href');
    }.property('href')
  });

  I18n.translations.en.js.filters.solved = { title: "Solved", help: "topics with solution" };
  I18n.translations.en.js.filters.unsolved = { title: "Unsolved", help: "topics without solution" };
  
  Discourse.NavItem.reopenClass({
    buildList : function(category, args) {
      var list = this._super(category, args);

      if(!category) {
        list.push(Discourse.ExternalNavItem.create({href: 'http://your-domain-url/?solved=yes', name: 'solved'}));
        list.push(Discourse.ExternalNavItem.create({href: 'http://your-domain-url/?solved=no', name: 'unsolved'}));
        
        
      }
      return list;
    }
  });
</script>

In this way you add the buttons Solved and Unsolved on your menu.
You need only to change the URLs with your domain (and customize with a particular category if you want, eg http://your-domain-url/c/support?solved=yes)


(David Taylor) #3

This will show the solved/unsolved buttons on the main pages, not the category pages.

If you want to add to category pages there’s an example here :slight_smile:


(RBoy) #4

I had the same question but didn’t quite understand how to make it happen. Where do I add this script?
Would it possible to have a configuration button or setting checkbox to enable sorting by solved?


(Stephen Chung) #5

The Latest button remains hightlighted. Is there a way to highlight the Unsolved button when this link is entered?


(RBoy) #6

It would really nice to have a button to sort or show only solved/unsolved posts. I know @david suggested a workaround to add custom HTML but if the plugin did that it would be awesome.


(David Taylor) #7

Agreed.

I had a very brief look at adding it in the form of a theme component, but I think it will need some changes in the plugin itself first.
I think we need to a Boolean to the category serialiser, as currently there’s no way to know whether a category has “discourse-solved” enabled, its only shipped to the client on a “per-topic” basis.

Definitely achievable though :slight_smile:


Adding Unsolved button to top menu using custom HTML
(RBoy) #8

Just checking in on this