Skip to content

Commit 63d6909

Browse files
Merge pull request #7521 from christianbeeznest/GH-7505-2
Admin: Add more improvements to admin stats - refs #7505
2 parents 6d2e561 + bc153dc commit 63d6909

2 files changed

Lines changed: 51 additions & 113 deletions

File tree

public/main/admin/statistics/index.php

Lines changed: 42 additions & 108 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,9 @@
3434
}
3535
[id$="_chart_wrap"] > canvas,
3636
#courses_chart_wrap > canvas, #tools_chart_wrap > canvas, #coursebylanguage_chart_wrap > canvas,
37-
#recentlogins_chart_wrap > canvas, #subscriptions_chart_wrap > canvas {
38-
position: absolute;
39-
inset: 0;
40-
width: 100% !important;
41-
height: 100% !important;
42-
display: block;
43-
}
37+
#recentlogins_chart_wrap > canvas, #subscriptions_chart_wrap > canvas {display: block;width: 100%;height: 100%;}
38+
#courses_chart_wrap{display:flex;align-items:center;justify-content:center;}
39+
#courses_chart_wrap > canvas{max-height: 100%;width: auto;}
4440
</style>';
4541
$htmlHeadXtra[] = api_get_build_js('libs/chartjs/chart.js');
4642
//$htmlHeadXtra[] = api_get_asset('chartjs-plugin-labels/build/chartjs-plugin-labels.min.js');
@@ -269,6 +265,19 @@
269265

270266
break;
271267
case 'session_by_date':
268+
$htmlHeadXtra[] = '<style>
269+
.sbd-filters form{display:flex;flex-wrap:wrap;align-items:flex-end;gap:12px 14px}
270+
.sbd-filters form :is(.form-group,.control-group,.form-row,.form-actions){margin:0!important}
271+
.sbd-filters form .form-actions{padding:0!important;border:0!important;background:transparent!important}
272+
.sbd-filters .form-group {visibility: hidden;}
273+
.sbd-cards{display:grid;grid-template-columns:repeat(3,minmax(0,1fr));gap:16px;margin:16px 0}
274+
@media (max-width:1200px){.sbd-cards{grid-template-columns:repeat(2,1fr)}}
275+
@media (max-width:768px){.sbd-filters form{display:block}.sbd-cards{grid-template-columns:1fr}}
276+
.sbd-card{background:#fff;border:1px solid rgba(0,0,0,.08);border-radius:12px;padding:12px}
277+
.sbd-chart-wrap{position:relative;width:100%;max-width:360px;aspect-ratio:1/1;margin:0 auto}
278+
.sbd-chart-wrap--wide{max-width:none;aspect-ratio:auto;height:420px}
279+
.sbd-chart-wrap canvas{width:100%!important;height:100%!important;display:block}
280+
</style>';
272281
$form = new FormValidator('session_by_date', 'get');
273282
$form->addDateRangePicker(
274283
'range',
@@ -278,75 +287,8 @@
278287
);
279288
$options = SessionManager::getStatusList();
280289
$form->addSelect('status_id', get_lang('Session status'), $options, ['placeholder' => get_lang('All')]);
281-
282290
$form->addHidden('report', 'session_by_date');
283291
$form->addButtonSearch(get_lang('Search'));
284-
$htmlHeadXtra[] = '<style>
285-
.sbd-filters{
286-
max-width: 760px;
287-
margin: 0 0 16px 0;
288-
}
289-
290-
.sbd-cards{
291-
display: grid;
292-
grid-template-columns: repeat(3, minmax(0, 1fr));
293-
gap: 16px;
294-
margin: 14px 0 18px 0;
295-
}
296-
@media (max-width: 992px){
297-
.sbd-cards{ grid-template-columns: 1fr; }
298-
}
299-
300-
.sbd-card{
301-
background: #fff;
302-
border: 1px solid rgba(0,0,0,.08);
303-
border-radius: 12px;
304-
padding: 12px;
305-
box-shadow: 0 1px 2px rgba(0,0,0,.03);
306-
}
307-
308-
.sbd-card h4{
309-
margin: 0 0 10px 0;
310-
font-size: 14px;
311-
font-weight: 600;
312-
text-align: center;
313-
}
314-
315-
.sbd-chart-wrap{
316-
width: 100%;
317-
height: 320px;
318-
position: relative;
319-
}
320-
@media (max-width: 768px){
321-
.sbd-chart-wrap{ height: 260px; }
322-
}
323-
324-
.sbd-chart-wrap canvas{
325-
width: 100% !important;
326-
height: 100% !important;
327-
display: block;
328-
}
329-
330-
.sbd-table-responsive{
331-
width: 100%;
332-
overflow-x: auto;
333-
-webkit-overflow-scrolling: touch;
334-
}
335-
336-
.sbd-table-responsive table{
337-
min-width: 780px;
338-
}
339-
340-
.sbd-mini-table table{
341-
width: 100% !important;
342-
margin: 0 !important;
343-
}
344-
.sbd-mini-table td, .sbd-mini-table th{
345-
padding: 6px 8px !important;
346-
vertical-align: top;
347-
white-space: normal !important;
348-
}
349-
</style>';
350292

351293
$validated = $form->validate()
352294
|| isset($_REQUEST['range'])
@@ -404,14 +346,11 @@
404346

405347
$reportType = 'pie';
406348
$reportOptions = '
407-
legend: {
408-
position: "left"
409-
},
410-
title: {
411-
text: "%s",
412-
display: true
413-
},
414-
cutoutPercentage: 25
349+
legend: { position: "bottom" },
350+
title:{ text:"%s", display:true },
351+
responsive:true,
352+
maintainAspectRatio:false,
353+
cutoutPercentage:25
415354
';
416355
$reportOptions1 = sprintf($reportOptions, $reportName1);
417356
$reportOptions2 = sprintf($reportOptions, $reportName2);
@@ -467,13 +406,6 @@
467406
}
468407
}
469408
';
470-
471-
$htmlHeadXtra[] = Statistics::getJSChartTemplate(
472-
$url4,
473-
$reportType,
474-
$reportOptions,
475-
'canvas4'
476-
);
477409
}
478410
break;
479411
}
@@ -767,11 +699,13 @@
767699
$row++;
768700

