Skip to content
This repository was archived by the owner on Sep 19, 2022. It is now read-only.

Commit c2a60b8

Browse files
melangervyskocilpavel
authored andcommitted
move JS from listOfSps to external file (#62)
* move JS from listOfSps to external file
1 parent 906be7e commit c2a60b8

File tree

2 files changed

+85
-63
lines changed

2 files changed

+85
-63
lines changed

templates/listOfSps-tpl.php

Lines changed: 17 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,13 @@
1010
$this->data['header'] = '';
1111
$this->data['head'] = '<link rel="stylesheet" media="screen" type="text/css" href="' .
1212
Module::getModuleUrl('perun/res/css/listOfSps.css') . '" />';
13-
$this->includeAtTemplateBase('includes/header.php');
13+
14+
$this->data['head'] .= '<meta name="translations" id="translations" content="'.htmlspecialchars(json_encode([
15+
'saml_production' => $this->t('{perun:listOfSps:saml_production}'),
16+
'saml_test' => $this->t('{perun:listOfSps:saml_test}'),
17+
'oidc_production' => $this->t('{perun:listOfSps:oidc_production}'),
18+
'oidc_test' => $this->t('{perun:listOfSps:oidc_test}'),
19+
])).'">';
1420

1521
$statistics = $this->data['statistics'];
1622
$attributesToShow = $this->data['attributesToShow'];
@@ -24,6 +30,15 @@
2430
$testServicesCount = $statistics['samlTestServicesCount'] + $statistics['oidcTestServicesCount'];
2531
$samlProductionCount = $statistics['samlServicesCount'] - $statistics['samlTestServicesCount'];
2632
$oidcProductionCount = $statistics['oidcServicesCount'] - $statistics['oidcTestServicesCount'];
33+
34+
$this->data['head'] .= '<meta name="data" id="data" content="'.htmlspecialchars(json_encode([
35+
'samlProductionCount' => $samlProductionCount,
36+
'samlTestServicesCount' => $statistics['samlTestServicesCount'],
37+
'oidcProductionCount' => $oidcProductionCount,
38+
'oidcTestServicesCount' => $statistics['oidcTestServicesCount'],
39+
])).'">';
40+
41+
$this->includeAtTemplateBase('includes/header.php');
2742
?>
2843

2944
<div class="row">
@@ -199,65 +214,4 @@ function getClass($attribute)
199214

200215
<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.7.3/Chart.bundle.js"></script>
201216

202-
<script>
203-
var ctx = document.getElementById("myChart").getContext('2d');
204-
var myChart = new Chart(ctx, {
205-
type: 'bar',
206-
data: {
207-
labels: [
208-
<?php echo
209-
'"' . $this->t('{perun:listOfSps:saml_production}') . '"' . ", " .
210-
'"' . $this->t('{perun:listOfSps:saml_test}') . '"' . ", " .
211-
'"' . $this->t('{perun:listOfSps:oidc_production}') . '"' . ", " .
212-
'"' . $this->t('{perun:listOfSps:oidc_test}') . '"'
213-
?>
214-
],
215-
datasets: [{
216-
label: '',
217-
data: [
218-
<?php echo
219-
$samlProductionCount . ', ' . $statistics['samlTestServicesCount'] .
220-
', ' . $oidcProductionCount . ', ' . $statistics['oidcTestServicesCount']
221-
?>
222-
],
223-
backgroundColor: [
224-
'rgba(255, 99, 132, 0.2)',
225-
'rgba(54, 162, 235, 0.2)',
226-
'rgba(255, 206, 86, 0.2)',
227-
'rgba(75, 192, 192, 0.2)'
228-
],
229-
borderColor: [
230-
'rgba(255,99,132,1)',
231-
'rgba(54, 162, 235, 1)',
232-
'rgba(255, 206, 86, 1)',
233-
'rgba(75, 192, 192, 1)'
234-
],
235-
borderWidth: 1
236-
}]
237-
},
238-
options: {
239-
scales: {
240-
yAxes: [{
241-
ticks: {
242-
beginAtZero: true,
243-
callback: function (value) {
244-
if (Number.isInteger(value)) {
245-
return value;
246-
}
247-
}
248-
}
249-
}]
250-
},
251-
legend: {
252-
display: false
253-
},
254-
tooltips: {
255-
callbacks: {
256-
label: function (tooltipItem) {
257-
return tooltipItem.yLabel;
258-
}
259-
}
260-
}
261-
}
262-
});
263-
</script>
217+
<script src="<?php echo htmlspecialchars(\SimpleSAML\Module::getModuleURL('perun/listOfSps.js'));?>"></script>

www/listOfSps.js

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
function getTranslation(str) {
2+
return JSON.parse(document.getElementById('translations').getAttribute('content'))[str];
3+
}
4+
5+
function getDataItem(name) {
6+
return JSON.parse(document.getElementById('data').getAttribute('content'))[name];
7+
}
8+
9+
Chart.platform.disableCSSInjection = true;
10+
11+
var ctx = document.getElementById("myChart").getContext('2d');
12+
new Chart(ctx, { // eslint-disable-line no-new
13+
type: 'bar',
14+
data: {
15+
labels: [
16+
getTranslation('saml_production'),
17+
getTranslation('saml_test'),
18+
getTranslation('oidc_production'),
19+
getTranslation('oidc_test')
20+
],
21+
datasets: [{
22+
label: '',
23+
data: [
24+
getDataItem('samlProductionCount'),
25+
getDataItem('samlTestServicesCount'),
26+
getDataItem('oidcProductionCount'),
27+
getDataItem('oidcTestServicesCount')
28+
],
29+
backgroundColor: [
30+
'rgba(255, 99, 132, 0.2)',
31+
'rgba(54, 162, 235, 0.2)',
32+
'rgba(255, 206, 86, 0.2)',
33+
'rgba(75, 192, 192, 0.2)'
34+
],
35+
borderColor: [
36+
'rgba(255,99,132,1)',
37+
'rgba(54, 162, 235, 1)',
38+
'rgba(255, 206, 86, 1)',
39+
'rgba(75, 192, 192, 1)'
40+
],
41+
borderWidth: 1
42+
}]
43+
},
44+
options: {
45+
scales: {
46+
yAxes: [{
47+
ticks: {
48+
beginAtZero: true,
49+
callback: function (value) {
50+
if (Number.isInteger(value)) {
51+
return value;
52+
}
53+
}
54+
}
55+
}]
56+
},
57+
legend: {
58+
display: false
59+
},
60+
tooltips: {
61+
callbacks: {
62+
label: function (tooltipItem) {
63+
return tooltipItem.yLabel;
64+
}
65+
}
66+
}
67+
}
68+
});

0 commit comments

Comments
 (0)