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

Move angular_view function to AbstractController #2443

Merged
merged 1 commit into from
Sep 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions app/Http/Controllers/AbstractController.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Illuminate\Routing\Controller as BaseController;
use Illuminate\Foundation\Validation\ValidatesRequests;
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
use Illuminate\Support\Str;
use Illuminate\View\View;

abstract class AbstractController extends BaseController
Expand All @@ -29,6 +30,32 @@ protected function view(string $view, string $title = ''): View
return $result;
}

protected function angular_view(string $view): View
{
// A hack to ensure that redirects work properly after being redirected to the login page
session(['url.intended' => url()->full()]);

$controller_name = '';
$path = request()->path() === '/' ? 'index.php' : request()->path();
$file = pathinfo(substr($path, strrpos($path, '/')), PATHINFO_FILENAME);

// Special case: viewBuildGroup.php shares a controller with index.php.
if ($file === 'viewBuildGroup') {
$file = 'index';
}
$controller_path = config('cdash.file.path.js.controllers');
$controller = "{$controller_path}/{$file}.js";
if (is_readable($controller)) {
$controller_name = Str::studly($file) . 'Controller';
}

return $this->view('cdash')
->with('xsl_content', file_get_contents(base_path("public/build/views/$view.html")))
->with('xsl', true)
->with('angular', true)
->with('angular_controller', $controller_name);
}

public static function getCDashVersion(): string
{
return file_get_contents(public_path('VERSION'));
Expand Down
4 changes: 2 additions & 2 deletions app/Http/Controllers/AdminController.php
Original file line number Diff line number Diff line change
Expand Up @@ -502,9 +502,9 @@ public function upgrade()
->with('xsl_content', generate_XSLT($xml, base_path() . '/app/cdash/public/upgrade', true));
}

public function userStatistics(): \Illuminate\Http\Response
public function userStatistics(): View
{
return response()->angular_view('userStatistics');
return $this->angular_view('userStatistics');
}

/** Delete unused rows */
Expand Down
12 changes: 6 additions & 6 deletions app/Http/Controllers/BuildController.php
Original file line number Diff line number Diff line change
Expand Up @@ -1006,19 +1006,19 @@ public function apiViewBuildError(): JsonResponse
return response()->json(cast_data_for_JSON($response));
}

public function manageBuildGroup(): Response
public function manageBuildGroup(): View
{
return response()->angular_view('manageBuildGroup');
return $this->angular_view('manageBuildGroup');
}

public function viewBuildError(): Response
public function viewBuildError(): View
{
return response()->angular_view('viewBuildError');
return $this->angular_view('viewBuildError');
}

public function viewBuildGroup(): Response
public function viewBuildGroup(): View
{
return response()->angular_view('index');
return $this->angular_view('index');
}