769701
$content .= '<div class="sbd-table-responsive">'.$table->toHtml().'</div>';
770-
$content .= '<div class="sbd-cards">';
771-
$content .= ' <div class="sbd-card sbd-mini-table"><h4 id="canvas1_title"></h4><div id="canvas1_table"></div></div>';
772-
$content .= ' <div class="sbd-card sbd-mini-table"><h4 id="canvas2_title"></h4><div id="canvas2_table"></div></div>';
773-
$content .= ' <div class="sbd-card sbd-mini-table"><h4 id="canvas3_title"></h4><div id="canvas3_table"></div></div>';
774-
$content .= '</div>';
702+
if ($sessionCount > 0) {
703+
$content .= '<div class="sbd-cards">';
704+
$content .= ' <div class="sbd-card sbd-mini-table"><h4 id="canvas1_title"></h4><div id="canvas1_table"></div></div>';
705+
$content .= ' <div class="sbd-card sbd-mini-table"><h4 id="canvas2_title"></h4><div id="canvas2_table"></div></div>';
706+
$content .= ' <div class="sbd-card sbd-mini-table"><h4 id="canvas3_title"></h4><div id="canvas3_table"></div></div>';
707+
$content .= '</div>';
708+
}
775709

776710
// Courses table
777711
$tableCourse = new HTML_Table(['class' => 'table table-hover table-striped table-bordered']);
@@ -800,15 +734,13 @@
800734
}
801735

802736
$content .= '<div class="sbd-table-responsive">'.$tableCourse->toHtml().'</div>';
803-
$content .= '<div class="sbd-cards">';
804-
$content .= ' <div class="sbd-card"><div class="sbd-chart-wrap"><canvas id="canvas1"></canvas></div></div>';
805-
$content .= ' <div class="sbd-card"><div class="sbd-chart-wrap"><canvas id="canvas2"></canvas></div></div>';
806-
$content .= ' <div class="sbd-card"><div class="sbd-chart-wrap"><canvas id="canvas3"></canvas></div></div>';
807-
$content .= '</div>';
808-
809-
$content .= '<div class="sbd-card">';
810-
$content .= ' <div class="sbd-chart-wrap" style="height:420px;"><canvas id="canvas4"></canvas></div>';
811-
$content .= '</div>';
737+
if ($sessionCount > 0) {
738+
$content .= '<div class="sbd-cards">';
739+
$content .= ' <div class="sbd-card"><div class="sbd-chart-wrap"><canvas id="canvas1"></canvas></div></div>';
740+
$content .= ' <div class="sbd-card"><div class="sbd-chart-wrap"><canvas id="canvas2"></canvas></div></div>';
741+
$content .= ' <div class="sbd-card"><div class="sbd-chart-wrap"><canvas id="canvas3"></canvas></div></div>';
742+
$content .= '</div>';
743+
}
812744
}
813745

