Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Testing out the templating with breakdownTimeline.php #2489

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

sammeboy635
Copy link
Contributor

@stoyan I was hoping to get some help on this if you wouldn't mind but I'm a little unsure how to PR this cleanly.
I did the bare minimum to just get breakdownTimeline.php to work with the templater and it seems to work just fine. Do you have thoughts on it?

Preview with templater
breakdown

Copy link
Contributor

@stoyan stoyan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sweet, I love it. I tried to address your questions inline.

www/resources/views/pages/breakdownTimeline.blade.php Outdated Show resolved Hide resolved
www/breakdownTimeline.php Show resolved Hide resolved
echo view('pages.breakdownTimeline', [
//'test_results_view' => true, // Not Sure if we need this
'body_class' => 'result',
// 'results_header' => $results_header, // Null Value, Not sure if we need this
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the consolelog.php case $results_header is the contents of include_once 'header.inc' but with output buffering. Because I need the content but it should come after the overall header which comes with the default template.

Otherwise the test results header will come before the top menu in my experience.

Screen Shot 2022-10-21 at 12 07 32 PM

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

image

I see what you mean, it was to fix the layout of the header. Currently without using $result_header my header looks like the image above.

Would you still recommend I pass in $result_header like you did in consolelog.php even though it is ok?
like this ?

ob_start();
define('NOBANNER', true); // otherwise Twitch banner shows 2x
$tab = 'Test Result';
$subtab = 'Processing';
include_once 'header.inc';
$results_header = ob_get_contents();
ob_end_clean();

www/resources/views/pages/breakdownTimeline.blade.php Outdated Show resolved Hide resolved
www/breakdownTimeline.php Outdated Show resolved Hide resolved
www/breakdownTimeline.php Outdated Show resolved Hide resolved
www/resources/views/pages/breakdownTimeline.blade.php Outdated Show resolved Hide resolved
@sammeboy635
Copy link
Contributor Author

Sweet, I love it. I tried to address your questions inline.

Hey thanks a lot for all the great feedback!

@sammeboy635
Copy link
Contributor Author

It's ready for review :).

WebPageTest.-.Google.Chrome.2022-10-27.11-41-25.mp4

@sammeboy635 sammeboy635 marked this pull request as ready for review October 27, 2022 17:51
Copy link
Contributor

@stoyan stoyan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

back to your queue to see if you can remove some of the <?php in the template

Comment on lines 12 to 13
// $page_keywords = array('Timeline Breakdown','WebPageTest','Website Speed Test','Page Speed');
// $page_description = "Chrome main-thread processing breakdown$testLabel";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can move these as globals to the .php file (outside the template)

They should just work. If not we'll fix in a follow up diff

Comment on lines 78 to 79
if (isset($groups) && is_array($groups) && count($groups)) {
foreach ($groups as $type => $time) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there are loops and ifs in Blade, could you try them?

https://laravel.com/docs/9.x/blade#if-statements
https://laravel.com/docs/9.x/blade#loops

the idea is to minimize <?php as much as we can

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And echo is really what we don't need when we have templates :)

echo "groups.setValue($index, 1, $time);\n";
$color = $groupColors[$type];
echo "groupColors.push('$color');\n";
$index++;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

check out the magical $loop var:
https://laravel.com/docs/9.x/blade#the-loop-variable

It gives you $loop->index :)

var groupsIdle = new google.visualization.DataTable();
groupsIdle.addColumn('string', 'Category');
groupsIdle.addColumn('number', 'Time (ms)');
groupsIdle.addRows(<?php echo count($groups); ?>);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think these count calls should work in hte template too, like

groupsIdle.addRows({{ count($groups) }});

@sammeboy635
Copy link
Contributor Author

I was going to push another PR for this but I was thinking to clean up the php we could process everything on the JS side. This way we are not passing 200+ lines of groupsIdle.addRows. Instead we just pass a json string to JS through var processing = {{ Illuminate\Support\Js::from($processing) }}; . In addition this way allows for better code reusability. Where the Timing Breakdown graph we only have to just append idle data like this

    // Add Idle Data to group Table
    groupTable['data'].push(['Idle' , Groups['Idle']]);
    groupTable['colors'].push(GroupColors['Idle']);

Let me know if you would rather me go the larvel templating method instead.

@stoyan
Copy link
Contributor

stoyan commented Nov 14, 2022

yeah, I like the idea! But also I wanted to replace all these google API-powered graphs and pies with something self-hosted, throughout the site. Something like https://www.chartjs.org/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants