From 857dc20fba3ad2ff225b1c124f16780d6f590122 Mon Sep 17 00:00:00 2001 From: Rhilip Date: Thu, 31 Jan 2019 22:12:48 +0800 Subject: [PATCH] style(Admin Panel): replace _ to backspace in render It seems unnecessary to replace _ to backspace by using array_map , So we replace it when render those `Variable_name` --- apps/controllers/AdminController.php | 6 +----- apps/views/admin/mysql_status.html.twig | 28 ++++++++++++------------- 2 files changed, 15 insertions(+), 19 deletions(-) diff --git a/apps/controllers/AdminController.php b/apps/controllers/AdminController.php index 8bdef2e..850842e 100644 --- a/apps/controllers/AdminController.php +++ b/apps/controllers/AdminController.php @@ -116,10 +116,6 @@ private function infoRedis() private function infoMysql() { $res = app()->pdo->createCommand('SHOW GLOBAL STATUS')->queryAll(); - $res = array_map(function ($s) { - $s['Variable_name'] = str_replace('_', ' ', $s['Variable_name']); - return $s; - }, $res); $serverStatus = array_column($res, 'Value', 'Variable_name'); $startAt = app()->pdo->createCommand('SELECT UNIX_TIMESTAMP() - :uptime')->bindParams([ 'uptime' => $serverStatus['Uptime'] @@ -127,7 +123,7 @@ private function infoMysql() $queryStats = []; $tmp_array = $serverStatus; foreach ($tmp_array AS $name => $value) { - if (substr($name, 0, 4) == 'Com ') { + if (substr($name, 0, 4) == 'Com_') { $queryStats[substr($name, 4)] = $value; unset($serverStatus[$name]); } diff --git a/apps/views/admin/mysql_status.html.twig b/apps/views/admin/mysql_status.html.twig index a2c2256..92e6ba2 100644 --- a/apps/views/admin/mysql_status.html.twig +++ b/apps/views/admin/mysql_status.html.twig @@ -26,18 +26,18 @@ Received - {{ serverStatus['Bytes received'] | format_bytes }} - {{ (serverStatus['Bytes received'] * 3600 / serverStatus['Uptime']) | format_bytes }} + {{ serverStatus['Bytes_received'] | format_bytes }} + {{ (serverStatus['Bytes_received'] * 3600 / serverStatus['Uptime']) | format_bytes }} Sent - {{ serverStatus['Bytes sent'] | format_bytes }} - {{ (serverStatus['Bytes sent'] * 3600 / serverStatus['Uptime']) | format_bytes }} + {{ serverStatus['Bytes_sent'] | format_bytes }} + {{ (serverStatus['Bytes_sent'] * 3600 / serverStatus['Uptime']) | format_bytes }} Total - {{ (serverStatus['Bytes received'] + serverStatus['Bytes sent']) | format_bytes }} - {{ ((serverStatus['Bytes sent'] + serverStatus['Bytes sent']) * 3600 / serverStatus['Uptime']) | format_bytes }} + {{ (serverStatus['Bytes_received'] + serverStatus['Bytes_sent']) | format_bytes }} + {{ ((serverStatus['Bytes_sent'] + serverStatus['Bytes_sent']) * 3600 / serverStatus['Uptime']) | format_bytes }} @@ -55,18 +55,18 @@ Failed Attempts - {{ serverStatus['Aborted connects'] | number_format(0,'.', ',') }} - {{ (serverStatus['Aborted connects'] * 3600 / serverStatus['Uptime']) | number_format(2,'.',',') }} + {{ serverStatus['Aborted_connects'] | number_format(0,'.', ',') }} + {{ (serverStatus['Aborted_connects'] * 3600 / serverStatus['Uptime']) | number_format(2,'.',',') }} - {% if serverStatus['Connections'] > 0 %}{{ (serverStatus['Aborted connects'] * 100 / serverStatus['Connections']) | number_format(2,'.',',') }} %{% else %}---{% endif %} + {% if serverStatus['Connections'] > 0 %}{{ (serverStatus['Aborted_connects'] * 100 / serverStatus['Connections']) | number_format(2,'.',',') }} %{% else %}---{% endif %} Aborted Clients - {{ serverStatus['Aborted clients'] | number_format(0,'.', ',') }} - {{ (serverStatus['Aborted clients'] * 3600 / serverStatus['Uptime']) | number_format(2,'.',',') }} + {{ serverStatus['Aborted_clients'] | number_format(0,'.', ',') }} + {{ (serverStatus['Aborted_clients'] * 3600 / serverStatus['Uptime']) | number_format(2,'.',',') }} - {% if serverStatus['Connections'] > 0 %}{{ (serverStatus['Aborted clients'] * 100 / serverStatus['Connections']) | number_format(2,'.',',') }} %{% else %}---{% endif %} + {% if serverStatus['Connections'] > 0 %}{{ (serverStatus['Aborted_clients'] * 100 / serverStatus['Connections']) | number_format(2,'.',',') }} %{% else %}---{% endif %} @@ -108,7 +108,7 @@ {% for key, value in rows %} - {{ key }} + {{ key|replace({'_':' '}) }} {{ value | number_format(0,'.',',') }} {{ (value * 3600 / serverStatus['Uptime']) | number_format(2,'.',',') }} {{ (value * 100 / (serverStatus['Questions'] - serverStatus['Connections'])) | number_format(2,'.',',') }} @@ -139,7 +139,7 @@ {% for key,value in serverStatus %} - {{ key }} + {{ key|replace({'_':' '}) }} {{ value }} {% endfor %}