/**
Expand Down
4 changes: 2 additions & 2 deletions app/Http/Controllers/CoverageController.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,14 @@

final class CoverageController extends AbstractBuildController
{
public function compareCoverage(): Response|RedirectResponse
public function compareCoverage(): View|RedirectResponse
{
// If the project name is not set we display the table of projects.
if (!isset($_GET['project'])) {
return redirect('projects');
}

return response()->angular_view('compareCoverage');
return $this->angular_view('compareCoverage');
}

/**
Expand Down
5 changes: 2 additions & 3 deletions app/Http/Controllers/DynamicAnalysisController.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
use App\Utils\TestingDay;
use CDash\Model\DynamicAnalysis;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Response;
use Illuminate\Support\Facades\DB;
use Illuminate\View\View;

Expand All @@ -17,9 +16,9 @@ public function viewDynamicAnalysis(int $buildid): View
return $this->view('dynamicanalysis.dynamic-analysis');
}

public function viewDynamicAnalysisFile(): Response
public function viewDynamicAnalysisFile(): View
{
return response()->angular_view('viewDynamicAnalysisFile');
return $this->angular_view('viewDynamicAnalysisFile');
}

public function apiViewDynamicAnalysis(): JsonResponse
Expand Down
6 changes: 3 additions & 3 deletions app/Http/Controllers/IndexController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,18 @@
namespace App\Http\Controllers;

use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Response;
use Illuminate\View\View;

final class IndexController extends AbstractController
{
public function showIndexPage(): Response|RedirectResponse
public function showIndexPage(): View|RedirectResponse
{
if (!isset($_GET['project'])) {
$default_project = config('cdash.default_project');
$url = $default_project ? "index.php?project={$default_project}" : 'projects';
return redirect($url);
}

return response()->angular_view('index');
return $this->angular_view('index');
}
}
9 changes: 5 additions & 4 deletions app/Http/Controllers/ProjectOverviewController.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,13 @@
use Illuminate\Support\Facades\Gate;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\Facades\Request;
use Illuminate\View\View;

final class ProjectOverviewController extends AbstractProjectController
{
public function overview(): Response
public function overview(): View
{
return response()->angular_view('overview');
return $this->angular_view('overview');
}

public function apiOverview(): JsonResponse
Expand Down Expand Up @@ -750,9 +751,9 @@ private static function get_DA_chart_data($group_name, $checker, $date_range, $d
return json_encode($chart_data);
}

public function manageOverview(): Response
public function manageOverview(): View
{
return response()->angular_view('manageOverview');
return $this->angular_view('manageOverview');
}

public function apiManageOverview(): JsonResponse
Expand Down
9 changes: 4 additions & 5 deletions app/Http/Controllers/SubProjectController.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
use CDash\Model\SubProject;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
use Illuminate\Http\Response;
use Illuminate\Support\Carbon;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\DB;
Expand All @@ -17,14 +16,14 @@

final class SubProjectController extends AbstractProjectController
{
public function viewSubProjects(): Response
public function viewSubProjects(): View
{
return response()->angular_view('viewSubProjects');
return $this->angular_view('viewSubProjects');
}

public function manageSubProject(): Response
public function manageSubProject(): View
{
return response()->angular_view('manageSubProject');
return $this->angular_view('manageSubProject');
}


Expand Down
12 changes: 6 additions & 6 deletions app/Http/Controllers/TestController.php
Original file line number Diff line number Diff line change
Expand Up @@ -124,9 +124,9 @@ public function ajaxTestFailureGraph(): View
->with('tarray', $tarray);
}

public function queryTests(): Response
public function queryTests(): View
{
return response()->angular_view('queryTests');
return $this->angular_view('queryTests');
}

public function apiQueryTests(): JsonResponse
Expand All @@ -141,9 +141,9 @@ public function apiQueryTests(): JsonResponse
return response()->json(cast_data_for_JSON($controller->getResponse()));
}

public function testOverview(): Response
public function testOverview(): View
{
return response()->angular_view('testOverview');
return $this->angular_view('testOverview');
}

public function apiTestOverview(): JsonResponse
Expand All @@ -159,9 +159,9 @@ public function apiTestOverview(): JsonResponse
return response()->json(cast_data_for_JSON($controller->getResponse()));
}

public function testSummary(): Response
public function testSummary(): View
{
return response()->angular_view('testSummary');
return $this->angular_view('testSummary');
}

public function apiTestSummary(): JsonResponse|StreamedResponse
Expand Down
29 changes: 0 additions & 29 deletions app/Providers/AppServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,10 @@

use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\Config;
use Illuminate\Support\Facades\Response;
use Illuminate\Support\Facades\Schema;
use Illuminate\Support\Facades\URL;
use Illuminate\Support\Facades\Validator;
use Illuminate\Support\ServiceProvider;
use Illuminate\Support\Str;

require_once 'include/common.php';
require_once 'include/pdo.php';
Expand All @@ -43,33 +41,6 @@ public function boot()
URL::forceScheme('https');
}

// This allows us to do response()->angular_view(<view_name>).
Response::macro('angular_view', function (string $view_name) {
// A hack to ensure that redirects work properly after being redirected to the login page
session(['url.intended' => url()->full()]);

$controller_name = '';
$path = request()->path() === '/' ? 'index.php' : request()->path();
$file = pathinfo(substr($path, strrpos($path, '/')), PATHINFO_FILENAME);

// Special case: viewBuildGroup.php shares a controller with index.php.
if ($file === 'viewBuildGroup') {
$file = 'index';
}
$controller_path = config('cdash.file.path.js.controllers');
$controller = "{$controller_path}/{$file}.js";
if (is_readable($controller)) {
$controller_name = Str::studly($file) . 'Controller';
}

return response()->view('cdash', [
'xsl_content' => file_get_contents(base_path("public/build/views/$view_name.html")),
'xsl' => true,
'angular' => true,
'angular_controller' => $controller_name,
]);
});

URL::forceRootUrl(Config::get('app.url'));

Model::preventSilentlyDiscardingAttributes(!$this->app->isProduction());
Expand Down
Loading