From 8868271c076d3982fc7d70ee86bea8efeea930a2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Gaillard?= Date: Thu, 5 Sep 2013 18:37:25 +0200 Subject: [PATCH 1/4] // push changes --- classes/Hook.php | 9 +++++++-- classes/module/Module.php | 7 ++++++- controllers/admin/AdminDashboardController.php | 2 +- js/admin-dashboard.js | 15 +++++++++------ modules/dashactivity/dashactivity.php | 5 ++--- .../views/templates/hook/dashboard_zone_one.tpl | 3 +-- 6 files changed, 26 insertions(+), 15 deletions(-) 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'} From f5e00a59f7511fac99e3588b1801eb317bf301dc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Gaillard?= Date: Thu, 5 Sep 2013 18:41:51 +0200 Subject: [PATCH 2/4] // --- js/admin-dashboard.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/js/admin-dashboard.js b/js/admin-dashboard.js index 03239b1ec..a1a166182 100644 --- a/js/admin-dashboard.js +++ b/js/admin-dashboard.js @@ -36,7 +36,7 @@ function refreshDashboard(use_push) { module_list = new Array(); - if (typeof(module_name) == 'undefined') + if (!use_push && typeof(module_name) == 'undefined') { $('.widget').each( function () { module_list.push($(this).attr('id')); @@ -168,4 +168,4 @@ function data_table(widget_name, data) else $('#'+data_id+' tbody').html(''+no_results_translation+''); } -} \ No newline at end of file +} From c35d8c7845a54da9cdca9a8b7c0cd0c3da34a18f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Gaillard?= Date: Thu, 5 Sep 2013 18:47:13 +0200 Subject: [PATCH 3/4] // --- js/admin-dashboard.js | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/js/admin-dashboard.js b/js/admin-dashboard.js index a1a166182..9d31eb2ec 100644 --- a/js/admin-dashboard.js +++ b/js/admin-dashboard.js @@ -36,19 +36,21 @@ function refreshDashboard(use_push) { module_list = new Array(); - if (!use_push && typeof(module_name) == 'undefined') + if (typeof(module_name) == 'undefined') { $('.widget').each( function () { module_list.push($(this).attr('id')); - $(this).addClass('loading'); + if (!use_push) + $(this).addClass('loading'); }); } else { module_list.push(module_name); - $('#'+module_name+' section').each( function (){ - $(this).addClass('loading'); - }); + if (!use_push) + $('#'+module_name+' section').each( function (){ + $(this).addClass('loading'); + }); } for (var module_id in module_list) From a3233cc00cced924a2489b891c6b6f1e4289b79f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Gaillard?= Date: Thu, 5 Sep 2013 18:51:53 +0200 Subject: [PATCH 4/4] // --- js/admin-dashboard.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/js/admin-dashboard.js b/js/admin-dashboard.js index 9d31eb2ec..c1cc02650 100644 --- a/js/admin-dashboard.js +++ b/js/admin-dashboard.js @@ -29,14 +29,14 @@ $(document).ready( function () { return false; }); - refreshDashboard(false); + refreshDashboard(false, false); }); -function refreshDashboard(use_push) +function refreshDashboard(module_name, use_push) { module_list = new Array(); - if (typeof(module_name) == 'undefined') + if (module_name === false) { $('.widget').each( function () { module_list.push($(this).attr('id')); @@ -73,7 +73,7 @@ function refreshDashboard(use_push) window[data_type](widget_name, widgets[widget_name][data_type]); if (parseInt(dashboard_use_push) == 1) - refreshDashboard(true); + refreshDashboard(false, true); }, error : function(data){ //@TODO display errors @@ -94,7 +94,7 @@ function setDashboardDateRange(action) success : function(jsonData){ if (!jsonData.has_errors) { - refreshDashboard(false); + refreshDashboard(false, false); $('#datepickerFrom').val(jsonData.date_from); $('#datepickerTo').val(jsonData.date_to); }