Skip to content

Commit 9a2380b

Browse files
Merge pull request #272 from JLG-WOCFR-DEV/codex/add-statistics-and-card-updates-to-dashboard
Enhance dashboard stats cards and filter persistence
2 parents a9f075a + d9a72f9 commit 9a2380b

File tree

4 files changed

+354
-53
lines changed

4 files changed

+354
-53
lines changed

liens-morts-detector-jlg/assets/css/blc-admin-styles.css

Lines changed: 98 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,22 +86,85 @@
8686
margin-bottom: 20px;
8787
border-left: 4px solid #72aee6; /* Couleur bleue standard de WordPress */
8888
}
89+
8990
.blc-stat {
9091
display: flex;
9192
flex-direction: column;
9293
align-items: center;
9394
justify-content: center;
94-
flex-grow: 1;
95+
flex: 1 1 180px;
9596
text-align: center;
97+
gap: 8px;
98+
padding: 18px;
99+
border: 1px solid #dcdcde;
100+
border-radius: 6px;
101+
background-color: #f6f7f7;
102+
color: #1d2327;
103+
text-decoration: none;
104+
transition: background-color 0.2s ease, color 0.2s ease, border-color 0.2s ease, box-shadow 0.2s ease;
105+
cursor: pointer;
106+
}
107+
108+
.blc-stat:hover,
109+
.blc-stat:focus-visible {
110+
background-color: #f0f6fc;
111+
border-color: #2271b1;
112+
color: #0a4b78;
113+
box-shadow: 0 0 0 1px #2271b1 inset;
114+
}
115+
116+
.blc-stat:focus-visible {
117+
outline: 2px solid #2271b1;
118+
outline-offset: 2px;
119+
}
120+
121+
.blc-stat:hover .blc-stat-label,
122+
.blc-stat:focus-visible .blc-stat-label {
123+
text-decoration: underline;
96124
}
125+
97126
.blc-stat-value {
98-
font-size: 2.5em;
127+
font-size: 2.2em;
99128
font-weight: 600;
100129
line-height: 1.2;
101-
color: #1d2327;
130+
color: inherit;
102131
}
132+
103133
.blc-stat-label {
104134
font-size: 1em;
135+
color: inherit;
136+
}
137+
138+
.blc-meta-box {
139+
display: flex;
140+
gap: 20px;
141+
flex-wrap: wrap;
142+
background-color: #fff;
143+
border: 1px solid #c3c4c7;
144+
padding: 20px;
145+
margin-bottom: 20px;
146+
border-left: 4px solid #dcdcde;
147+
}
148+
149+
.blc-meta {
150+
display: flex;
151+
flex-direction: column;
152+
align-items: center;
153+
justify-content: center;
154+
flex: 1 1 180px;
155+
text-align: center;
156+
gap: 6px;
157+
}
158+
159+
.blc-meta-value {
160+
font-size: 1.6em;
161+
font-weight: 600;
162+
line-height: 1.3;
163+
color: #1d2327;
164+
}
165+
166+
.blc-meta-label {
167+
font-size: 0.95em;
105168
color: #50575e;
106169
}
107170

@@ -113,7 +176,39 @@
113176
display: block;
114177
}
115178

