Please upgrade here. These earlier versions are no longer being updated and have security issues.
HackerOne users: Testing against this community violates our program's Terms of Service and will result in your bounty being denied.

Adding "Options Gear" after Category in "Mixed" Category view

DoyceTDoyceT Model Questioner ✭✭✭

Vanilla 2.1, Default Theme.

In both the Table and Modern category views, the user is shown an 'options' gear when they mouse over a given category. (Typically, the menu this gear displays includes 'Mark Read', and either 'Hide' or "Unhide'.)

The code for this "Options Gear" seems to be found in /applications/vanilla/views/categories/helper_functions.php, lines 57 to 97.

In the Mixed category view, this options gear is not available, and I'd like to fix that.

My problem: I can't figure out how/where that code is being called in the Table and Modern views, and thus I can't replicate it for the Mixed view.

Tagged:
«13

Comments

  • vrijvlindervrijvlinder Papillon-Sauvage MVP
    edited June 2014

    I see the cog in the mixed view. Could it be a theme issue?

    Try adding this to the custom.css temporarily to make it visible all the time. Maybe it is hiding behind something else

    .Item .OptionsTitle {
    visibility: visible;
    display:block;
    }
    

    You need to also set the permissions in the dashboard for members to be able to edit but this permission may be to edit everything not just their posts.

    I think there may be a bug here. Because the cog won't show in mixed view if permissions to edit are not set.

  • DoyceTDoyceT Model Questioner ✭✭✭


    See the attached image.

    Basically, adding that bit of css shows me the options gear after individual discussions, but not for the Category itself.

  • DoyceTDoyceT Model Questioner ✭✭✭

    I'm attaching a screen cap from firebug.

    In it, I'm examining the category and first discussion from the screen capture above.

    It seems that there is no "options" being written for the Category at all - it's not hidden behind something, it's just not there.

    The discussion immediately below that one has the span class "Options" with all the requisite code included.

  • peregrineperegrine MVP
    edited June 2014

    .

    I may not provide the completed solution you might desire, but I do try to provide honest suggestions to help you solve your issue.

  • vrijvlindervrijvlinder Papillon-Sauvage MVP

    yes I can see that too. The options are not showing in the selected category. Not to edit or anything and does not appear in the source.

    I think this is a permissions thing but I could not find the root of it .

  • DoyceTDoyceT Model Questioner ✭✭✭
    edited June 2014

    What I'm looking for is basically this:

    Functional Goal: I want to be able to easily hide and unhide categories while using the Mixed category view. As it stands, the only way to do that is to switch category view to one of the other views, make the hide-unhide changes, then switch back. Annoying for me, and over-complex for some of my users. :expressionless:

  • I can't verify if it works correctly, you would have to experiment, but here is a possible start.
    it may work but you have to test with a variety of permissions.

    public function CategoriesController_AfterCategoryTitle_Handler($Sender) {
       $Category =$Sender->Category;
       $CategoryID = GetValue('CategoryID', $Category);
       $Result = '<div class="Options">';
       $TKey = urlencode(Gdn::Session()->TransientKey());
    
       // Mark category read.
       $Options .= '<li rel="MarkRead">'.Anchor(T('Mark Read'), "/vanilla/category/markread?categoryid=$CategoryID&tkey=$TKey").'</li>';
    
       // Follow/Unfollow category.
       if (!GetValue('Following', $Category))
          $Options .= '<li rel="Hide">'.Anchor(T('Unhide'), "/vanilla/category/follow?categoryid=$CategoryID&value=1&tkey=$TKey").'</li>';
       else
          $Options .= '<li rel="Hide">'.Anchor(T('Hide'), "/vanilla/category/follow?categoryid=$CategoryID&value=0&tkey=$TKey").'</li>';
    
       // Allow plugins to add options
       $Sender->FireEvent('CategoryOptions');
    
       if ($Options != '') {
             $Result .= '<span class="ToggleFlyout OptionsMenu">';
                $Result .= '<span class="OptionsTitle">'.T('Options').'</span>';
                $Result .= '<span class="SpFlyoutHandle"></span>';
                $Result .= '<ul class="Flyout MenuItems">'.$Options.'</ul>';
             $Result .= '</span>';
          $Result .= '</div>';
          echo $Result;
    
    }
    }
    

    I may not provide the completed solution you might desire, but I do try to provide honest suggestions to help you solve your issue.

  • R_JR_J Ex-Fanboy Munich Admin

    That one might either be a resource for possibilities or a solution: http://vanillaforums.org/addon/categoriesmoduleplus-plugin ;)

  • vrijvlindervrijvlinder Papillon-Sauvage MVP

    ok I added that function to my categories drop down plugin, it now shows the cog but only by the category , not each category in the category list. Is that what it is supposed to do? or also add it by each cat ?

  • hgtonighthgtonight ∞ · New Moderator

    You need to add a call to the GetOptions() function in your categories/discussions view.

    Copy the file from /applications/vanilla/views/categories/discussions.php to /themes/yourTheme/views/categories/discussions.php.

    Add the following code on line 2 of the new file:

    if (!function_exists('GetOptions')) {
      include $this->FetchViewLocation('helper_functions', 'categories');
    }
    

    Then you need to add echo GetOptions($Category); right after the line that looks like Gdn::Controller()->FireEvent('AfterCategoryTitle');

    You should now have a static gear icon that has the category options available. If you want it to only show on hover, you need to bust out your CSS skills, or ask the guru (@vrijvlinder).

    Search first

    Check out the Documentation! We are always looking for new content and pull requests.

    Click on insightful, awesome, and funny reactions to thank community volunteers for their valuable posts.

  • peregrineperegrine MVP
    edited June 2014

    so is it better to replace the view or just add a plugin in case the view changes :)

    I may not provide the completed solution you might desire, but I do try to provide honest suggestions to help you solve your issue.

  • hgtonighthgtonight ∞ · New Moderator

    @peregrine said:
    so is it better to replace the view or just add a plugin in case the view changes :)

    I cross-posted... AGAIN.

    Honestly, I would hook into the view via a plugin and load up the categories' helper_functions view. Then use the GetOptions() function.

    This will ensure changing the GetOptions function (or overriding it elsewhere) will be reflected in your plugin.

    Probably the cleanest solution.

    Search first

    Check out the Documentation! We are always looking for new content and pull requests.

    Click on insightful, awesome, and funny reactions to thank community volunteers for their valuable posts.

  • vrijvlindervrijvlinder Papillon-Sauvage MVP

    ok I tried that

    You should now have a static gear icon that has the category options available.

    Same result for member role than the code from peregrine that I added to my plugin, however the cog also shows if logged out....

  • hgtonighthgtonight ∞ · New Moderator

    Here is the plugin based code:

    public function CategoriesController_AfterCategoryTitle_Handler($Sender) {
      if (!function_exists('GetOptions')) {
        include $Sender->FetchViewLocation('helper_functions', 'categories');
      }
      $Category = $Sender->EventArguments['Category'];
    
      echo GetOptions($Category);    
    }
    

    Search first

    Check out the Documentation! We are always looking for new content and pull requests.

    Click on insightful, awesome, and funny reactions to thank community volunteers for their valuable posts.

  • hgtonighthgtonight ∞ · New Moderator

    @vrijvlinder said:
    ok I tried that

    Same result for member role than the code from peregrine that I added to my plugin, however the cog also shows if logged out....

    I am not seeing that on my test install of 2.1. The GetOptions() function checks for a valid session before spitting out any markup as well.

    Search first

    Check out the Documentation! We are always looking for new content and pull requests.

    Click on insightful, awesome, and funny reactions to thank community volunteers for their valuable posts.

  • vrijvlindervrijvlinder Papillon-Sauvage MVP

    No, when I added it to categories drop down it shows even if logged out. Because the plugin does not check for session.

    But both result in no cog for individual discussions in the category list

  • peregrineperegrine MVP
    edited June 2014

    didn't see your cross-posted code again :) or I'll take the blame. I cross-posted.

    so I removed mine.

    I may not provide the completed solution you might desire, but I do try to provide honest suggestions to help you solve your issue.

  • DoyceTDoyceT Model Questioner ✭✭✭

    @vrijvlinder said:

    But both result in no cog for individual discussions in the category list

    Hmm. I'm definitely not getting that.

    All three solutions seem to give the same end result - I'm currently using the Plugin that calls helper_functions, as it seemed the best of both worlds.

    This gives an always-visible gear after all categories while in mixed view, and 'hidden until moused over' gears for individual discussion.

    Only remaining challenge, as hg mentioned, is figuring out the css that allows the category-level gear to hide until moused over, without also hiding the Bookmark sprite. :pensive:

  • DoyceTDoyceT Model Questioner ✭✭✭
    edited June 2014

    Oh... and one other issue: when you switch to any of the other category views, you get two identical gears on mouseover, since the other two views are already calling helper_functions in some fashion.

  • On the forums I used people find the hiding of stuff very hard to use. surprising that you want to hide it.

    it is just a tiny cogwheel.

    half the time people can't find how to do something because it is hidden. e.g. reactions is another one.

    Just my soapbox rant I hate the hiding of stuff and make it all visible, unless it is a total distractions.

    I may not provide the completed solution you might desire, but I do try to provide honest suggestions to help you solve your issue.

Sign In or Register to comment.