Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Graphs #12

Merged
merged 19 commits into from Aug 21, 2013
Merged
Show file tree
Hide file tree
Changes from 18 commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
05ec60f
Added g.Raphael files to repo
m0hamed Aug 14, 2013
abb708b
Added g.Raphael and g.pie to the list of loaded script files in the d…
m0hamed Aug 14, 2013
6ae7122
Added raphael.js file to repo
m0hamed Aug 16, 2013
fd99b3a
Added raphael js file to default layout
m0hamed Aug 16, 2013
6b8e563
Changed the way the related entries information is passed to the repo…
m0hamed Aug 16, 2013
5cffe50
Added pie.js which has a function to draw a piechart
m0hamed Aug 16, 2013
6669bb4
Now draws charts for all relevant columns that a summary is collected…
m0hamed Aug 16, 2013
440c0f4
Fixed key for configuration storage and scriptname in incidents view
m0hamed Aug 18, 2013
77524c9
Added migration to add extra columns to incidents table
m0hamed Aug 18, 2013
7118689
Added syntax highlighter files to repo
m0hamed Aug 18, 2013
1ad41ed
Added shBrushXml.js to the repo
m0hamed Aug 18, 2013
9d4a569
Added script name and configuration storage to summarized columns
m0hamed Aug 18, 2013
9e22db4
Added pma version to linenumber and file name for report grouping
m0hamed Aug 18, 2013
2781544
Added fallback if error occurs in error_report.js
m0hamed Aug 18, 2013
601f07b
Added syntax highlighting to code snipets
m0hamed Aug 18, 2013
dbc95d2
removed log messages to console used in debugging
m0hamed Aug 18, 2013
5aa121e
Stopped using html-script within the syntax highlighting since it doe…
m0hamed Aug 18, 2013
46902db
Fixed 'scriptname' index in incident model array
m0hamed Aug 18, 2013
54f258f
Sanitized column name in chart helper method
m0hamed Aug 20, 2013
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
@@ -0,0 +1,55 @@
<?php
class AddExtraColumnsToIncidentsTable extends CakeMigration {

/**
* Migration description
*
* @var string
* @access public
*/
public $description = 'Add two extra columns to the incidents table';

/**
* Actions to be performed
*
* @var array $migration
* @access public
*/
public $migration = array(
'up' => array(
'create_field' => array(
'incidents' => array(
'script_name' => array('type' => 'string', 'null' => true, 'default' => NULL, 'collate' => 'utf8_general_ci', 'charset' => 'utf8', 'after' => 'server_software'),
'configuration_storage' => array('type' => 'string', 'null' => true, 'default' => NULL, 'length' => 30, 'collate' => 'utf8_general_ci', 'charset' => 'utf8', 'after' => 'server_software'),
),
),
),
'down' => array(
'drop_field' => array(
'incidents' => array('script_name', 'configuration_storage',),
),
),
);

/**
* Before migration callback
*
* @param string $direction, up or down direction of migration process
* @return boolean Should process continue
* @access public
*/
public function before($direction) {
return true;
}

/**
* After migration callback
*
* @param string $direction, up or down direction of migration process
* @return boolean Should process continue
* @access public
*/
public function after($direction) {
return true;
}
}
7 changes: 5 additions & 2 deletions app/Controller/ReportsController.php
Expand Up @@ -126,16 +126,19 @@ public function unmark_related_to($reportId) {
## HELPERS
protected function _setSimilarFields($id) {
$fields = array('browser', 'pma_version', 'php_version', 'server_software',
'user_os');
'user_os', 'script_name', 'configuration_storage');

$this->Report->read(null, $id);

$this->set('columns', $fields);

foreach ($fields as $field) {
list($entriesWithCount, $totalEntries) =
$this->Report->getRelatedByField($field, 25, true);
$this->set("${field}_related_entries", $entriesWithCount);
$relatedEntries[$field] = $entriesWithCount;
$this->set("${field}_distinct_count", $totalEntries);
}
$this->set("related_entries", $relatedEntries);
}

