send page-generation- and session-restore-time via json response not as dom fragment

This commit is contained in:
Ralf Becker 2016-07-14 14:47:26 +02:00 committed by Hadi Nategh
parent d484dbd2ff
commit 554bca8393
3 changed files with 27 additions and 12 deletions

View File

@ -231,12 +231,6 @@ class Etemplate extends Etemplate\Widget\Template
{
$content = '<form target="egw_iframe_autocomplete_helper" action="'.$form_action.'" id="'.$dom_id.'" class="et2_container"></form>'."\n".
'<iframe name="egw_iframe_autocomplete_helper" style="width:0;height:0;position: absolute;visibility:hidden;"></iframe>';
// add server-side page-generation times
if($GLOBALS['egw_info']['user']['preferences']['common']['show_generation_time'])
{
$vars = $GLOBALS['egw']->framework->_get_footer();
$content .= "\n".$vars['page_generation_time'];
}
$GLOBALS['egw']->framework->response->generic("data", array($content));
$GLOBALS['egw']->framework->response->generic('et2_load',$load_array+Framework::get_extra());
Framework::clear_extra(); // to not send/set it twice for multiple etemplates (eg. CRM view)

View File

@ -348,6 +348,23 @@ abstract class Framework extends Framework\Extra
(new Framework\Login($this))->deny_screen();
}
/**
* Calculate page-generation- and session-restore times
*
* @return array values for keys 'page_generation_time' and 'session_restore_time', if display is an
*/
public static function get_page_generation_time()
{
$times = array(
'page_generation_time' => sprintf('%4.2lf', microtime(true) - $GLOBALS['egw_info']['flags']['page_start_time']),
);
if ($GLOBALS['egw_info']['flags']['session_restore_time'])
{
$times['session_restore_time'] = sprintf('%4.2lf', $GLOBALS['egw_info']['flags']['session_restore_time']);
}
return $times;
}
/**
* Get footer as array to eg. set as vars for a template (from idots' head.inc.php)
*
@ -362,13 +379,15 @@ abstract class Framework extends Framework\Extra
$var['page_generation_time'] = '';
if($GLOBALS['egw_info']['user']['preferences']['common']['show_generation_time'])
{
$totaltime = sprintf('%4.2lf',microtime(true) - $GLOBALS['egw_info']['flags']['page_start_time']);
$times = self::get_page_generation_time();
$var['page_generation_time'] = '<div class="pageGenTime" id="divGenTime_'.$GLOBALS['egw_info']['flags']['currentapp'].'"><span>'.lang('Page was generated in %1 seconds',$totaltime);
if ($GLOBALS['egw_info']['flags']['session_restore_time'])
$var['page_generation_time'] = '<div class="pageGenTime" id="divGenTime_'.$GLOBALS['egw_info']['flags']['currentapp'].'"><span>'.
lang('Page was generated in %1 seconds', $times['page_generation_time']);
if (isset($times['session_restore_time']))
{
$var['page_generation_time'] .= ' '.lang('(session restored in %1 seconds)',
sprintf('%4.2lf',$GLOBALS['egw_info']['flags']['session_restore_time']));
$times['session_restore_time']);
}
$var['page_generation_time'] .= '</span></div>';
}

View File

@ -223,8 +223,10 @@ class Response extends Msg
{
$inst = self::get();
/* Wrap the result array into a parent "response" Object */
$res = array('response' => $inst->responseArray);
// Wrap the result array into a parent "response" Object
$res = array(
'response' => $inst->responseArray,
)+Api\Framework::get_page_generation_time();
return self::json_encode($res); //PHP5.3+, JSON_HEX_TAG | JSON_HEX_APOS | JSON_HEX_QUOT | JSON_HEX_AMP);
}