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

Add client-side GraphQL handling #2219

Merged
merged 12 commits into from
Jun 3, 2024
Merged
13 changes: 12 additions & 1 deletion app/Http/Controllers/ViewProjectsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,16 @@
final class ViewProjectsController extends AbstractController
{
public function viewAllProjects(): View|RedirectResponse
{
return $this->viewProjects(true);
}

public function viewActiveProjects(): View|RedirectResponse
{
return $this->viewProjects();
}

private function viewProjects(bool $all = false): View|RedirectResponse
{
$num_public_projects = (int) DB::select('
SELECT COUNT(*) AS c FROM project WHERE public=?
Expand All @@ -22,7 +32,8 @@ public function viewAllProjects(): View|RedirectResponse
return $this->redirectToLogin();
}

return $this->view("project.view-all-projects");
return $this->view("project.view-all-projects")
->with('show_all', $all);
}

public function fetchPageContent(): JsonResponse
Expand Down
16 changes: 16 additions & 0 deletions app/Models/Project.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Database\Eloquent\Relations\HasOne;
use Illuminate\Support\Carbon;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
use Illuminate\Support\Facades\Auth;
Expand Down Expand Up @@ -216,6 +217,21 @@ public function builds(): HasMany
});
}

/**
* TODO: Share code with builds(). As of Laravel 10, aggregates added to hasMany relations
* with conditional clauses are unsupported/broken. A reusable scope may be a better approach.
*
* @return HasOne<Build>
*/
public function mostRecentBuild(): HasOne
{
return $this->hasOne(Build::class, 'projectid', 'id')
->ofMany(['submittime' => 'max'], function (Builder $query) {
$query->where('parentid', 0)
->orWhere('parentid', -1);
});
}

/**
* @return HasMany<BlockedBuild>
*/
Expand Down
5 changes: 3 additions & 2 deletions app/cdash/app/Controller/Api/ViewProjects.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@
use Illuminate\Support\Facades\DB;

/**
* TODO: (williamjallen) move all of this logic over to app/Http/Controllers/ViewProjectsController.php
*
* API controller for viewProjects.php.
*
* @deprecated 05/23/2024 This endpoint is deprecated in favor of the GraphQL API and will eventually be removed.
**/
class ViewProjects extends \CDash\Controller\Api
{
Expand All @@ -46,6 +46,7 @@ public function __construct(Database $db)
public function getResponse()
{
$response = begin_JSON_response();
$response['deprecated'] = 'This endpoint is deprecated and will eventually be removed.';

$global_banner = Banner::find(0);
if ($global_banner !== null && strlen($global_banner->text) > 0) {
Expand Down
6 changes: 6 additions & 0 deletions graphql/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,12 @@ type Project {
filters: _ @filter(inputType: "BuildFilterInput")
): [Build!]! @hasMany(type: CONNECTION) @orderBy(column: "id")

"""
The most recent build submitted to this server. Note: this is determined by
submission time, not build start time.
"""
mostRecentBuild: Build @hasOne

"The sites which have submitted a build to this project."
sites(
filters: _ @filter(inputType: "SiteFilterInput")
Expand Down
Loading