Skip to content

Commit

Permalink
Merge branch 'refactor-diagnostics-utility' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
bencroker committed Feb 12, 2024
2 parents 740aae8 + 5fcf442 commit 8781d9c
Show file tree
Hide file tree
Showing 26 changed files with 220 additions and 285 deletions.
1 change: 1 addition & 0 deletions src/Blitz.php
Original file line number Diff line number Diff line change
Expand Up @@ -489,6 +489,7 @@ function(RegisterUrlRulesEvent $event) {
// Merge so that settings controller action comes first (important!)
$event->rules = array_merge([
'settings/plugins/blitz' => 'blitz/settings/edit',
'blitz/diagnostics/<path:(.*)?>' => 'blitz/diagnostics/index',
],
$event->rules
);
Expand Down
27 changes: 26 additions & 1 deletion src/controllers/DiagnosticsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,14 @@

namespace putyourlightson\blitz\controllers;

use Craft;
use craft\helpers\App;
use craft\web\Controller;
use craft\web\CsvResponseFormatter;
use craft\web\Response;
use putyourlightson\blitz\assets\BlitzAsset;
use putyourlightson\blitz\helpers\DiagnosticsHelper;
use putyourlightson\sprig\Sprig;
use yii\web\Response;

/**
* @since 4.10.0
Expand All @@ -23,6 +26,28 @@ public function beforeAction($action): bool
return parent::beforeAction($action);
}

public function actionIndex(string $path): Response
{
Craft::$app->getView()->registerAssetBundle(BlitzAsset::class);

Sprig::bootstrap();
Sprig::$core->components->setConfig(['requestClass' => 'busy']);

$siteId = null;
$site = Craft::$app->getRequest()->getParam('site');
if ($site) {
$site = Craft::$app->getSites()->getSiteByHandle($site);
$siteId = $site ? $site->id : null;
}
if (empty($siteId)) {
$siteId = Craft::$app->getSites()->getCurrentSite()->id;
}

return $this->renderTemplate('blitz/_utilities/diagnostics/' . $path, [
'siteId' => $siteId,
]);
}

public function actionExportPages(int $siteId): Response
{
App::maxPowerCaptain();
Expand Down
27 changes: 7 additions & 20 deletions src/resources/css/cp.css
Original file line number Diff line number Diff line change
Expand Up @@ -90,34 +90,21 @@ table.editable th.code {
font-size: inherit !important;
}

.breadcrumb-list li.leaf:after {
border: none;
}

.blitz-diagnostics {
margin-top: -10px;
}

.blitz-diagnostics #header {
padding-left: 0;
padding-right: 0;
margin-bottom: 0.5rem;
width: calc(100vw - 226px - 226px - 24px - 24px - 24px);
}

@media only screen and (max-width: 1199px) {
.blitz-diagnostics #header {
width: calc(100vw - 24px - 24px - 24px - 24px);
}
padding: 0;
}

.blitz-diagnostics > h1 {
padding-top: var(--s);
line-height: 34px;
}

.blitz-diagnostics .elements {
margin-top: 1rem;
.blitz-diagnostics .search-container {
margin-bottom: 1rem;
}

.blitz-diagnostics .chip {
background-color: transparent;
}

#footer {
Expand Down
4 changes: 0 additions & 4 deletions src/resources/js/cp.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
$('.putyourlightson\\\\blitz\\\\widgets\\\\cachewidget .action .heading').click(function() {
$(this).closest('.action').find('.form').toggleClass('hidden');
});

if ($('.blitz-diagnostics #crumbs').length) {
$('#global-header #crumbs').replaceWith($('.blitz-diagnostics #crumbs').removeClass('hidden'));
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,10 @@
.all() %}

<div s-replace="#elementqueries" s-swap="outerHTML show:#main:top" s-indicator="#elementqueries .elements">
<header id="header">
<div class="page-title flex">
<h1>{{ pluralDisplayName }}</h1>
</div>
<div id="toolbar" class="flex">
<div class="search-container flex-grow texticon has-filter-btn">
<span class="texticon-icon search icon" aria-hidden="true"></span>
<input sprig s-trigger="keyup changed delay:400ms" name="search" type="text" class="clearable text fullwidth" autocomplete="off" placeholder="Search">
</div>
</div>
</header>
<div class="search-container flex-grow texticon has-filter-btn">
<span class="texticon-icon search icon" aria-hidden="true"></span>
<input sprig s-trigger="keyup changed delay:400ms" name="search" type="text" class="clearable text fullwidth" autocomplete="off" placeholder="Search">
</div>
<div id="elementqueries">
{{ hiddenInput('orderBy', orderBy) }}
{{ hiddenInput('sortBy', sortBy) }}
Expand Down
15 changes: 4 additions & 11 deletions src/templates/_utilities/diagnostics/components/elements.twig
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,10 @@
{% set elements = craft.blitz.diagnostics.getElementsFromIds(siteId, elementType, elementIds) %}

<div s-replace="#elements" s-swap="outerHTML show:#main:top" s-indicator="#elements .elements">
<header id="header">
<div class="page-title flex">
<h1>{{ pluralDisplayName }}</h1>
</div>
<div id="toolbar" class="flex">
<div class="search-container flex-grow texticon has-filter-btn">
<span class="texticon-icon search icon" aria-hidden="true"></span>
<input sprig s-trigger="keyup changed delay:400ms" name="search" type="text" class="clearable text fullwidth" autocomplete="off" placeholder="Search">
</div>
</div>
</header>
<div class="search-container flex-grow texticon has-filter-btn">
<span class="texticon-icon search icon" aria-hidden="true"></span>
<input sprig s-trigger="keyup changed delay:400ms" name="search" type="text" class="clearable text fullwidth" autocomplete="off" placeholder="Search">
</div>
<div id="elements">
{{ hiddenInput('orderBy', orderBy) }}
{{ hiddenInput('sortBy', sortBy) }}
Expand Down
23 changes: 5 additions & 18 deletions src/templates/_utilities/diagnostics/components/pages.twig
Original file line number Diff line number Diff line change
Expand Up @@ -21,23 +21,10 @@
{% set maxVisible = rows|length + offset %}

<div s-replace="#results" s-swap="outerHTML show:#main:top" s-indicator="#results .elements">
<header id="header">
<div class="page-title flex">
<h1>{{ 'Tracked Pages'|t('blitz') }}</h1>
{% if craft.app.getIsMultiSite() %}
{% include '_elements/sitemenu' with {
selectedSiteId: siteId,
urlFormat: 'utilities/blitz-diagnostics/pages?site={handle}',
} only %}
{% endif %}
</div>
<div id="toolbar" class="flex">
<div class="search-container flex-grow texticon has-filter-btn">
<span class="texticon-icon search icon" aria-hidden="true"></span>
<input sprig s-trigger="keyup changed delay:400ms" name="search" type="text" class="clearable text fullwidth" autocomplete="off" placeholder="Search">
</div>
</div>
</header>
<div class="search-container flex-grow texticon has-filter-btn">
<span class="texticon-icon search icon" aria-hidden="true"></span>
<input sprig s-trigger="keyup changed delay:400ms" name="search" type="text" class="clearable text fullwidth" autocomplete="off" placeholder="Search">
</div>
<div id="results">
{{ hiddenInput('orderBy', orderBy) }}
{{ hiddenInput('sortBy', sortBy) }}
Expand Down Expand Up @@ -82,7 +69,7 @@
{% set url = siteUrl(uri, null, null, siteId) %}
<tr>
<td class="code">
<a href="{{ url('utilities/blitz-diagnostics/pages/page', { pageId: row.id }) }}">
<a href="{{ url('blitz/diagnostics/pages/page', { pageId: row.id }) }}">
{{ uri }}
</a>
</td>
Expand Down
15 changes: 4 additions & 11 deletions src/templates/_utilities/diagnostics/components/paramPages.twig
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,10 @@
{% set rows = query.all() %}

<div s-replace="#pages" s-swap="outerHTML show:#main:top" s-indicator="#pages .elements">
<header id="header">
<div class="page-title flex">
<h1>{{ pluralDisplayName }}</h1>
</div>
<div id="toolbar" class="flex">
<div class="search-container flex-grow texticon has-filter-btn">
<span class="texticon-icon search icon" aria-hidden="true"></span>
<input sprig s-trigger="keyup changed delay:400ms" name="search" type="text" class="clearable text fullwidth" autocomplete="off" placeholder="Search">
</div>
</div>
</header>
<div class="search-container flex-grow texticon has-filter-btn">
<span class="texticon-icon search icon" aria-hidden="true"></span>
<input sprig s-trigger="keyup changed delay:400ms" name="search" type="text" class="clearable text fullwidth" autocomplete="off" placeholder="Search">
</div>
<div id="pages">
{{ hiddenInput('orderBy', orderBy) }}
{{ hiddenInput('sortBy', sortBy) }}
Expand Down
25 changes: 5 additions & 20 deletions src/templates/_utilities/diagnostics/components/params.twig
Original file line number Diff line number Diff line change
Expand Up @@ -17,25 +17,10 @@
{% set maxVisible = rows|length + offset %}

<div s-replace="#results" s-swap="outerHTML show:#main:top" s-indicator="#results .elements">
<header id="header">
<div class="page-title flex">
<h1>
{{ 'Tracked Query String Params'|t('blitz') }}
</h1>
{% if craft.app.getIsMultiSite() %}
{% include '_elements/sitemenu' with {
selectedSiteId: siteId,
urlFormat: 'utilities/blitz-diagnostics/params?site={handle}',
} only %}
{% endif %}
</div>
<div id="toolbar" class="flex">
<div class="search-container flex-grow texticon has-filter-btn">
<span class="texticon-icon search icon" aria-hidden="true"></span>
<input sprig s-trigger="keyup changed delay:400ms" name="search" type="text" class="clearable text fullwidth" autocomplete="off" placeholder="Search">
</div>
</div>
</header>
<div class="search-container flex-grow texticon has-filter-btn">
<span class="texticon-icon search icon" aria-hidden="true"></span>
<input sprig s-trigger="keyup changed delay:400ms" name="search" type="text" class="clearable text fullwidth" autocomplete="off" placeholder="Search">
</div>
<div id="results">
{{ hiddenInput('orderBy', orderBy) }}
{{ hiddenInput('sortBy', sortBy) }}
Expand All @@ -59,7 +44,7 @@
{% for row in rows %}
<tr>
<td class="code">
<a href="{{ url('utilities/blitz-diagnostics/params/param', {
<a href="{{ url('blitz/diagnostics/params/param', {
param: row.param,
}) }}">
{{ row.param }}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
{% extends 'blitz/_utilities/diagnostics/layouts/element-queries' %}

{% set element = craft.blitz.diagnostics.getElementOfType() %}
{% set title = 'Tracked ' ~ element.displayName ~ ' Queries' %}

{% block content %}

{{ sprig('blitz/_utilities/diagnostics/components/elementQueries', {
siteId: siteId,
elementType: className(element),
displayName: element.displayName,
pluralDisplayName: element.displayName ~ ' Queries',
}) }}

{% endblock %}
88 changes: 41 additions & 47 deletions src/templates/_utilities/diagnostics/element-queries/index.twig
Original file line number Diff line number Diff line change
@@ -1,55 +1,49 @@
{% extends 'blitz/_utilities/diagnostics/layouts/base' %}

{% set crumbs = [] %}
{% set title = 'Tracked Element Queries'|t('blitz') %}
{% set elementQueryTypes = craft.blitz.diagnostics.getElementQueryTypes(siteId) %}

{% block content %}

<header id="header">
<div class="page-title flex">
<h1>
{{ elementQueryTypes|length ? 'Tracked Element Queries'|t('blitz') : 'No Tracked Element Queries'|t('blitz') }}
</h1>
{% if craft.app.getIsMultiSite() %}
{% include '_elements/sitemenu' with {
selectedSiteId: siteId,
urlFormat: 'utilities/blitz-diagnostics/element-queries?site={handle}',
} only %}
{% endif %}
</div>
</header>
{% block pageTitle %}
<div class="page-title flex">
<h1 class="screen-title" title="{{ title }}">{{ title }}</h1>
{% if craft.app.getIsMultiSite() %}
{% include '_elements/sitemenu' with {
selectedSiteId: siteId,
urlFormat: 'blitz/diagnostics/element-queries?site={handle}',
} only %}
{% endif %}
</div>
{% endblock %}

{% if elementQueryTypes|length %}
<div class="elements">
<table class="data fullwidth">
<thead>
{% block content %}
<div class="elements">
<table class="data fullwidth">
<thead>
<tr>
<th>
{{ 'Element Type'|t('blitz') }}
</th>
<th>
{{ 'Element Queries'|t('blitz') }}
</th>
</tr>
</thead>
<tbody>
{% for elementQueryType in elementQueryTypes %}
<tr>
<th>
{{ 'Element Type'|t('blitz') }}
</th>
<th>
{{ 'Element Queries'|t('blitz') }}
</th>
<td class="code">
<a href="{{ url('blitz/diagnostics/element-queries/element-query-type', {
elementType: elementQueryType.type
}) }}">
{{ elementQueryType.type }}
</a>
</td>
<td>
{{ elementQueryType.count|number }}
</td>
</tr>
</thead>
<tbody>
{% for elementQueryType in elementQueryTypes %}
<tr>
<td class="code">
<a href="{{ url('utilities/blitz-diagnostics/element-queries/element-query-type', {
elementType: elementQueryType.type
}) }}">
{{ elementQueryType.type }}
</a>
</td>
<td>
{{ elementQueryType.count|number }}
</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
{% endif %}

{% endfor %}
</tbody>
</table>
</div>
{% endblock %}
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
{% extends 'blitz/_utilities/diagnostics/layouts/elements' %}

{% set element = craft.blitz.diagnostics.getElementOfType() %}
{% set title = 'Tracked ' ~ element.pluralDisplayName %}

{% block content %}

{{ sprig('blitz/_utilities/diagnostics/components/elements', {
siteId: siteId,
elementType: className(element),
displayName: element.displayName,
pluralDisplayName: element.pluralDisplayName,
hasUris: element.hasUris,
}) }}

{% endblock %}
Loading

0 comments on commit 8781d9c

Please sign in to comment.