Blame view

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