log working with statesystem

This commit is contained in:
Ulf Gebhardt 2015-04-10 02:10:46 +02:00
parent e7c6bc9779
commit c19f9ad6c8
7 changed files with 42 additions and 71 deletions

View File

@ -25,7 +25,7 @@ SYSTEM.prototype.hashchange = function () {
system.go_state(system.start_state);
//user callback
if(system.hash_change){
system.hash_change(system.cur_state().split('(')[0]);}
system.hash_change(system.cur_state().split(';')[0].split('(')[0]);}
};
SYSTEM.prototype.handle_call_pages_page = function (html,entry,id,forced,cached) {
var url = entry['url']+(window.location.search.substr(1) ? '&'+window.location.search.substr(1) : '' );
@ -76,6 +76,13 @@ SYSTEM.prototype.handle_call_pages_page = function (html,entry,id,forced,cached)
}
}
}
//try 2 call function even when no js is loaded(substates do that)
var fn = window[entry['func']];
if(call_func && typeof fn === 'function'){
call_func = false;
fn();
system.log_info('call func: '+entry['func']);
}
//update state
this.state[entry['div']] = url;
}

View File

@ -22,15 +22,27 @@ class State {
$row['url'] = \SYSTEM\PAGE\replace::replace($row['url'], $vars);
$row['url'] = \SYSTEM\PAGE\replace::clean($row['url']);
//clean url of empty variables
$row['url'] = preg_replace('/&.*?=(&|$)/', '&', $row['url']);
$row['url'] = preg_replace('/&$/', '', $row['url']);
//$row['url'] = preg_replace('/&.*?=(&|$)/', '&', $row['url']);
$row['url'] = preg_replace('/[^=&]+=(&|$)/', '&', $row['url']);
$row['url'] = preg_replace('/&&$/', '', $row['url']);
$row['css'] = $row['js'] = array();
if(\class_exists($row['php_class']) && \method_exists($row['php_class'], 'css') && \is_callable($row['php_class'].'::css')){
$row['css'] = array_merge($row['css'], call_user_func($row['php_class'].'::css'));}
if(\class_exists($row['php_class']) && \method_exists($row['php_class'], 'js') && \is_callable($row['php_class'].'::js')){
$row['js'] = array_merge($row['js'], call_user_func($row['php_class'].'::js'));}
$row['php_class'] = '';
$result[] = $row;
$skip = false;
for($i=0;$i<count($result);$i++){
if($result[$i]['div'] == $row['div']){
$skip = true;
if($row['type'] == 1){
$result[$i] = $row;}
break;
}
}
if(!$skip){
$result[] = $row;}
}
return $returnasjson ? \SYSTEM\LOG\JsonResult::toString($result) : $result;
}

View File

