Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

detail.php 3.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. <?php
  2. /* @var $panel yii\debug\panels\DbPanel */
  3. /* @var $searchModel yii\debug\models\search\Db */
  4. /* @var $dataProvider yii\data\ArrayDataProvider */
  5. use yii\helpers\Html;
  6. use yii\grid\GridView;
  7. use yii\web\View;
  8. echo Html::tag('h1', $panel->getName() . ' Queries');
  9. echo GridView::widget([
  10. 'dataProvider' => $dataProvider,
  11. 'id' => 'db-panel-detailed-grid',
  12. 'options' => ['class' => 'detail-grid-view table-responsive'],
  13. 'filterModel' => $searchModel,
  14. 'filterUrl' => $panel->getUrl(),
  15. 'columns' => [
  16. ['class' => 'yii\grid\SerialColumn'],
  17. [
  18. 'attribute' => 'seq',
  19. 'label' => 'Time',
  20. 'value' => function ($data) {
  21. $timeInSeconds = $data['timestamp'] / 1000;
  22. $millisecondsDiff = (int) (($timeInSeconds - (int) $timeInSeconds) * 1000);
  23. return date('H:i:s.', $timeInSeconds) . sprintf('%03d', $millisecondsDiff);
  24. },
  25. 'headerOptions' => [
  26. 'class' => 'sort-numerical'
  27. ]
  28. ],
  29. [
  30. 'attribute' => 'duration',
  31. 'value' => function ($data) {
  32. return sprintf('%.1f ms', $data['duration']);
  33. },
  34. 'options' => [
  35. 'width' => '10%',
  36. ],
  37. 'headerOptions' => [
  38. 'class' => 'sort-numerical'
  39. ]
  40. ],
  41. [
  42. 'attribute' => 'type',
  43. 'value' => function ($data) {
  44. return Html::encode($data['type']);
  45. },
  46. 'filter' => $panel->getTypes(),
  47. ],
  48. [
  49. 'attribute' => 'query',
  50. 'value' => function ($data) use ($hasExplain, $panel) {
  51. $query = Html::encode($data['query']);
  52. if (!empty($data['trace'])) {
  53. $query .= Html::ul($data['trace'], [
  54. 'class' => 'trace',
  55. 'item' => function ($trace) {
  56. return "<li>{$trace['file']} ({$trace['line']})</li>";
  57. },
  58. ]);
  59. }
  60. if ($hasExplain && $panel::canBeExplained($data['type'])) {
  61. $query .= Html::tag('p', '', ['class' => 'db-explain-text']);
  62. $query .= Html::tag(
  63. 'div',
  64. Html::a('[+] Explain', (['db-explain', 'seq' => $data['seq'], 'tag' => Yii::$app->controller->summary['tag']])),
  65. ['class' => 'db-explain']
  66. );
  67. }
  68. return $query;
  69. },
  70. 'format' => 'html',
  71. 'options' => [
  72. 'width' => '60%',
  73. ],
  74. ]
  75. ],
  76. ]);
  77. if ($hasExplain) {
  78. echo Html::tag(
  79. 'div',
  80. Html::a('[+] Explain all', '#'),
  81. ['id' => 'db-explain-all']
  82. );
  83. }
  84. $this->registerJs('debug_db_detail();', View::POS_READY);
  85. ?>
  86. <script>
  87. function debug_db_detail() {
  88. $('.db-explain a').on('click', function(e) {
  89. e.preventDefault();
  90. var $explain = $('.db-explain-text', $(this).parent().parent());
  91. if ($explain.is(':visible')) {
  92. $explain.hide();
  93. $(this).text('[+] Explain');
  94. } else {
  95. $explain.load($(this).attr('href')).show();
  96. $(this).text('[-] Explain');
  97. }
  98. });
  99. $('#db-explain-all a').on('click', function(e) {
  100. e.preventDefault();
  101. $('.db-explain a').click();
  102. });
  103. }
  104. </script>