From 02b5dc563e4cd04d59d439fe99bc2aa01fb7d6ed Mon Sep 17 00:00:00 2001 From: Stig Lindqvist Date: Wed, 3 Sep 2014 21:07:37 +1200 Subject: [PATCH] Updating the UX of the module --- code/DBProfilerQuery.php | 41 +++++++++- code/DBProfilerViewer.php | 43 ++++++++-- css/dbprofiler.css | 56 +++++++++++++ javascript/dbprofiler.js | 14 +++- templates/DBProfilerViewer_index.ss | 92 ++++++++++------------ templates/DBProfilerViewer_show.ss | 118 +++++++++++++--------------- 6 files changed, 239 insertions(+), 125 deletions(-) create mode 100644 css/dbprofiler.css diff --git a/code/DBProfilerQuery.php b/code/DBProfilerQuery.php index 2549fc2..d188757 100644 --- a/code/DBProfilerQuery.php +++ b/code/DBProfilerQuery.php @@ -2,8 +2,16 @@ class DBProfilerQuery extends ViewableData { + + /** + * + * @var string - select, delete, update, insert, show + */ public $type = null; + /** + * @var int + */ protected $duplicates = 0; /** @@ -12,21 +20,30 @@ class DBProfilerQuery extends ViewableData { */ protected $stacktrace = null; + /** + * @return bool + */ public function canView() { return true; } + /** + * @return string + */ public function getTime() { return sprintf("%0.1f", $this->time); } + /** + * @return string + */ public function getBackgroundColor() { return substr($this->hash,0,6); } /** * - * @param array $trace + * @param \DBStacktrace $trace */ public function setStacktrace(DBStacktrace $trace) { $this->stacktrace = $trace; @@ -54,22 +71,40 @@ public function getColor() { return ($tot/3<128)?'fff':'000'; } + /** + * @return mixed + */ public function getSha1() { return $this->hash; } + /** + * @return string + */ public function getQuerySummary() { - return substr($this->query,0,80); + if(strlen($this->query)<80) { + return false; + } + return substr($this->query,0,80) . '...'; } + /** + * @return mixed + */ public function getQuery() { return $this->query; } + /** + * @return string - select, delete, update, insert, show + */ public function getType() { return $this->type; } - + + /** + * @return int + */ public function getDuplicates() { return $this->duplicates; } diff --git a/code/DBProfilerViewer.php b/code/DBProfilerViewer.php index 6816371..316beec 100644 --- a/code/DBProfilerViewer.php +++ b/code/DBProfilerViewer.php @@ -5,23 +5,47 @@ */ class DBProfilerViewer extends Controller { + /** + * @var array + */ private static $allowed_actions = array( 'show', ); + /** + * @var array + */ public static $url_handlers = array( '' => 'index', '$Action' => 'show', ); - + + /** + * @var ArrayList + */ protected $List = null; + /** + * + */ + public function init() { + parent::init(); + $jQuery = Controller::join_links(Director::absoluteBaseURL(), THIRDPARTY_DIR, 'jquery/jquery.js'); + Requirements::javascript($jQuery); + Requirements::javascript('//cdn.datatables.net/1.10.2/js/jquery.dataTables.min.js'); + Requirements::javascript('profiler/javascript/dbprofiler.js'); + Requirements::css('//cdn.datatables.net/1.10.2/css/jquery.dataTables.min.css'); + Requirements::css('profiler/css/dbprofiler.css'); + $debugCSS = Controller::join_links(Director::absoluteBaseURL(), FRAMEWORK_DIR, 'css/debug.css'); + Requirements::css($debugCSS); + } + /** * * @param SS_HTTPRequest $request + * @return \HTMLText */ public function index(SS_HTTPRequest $request) { - $list = new ArrayList(); foreach($this->getHistory() as $data) { $query = unserialize(file_get_contents($data['filepath'])); @@ -33,6 +57,9 @@ public function index(SS_HTTPRequest $request) { return $this->renderWith('DBProfilerViewer_index'); } + /** + * @return string + */ public function Link() { return Director::absoluteBaseURL().'dev/profiler/'; } @@ -40,10 +67,9 @@ public function Link() { /** * * @param SS_HTTPRequest $request + * @return \HTMLText */ public function show(SS_HTTPRequest $request) { - Requirements::javascript('framework/thirdparty/jquery/jquery.js'); - Requirements::javascript('profiler/javascript/dbprofiler.js'); $sha = $request->param('Action'); $list = $this->getLogData($sha); $this->List = $list; @@ -106,6 +132,10 @@ protected function getLogData($sha) { return $niceList; } + /** + * @param $list + * @return DBProfilerQueryList + */ protected function markDuplicates($list) { $counted = array_count_values($list->column('hash')); $result = new DBProfilerQueryList(); @@ -118,6 +148,10 @@ protected function markDuplicates($list) { return $result; } + /** + * @param $query + * @return string + */ protected function getAnalyzedQueryObject($query) { preg_match_all('|\"([a-z_A-Z]*)\"\."([a-z_A-Z]*)\"|', $query->query, $matches); $query->tables = array_unique($matches[1]); @@ -136,7 +170,6 @@ protected function getAnalyzedQueryObject($query) { } elseif(strpos(trim($query->query), 'DESCRIBE') === 0) { $query->type = 'show'; } - return $query; } } \ No newline at end of file diff --git a/css/dbprofiler.css b/css/dbprofiler.css new file mode 100644 index 0000000..f180a86 --- /dev/null +++ b/css/dbprofiler.css @@ -0,0 +1,56 @@ +#listview { + font-size: 13px; +} + +#listview td { + vertical-align: text-top; +} + +#listview .hide { + display: none; +} + +.type-show { + color: #888; +} + +.type-select { + color: #000; +} + +.type-delete { + color: #900; +} + +.type-update { + color: #006; +} + +.type-insert { + color: #060 +} + +.center { + text-align: center; +} + +.duplicates { + border: 1px solid #000; + margin: 1px; +} + +td.query { + font-family: monospace; +} + +.cursor { + cursor: pointer; +} + +tr.odd td { + background: #dde9ff; +} + +tr.even { + +} \ No newline at end of file diff --git a/javascript/dbprofiler.js b/javascript/dbprofiler.js index 31e55d9..247f8e1 100644 --- a/javascript/dbprofiler.js +++ b/javascript/dbprofiler.js @@ -1,11 +1,17 @@ $(document).ready(function() { - $('td').each(function(){ - $(this).click(function(){ - var hidden = $(this).find('.hide'); - var displayed = $(this).find('.display'); + $('td .cursor').each(function(){ + $(this).dblclick(function(){ + var hidden = $(this).parent().find('.hide'); + var displayed = $(this).parent().find('.display'); + console.log(displayed); displayed.removeClass('display').addClass('hide'); hidden.removeClass('hide').addClass('display'); + + $('html, body').animate({ + scrollTop: $(this).parent().offset().top + }, 0); + return false; }); }); diff --git a/templates/DBProfilerViewer_index.ss b/templates/DBProfilerViewer_index.ss index fa80706..61054e2 100644 --- a/templates/DBProfilerViewer_index.ss +++ b/templates/DBProfilerViewer_index.ss @@ -1,53 +1,43 @@ - - DBProfiler - - - -
-

DBProfiler

-
-
- - - - - - - - - <% loop List %> - - - - - - - <% end_loop %> - -
Total timeQueriesUrlWhen
$TotalTime$Count$Url$DateTime
-
- - \ No newline at end of file +GET /dev/ + + + +
+

SilverStripe Development DBProfiler

+

$AbsoluteBaseURL

DBProfile
+
+ + + + + + + + + + + <% loop $List %> + + + + + + + <% end_loop %> + + +
Total timeQueriesUrlWhen
$TotalTime$Count$Url$DateTime
+
+ + + + diff --git a/templates/DBProfilerViewer_show.ss b/templates/DBProfilerViewer_show.ss index 7601ccf..f27524b 100644 --- a/templates/DBProfilerViewer_show.ss +++ b/templates/DBProfilerViewer_show.ss @@ -1,66 +1,60 @@ - - DBProfiler - Show queries for request - +GET /dev/ + + + +
+

SilverStripe Development DBProfiler

+

$AbsoluteBaseURL

DBProfile +
$List.Count queries took $List.TotalTime ms and $List.DuplicateCount duplicates stole $List.DuplicateTime ms
+
- - -
-

DBProfiler

- Back to list -
-
$List.Count queries took $List.TotalTime ms and $List.DuplicateCount duplicates stole $List.DuplicateTime ms
-
-
- -
- - - - - - - - - - <% loop List %> - - - - - - - - <% end_loop %> - -
msdupesha1querystack
$Timeclass="duplicates" style="background-color: #$BackgroundColor; color: #$Color">$Duplicates <% else %>><% end_if %>$Sha1$QuerySummary$Query - Show trace - $Stacktrace.Trace -
-
- +
+ + + + + + + + + + + + + <% loop $List %> + + + + + + <% else %> + $Query + <% end_if %> + + + <% end_loop %> + + +
MsDupessha1QueryTrace
$Time +
class="duplicates" style="background-color: #$BackgroundColor; color: #$Color"<% else %><% end_if %>>$Duplicates
+
$Sha1 + <% if $QuerySummary %> + $QuerySummary + $Query + show + $Stacktrace.Trace +
+
+ + + \ No newline at end of file