0

I have some views that I want to refresh in a time interval (15sec) OR if there is changes in the content. For that I tried to use module "Views Auto Refresh". It works fine for a time interval but only if I have one view in a page.

If I have multiple views inside a panel (using Panels module), only one of the views is refreshed.

Is there any other way (module or custom code) to achieve this behaviour?

Thanks!

EDIT: As suggested, I tracked the ajax requests. In my case I'm refreshing every 15seconds. In a panel with 2 views I notice that I have only one request every 15sec, should I have two?!?!? Anyway, below is the piece of code I get when clicking in the function in red in the picture (I think is this one). The debug highlights the following line:

$(anchor).trigger('click');

Ajax Requset

Drupal.views_autorefresh.timer = function(view_name, anchor, target) {
  Drupal.settings.views_autorefresh[view_name].timer = setTimeout(function() {
    clearTimeout(Drupal.settings.views_autorefresh[view_name].timer);

    // Turn off "new" items class.
    $('.views-autorefresh-new', target).removeClass('views-autorefresh-new');

    // Handle ping path.
    var ping_base_path;
    if (Drupal.settings.views_autorefresh[view_name].ping) {
      ping_base_path = Drupal.settings.views_autorefresh[view_name].ping.ping_base_path;
    }

    // Handle secondary view for incremental refresh.
    // http://stackoverflow.com/questions/122102/what-is-the-most-efficient-way-to-clone-a-javascript-object
    var viewData = Drupal.settings.views_autorefresh[view_name].ajax.submit;
    var viewArgs = Drupal.settings.views_autorefresh[view_name].view_args;
    if (Drupal.settings.views_autorefresh[view_name].incremental) {
      if (!viewData.original_view_data) viewData.original_view_data = $.extend(true, {}, viewData);
      viewData.view_args = viewArgs + (viewArgs.length ? '/' : '') + Drupal.settings.views_autorefresh[view_name].timestamp;
      viewData.view_base_path = Drupal.settings.views_autorefresh[view_name].incremental.view_base_path;
      viewData.view_display_id = Drupal.settings.views_autorefresh[view_name].incremental.view_display_id;
      viewData.view_name = Drupal.settings.views_autorefresh[view_name].incremental.view_name;
    }
    viewData.autorefreshRequest = 'autorefreshRequest';
    Drupal.settings.views_autorefresh[view_name].ajax.submit = viewData;

    // If there's a ping URL, hit it first.
    if (ping_base_path) {
      var pingData = { 'timestamp': Drupal.settings.views_autorefresh[view_name].timestamp };
      $.extend(pingData, Drupal.settings.views_autorefresh[view_name].ping.ping_args);
      $.ajax({
        url: Drupal.settings.basePath + ping_base_path,
        data: pingData,
        success: function(response) {
          if (response.pong && parseInt(response.pong) > 0) {
            $(target).trigger('autorefresh_ping', parseInt(response.pong));
            $(anchor).trigger('click');
          }
          else {
            Drupal.views_autorefresh.timer(view_name, anchor, target);
          }
        },
        error: function(xhr) {},
        dataType: 'json',
      });
    }
    else {
      $(anchor).trigger('click');
    }
  }, Drupal.settings.views_autorefresh[view_name].interval);
}
4
  • You should track the ajax requests to see what parameters sent, after that you may check the module source code and api to find how achieve your scenario BTW I know the module developer personally so He could help – Mohammed Gomma Aug 26 '15 at 11:51
  • Thanks Mhmdgomma. I edited my question with the ajax request. That help would be awesome! – zephirus Aug 26 '15 at 13:58
  • The problem is that I'm not using two different views in the same page. I'm using same view, different displays and this module only takes into account view name. – zephirus Aug 26 '15 at 15:08
  • You are welcomed and I am very happy that your problem solved – Mohammed Gomma Aug 27 '15 at 7:58
0

You need to use Views Auto-Refresh module with this patch

0
0

I have done this in the past with the help of Views Auto-Refresh

Try the module and let us know if it work.

1
  • Hi Yama, I have that module installed as I said in my question. The problem is that it doesn't update all views if they are inside a panel. – zephirus Aug 26 '15 at 13:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.