Friday, February 3, 2017

Return MouseWheel Event to Sitecore 8+ Ribbon

Do you know that there was  nice feature in Sitecore 6 - 7.2 that allows use mouse scroll on Content Editor Ribbon?

Once working on project based on Sitecore 7.2 I accidentally scrolls mouse wheel when cursor was on Content Editor ribbon. Sitecore behavior surprised me: it switched to the next Content Editor tab. I found it nice useful feature that speed up work in Content Editor, especially when you are looking for some button and forgot where it is located. It saves time and nerves and I used to utilize this feature day to day.

But, when I switched to project based on Sitecore 8, I was disappointed. Scroll doesn't work on ribbon any more... And I decided return this feature into Sitecore and even a little bit improve it.

All that you need, find \sitecore\shell\Applications\Content Manager\Content Editor.js file and put this JavaScript to the end:

jQuery(document).ready(function () {
    jQuery("#RibbonPanel").bind("mousewheel", function (event) {
        var array = jQuery(event.currentTarget).find(".scRibbonNavigatorButtonsGroupButtons a");
        if (array.length > 1) {
            var active = jQuery(event.currentTarget).find(".scRibbonNavigatorButtonsGroupButtons a.scRibbonNavigatorButtonsActive");
            var index = array.index(active);
            var delta = (event.originalEvent.wheelDelta > 0 ? 1 : -1);
            if (index === array.length - delta) {
                if (delta < 0) {
                    array[0].click();
                }
                else {
                    array[1].click();
                }
            }
            else {
                if (index === 0) {
                    array.last().click();
                }
                else {
                    array[index + delta].click();
                }
            }
        }
    });
});

Voila, you can use scroll for ribbon navigation again!




Wednesday, January 4, 2017

Sitecore Log4Net Appender for Slack


    Slack became essential part of almost all projects(or teams). It is very powerful communication tool that speed up sharing information. As we use Slack for our Sitecore-based project I decided to create prototype of slack bot that will share information about Sitecore production site health to Slack channel. 


    After quick search I found that something similar was already created on Sitecore Hackathon, named Slack for Sitecore. There is also video that describe how it works.

    But as for me, it is too complex to use it in real projects. You don't need to have a lot of information in Slack channel, otherwise you will skip all messages from Slack bot. And also you don't need to spend a time on configuration of module. Sitecore already has mechanism how to show that something went wrong - logging errors to log file. Why don't use it for our Slack bot?

    First of all, we should take Slack log4net appender and change it to be suitable for Sitecore. It could be done quite easily by changing dependency from log4net assembly to Sitecore.Logging assembly.

    Now, we are able to add log4slack appender to our Sitecore configuration:

<appender name="SlackAppender"
    type="Log4Slack.SlackAppender, Log4Slack">
  <WebhookUrl value="https://hooks.slack.com/**********************" />
  <Channel value="#testing" />
  <Username value="*********" />
  <IconUrl value="" />
  <IconEmoji value=":ghost:" />
  <AddAttachment value="true" />
  <AddExceptionTraceField value="true" />
  <UsernameAppendLoggerName value="true"/>
  <threshold value="Error" />
</appender>
....
<root>
  <priority value="INFO"/>
  <appender-ref ref="LogFileAppender"/>
  <appender-ref ref="SlackAppender"/>
</root>

   And we got next messages in our Slack channel:

    Of course, you don't need having all logs to be transferred to your Slack channel, because no one will read them. That is why you either should set up separate logger for critical messages or set logging level for this appender to error: <threshold value="Error" />. And you will not miss any critical exception on your site.