// add push
This commit is contained in:
@@ -25,7 +25,7 @@
|
||||
|
||||
<script>
|
||||
var dashboard_ajax_url = '{$link->getAdminLink('AdminDashboard')}';
|
||||
var no_results_translation = '{l s='No result'}';
|
||||
var use_push = 1;
|
||||
</script>
|
||||
|
||||
<div class="page-head">
|
||||
|
||||
Vendored
@@ -2572,6 +2572,33 @@ exit;
|
||||
}
|
||||
return $fileAttachment;
|
||||
}
|
||||
|
||||
public static function changeFileMTime($file_name, $time = null)
|
||||
{
|
||||
if ($time === null)
|
||||
$time = time();
|
||||
|
||||
touch($file_name, $time);
|
||||
}
|
||||
|
||||
public static function waitUntilFileIsModified($file_name, $timeout = 180)
|
||||
{
|
||||
@ini_set('max_execution_time', $timeout);
|
||||
if (($time_limit = ini_get('max_execution_time')) === null)
|
||||
$time_limit = 30;
|
||||
|
||||
$time_limit -= 5;
|
||||
$start_time = microtime(true);
|
||||
$last_modified = filemtime($file_name);
|
||||
|
||||
while(true)
|
||||
{
|
||||
if (((microtime(true) - $start_time) > $time_limit) || filemtime($file_name) > $last_modified)
|
||||
break;
|
||||
clearstatcache();
|
||||
usleep(300);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -71,16 +71,17 @@ class AdminDashboardControllerCore extends AdminController
|
||||
);
|
||||
return parent::renderView();
|
||||
}
|
||||
|
||||
|
||||
public function ajaxProcessRefreshDashboard()
|
||||
{
|
||||
$id_module = null;
|
||||
if ($module = Tools::getValue('module'))
|
||||
$id_module = Module::getInstanceByName($module)->id;
|
||||
|
||||
|
||||
$params = array(
|
||||
'date_from' => $this->context->employee->stats_date_from,
|
||||
'date_to' => $this->context->employee->stats_date_to,
|
||||
'use_push' => (int)Tools::getValue('use_push')
|
||||
);
|
||||
|
||||
die(Tools::jsonEncode(Hook::exec('dashboardData', $params, $id_module, true)));
|
||||
|
||||
@@ -24,8 +24,31 @@
|
||||
|
||||
$(document).ready( function () {
|
||||
refreshDashbard();
|
||||
if (use_push)
|
||||
launchPush();
|
||||
});
|
||||
|
||||
function launchPush()
|
||||
{
|
||||
$.ajax({
|
||||
url : dashboard_ajax_url,
|
||||
data : {
|
||||
ajax:true,
|
||||
action:'refreshDashboard',
|
||||
module:'dashactivity',
|
||||
use_push:1,
|
||||
},
|
||||
dataType: 'json',
|
||||
success : function(widgets){
|
||||
for (var name in widgets)
|
||||
{
|
||||
for (data_type in widgets[name])
|
||||
window[data_type](widgets[name][data_type]);
|
||||
}
|
||||
launchPush();
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
function refreshDashbard(module_name)
|
||||
{
|
||||
|
||||
@@ -36,13 +36,23 @@ class Dashactivity extends Module
|
||||
$this->tab = '';
|
||||
$this->version = '0.1';
|
||||
$this->author = 'PrestaShop';
|
||||
|
||||
$this->push_filename = _PS_CACHE_DIR_.'push/activity';
|
||||
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
public function install()
|
||||
{
|
||||
if (!parent::install() || !$this->registerHook('dashboardZoneOne') || !$this->registerHook('dashboardData'))
|
||||
if (!parent::install()
|
||||
|| !$this->registerHook('dashboardZoneOne')
|
||||
|| !$this->registerHook('dashboardData')
|
||||
|| !$this->registerHook('actionObjectOrderAddAfter')
|
||||
|| !$this->registerHook('actionObjectCustomerAddAfter')
|
||||
|| !$this->registerHook('actionObjectCustomerMessageAddAfter')
|
||||
|| !$this->registerHook('actionObjectCustomerThreadAddAfter')
|
||||
|| !$this->registerHook('actionObjectOrderReturnAddAfter')
|
||||
|
||||
)
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
@@ -54,6 +64,9 @@ class Dashactivity extends Module
|
||||
|
||||
public function hookDashboardData($params)
|
||||
{
|
||||
if ($params['use_push'])
|
||||
Tools::waitUntilFileIsModified($this->push_filename, 30);
|
||||
|
||||
$gapi = Module::isInstalled('gapi') ? Module::getInstanceByName('gapi') : false;
|
||||
if (Validate::isLoadedObject($gapi) && $gapi->isConfigured())
|
||||
{
|
||||
@@ -187,4 +200,29 @@ class Dashactivity extends Module
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
public function hookActionObjectCustomerMessageAddAfter($params)
|
||||
{
|
||||
return $this->hookActionObjectOrderAddAfter($params);
|
||||
}
|
||||
|
||||
public function hookActionObjectCustomerThreadAddAfter($params)
|
||||
{
|
||||
return $this->hookActionObjectOrderAddAfter($params);
|
||||
}
|
||||
|
||||
public function hookActionObjectCustomerAddAfter($params)
|
||||
{
|
||||
return $this->hookActionObjectOrderAddAfter($params);
|
||||
}
|
||||
|
||||
public function hookActionObjectOrderReturnAddAfter($params)
|
||||
{
|
||||
return $this->hookActionObjectOrderAddAfter($params);
|
||||
}
|
||||
|
||||
public function hookActionObjectOrderAddAfter($params)
|
||||
{
|
||||
Tools::changeFileMTime($this->push_filename);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user