diff --git a/classes/Hook.php b/classes/Hook.php index fe2b80819..3b07e2c14 100644 --- a/classes/Hook.php +++ b/classes/Hook.php @@ -387,7 +387,7 @@ class HookCore extends ObjectModel * @param int $id_module Execute hook for this module only * @return string modules output */ - public static function exec($hook_name, $hook_args = array(), $id_module = null, $array_return = false, $check_exceptions = true) + public static function exec($hook_name, $hook_args = array(), $id_module = null, $array_return = false, $check_exceptions = true, $use_push = false) { // Check arguments validity if (($id_module && !is_numeric($id_module)) || !Validate::isHookName($hook_name)) @@ -446,6 +446,8 @@ class HookCore extends ObjectModel continue; } + if ($use_push && !$moduleInstance->allow_push) + continue; // Check which / if method is callable $hook_callable = is_callable(array($moduleInstance, 'hook'.$hook_name)); $hook_retro_callable = is_callable(array($moduleInstance, 'hook'.$retro_hook_name)); @@ -453,10 +455,13 @@ class HookCore extends ObjectModel { $hook_args['altern'] = ++$altern; + if ($use_push && isset($moduleInstance->push_filename) && file_exists($moduleInstance->push_filename)) + Tools::waitUntilFileIsModified($moduleInstance->push_filename, $moduleInstance->push_time_limit); + // Call hook method if ($hook_callable) $display = $moduleInstance->{'hook'.$hook_name}($hook_args); - else if ($hook_retro_callable) + elseif ($hook_retro_callable) $display = $moduleInstance->{'hook'.$retro_hook_name}($hook_args); // Live edit if (!$array_return && $array['live_edit'] && Tools::isSubmit('live_edit') && Tools::getValue('ad') && Tools::getValue('liveToken') == Tools::getAdminToken('AdminModulesPositions'.(int)Tab::getIdFromClassName('AdminModulesPositions').(int)Tools::getValue('id_employee'))) diff --git a/classes/module/Module.php b/classes/module/Module.php index 3ffb10117..6393edfbc 100644 --- a/classes/module/Module.php +++ b/classes/module/Module.php @@ -119,6 +119,10 @@ abstract class ModuleCore /** @var Smarty_Data */ protected $smarty; + /** @var allow push */ + public $allow_push; + + public $push_time_limit = 180; const CACHE_FILE_MODULES_LIST = '/config/xml/modules_list.xml'; @@ -1643,7 +1647,8 @@ abstract class ModuleCore { $this->smarty->assign(array( 'module_dir' => __PS_BASE_URI__.'modules/'.basename($file, '.php').'/', - 'module_template_dir' => ($overloaded ? _THEME_DIR_ : __PS_BASE_URI__).'modules/'.basename($file, '.php').'/' + 'module_template_dir' => ($overloaded ? _THEME_DIR_ : __PS_BASE_URI__).'modules/'.basename($file, '.php').'/', + 'allow_push' => $this->allow_push )); if ($cacheId !== null) diff --git a/controllers/admin/AdminDashboardController.php b/controllers/admin/AdminDashboardController.php index 74e13f4f5..78450f268 100644 --- a/controllers/admin/AdminDashboardController.php +++ b/controllers/admin/AdminDashboardController.php @@ -89,6 +89,6 @@ class AdminDashboardControllerCore extends AdminController 'dashboard_use_push' => (int)Tools::getValue('dashboard_use_push') ); - die(Tools::jsonEncode(Hook::exec('dashboardData', $params, $id_module, true))); + die(Tools::jsonEncode(Hook::exec('dashboardData', $params, $id_module, true, true, (int)Tools::getValue('dashboard_use_push')))); } } \ No newline at end of file diff --git a/js/admin-dashboard.js b/js/admin-dashboard.js index e362744f0..03239b1ec 100644 --- a/js/admin-dashboard.js +++ b/js/admin-dashboard.js @@ -29,10 +29,10 @@ $(document).ready( function () { return false; }); - refreshDashboard(); + refreshDashboard(false); }); -function refreshDashboard(module_name) +function refreshDashboard(use_push) { module_list = new Array(); @@ -50,16 +50,19 @@ function refreshDashboard(module_name) $(this).addClass('loading'); }); } - console.log(module_list); + for (var module_id in module_list) { + if (use_push && !$('#'+module_list[module_id]).hasClass('allow_push')) + continue; + $.ajax({ url : dashboard_ajax_url, data : { ajax:true, action:'refreshDashboard', module:module_list[module_id], - dashboard_use_push:parseInt(dashboard_use_push) + dashboard_use_push:Number(use_push) }, dataType: 'json', success : function(widgets){ @@ -68,7 +71,7 @@ function refreshDashboard(module_name) window[data_type](widget_name, widgets[widget_name][data_type]); if (parseInt(dashboard_use_push) == 1) - refreshDashboard(); + refreshDashboard(true); }, error : function(data){ //@TODO display errors @@ -89,7 +92,7 @@ function setDashboardDateRange(action) success : function(jsonData){ if (!jsonData.has_errors) { - refreshDashboard(); + refreshDashboard(false); $('#datepickerFrom').val(jsonData.date_from); $('#datepickerTo').val(jsonData.date_to); } diff --git a/modules/dashactivity/dashactivity.php b/modules/dashactivity/dashactivity.php index 740c87bd7..81708c94c 100644 --- a/modules/dashactivity/dashactivity.php +++ b/modules/dashactivity/dashactivity.php @@ -37,6 +37,8 @@ class Dashactivity extends Module $this->version = '0.1'; $this->author = 'PrestaShop'; $this->push_filename = _PS_CACHE_DIR_.'push/activity'; + $this->allow_push = true; + $this->push_time_limit = 180; parent::__construct(); } @@ -64,9 +66,6 @@ class Dashactivity extends Module public function hookDashboardData($params) { - if ($params['dashboard_use_push']) - Tools::waitUntilFileIsModified($this->push_filename, 30); - $gapi = Module::isInstalled('gapi') ? Module::getInstanceByName('gapi') : false; if (Validate::isLoadedObject($gapi) && $gapi->isConfigured()) { diff --git a/modules/dashactivity/views/templates/hook/dashboard_zone_one.tpl b/modules/dashactivity/views/templates/hook/dashboard_zone_one.tpl index a4aec1cc9..a415de819 100644 --- a/modules/dashactivity/views/templates/hook/dashboard_zone_one.tpl +++ b/modules/dashactivity/views/templates/hook/dashboard_zone_one.tpl @@ -22,8 +22,7 @@ * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) * International Registered Trademark & Property of PrestaShop SA *} - -
+
{l s='Recent Activity'}