Conditions | 2 |
Paths | 2 |
Total Lines | 33 |
Code Lines | 15 |
Lines | 0 |
Ratio | 0 % |
Tests | 10 |
CRAP Score | 2.003 |
Changes | 0 |
1 | <?php |
||
17 | 1 | public function graph(User $user = null) |
|
18 | { |
||
19 | 1 | $params = ['controller' => 'status', 'action' => 'graph']; |
|
20 | 1 | if ($user) { |
|
21 | $params['user'] = $user->id; |
||
|
|||
22 | } |
||
23 | 1 | $url = $this->view->serverUrl() . $this->view->url($params, 'default'); |
|
24 | |||
25 | $js = <<<STRING |
||
26 | $(document).ready(function() { |
||
27 | const refreshGraph = function() { |
||
28 | const percentage = $('#graph_percent').is(':checked') ? '?percent=1' : ''; |
||
29 | 1 | $.get('$url' + percentage, function (chart) { |
|
30 | chart = $.parseJSON(chart); |
||
31 | $('#chart_container').highcharts(chart); |
||
32 | }); |
||
33 | }; |
||
34 | |||
35 | $('#graph_percent').change(refreshGraph); |
||
36 | refreshGraph(); |
||
37 | |||
38 | }); |
||
39 | STRING; |
||
40 | |||
41 | 1 | $html = '<div id="chart_container" style="min-height: 400px"></div> |
|
42 | <input type="checkbox" name="graph_percent" id="graph_percent" value="1"> |
||
43 | <label for="graph_percent">Show graph as stacked percentage</label>'; |
||
44 | |||
45 | 1 | $this->view->headScript() |
|
46 | 1 | ->appendFile('/js/min/highcharts.js') |
|
47 | 1 | ->appendScript($js); |
|
48 | |||
49 | 1 | return $html; |
|
50 | } |
||
52 |