diff --git a/public_html/deployment/classes/actionlog.class.php b/public_html/deployment/classes/actionlog.class.php index 990f71c306d6441399cac40db47e65be7c0cdd5f..5009d75c472690b040886e32ae34d310764e15fe 100644 --- a/public_html/deployment/classes/actionlog.class.php +++ b/public_html/deployment/classes/actionlog.class.php @@ -112,7 +112,7 @@ class Actionlog { // var_dump(R::findAll( 'log' )); $aReturn = array(); - $sSql = 'SELECT * from logs '; + $sSql = 'SELECT `id`,`time`,`loglevel`,`ip`,`user`,`project`,`action`,`message` from logs '; $sWhere = false; if (array_key_exists("where", $aFilter) && $aFilter["where"]) { $sWhere.=' WHERE (' . $aFilter["where"] . ') '; @@ -131,7 +131,7 @@ class Actionlog { if (array_key_exists("limit", $aFilter) && $aFilter["limit"]) { $sSql.=' LIMIT ' . $aFilter["limit"]; } - + foreach ($this->_makeQuery($sSql) as $row) { for ($i = 0; $i <= 7; $i++) { unset($row[$i]); @@ -146,68 +146,121 @@ class Actionlog { * getLogs method. * @param array $aFilter with the following keys: * 'project' - filter by project; will be mixed with where (see next key) - * 'where' - where clausel - part behind "WHERE " - * 'order' - order clausel - part behind "ORDER BY "; default is "id DESC" (order by newest entries) * 'limit' - limit clausel - part behind "LIMIT " * @return string */ public function renderLogs($aFilter = array(), $bIsFullsearch=false) { - $sReturn = ""; + $sReturn = ''; static $bWasShown; if ($bWasShown) return " "; $bWasShown = true; - $aData = $this->getLogs($aFilter); - if (!count($aData)) { - $sReturn = t("class-actionlog-nolog"); - } else { - $sReturn.='<thead><tr>'; - foreach (array_keys($aData[0]) as $sRow) { - $sReturn.='<th>' . $sRow . '</th>'; - } - $sReturn.='</tr></thead>'; - $sReturn.='<tbody>'; - foreach ($aData as $aRow) { - $sReturn.='<tr class="tractionlogs loglevel-' . $aRow["loglevel"] . ' ' . $aRow["project"] . '">'; - foreach ($aRow as $sValue) { - $sReturn.='<td>' . $sValue . '</td>'; + require_once 'formgen.class.php'; + + // values for dropdowns - limit of lines; time + + $aLimits=array( + '20'=>array('label'=>20), + '50'=>array('label'=>50), + '100'=>array('label'=>100), + ''=>array('label'=>t("all")), + ); + $aTimes=array( + ''=>array('label'=>t("all")), + ">'".date("Y-m-d", date("U"))."'"=>array('label'=>'heute'), + ">'".date("Y-m-d", date("U") - 60*60*24*1)."'"=>array('label'=>'seit gestern'), + ">'".date("Y-m-d", date("U") - 60*60*24*7)."'"=>array('label'=>'seit 1 Woche'), + ); + + $aForms = array( + 'filter' => array( + 'meta' => array( + 'method' => 'GET', + 'action' => '?', + ), + 'validate' => array(), + 'form' => array( + ), + )); + + if ($bIsFullsearch){ + + // --- list of all projects in log + $sSql='SELECT DISTINCT(project) from `logs`'; + $aForms["filter"]["form"]['selectproject'] = array( + 'type' => 'select', + 'name' => 'selectproject', + 'label' => '<i class="icon-tag"></i> ' . t('project'), + 'onchange'=>'updateActionlog();', + ); + $aForms["filter"]["form"]['selectproject']['options']['']=array('label'=>t("all")); + foreach ($this->_makeQuery($sSql) as $row) { + if ($row[0]){ + $aForms["filter"]["form"]['selectproject']['options'][$row[0]]=array('label'=>$row[0]); } - $sReturn.='</tr>'; } - $sReturn.='</tbody>'; - $sReturn .= ' - <i class="icon-filter"></i> - ' . t("overview-textsearch") . ': - <input type="text" id="efilterlogs" name="efilterlogs" - style="width: 150px;" - onchange="filterLogTable();" - onKeypress="filterLogTable(); " - onKeyup="filterLogTable(); " - title="' . t("overview-textsearch-hint") . '" - >'; - if ($bIsFullsearch){ - $sSelect=''; - $sSql='SELECT DISTINCT(project) from `logs`'; - foreach ($this->_makeQuery($sSql) as $row) { - $sSelect.='<option value="'.$row[0].'"'; - $sSelect.='>' . $row[0] . '</option>'; - } - if ($sSelect){ - $sReturn .= ' '. t('project') . ': <select id="selproject" name="project">' - . '<option value="">'.t("all").'</option>' - . $sSelect - . '</select>'; - } - } else { - $sReturn .= ' - <i class="icon-list-alt"></i> - <a href="/deployment/all/setup/actionlog/">all</a>'; + $aForms["filter"]["form"]['selectWheretime'] = array( + 'type' => 'select', + 'name' => 'selectWheretime', + 'label' => '<i class="icon-calendar"></i> time', + 'onchange'=>'updateActionlog();', + 'options' => $aTimes + ); + $aForms["filter"]["form"]['selectlimit'] = array( + 'type' => 'select', + 'name' => 'selectlimit', + 'label' => '<i class="icon-list"></i> limit', + 'onchange'=>'updateActionlog();', + 'options' => $aLimits + ); + $aForms["filter"]["form"]['line'] = array( + 'type' => 'markup', + 'value' => '<hr>', + ); + + + } else { + + // write filters as hidden fields + if (array_key_exists("project", $aFilter)){ + $aForms["filter"]["form"]['selectproject'] = array( + 'type' => 'hidden', + 'value' => $aFilter["project"] + ); } - $sReturn = '<br> - <table class="table">' . $sReturn . '</table>'; + if (array_key_exists("limit", $aFilter)){ + $aForms["filter"]["form"]['selectlimit'] = array( + 'type' => 'hidden', + 'value' => $aFilter["limit"] + ); + } + $aForms["filter"]["form"]['btnalllogs'] = array( + 'type' => 'button', + 'label' => '<i class="icon-list-alt"></i> ' . t('all'), + 'value' => t('all'), + 'href'=>'/deployment/all/setup/actionlog/', + 'onclick'=>'location.href=\'/deployment/all/setup/actionlog/\'; return false;', + ); } + $aForms["filter"]["form"]['efilterlogs'] = array( + 'type' => 'text', + 'name' => 'efilterlogs', + 'label' => '<i class="icon-filter"></i>' . t("overview-textsearch"), + 'onkeyup' => 'filterLogTable();', + 'onkeypress' => 'filterLogTable();', + 'onchange' => 'filterLogTable();', + 'size' => 10, + ); + + $oForm = new formgen($aForms); + + $sReturn = '<br>'.$oForm->renderHtml("filter").' + <div id="tableLogactions"> + <table class="table">' . $sReturn . '</table> + </div>'; + $sReturn = '<strong>' . '<button onclick="setLogVisibility(\'block\');" id="btnShowLogs" class="btnLogs"><b class="icon-chevron-right"></b> </button>' @@ -216,11 +269,9 @@ class Actionlog { . '</strong>' . '<div id="divActionlogs">' - . '<p>' . t("class-actionlog-filter") . ': ' . print_r($aFilter, true) . ')</p>' . $sReturn . '</div> <script> - function getLogVisibility(){ var sReturn=localStorage.getItem("bActionlogsVisible"); sReturn=(sReturn=="block")?"block":"none"; @@ -233,6 +284,9 @@ class Actionlog { $(".btnLogs").css("display", "none"); if (sVisibility=="block"){ $("#btnHideLogs").css("display", "inline"); + $(document).ready(function() { + updateActionlog(); + }); } else { $("#btnShowLogs").css("display", "inline"); } diff --git a/public_html/deployment/classes/formgen.class.php b/public_html/deployment/classes/formgen.class.php index 924a2e8fb36a91f517a39bb695293907e4228ab8..1a20b1a11e56d27afc26b206042972d84656082d 100644 --- a/public_html/deployment/classes/formgen.class.php +++ b/public_html/deployment/classes/formgen.class.php @@ -207,7 +207,7 @@ class formgen { $this->_checkReqiredKeys($elementData, array("name")); $sFormElement.='<select id="' . $sId . '" '; ; - $sFormElement.=$this->_addHtmlAtrributes(explode(",", "$sDefaultAttributes,name"), $elementData); + $sFormElement.=$this->_addHtmlAtrributes(explode(",", "$sDefaultAttributes,name,onchange"), $elementData); $sFormElement.=">\n"; foreach ($elementData["options"] as $idOption => $aOptionData) { $s = preg_replace('/\W/iu', '', $sId . $idOption); @@ -251,7 +251,7 @@ class formgen { $sFormElement.=$this->_addHtmlAtrributes(explode(",", "$sDefaultAttributes,name,disabled,onkeyup,onkeydown,onchange,pattern,placeholder,required,size,value"), $elementData); // $sFormElement.=$this->_addHtmlAtrributes(array("name", "value", "size", "placeholder", "required"), $elementData); // IE: Return abfangen lassen - $sFormElement.=' onkeypress="return checkKey(event);"'; + // $sFormElement.=' onkeypress="return checkKey(event);"'; $sFormElement.=' />'; $sFormElement.="\n"; diff --git a/public_html/deployment/classes/sws.class.php b/public_html/deployment/classes/sws.class.php index 7296b3d1be27cc31d6fc9b18a635fb73487edeb8..6b943953501762b01b05b5af1b825e80ddae1f27 100644 --- a/public_html/deployment/classes/sws.class.php +++ b/public_html/deployment/classes/sws.class.php @@ -649,7 +649,7 @@ class sws { default: die("internal ERROR: need to set a new case with up to " . count($this->_aArgs) . " arguments in " . __FILE__); } if (!$return) { - quit("ERROR: no output"); + $this->_quit("ERROR: no output"); } // ------------------------------------------------------------ diff --git a/public_html/deployment/js/functions.js b/public_html/deployment/js/functions.js index e965c38eef24736604611c9fcda7593c9dd20aef..9d1bdbcbc11df19336b19f06d6843366685d219d 100644 --- a/public_html/deployment/js/functions.js +++ b/public_html/deployment/js/functions.js @@ -1,5 +1,10 @@ + +/** + * initialize soft scrolling for links with css class "scroll-link" + * @see http://css-tricks.com/snippets/jquery/smooth-scrolling/ + * @returns {undefined} + */ function initSoftscroll(){ - // http://css-tricks.com/snippets/jquery/smooth-scrolling/ $(function() { // $('a[href*=#]:not([href=#])').click(function() { $('a.scroll-link').click(function() { @@ -18,6 +23,75 @@ function initSoftscroll(){ } +// http://dev.ci.iml.unibe.ch/webservice/?class=Actionlog&action=getLogs&args=[{%22project%22:%22ci%22},%22blubb%22] +/** + * get filtered action log table + * @returns {undefined} + */ +function updateActionlog(){ + var sUrlBase="/webservice/?class=Actionlog&action=getLogs&type=json&args="; + var aArgs={}; + + var aFilteritems=["project", "where", "order", "limit"]; + var aTableitems=["id", "time", "loglevel", "ip", "user", "project", "action", "message"]; + + // --- create query url + + for (i=0; i<aFilteritems.length; i++){ + sValue=$('#select' + aFilteritems[i]).val(); + if(sValue){ + aArgs[aFilteritems[i]]=sValue; + } + } + + var sWhere=''; + for (j=0; j<aTableitems.length; j++){ + sValue=$('#selectWhere' + aTableitems[j]).val(); + if(sValue){ + if (sWhere){ + sWhere+' AND '; + } + sWhere+='`'+aTableitems[j]+'`'+sValue; + } + } + if (sWhere) { + aArgs["where"]=sWhere; + } + + // --- get data + + var sUrl=sUrlBase+'['+JSON.stringify(aArgs)+']'; + console.log(sUrl); + $.post( sUrl, function( aData ) { + var sHtml=''; + + // --- generate output + if (aData.length && aData[0]["id"]){ + for (i=0; i<aData.length; i++){ + sHtml+='<tr class="tractionlogs loglevel-'+aData[i]["loglevel"]+' '+aData[i]["project"]+'">'; + for (j=0; j<aTableitems.length; j++){ + sHtml+='<td>'+aData[i][aTableitems[j]]+'</td>'; + } + sHtml+='</tr>'; + } + } + + if (!sHtml){ + sHtml='ERROR: no data '; + } else { + sHead=''; + for (j=0; j<aTableitems.length; j++){ + sHead+='<th>'+aTableitems[j]+'</th>'; + } + sHead='<thead><tr>'+sHead+'</tr></thead>'; + sHtml='<table class="table">'+sHead+'<tbody>'+sHtml+'</tbody></table>'; + } + $('#tableLogactions').html(sHtml); + filterLogTable(); + }); + +} + $(document).ready(function() { initSoftscroll(); $(".optionName").popover({trigger: "hover"});