From 4edeed8d8322eeed8418fc87458f778420c991d5 Mon Sep 17 00:00:00 2001
From: Niklan <niklanrus@gmail.com>
Date: Wed, 2 Apr 2025 18:19:03 +0500
Subject: [PATCH 1/3] WIP

---
 cache_pilot.install       | 11 ++++++++---
 src/Form/SettingsForm.php | 10 +---------
 2 files changed, 9 insertions(+), 12 deletions(-)

diff --git a/cache_pilot.install b/cache_pilot.install
index efefca2..5a09a21 100644
--- a/cache_pilot.install
+++ b/cache_pilot.install
@@ -4,6 +4,7 @@ declare(strict_types=1);
 
 use Drupal\cache_pilot\Cache\ApcuCache;
 use Drupal\cache_pilot\Client\Client;
+use Drupal\Component\Render\FormattableMarkup;
 use Drupal\Core\StringTranslation\TranslatableMarkup;
 
 /**
@@ -15,11 +16,15 @@ function cache_pilot_requirements(string $phase): array {
   if ($phase === 'runtime') {
     $fast_cgi_client = \Drupal::service(Client::class);
     $is_connected = $fast_cgi_client->isConnected();
+    $connection_dsn =\Drupal::configFactory()->get('cache_pilot.settings')->get('connection_dsn');
 
     $requirements['cache_pilot_connection'] = [
-      'title' => new TranslatableMarkup('Cache Pilot connection'),
-      'description' => $is_connected ? new TranslatableMarkup('Connected') : new TranslatableMarkup('Not connected'),
-      'severity' => $is_connected ? REQUIREMENT_OK : REQUIREMENT_WARNING,
+      'title' => new TranslatableMarkup('Cache Pilot'),
+      'value' => $is_connected ? new TranslatableMarkup('Connected') : new TranslatableMarkup('Not connected'),
+      'description' => $connection_dsn,
+      'severity' => $is_connected
+        ? \REQUIREMENT_OK
+        : ($connection_dsn === NULL ? \REQUIREMENT_WARNING : \REQUIREMENT_ERROR),
     ];
   }
 
diff --git a/src/Form/SettingsForm.php b/src/Form/SettingsForm.php
index a8f2a40..d1879b8 100644
--- a/src/Form/SettingsForm.php
+++ b/src/Form/SettingsForm.php
@@ -89,8 +89,7 @@ final class SettingsForm extends ConfigFormBase {
       '#type' => 'textfield',
       '#title' => new TranslatableMarkup('Connection DSN'),
       '#description' => new TranslatableMarkup('The connection string in the format <code>tcp://[host]:[port]</code> for TCP or <code>unix://[socket_path]</code> for a Unix socket.'),
-      '#default_value' => $this->config('cache_pilot.settings')->get('connection_dsn'),
-      '#placeholder' => 'tcp://127.0.0.1:9000 or unix:///var/run/php/php-fpm.sock',
+      '#config_target' => 'cache_pilot.settings:connection_dsn',
     ];
   }
 
@@ -168,13 +167,6 @@ final class SettingsForm extends ConfigFormBase {
     }
   }
 
-  /**
-   * {@inheritdoc}
-   */
-  public function submitForm(array &$form, FormStateInterface $form_state): void {
-    $this->config('cache_pilot.settings')->set('connection_dsn', $form_state->getValue('connection_dsn'))->save();
-  }
-
   /**
    * {@inheritdoc}
    */
-- 
GitLab


From 81dd419388d5b958374db46751113ad4e293c445 Mon Sep 17 00:00:00 2001
From: Niklan <niklanrus@gmail.com>
Date: Mon, 7 Apr 2025 17:49:53 +0500
Subject: [PATCH 2/3] WIP

---
 css/cache-pilot-fragmentation-bar.css             | 3 ++-
 templates/cache-pilot-fragmentation-bar.html.twig | 6 +++---
 2 files changed, 5 insertions(+), 4 deletions(-)

diff --git a/css/cache-pilot-fragmentation-bar.css b/css/cache-pilot-fragmentation-bar.css
index cd3cd83..4b56959 100644
--- a/css/cache-pilot-fragmentation-bar.css
+++ b/css/cache-pilot-fragmentation-bar.css
@@ -2,9 +2,10 @@
   display: flex;
   flex-direction: column;
   gap: var(--space-s, 0.5rem);
+  margin: 0;
 }
 
