From 55be4d478fdf912f4e30579bb8a8760c0f9e9727 Mon Sep 17 00:00:00 2001 From: Coleman Watts Date: Tue, 2 Aug 2016 13:34:25 -0400 Subject: [PATCH] Load home dashboard faster Eliminate unnecessary ajax call should speed up load times significantly. --- CRM/Contact/Page/DashBoard.php | 1 + js/jquery/jquery.dashboard.js | 16 ++++++---------- templates/CRM/common/dashboard.tpl | 15 ++------------- 3 files changed, 9 insertions(+), 23 deletions(-) diff --git a/CRM/Contact/Page/DashBoard.php b/CRM/Contact/Page/DashBoard.php index 5f95110a91..40019a3f0b 100644 --- a/CRM/Contact/Page/DashBoard.php +++ b/CRM/Contact/Page/DashBoard.php @@ -44,6 +44,7 @@ class CRM_Contact_Page_DashBoard extends CRM_Core_Page { $resources = CRM_Core_Resources::singleton(); $resources->addScriptFile('civicrm', 'js/jquery/jquery.dashboard.js', 0, 'html-header', FALSE); $resources->addStyleFile('civicrm', 'css/dashboard.css'); + $this->assign('contactDashlets', CRM_Core_BAO_Dashboard::getContactDashlets()); $resetCache = CRM_Utils_Request::retrieve('resetCache', 'Positive', CRM_Core_DAO::$_nullObject); diff --git a/js/jquery/jquery.dashboard.js b/js/jquery/jquery.dashboard.js index d1f68bb4e1..34cfec6109 100644 --- a/js/jquery/jquery.dashboard.js +++ b/js/jquery/jquery.dashboard.js @@ -159,10 +159,8 @@ // Merge in the caller's options with the defaults. var opts = $.extend({}, $.fn.dashboard.defaults, options); - // Execution 'forks' here and restarts in init(). Tell the user we're busy with a throbber. - var throbber = $(opts.throbberMarkup).appendTo(dashboard.element); - $.getJSON(opts.ajaxCallbacks.getWidgetsByColumn.url, opts.ajaxCallbacks.getWidgetsByColumn.data, init); - asynchronousRequestCounter++; + init(opts.widgetsByColumn); + return dashboard; // End of constructor and private properties for dashboard object. @@ -170,10 +168,8 @@ * Private methods of dashboard. */ - // Ajax callback for getWidgetsByColumn. - function init(widgets, status) { - asynchronousRequestCounter--; - throbber.remove(); + // Initialize widget columns. + function init(widgets) { var markup = '
  • ' + opts.emptyPlaceholderInner + '
  • '; // Build the dashboard in the DOM. For each column... @@ -462,12 +458,12 @@ minimize: { description: ts('Collapse or expand'), callback: widget.toggleMinimize, - icon: 'fa-caret-down', + icon: 'fa-caret-down' }, fullscreen: { description: ts('View fullscreen'), callback: widget.enterFullscreen, - icon: 'fa-expand', + icon: 'fa-expand' }, close: { description: ts('Remove from dashboard'), diff --git a/templates/CRM/common/dashboard.tpl b/templates/CRM/common/dashboard.tpl index 7c922c7d53..e009699bb3 100644 --- a/templates/CRM/common/dashboard.tpl +++ b/templates/CRM/common/dashboard.tpl @@ -38,22 +38,11 @@ CRM.$(function($) { // Required. emptyPlaceholderInner: '', + widgetsByColumn: {/literal}{$contactDashlets|@json_encode}{literal}, + // These define the urls and data objects used for all of the ajax requests to the server. - // data objects are extended with more properties, as defined below. - // All are required. All should return JSON. ajaxCallbacks: { - // Server returns the configuration of widgets for this user; - // An array (keyed by zero-indexed column ID), of arrays (keyed by widget ID) of - // booleans; true if the widget is minimized. False if not. - // E.g. [{ widgetID: isMinimized, ...}, ...] - getWidgetsByColumn: { - url: {/literal}'{crmURL p='civicrm/ajax/dashboard' h=0 }'{literal}, - data: { - op: 'get_widgets_by_column', key: {/literal}"{crmKey name='civicrm/ajax/dashboard'}"{literal} - } - }, - // Given the widget ID, the server returns the widget object as an associative array. // E.g. {content: '

    Widget content

    ', title: 'Widget Title', } // -- 2.25.1