179+
@media (prefers-reduced-motion: reduce) {
180+
.blc-stat {
181+
transition: none;
182+
}
183+
}
184+
116185
@media (prefers-color-scheme: dark) {
186+
.blc-stat {
187+
background-color: #1f1f1f;
188+
border-color: #3c434a;
189+
color: #f0f0f1;
190+
}
191+
192+
.blc-stat:hover,
193+
.blc-stat:focus-visible {
194+
background-color: #30363d;
195+
border-color: #72aee6;
196+
color: #cbe5ff;
197+
}
198+
199+
.blc-meta-box {
200+
background-color: #1d2327;
201+
border-color: #3c434a;
202+
}
203+
204+
.blc-meta-value {
205+
color: #f0f0f1;
206+
}
207+
208+
.blc-meta-label {
209+
color: #d0d3d7;
210+
}
211+
117212
.blc-stat-note {
118213
color: #b7c0cc;
119214
}

liens-morts-detector-jlg/assets/js/blc-admin-scripts.js

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2006,4 +2006,102 @@ jQuery(document).ready(function($) {
20062006
}
20072007
});
20082008
});
2009+
2010+
(function setupDashboardFilterPersistence() {
2011+
var STORAGE_KEY = 'blcDashboardLinkType';
2012+
var $dashboard = $('.blc-dashboard-links-page');
2013+
2014+
if (!$dashboard.length) {
2015+
return;
2016+
}
2017+
2018+
var storageAvailable = false;
2019+
try {
2020+
var testKey = STORAGE_KEY + '_test';
2021+
window.localStorage.setItem(testKey, '1');
2022+
window.localStorage.removeItem(testKey);
2023+
storageAvailable = true;
2024+
} catch (error) {
2025+
storageAvailable = false;
2026+
}
2027+
2028+
if (!storageAvailable) {
2029+
return;
2030+
}
2031+
2032+
var params;
2033+
try {
2034+
params = new URLSearchParams(window.location.search);
2035+
} catch (error) {
2036+
return;
2037+
}
2038+
2039+
if (params.get('page') !== 'blc-dashboard') {
2040+
return;
2041+
}
2042+
2043+
var storedType = window.localStorage.getItem(STORAGE_KEY) || '';
2044+
var hasLinkType = params.has('link_type') && params.get('link_type') !== null;
2045+
2046+
if (!hasLinkType) {
2047+
if (storedType && storedType !== 'all') {
2048+
params.set('link_type', storedType);
2049+
var redirectUrl = window.location.pathname + '?' + params.toString();
2050+
if (window.location.hash) {
2051+
redirectUrl += window.location.hash;
2052+
}
2053+
window.location.replace(redirectUrl);
2054+
return;
2055+
}
2056+
storedType = 'all';
2057+
} else {
2058+
storedType = params.get('link_type') || '';
2059+
if (!storedType) {
2060+
storedType = 'all';
2061+
}
2062+
}
2063+
2064+
window.localStorage.setItem(STORAGE_KEY, storedType);
2065+
2066+
$dashboard.on('click', '.blc-stats-box a[data-link-type]', function() {
2067+
var type = $(this).data('link-type');
2068+
if (typeof type === 'undefined' || type === null || type === '') {
2069+
type = 'all';
2070+
}
2071+
window.localStorage.setItem(STORAGE_KEY, String(type));
2072+
});
2073+
2074+
$(document).on('click', 'a[href*="page=blc-dashboard"]', function() {
2075+
var href = $(this).attr('href');
2076+
if (!href) {
2077+
return;
2078+
}
2079+
2080+
var linkType = null;
2081+
try {
2082+
var url = new URL(href, window.location.origin);
2083+
if (url.searchParams.get('page') !== 'blc-dashboard') {
2084+
return;
2085+
}
2086+
if (url.searchParams.has('link_type')) {
2087+
linkType = url.searchParams.get('link_type') || '';
2088+
} else {
2089+
linkType = 'all';
2090+
}
2091+
} catch (error) {
2092+
return;
2093+
}
2094+
2095+
if (linkType === null) {
2096+
return;
2097+
}
2098+
2099+
if (!linkType) {
2100+
linkType = 'all';
2101+
}
2102+
2103+
window.localStorage.setItem(STORAGE_KEY, linkType);
2104+
});
2105+
})();
2106+
20092107
});

liens-morts-detector-jlg/includes/blc-admin-pages.php

Lines changed: 90 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -549,13 +549,64 @@ function blc_dashboard_links_page() {
549549
}
550550

