Skip to content

Commit 448d471

Browse files
Set project image and title on initial page load (#2863)
Some pages currently use data from the primary API response to populate the project name and image. This means that there is a "flash" as the project name and logo is rendered after the rest of the initial page load occurs. This PR addresses the handful of locations where this behavior occurs, making all pages load the header in a consistent fashion. Despite rendering the content in the same amount of time, the pages now feel slightly snappier, especially when waiting for large pages to load.
1 parent 1628bd2 commit 448d471

22 files changed

+64
-98
lines changed

app/Http/Controllers/AbstractController.php

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,20 +19,13 @@ abstract class AbstractController extends BaseController
1919
/**
2020
* Add global data to each view
2121
*/
22-
protected function view(string $view, string $title = ''): View
22+
protected function view(string $view, string $title): View
2323
{
2424
session()->put('url.intended', url()->full());
25-
26-
$result = view($view);
27-
28-
if ($title !== '') {
29-
$result = $result->with('title', $title);
30-
}
31-
32-
return $result;
25+
return view($view)->with('title', $title);
3326
}
3427

35-
protected function angular_view(string $view): View
28+
protected function angular_view(string $view, string $title = ''): View
3629
{
3730
// A hack to ensure that redirects work properly after being redirected to the login page
3831
session(['url.intended' => url()->full()]);
@@ -51,7 +44,7 @@ protected function angular_view(string $view): View
5144
$controller_name = Str::studly($file) . 'Controller';
5245
}
5346

54-
return $this->view('cdash')
47+
return $this->view('cdash', $title)
5548
->with('xsl_content', file_get_contents(base_path("public/assets/js/angular/views/$view.html")))
5649
->with('xsl', true)
5750
->with('angular', true)

app/Http/Controllers/AbstractProjectController.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,12 @@ protected function view(string $view, string $title = ''): View
2424
return parent::view($view, $title);
2525
}
2626

27+
if ($title === '') {
28+
$title = $this->project->Name;
29+
} else {
30+
$title = $this->project->Name . ' - ' . $title;
31+
}
32+
2733
return parent::view($view, $title)
2834
->with('project', $this->project);
2935
}

app/Http/Controllers/AdminController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ public function removeBuilds(): View|RedirectResponse
100100
$alert = 'Removed ' . count($builds) . ' builds.';
101101
}
102102

103-
return $this->view('admin.remove-builds')
103+
return $this->view('admin.remove-builds', 'Remove Builds')
104104
->with('alert', $alert)
105105
->with('selected_projectid', $projectid)
106106
->with('available_projects', $available_projects)