@ -1,60 +1,18 @@
google.load("visualization", "1", {packages:["corechart"]});
function init_saimod_sys_log() {
$('#tabs_log a').click(function (e) {
e.preventDefault();
$(this).tab('show');
load_log_tab($(this).attr('action'));
});
load_log_tab("log");
};
function load_log_tab(action){
$('img#loader').show();
switch(action){
case 'log':
$('#tab_log').load('./sai.php?sai_mod=.SYSTEM.SAI.saimod_sys_log&action='+action, function(){
register_log();
register_error();
$('img#loader').hide();});
return;
case 'stats':
$('#tab_stats').load('./sai.php?sai_mod=.SYSTEM.SAI.saimod_sys_log&action='+action, function(){
register_stats();
$('img#loader').hide();});
return;
default:
$('img#loader').hide();
}
}
function register_error(){
$('.sai_log_error').click(function(){
$('img#loader').show();
$('#table_log').load('./sai.php?sai_mod=.SYSTEM.SAI.saimod_sys_log&action=error&error='+$(this).attr('error'), function(){
$('img#loader').hide();})});
}
function load_table_log(filter){
$('img#loader').show();
$('#table_log').load('./sai.php?sai_mod=.SYSTEM.SAI.saimod_sys_log&action=filter&filter='+filter, function(){
register_error();
$('img#loader').hide();});
}
var filter = "%";
function register_log(){
$('#refresh_error_table').click(function(){
load_table_log(filter);});
$("#error_filter a").click(function(){
$('#error_filter li').each(function(){
$('#tabs_log li').each(function(){
$(this).removeClass('active');});
$(this).parent().addClass('active');
filter = $(this).attr('filter');
load_table_log($(this).attr('filter'));
});
}
function register_stats(){
if(system.cur_state() === 'log(stats)'){
$('#tabs_log li').each(function(){
$(this).removeClass('active');});
$('#menu_stats').parent().addClass('active');
}
};
function init_saimod_sys_log_stats() {
load_visualisation();
$('#vis_filter_time').change(function(){
load_visualisation();})
@ -66,7 +24,6 @@ function register_stats(){
load_visualisation();
});
}
function load_visualisation(){
$('img#loader').show();
var name = $('#vis_filter_type').val();;

View File

@ -290,6 +290,7 @@ class saimod_sys_log extends \SYSTEM\SAI\SaiModule {
return \SYSTEM\PAGE\replace::replaceFile(\SYSTEM\SERVERPATH(new \SYSTEM\PSAI(),'modules/saimod_sys_log/tpl/saimod_sys_log_error.tpl'), $vars);}
public static function sai_mod__SYSTEM_SAI_saimod_sys_log_action_filter($filter = "%"){
$filter_ = $filter;
$filter = str_replace('\\', '\\\\', $filter);
$count = \SYSTEM\DBD\SYS_SAIMOD_LOG_FILTER_COUNT::Q1(array($filter));
$res = \SYSTEM\DBD\SYS_SAIMOD_LOG_FILTER::QQ(array($filter));
@ -305,14 +306,9 @@ class saimod_sys_log extends \SYSTEM\SAI\SaiModule {
$vars = array();
$vars['count'] = $count['count'];
$vars['table'] = $table;
return \SYSTEM\PAGE\replace::replaceFile(\SYSTEM\SERVERPATH(new \SYSTEM\PSAI(),'modules/saimod_sys_log/tpl/saimod_sys_log_table.tpl'), $vars);
}
public static function sai_mod__SYSTEM_SAI_saimod_sys_log_action_log(){
$vars = array();
$vars['table'] = self::sai_mod__SYSTEM_SAI_saimod_sys_log_action_filter();
$vars['error_filter'] = self::generate_error_filters();
return \SYSTEM\PAGE\replace::replaceFile(\SYSTEM\SERVERPATH(new \SYSTEM\PSAI(),'modules/saimod_sys_log/tpl/saimod_sys_log_filter.tpl'), $vars);
return \SYSTEM\PAGE\replace::replaceFile(\SYSTEM\SERVERPATH(new \SYSTEM\PSAI(),'modules/saimod_sys_log/tpl/saimod_sys_log_filter.tpl'),
array( 'table' => \SYSTEM\PAGE\replace::replaceFile(\SYSTEM\SERVERPATH(new \SYSTEM\PSAI(),'modules/saimod_sys_log/tpl/saimod_sys_log_table.tpl'), $vars),
'error_filter' => self::generate_error_filters($filter_)));
}
private static function time_elapsed_string($ptime){
@ -335,11 +331,11 @@ class saimod_sys_log extends \SYSTEM\SAI\SaiModule {
}
}
private static function generate_error_filters(){
private static function generate_error_filters($filter){
$res = \SYSTEM\DBD\SYS_SAIMOD_LOG_FILTERS::QQ();
$result = '';
while($row = $res->next()){
$result .= '<li><a href="#!log" filter="'.$row['class'].'">'.$row['class'].'</a></li>';}
$result .= '<li'.($filter == $row['class'] ? ' class="active"' : '').'><a href="#!log;filter.'.$row['class'].'">'.$row['class'].'</a></li>';}
return $result;
}

View File

@ -2,13 +2,12 @@
<hr>
<div class="tabbable">
<ul class="nav nav-tabs" id="tabs_log">
<li class="active"><a href="#tab_log" action="log">Log</a></li>
<li><a href="#tab_stats" action="stats">Statistics</a></li>
<li class="active"><a href="#!log">Log</a></li>
<li><a href="#!log(stats)" id="menu_stats">Statistics</a></li>
<img id="loader" src="${PICPATH}ajax-loader.gif" style="margin-left: 10px; margin-top: 10px; display: none; float: left"/>
<button id="refresh_error_table" class="btn-success" style="margin-right: 15px; height: 32px; font-size: 13px; float: right;">Refresh</button>
</ul>
<div class="tab-content">
<div class="tab-pane active" id="tab_log"></div>
<div class="tab-pane" id="tab_stats" style="overflow: hidden;"></div>
</div>
</div>

View File

@ -1,4 +1,4 @@
<tr class="sai_log_error ${class_row}" error="${ID}">
<tr class="sai_log_error ${class_row}" onClick="document.location = '#!log(error);error.${ID}';">
<td>${time}</td>
<td>${class}</td>
<td style="word-break: break-all;">${message}</td>

View File

@ -14,7 +14,7 @@ $(document).ready(function() {
});
function sys_hashchange(state){
$('#sai_navbar li, #project_navbar li').each(function(){
$('.nav li,#sai_navbar li, #project_navbar li').each(function(){
$(this).removeClass('active');});
$('#menu_'+state).parent().addClass('active');
}