814746
$table = new HTML_Table(['class' => 'table table-hover table-striped table-bordered data_table']);
@@ -872,11 +804,13 @@
872804
}
873805

874806
$url = api_get_self().'?'.http_build_query($exportParams);
875-
$link = Display::url(
876-
Display::getMdiIcon(ActionIcon::EXPORT_SPREADSHEET, 'ch-tool-icon').'&nbsp;'.get_lang('Export to XLS'),
877-
$url,
878-
['class' => 'btn btn--plain']
879-
);
807+
if ($sessionCount > 0) {
808+
$link = Display::url(
809+
Display::getMdiIcon(ActionIcon::EXPORT_SPREADSHEET, 'ch-tool-icon').'&nbsp;'.get_lang('Export to XLS'),
810+
$url,
811+
['class' => 'btn btn--plain']
812+
);
813+
}
880814
}
881815

882816
$content = '<div class="sbd-filters">'.$form->returnForm().'</div>'.$content.$link;

public/main/inc/lib/statistics.lib.php

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -900,6 +900,7 @@ public static function getToolsStats(): array
900900
'student_publication',
901901
'user',
902902
'forum',
903+
'glossary'
903904
];
904905
$tool_names = [];
905906
foreach ($tools as $tool) {
@@ -1635,11 +1636,11 @@ public static function getJSChartTemplate(
16351636
// - For circular charts, keep aspect ratio to avoid massive charts on tall wrappers.
16361637
$options = trim($options);
16371638
if ($isCircular) {
1638-
$baseOptions = 'responsive: true, maintainAspectRatio: true,';
1639+
$baseOptions = 'responsive: true, maintainAspectRatio: true, devicePixelRatio: Math.min(2, window.devicePixelRatio || 1),';
16391640
} else {
16401641
$baseOptions = $fullSize
1641-
? 'responsive: true, maintainAspectRatio: false,'
1642-
: 'responsive: true,';
1642+
? 'responsive: true, maintainAspectRatio: false, devicePixelRatio: Math.min(2, window.devicePixelRatio || 1),'
1643+
: 'responsive: true, devicePixelRatio: Math.min(2, window.devicePixelRatio || 1),';
16431644
}
16441645

16451646
$finalOptions = trim($baseOptions.' '.$options);
@@ -1736,6 +1737,9 @@ public static function getJSChartTemplate(
17361737
options: options
17371738
});
17381739
1740+
setTimeout(function(){ if (chart) chart.resize(); }, 80);
1741+
setTimeout(function(){ if (chart) chart.resize(); }, 280);
1742+
17391743
$afterInitBlock
17401744
});
17411745
});
@@ -2557,7 +2561,7 @@ public static function statistics_render_menu(array $tools): string
25572561
}
25582562
$aClass = $active
25592563
? 'bg-primary/10 text-primary ring-1 ring-primary/25'
2560-
: 'text-gray-50 hover:bg-gray-15 hover:text-gray-90';
2564+
: 'text-gray-90 hover:bg-gray-15 hover:text-gray-90';
25612565

25622566
$itemDotClass = $active ? 'bg-primary' : 'bg-gray-50 group-hover:bg-primary/60';
25632567

@@ -2587,7 +2591,7 @@ class="group flex items-start justify-between gap-3 rounded-xl px-3 py-2 text-sm
25872591
$out .= '</div></div>';
25882592

25892593
if (!empty($activeInfo)) {
2590-
$out .= '<div class="mt-4 flex flex-wrap items-center gap-2 text-sm text-gray-50">
2594+
$out .= '<div class="mt-4 flex flex-wrap items-center gap-2 text-sm text-gray-90">
25912595
<span class="font-semibold">' . htmlspecialchars(get_lang('You are here'), ENT_QUOTES) . ':</span>
25922596
<span class="inline-flex items-center rounded-full bg-primary/10 px-3 py-1 text-xs font-semibold text-primary">'
25932597
. htmlspecialchars($activeInfo['section'], ENT_QUOTES) . ' · ' . htmlspecialchars($activeInfo['label'], ENT_QUOTES) .

0 commit comments

Comments
 (0)