protected function _getSearchConditions($aColumns) {
Expand Down
35 changes: 23 additions & 12 deletions app/Model/Incident.php
Expand Up @@ -41,7 +41,7 @@ class Incident extends AppModel {

public function createIncidentFromBugReport($bugReport) {
$schematizedIncident = $this->_getSchematizedIncident($bugReport);
$closestReport = $this->_getClosestReport($bugReport["exception"]);
$closestReport = $this->_getClosestReport($bugReport);

if($closestReport) {
$schematizedIncident["report_id"] = $closestReport["Report"]["id"];
Expand Down Expand Up @@ -75,9 +75,11 @@ protected function _hasDifferentStacktrace($newIncident, $incidents) {
return true;
}

protected function _getClosestReport($exception) {
List($location, $linenumber) = $this->_getIdentifyingLocation($exception["stack"]);
$report = $this->Report->findByLocationAndLinenumber($location, $linenumber);
protected function _getClosestReport($bugReport) {
List($location, $linenumber) =
$this->_getIdentifyingLocation($bugReport['exception']['stack']);
$report = $this->Report->findByLocationAndLinenumberAndPmaVersion(
$location, $linenumber, $bugReport['pma_version']);
return $report;
}

Expand All @@ -91,6 +93,7 @@ protected function _getReportDetails($bugReport) {
'status' => 'new',
'location' => $location,
'linenumber' => $linenumber,
'pma_version' => $bugReport['pma_version'],
);
return $reportDetails;
}
Expand All @@ -106,6 +109,8 @@ protected function _getSchematizedIncident($bugReport) {
'browser' => $bugReport['browser_name'] . " "
. $this->_getMajorVersion($bugReport['browser_version']),
'user_os' => $bugReport['user_os'],
'script_name' => $bugReport['script_name'],
'configuration_storage' => $bugReport['configuration_storage'],
'server_software' => $this->_getServer($bugReport['server_software']),
'full_report' => json_encode($bugReport),
'stacktrace' => json_encode($bugReport['exception']['stack']),
Expand All @@ -117,19 +122,25 @@ protected function _getSchematizedIncident($bugReport) {
protected function _getIdentifyingLocation($stacktrace) {
foreach ($stacktrace as $level) {
if (isset($level["filename"])) {
if ($level["filename"] !== "tracekit.js"
&& $level["filename"] !== "error_report.js") {
return array($level["filename"], $level["line"]);
} else {
// ignore unrelated files that sometimes appear in the error report
if ($level["filename"] === "tracekit.js") {
continue;
} elseif($level["filename"] === "error_report.js") {
// incase the error is in the error_report.js file
if(!isset($fallback)) {
$fallback = array($level["filename"], $level["line"]);
}
continue;
} else {
return array($level["filename"], $level["line"]);
}
}
if (isset($level["uri"])) {
return array($level["uri"], $level["line"]);
} elseif (isset($level["scriptname"])) {
return array($level["scriptname"], $level["line"]);
} else {
return array($level["url"], $level["line"]);
continue;
}
}
return $fallback;
}

protected function _getMajorVersion($fullVersion) {
Expand Down
2 changes: 1 addition & 1 deletion app/View/Helper/IncidentsHelper.php
Expand Up @@ -62,7 +62,7 @@ public function getStacktrace($incident, $divClass) {

foreach ($incident["Incident"]["stacktrace"] as $level) {
$html .= $this->_getStackLevelInfo($level);
$html .= "<pre>";
$html .= "<pre class='brush: js; tab-size: 2'>";
$html .= join("\n", Sanitize::clean($level["context"]));
$html .= "</pre>";
}
Expand Down
19 changes: 18 additions & 1 deletion app/View/Helper/ReportsHelper.php
Expand Up @@ -3,9 +3,10 @@
App::uses('AppHelper', 'View/Helper');
App::uses('IncidentsHelper', 'View/Helper');
App::uses('Sanitize', 'Utility');
App::uses('Inflector', 'Utility');

class ReportsHelper extends AppHelper {
public $helpers = array('Incidents');
public $helpers = array('Incidents');

public function __construct(View $view, $settings = array()) {
parent::__construct($view, $settings);
Expand Down Expand Up @@ -59,6 +60,22 @@ public function getStacktracesForIncidents($incidents) {
return $html;
}

public function getChartArray($arrayName, $columns, $relatedEntries) {
$html = "var $arrayName = [], chart = {};";
foreach ($columns as $column) {
$html .= "chart = {};";
$html .= "chart.name = '$column';";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shouldn't $column be escaped with htmlspecialchars() or a similar function?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

$columns is an array that I have defined in the controller to store the list of summarizable columns in one place so its not exactly user entered but using htmlspecialchars() wouldnt hurt

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please escape it, better safe than sorry. ;) You never know what might end up in the array in the future.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I escaped it just in case

$html .= "chart.title = '" . Inflector::humanize($column) . "';";
$html .= "chart.labels = []; chart.values = [];";
foreach ($relatedEntries[$column] as $entry => $count) {
$html .= "chart.labels.push('$entry ($count)');";
$html .= "chart.values.push($count);";
}
$html .= "$arrayName.push(chart);";
}
return $html;
}

protected function _getStackLevelInfo($level) {
$html = "<span>";
$elements = array("filename", "scriptname", "line", "func", "column");
Expand Down
10 changes: 2 additions & 8 deletions app/View/Incidents/view.ctp
Expand Up @@ -66,7 +66,7 @@
<tr>
<td>Script name</td>
<td>
<?php echo $incident["Incident"]["full_report"]["script_name"]; ?>
<?php echo $incident["Incident"]["script_name"]; ?>
</td>
</tr>
<tr>
Expand All @@ -78,13 +78,7 @@
<tr>
<td>Configuration storage enabled</td>
<td>
<?php
if ($incident["Incident"]["full_report"]["configuration_storage_enabled"]) {
echo "true";
} else {
echo "false";
}
?>
<?php echo $incident["Incident"]["full_report"]["configuration_storage"]; ?>
</td>
</tr>
</table>
Expand Down
9 changes: 9 additions & 0 deletions app/View/Layouts/default.ctp
Expand Up @@ -34,11 +34,20 @@
echo $this->Html->css('jquery.dataTables_themeroller');
echo $this->Html->css('bootstrap.min');
echo $this->Html->css('bootstrap-responsive.min');
echo $this->Html->css('shCore.css');
echo $this->Html->css('shThemeDefault.css');
echo $this->Html->css('custom');

echo $this->Html->script('jquery');
echo $this->Html->script('jquery.dataTables.min');
echo $this->Html->script('bootstrap');
echo $this->Html->script('shCore.js');
echo $this->Html->script('shBrushXml.js');
echo $this->Html->script('shBrushJScript.js');
echo $this->Html->script('raphael-min.js');
echo $this->Html->script('g.raphael-min.js');
echo $this->Html->script('g.pie-min.js');
echo $this->Html->script('pie.js');
echo $this->Html->script('custom');

echo $this->fetch('meta');
Expand Down
40 changes: 35 additions & 5 deletions app/View/Reports/view.ctp
Expand Up @@ -42,39 +42,55 @@
<td>PMA Versions</td>
<td>
<?php echo $this->Reports->entriesFromIncidents(
$pma_version_related_entries, $pma_version_distinct_count);
$related_entries["pma_version"], $pma_version_distinct_count);
?>
</td>
</tr>
<tr>
<td>PHP Versions</td>
<td>
<?php echo $this->Reports->entriesFromIncidents(
$php_version_related_entries, $php_version_distinct_count);
$related_entries["php_version"], $php_version_distinct_count);
?>
</td>
</tr>
<tr>
<td>Browsers</td>
<td>
<?php echo $this->Reports->entriesFromIncidents(
$browser_related_entries, $browser_distinct_count);
$related_entries["browser"], $browser_distinct_count);
?>
</td>
</tr>
<tr>
<td>Script Name</td>
<td>
<?php echo $this->Reports->entriesFromIncidents(
$related_entries["script_name"], $script_name_distinct_count);
?>
</td>
</tr>
<tr>
<td>Configuration Storage</td>
<td>
<?php echo $this->Reports->entriesFromIncidents(
$related_entries["configuration_storage"], $configuration_storage_distinct_count);
?>
</td>
</tr>
<tr>
<td>Server Software</td>
<td>
<?php echo $this->Reports->entriesFromIncidents(
$server_software_related_entries, $server_software_distinct_count);
$related_entries["server_software"], $server_software_distinct_count);
?>
</td>
</tr>
<tr>
<td>User OS</td>
<td>
<?php echo $this->Reports->entriesFromIncidents(
$user_os_related_entries, $user_os_distinct_count);
$related_entries["user_os"], $user_os_distinct_count);
?>
</td>
</tr>
Expand Down Expand Up @@ -103,3 +119,17 @@

<h4>Descriptions submited by users:</h4>
<?php echo $this->Incidents->incidentsDescriptions($incidents_with_description); ?>
<h4>Stats and Graphs</h4>
<span id="graphs"></span>
<script type="text/javascript">
<?php echo $this->Reports->getChartArray("chartArray", $columns,
$related_entries); ?>
window.onload = function () {
chartArray.forEach(function(chart) {
var span_id = "graph_" + chart.name;
var $span = $("<span class='span5'>").attr("id", span_id);
$("#graphs").append($span);
piechart(span_id, chart.title, chart.values, chart.labels);
});
};
</script>