No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.

119 líneas
3.4KB

  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. [
  17. 'attribute' => 'seq',
  18. 'label' => 'Time',
  19. 'value' => function ($data) {
  20. $timeInSeconds = $data['timestamp'] / 1000;
  21. $millisecondsDiff = (int) (($timeInSeconds - (int) $timeInSeconds) * 1000);
  22. return date('H:i:s.', $timeInSeconds) . sprintf('%03d', $millisecondsDiff);
  23. },
  24. 'headerOptions' => [
  25. 'class' => 'sort-numerical'
  26. ]
  27. ],
  28. [
  29. 'attribute' => 'duration',
  30. 'value' => function ($data) {
  31. return sprintf('%.1f ms', $data['duration']);
  32. },
  33. 'options' => [
  34. 'width' => '10%',
  35. ],
  36. 'headerOptions' => [
  37. 'class' => 'sort-numerical'
  38. ]
  39. ],
  40. [
  41. 'attribute' => 'type',
  42. 'value' => function ($data) {
  43. return Html::encode($data['type']);
  44. },
  45. 'filter' => $panel->getTypes(),
  46. ],
  47. [
  48. 'attribute' => 'query',
  49. 'value' => function ($data) use ($hasExplain, $panel) {
  50. $query = Html::encode($data['query']);
  51. if (!empty($data['trace'])) {
  52. $query .= Html::ul($data['trace'], [
  53. 'class' => 'trace',
  54. 'item' => function ($trace) use ($panel) {
  55. return '<li>' . $panel->getTraceLine($trace) . '</li>';
  56. },
  57. ]);
  58. }
  59. if ($hasExplain && $panel::canBeExplained($data['type'])) {
  60. $query .= Html::tag('p', '', ['class' => 'db-explain-text']);
  61. $query .= Html::tag(
  62. 'div',
  63. Html::a('[+] Explain', (['db-explain', 'seq' => $data['seq'], 'tag' => Yii::$app->controller->summary['tag']])),
  64. ['class' => 'db-explain']
  65. );
  66. }
  67. return $query;
  68. },
  69. 'format' => 'raw',
  70. 'options' => [
  71. 'width' => '60%',
  72. ],
  73. ]
  74. ],
  75. ]);
  76. if ($hasExplain) {
  77. echo Html::tag(
  78. 'div',
  79. Html::a('[+] Explain all', '#'),
  80. ['id' => 'db-explain-all']
  81. );
  82. }
  83. $this->registerJs('debug_db_detail();', View::POS_READY);
  84. ?>
  85. <script>
  86. function debug_db_detail() {
  87. $('.db-explain a').on('click', function(e) {
  88. e.preventDefault();
  89. var $explain = $('.db-explain-text', $(this).parent().parent());
  90. if ($explain.is(':visible')) {
  91. $explain.hide();
  92. $(this).text('[+] Explain');
  93. } else {
  94. $explain.load($(this).attr('href')).show();
  95. $(this).text('[-] Explain');
  96. }
  97. });
  98. $('#db-explain-all a').on('click', function(e) {
  99. e.preventDefault();
  100. $('.db-explain a').click();
  101. });
  102. }
  103. </script>