551551
// Préparation des données et des statistiques pour les liens
552-
global $wpdb;
553-
$table_name = $wpdb->prefix . 'blc_broken_links';
554-
$broken_links_count = (int) $wpdb->get_var(
555-
$wpdb->prepare(
556-
"SELECT COUNT(*) FROM $table_name WHERE type = %s AND ignored_at IS NULL",
557-
'link'
558-
)
552+
$list_table = new BLC_Links_List_Table();
553+
$status_counts = $list_table->get_status_counts();
554+
555+
$broken_links_count = isset($status_counts['active_count']) ? (int) $status_counts['active_count'] : 0;
556+
$not_found_count = isset($status_counts['not_found_count']) ? (int) $status_counts['not_found_count'] : 0;
557+
$server_error_count = isset($status_counts['server_error_count']) ? (int) $status_counts['server_error_count'] : 0;
558+
$redirect_count = isset($status_counts['redirect_count']) ? (int) $status_counts['redirect_count'] : 0;
559+
$needs_recheck_count = isset($status_counts['needs_recheck_count']) ? (int) $status_counts['needs_recheck_count'] : 0;
560+
561+
$dashboard_base_url = function_exists('admin_url')
562+
? admin_url('admin.php?page=blc-dashboard')
563+
: 'admin.php?page=blc-dashboard';
564+
565+
$build_dashboard_url = static function($link_type) use ($dashboard_base_url) {
566+
if ($link_type === 'all') {
567+
return $dashboard_base_url;
568+
}
569+
570+
if (function_exists('add_query_arg')) {
571+
return add_query_arg('link_type', $link_type, $dashboard_base_url);
572+
}
573+
574+
$separator = (false === strpos($dashboard_base_url, '?')) ? '?' : '&';
575+
576+
return $dashboard_base_url . $separator . 'link_type=' . rawurlencode($link_type);
577+
};
578+
579+
$stats_cards = array(
580+
array(
581+
'slug' => 'all',
582+
'link_type' => 'all',
583+
'value' => number_format_i18n($broken_links_count),
584+
'label' => __('Liens morts trouvés', 'liens-morts-detector-jlg'),
585+
),
586+
array(
587+
'slug' => '404',
588+
'link_type' => 'status_404_410',
589+
'value' => number_format_i18n($not_found_count),
590+
'label' => __('Erreurs 404 / 410', 'liens-morts-detector-jlg'),
591+
),
592+
array(
593+
'slug' => '5xx',
594+
'link_type' => 'status_5xx',
595+
'value' => number_format_i18n($server_error_count),
596+
'label' => __('Erreurs 5xx', 'liens-morts-detector-jlg'),
597+
),
598+
array(
599+
'slug' => 'redirects',
600+
'link_type' => 'status_redirects',
601+
'value' => number_format_i18n($redirect_count),
602+
'label' => __('Redirections détectées', 'liens-morts-detector-jlg'),
603+
),
604+
array(
605+
'slug' => 'recheck',
606+
'link_type' => 'needs_recheck',
607+
'value' => number_format_i18n($needs_recheck_count),
608+
'label' => __('Liens à revérifier', 'liens-morts-detector-jlg'),
609+
),
559610
);
560611
$option_size_bytes = blc_get_dataset_storage_footprint_bytes('link');
561612
$last_check_time = get_option('blc_last_check_time', 0);
@@ -567,30 +618,47 @@ function blc_dashboard_links_page() {
567618
? wp_date('j M Y', $last_check_time)
568619
: __('Jamais', 'liens-morts-detector-jlg');
569620

570-
$list_table = new BLC_Links_List_Table();
571621
$list_table->prepare_items();
572622
blc_render_action_modal();
573623

574624
?>
575-
<div class="wrap">
625+
<div class="wrap blc-dashboard-links-page">
576626
<?php blc_render_dashboard_tabs('links'); ?>
577627
<h1><?php esc_html_e('Rapport des Liens Cassés', 'liens-morts-detector-jlg'); ?></h1>
578628
<div class="blc-stats-box">
579-
<div class="blc-stat">
580-
<span class="blc-stat-value"><?php echo esc_html($broken_links_count); ?></span>
581-
<span class="blc-stat-label"><?php esc_html_e('Liens morts trouvés', 'liens-morts-detector-jlg'); ?></span>
582-
</div>
583-
<div class="blc-stat">
584-
<span class="blc-stat-value"><?php echo esc_html($size_display); ?></span>
585-
<span class="blc-stat-label"><?php esc_html_e('Poids des données', 'liens-morts-detector-jlg'); ?></span>
629+
<?php foreach ($stats_cards as $card) :
630+
$link_type = $card['link_type'];
631+
$card_url = $build_dashboard_url($link_type);
632+
$aria_label = sprintf(
633+
/* translators: 1: Stat label, 2: number of items. */
634+
__('Afficher %1$s (%2$s)', 'liens-morts-detector-jlg'),
635+
$card['label'],
636+
$card['value']
637+
);
638+
?>
639+
<a
640+
class="blc-stat blc-stat--<?php echo esc_attr($card['slug']); ?>"
641+
href="<?php echo esc_url($card_url); ?>"
642+
data-link-type="<?php echo esc_attr($link_type); ?>"
643+
aria-label="<?php echo esc_attr($aria_label); ?>"
644+
>
645+
<span class="blc-stat-value"><?php echo esc_html($card['value']); ?></span>
646+
<span class="blc-stat-label"><?php echo esc_html($card['label']); ?></span>
647+
</a>
648+
<?php endforeach; ?>
649+
</div>
650+
<div class="blc-meta-box">
651+
<div class="blc-meta">
652+
<span class="blc-meta-value"><?php echo esc_html($size_display); ?></span>
653+
<span class="blc-meta-label"><?php esc_html_e('Poids des données', 'liens-morts-detector-jlg'); ?></span>
586654
</div>
587-
<div class="blc-stat">
588-
<span class="blc-stat-value"><?php echo esc_html($last_check_display); ?></span>
589-
<span class="blc-stat-label"><?php esc_html_e('Dernière analyse', 'liens-morts-detector-jlg'); ?></span>
655+
<div class="blc-meta">
656+
<span class="blc-meta-value"><?php echo esc_html($last_check_display); ?></span>
657+
<span class="blc-meta-label"><?php esc_html_e('Dernière analyse', 'liens-morts-detector-jlg'); ?></span>
590658
</div>
591-
<div class="blc-stat">
592-
<span class="blc-stat-value"><?php echo esc_html($next_scheduled_display); ?></span>
593-
<span class="blc-stat-label"><?php esc_html_e('Prochaine analyse automatique', 'liens-morts-detector-jlg'); ?></span>
659+
<div class="blc-meta">
660+
<span class="blc-meta-value"><?php echo esc_html($next_scheduled_display); ?></span>
661+
<span class="blc-meta-label"><?php esc_html_e('Prochaine analyse automatique', 'liens-morts-detector-jlg'); ?></span>
594662
<?php if ('' !== $schedule_note) : ?>
595663
<span class="blc-stat-note"><?php echo esc_html($schedule_note); ?></span>
596664
<?php endif; ?>

0 commit comments

Comments
 (0)