-.cache-pilot-fragmentation-bar__progress {
+.cache-pilot-fragmentation-bar__indicator {
   border-radius: var(--progress-bar-default-size-radius, 1.5rem);
   overflow: hidden;
   display: flex;
diff --git a/templates/cache-pilot-fragmentation-bar.html.twig b/templates/cache-pilot-fragmentation-bar.html.twig
index 13f8cb3..22f5786 100644
--- a/templates/cache-pilot-fragmentation-bar.html.twig
+++ b/templates/cache-pilot-fragmentation-bar.html.twig
@@ -13,8 +13,8 @@
  */
 #}
 {{ attach_library('cache_pilot/fragmentation-bar') }}
-<div{{ attributes.addClass('cache-pilot-fragmentation-bar') }}>
-  <div class="cache-pilot-fragmentation-bar__progress">
+<figure{{ attributes.addClass('cache-pilot-fragmentation-bar') }}>
+  <div class="cache-pilot-fragmentation-bar__indicator">
     {% for fragment in fragments %}
       <div class="cache-pilot-fragmentation-bar__fragment"
            style="--fragment-background-color: {{ fragment.color }}; --fragment-percentage: {{ fragment.percentage }}%;">
@@ -34,4 +34,4 @@
       </div>
     {% endfor %}
   </div>
-</div>
+</figure>
-- 
GitLab


From 2789576fc0241737198aec2071884828a8160de9 Mon Sep 17 00:00:00 2001
From: Niklan <niklanrus@gmail.com>
Date: Tue, 8 Apr 2025 17:30:34 +0500
Subject: [PATCH 3/3] WIP

---
 cache_pilot.links.task.yml                    | 12 ++++
 cache_pilot.module                            |  6 --
 cache_pilot.routing.yml                       | 14 ++++-
 src/Controller/DashboardController.php        | 60 ++++++++++++-------
 src/Form/SettingsForm.php                     |  2 +-
 .../PreprocessCachePilotOpcacheStatistics.php |  2 +-
 templates/cache-pilot-dashboard.html.twig     | 29 ---------
 .../cache-pilot-opcache-statistics.html.twig  |  2 +-
 8 files changed, 65 insertions(+), 62 deletions(-)
 delete mode 100644 templates/cache-pilot-dashboard.html.twig

diff --git a/cache_pilot.links.task.yml b/cache_pilot.links.task.yml
index 108cdc7..bf50ed7 100644
--- a/cache_pilot.links.task.yml
+++ b/cache_pilot.links.task.yml
@@ -2,3 +2,15 @@ cache_pilot.settings:
   title: 'Cache Pilot settings'
   route_name: cache_pilot.settings
   base_route: system.performance_settings
+
+cache_pilot.dashboard.apcu:
+  title: 'APCu'
+  route_name: cache_pilot.dashboard
+  base_route: cache_pilot.dashboard
+
+cache_pilot.dashboard.opcache:
+  title: 'OPcache'
+  route_name: cache_pilot.dashboard.statistics
+  base_route: cache_pilot.dashboard
+  route_parameters:
+    cache_type: 'opcache'
diff --git a/cache_pilot.module b/cache_pilot.module
index ded4d0a..6ef3798 100644
--- a/cache_pilot.module
+++ b/cache_pilot.module
@@ -19,12 +19,6 @@ function cache_pilot_cache_flush(): void {
  */
 function cache_pilot_theme(): array {
   return [
-    'cache_pilot_dashboard' => [
-      'variables' => [
-        'apcu' => [],
-        'opcache' => [],
-      ],
-    ],
     'cache_pilot_apcu_statistics' => [
       'variables' => [
         'statistics' => [],
diff --git a/cache_pilot.routing.yml b/cache_pilot.routing.yml
index 1b6acc5..0eb2c83 100644
--- a/cache_pilot.routing.yml
+++ b/cache_pilot.routing.yml
@@ -11,7 +11,17 @@ cache_pilot.dashboard:
   path: '/admin/reports/cache-pilot'
   methods: ['GET']
   defaults:
-    _controller: '\Drupal\cache_pilot\Controller\DashboardController'
-    _title: 'Cache Pilot dashboard'
+    _controller: \Drupal\cache_pilot\Controller\DashboardController
+    _title_callback: \Drupal\cache_pilot\Controller\DashboardController::pageTitle
+    cache_type: 'apcu'
   requirements:
     _permission: 'cache_pilot.administer'
+
+cache_pilot.dashboard.statistics:
+  path: '/admin/reports/cache-pilot/{cache_type}'
+  methods: ['GET']
+  defaults:
+    _controller: \Drupal\cache_pilot\Controller\DashboardController
+    _title_callback: \Drupal\cache_pilot\Controller\DashboardController::pageTitle
+  requirements:
+    _permission: 'cache_pilot.administer'
\ No newline at end of file
diff --git a/src/Controller/DashboardController.php b/src/Controller/DashboardController.php
index 6c4451f..e5f81eb 100644
--- a/src/Controller/DashboardController.php
+++ b/src/Controller/DashboardController.php
@@ -34,36 +34,52 @@ final readonly class DashboardController implements ContainerInjectionInterface
   ) {}
 
   /**
-   * Returns the cache statistics dashboard.
+   * Builds a page title.
+   *
+   * @param string $cache_type
+   *   The requested cache type.
+   *
+   * @return \Drupal\Core\StringTranslation\TranslatableMarkup
+   *   The page title.
    */
-  public function __invoke(): array {
-    $build = [
-      '#theme' => 'cache_pilot_dashboard',
-    ];
-
-    $apcu_statistics = $this->apcu->statistics();
-    if ($apcu_statistics) {
-      $build['#apcu'] = [
-        '#theme' => 'cache_pilot_apcu_statistics',
-        '#statistics' => $apcu_statistics,
-      ];
-    }
+  public function pageTitle(string $cache_type): TranslatableMarkup {
+    return match ($cache_type) {
+      'apcu' => new TranslatableMarkup('APCu statistics'),
+      'opcache' => new TranslatableMarkup('Zend OPcache statistics'),
+      default => new TranslatableMarkup('Cache Pilot dashboard'),
+    };
+  }
 
-    $opcache_statistics = $this->opcache->statistics();
-    if ($opcache_statistics) {
-      $build['#opcache'] = [
-        '#theme' => 'cache_pilot_opcache_statistics',
-        '#statistics' => $opcache_statistics,
-      ];
-    }
+  /**
+   * Returns the cache statistics dashboard.
+   *
+   * @param string $cache_type
+   *   The requested cache type.
+   *
+   * @return array
+   *   The page contents.
+   */
+  public function __invoke(string $cache_type): array {
+    $statistics = match ($cache_type) {
+      'apcu' => $this->apcu->statistics(),
+      'opcache' => $this->opcache->statistics(),
+      default => NULL,
+    };
 
-    if (!isset($build['#apcu']) && !isset($build['#opcache'])) {
+    if (!$statistics) {
       return [
         '#markup' => new TranslatableMarkup('Looks like there is a problem with the connection to FastCGI.'),
       ];
     }
 
-    return $build;
+    return [
+      '#theme' => match($cache_type) {
+        'apcu' => 'cache_pilot_apcu_statistics',
+        'opcache' => 'cache_pilot_opcache_statistics',
+        default => throw new \InvalidArgumentException(\sprintf('Unexpected cache type %s', $cache_type)),
+      },
+      '#statistics' => $statistics,
+    ];
   }
 
 }
diff --git a/src/Form/SettingsForm.php b/src/Form/SettingsForm.php
index d1879b8..98b99a7 100644
--- a/src/Form/SettingsForm.php
+++ b/src/Form/SettingsForm.php
@@ -139,7 +139,7 @@ final class SettingsForm extends ConfigFormBase {
   }
 
   /**
-   * Attempts to clear Zend OPCache.
+   * Attempts to clear Zend OPcache.
    */
   public function clearOpcache(): void {
     $this->opcacheCache->clear();
diff --git a/src/Hook/Theme/PreprocessCachePilotOpcacheStatistics.php b/src/Hook/Theme/PreprocessCachePilotOpcacheStatistics.php
index 0684050..4d06638 100644
--- a/src/Hook/Theme/PreprocessCachePilotOpcacheStatistics.php
+++ b/src/Hook/Theme/PreprocessCachePilotOpcacheStatistics.php
@@ -160,7 +160,7 @@ final readonly class PreprocessCachePilotOpcacheStatistics {
   }
 
   /**
-   * Prepares OPCache stats information.
+   * Prepares OPcache stats information.
    */
   private function prepareOpcacheStatsInformation(array &$variables): void {
     $statistics = $variables['statistics'];
diff --git a/templates/cache-pilot-dashboard.html.twig b/templates/cache-pilot-dashboard.html.twig
deleted file mode 100644
index 7fc585a..0000000
--- a/templates/cache-pilot-dashboard.html.twig
+++ /dev/null
@@ -1,29 +0,0 @@
-{#
-/**
- * @file
- * Default theme implementation to display Cache Pilot dashboard items.
- *
- * Available variables:
- * - attributes: The main wrapper element attributes.
- * - apcu: (optional) The APCu statistics pane.
- * - opcache: (optional) The Zend OPCache statistics pane.
- */
-#}
-<div{{ attributes.addClass('cache-pilot-dashboard') }}>
-  {% if apcu %}
-    {{ _self.section('APCu statistics'|t, apcu) }}
-  {% endif %}
-
-  {% if opcache %}
-    {{ _self.section('Zend OPCache statistics'|t, opcache) }}
-  {% endif %}
-</div>
-
-{% macro section(title, content) %}
-  <div class="cache-pilot-dashboard__section">
-    <h2 class="cache-pilot-dashboard__header">{{ title }}</h2>
-    <div class="cache-pilot-dashboard__pane">
-      {{ content }}
-    </div>
-  </div>
-{% endmacro %}
diff --git a/templates/cache-pilot-opcache-statistics.html.twig b/templates/cache-pilot-opcache-statistics.html.twig
index c4771fc..032c81c 100644
--- a/templates/cache-pilot-opcache-statistics.html.twig
+++ b/templates/cache-pilot-opcache-statistics.html.twig
@@ -8,7 +8,7 @@
  * - statistics: An array with raw data from opcache_get_status().
  * - general: The general information.
  * - strings: The information about strings cache.
- * - opcache_stats: The OPCache statistics information.
+ * - opcache_stats: The OPcache statistics information.
  */
 #}
 <div{{ attributes.addClass('cache-pilot-opcache-statistics') }}>
-- 
GitLab