app/Http/Controllers/AuthTokenController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ final class AuthTokenController extends AbstractController
1717
{
1818
public function manage(): View
1919
{
20-
return $this->view('admin.manage-authtokens');
20+
return $this->view('admin.manage-authtokens', 'Authentication Tokens');
2121
}
2222

2323
/**

app/Http/Controllers/BuildController.php

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -550,8 +550,7 @@ public function buildOverview(): View|RedirectResponse
550550
];
551551
}
552552

553-
return $this->view('build.overview')
554-
->with('project', $this->project)
553+
return $this->view('build.overview', 'Build Overview')
555554
->with('selected_group', $selected_group)
556555
->with('sourcefiles', $sourcefiles)
557556
->with('startdate', date('l, F d Y H:i:s', $currentstarttime));
@@ -804,7 +803,7 @@ public function files(int $build_id): View
804803
}
805804
}
806805

807-
return $this->view('build.files')
806+
return $this->view('build.files', 'Files')
808807
->with('build', $this->build)
809808
->with('files', $files)
810809
->with('urls', $urls);
@@ -856,7 +855,7 @@ public function ajaxBuildNote(): View
856855
$note->user = $user;
857856
}
858857

859-
return $this->view('build.note')
858+
return $this->view('build.note', 'Notes')
860859
->with('notes', $notes);
861860
}
862861

@@ -1013,16 +1012,19 @@ public function apiViewBuildError(): JsonResponse
10131012

10141013
public function manageBuildGroup(): View
10151014
{
1016-
return $this->angular_view('manageBuildGroup');
1015+
$this->setProjectById(request()->integer('projectid'));
1016+
return $this->angular_view('manageBuildGroup', 'Manage Build Groups');
10171017
}
10181018

10191019
public function viewBuildError(): View
10201020
{
1021-
return $this->angular_view('viewBuildError');
1021+
$this->setBuildById(request()->integer('buildid'));
1022+
return $this->angular_view('viewBuildError', 'Build Errors');
10221023
}
10231024

10241025
public function viewBuildGroup(): View
10251026
{
1027+
$this->setProjectByName(request()->input('project'));
10261028
return $this->angular_view('index');
10271029
}
10281030

@@ -1231,7 +1233,7 @@ public function apiBuildExpected(): JsonResponse
12311233

12321234
public function apiRelateBuilds(): JsonResponse
12331235
{
1234-
$this->setProjectByName(request()->input('project') ?? '');
1236+
$this->setProjectByName(request()->string('project') ?? '');
12351237

12361238
if (!request()->has('buildid')) {
12371239
abort(400, '"buildid" parameter required.');

app/Http/Controllers/BuildPropertiesController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ final class BuildPropertiesController extends AbstractBuildController
1717
{
1818
public function buildProperties(): View
1919
{
20-
return $this->view('build.properties');
20+
return $this->view('build.properties', 'Build Properties');
2121
}
2222

2323
public function apiBuildProperties(): JsonResponse

app/Http/Controllers/CTestConfigurationController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ public function get(int $id): Response
1010
{
1111
$this->setProjectById($id);
1212

13-
$view = $this->view('project.ctest-configuration')
13+
$view = $this->view('project.ctest-configuration', '')
1414
->with('subprojects', $this->project->GetSubProjects());
1515
return response($view, 200, ['Content-Type' => 'text/plain']);
1616
}

app/Http/Controllers/CoverageController.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public function compareCoverage(): View|RedirectResponse
2929
return redirect('projects');
3030
}
3131

32-
return $this->angular_view('compareCoverage');
32+
return $this->angular_view('compareCoverage', 'Compare Coverage');
3333
}
3434

3535
private static function get_cdash_dashboard_xml_by_name(string $projectname, $date): string
@@ -539,7 +539,7 @@ public function viewCoverageFile(): View
539539

540540
$file = implode('<br>', $file_array);
541541

542-
return $this->view('coverage.coverage-file')
542+
return $this->view('coverage.coverage-file', 'Coverage')
543543
->with('coverage_file', $coverageFile)
544544
->with('log', $file);
545545
}

app/Http/Controllers/DynamicAnalysisController.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,12 @@ final class DynamicAnalysisController extends AbstractBuildController
1414
public function viewDynamicAnalysis(int $buildid): View
1515
{
1616
$this->setBuildById($buildid);
17-
return $this->view('dynamicanalysis.dynamic-analysis');
17+
return $this->view('dynamicanalysis.dynamic-analysis', 'Dynamic Analysis');
1818
}
1919

2020
public function viewDynamicAnalysisFile(): View
2121
{
22-
return $this->angular_view('viewDynamicAnalysisFile');
22+
return $this->angular_view('viewDynamicAnalysisFile', 'Dynamic Analysis');
2323
}
2424

2525
public function apiViewDynamicAnalysis(): JsonResponse

app/Http/Controllers/IndexController.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
use Illuminate\Http\RedirectResponse;
66
use Illuminate\View\View;
77

8-
final class IndexController extends AbstractController
8+
final class IndexController extends AbstractProjectController
99
{
1010
public function showIndexPage(): View|RedirectResponse
1111
{
@@ -15,6 +15,8 @@ public function showIndexPage(): View|RedirectResponse
1515
return redirect($url);
1616
}
1717

18+
$this->setProjectByName($_GET['project']);
19+
1820
return $this->angular_view('index');
1921
}
2022
}

0 commit comments

Comments
 (0)