Skip to content

Commit

Permalink
Move showcoveragegraph.php AJAX endpoint to controller (#1521)
Browse files Browse the repository at this point in the history
This PR is part of an ongoing series of refactor PRs with the goal of
migrating all of the `/ajax/*` routes to Laravel's routing/controller
scheme.
  • Loading branch information
williamjallen committed Jun 28, 2023
1 parent ae056e2 commit 8e39fe0
Show file tree
Hide file tree
Showing 5 changed files with 90 additions and 134 deletions.
33 changes: 33 additions & 0 deletions app/Http/Controllers/CoverageController.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
use Illuminate\Http\JsonResponse;
use Illuminate\Http\RedirectResponse;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Gate;
use Illuminate\View\View;

Expand Down Expand Up @@ -1703,4 +1704,36 @@ private function sort_priority($a, $b): int
}
return $a['priority'] > $b['priority'] ? 1 : -1;
}

public function ajaxShowCoverageGraph(): View
{
$buildid = $_GET['buildid'];
if (!isset($buildid) || !is_numeric($buildid)) {
abort(400, 'Not a valid buildid!');
}
$this->setBuildById((int) $buildid);

$buildtype = $this->build->Type;
$buildname = $this->build->Name;
$siteid = $this->build->SiteId;
$starttime = $this->build->StartTime;
$projectid = $this->build->ProjectId;

// Find the other builds
$previousbuilds = DB::select('
SELECT id, starttime, endtime, loctested, locuntested
FROM build, coveragesummary as cs
WHERE
cs.buildid=build.id
AND siteid=?
AND type=?
AND name=?
AND projectid=?
AND starttime<=?
ORDER BY starttime ASC
', [$siteid, $buildtype, $buildname, $projectid, $starttime]);

return view('coverage.ajax-coverage-graph')
->with('previousbuilds', $previousbuilds);
}
}
118 changes: 0 additions & 118 deletions app/cdash/public/ajax/showcoveragegraph.php

This file was deleted.

16 changes: 0 additions & 16 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -15336,22 +15336,6 @@ parameters:
count: 1
path: app/cdash/include/upgrade_functions.php

-
message: """
#^Call to deprecated method executePrepared\\(\\) of class CDash\\\\Database\\:
04/22/2023 Use Laravel query builder or Eloquent instead$#
"""
count: 1
path: app/cdash/public/ajax/showcoveragegraph.php

-
message: """
#^Call to deprecated method executePreparedSingleRow\\(\\) of class CDash\\\\Database\\:
04/22/2023 Use Laravel query builder or Eloquent instead$#
"""
count: 1
path: app/cdash/public/ajax/showcoveragegraph.php

-
message: """
#^Call to deprecated function add_log\\(\\)\\:
Expand Down
55 changes: 55 additions & 0 deletions resources/views/coverage/ajax-coverage-graph.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<script type="text/javascript">
$(function () {
const percent_array = [];
const loctested_array = [];
const locuntested_array = [];
const buildids = [];
@php($i = 0)
@foreach($previousbuilds as $build_array)
@php($t = strtotime($build_array->starttime) * 1000) {{-- flot expects milliseconds --}}
@php(@$percent = round(intval($build_array->loctested) / (intval($build_array->loctested) + intval($build_array->locuntested)) * 100, 2))
percent_array.push([{{ $t }}, {{ $percent }}]);
loctested_array.push([{{ $t }}, {{ $build_array->loctested }}]);
locuntested_array.push([{{ $t }}, {{ $build_array->locuntested }}]);
buildids[{{ $t }}] = {{ $build_array->id }};
@php($i++)
@endforeach
const options = {
lines: {show: true},
points: {show: true},
xaxis: {mode: "time"},
yaxis: {min: 0, max: 100},
legend: {position: "nw"},
grid: {
backgroundColor: "#fffaff",
clickable: true,
hoverable: true,
hoverFill: '#444',
hoverRadius: 4
},
selection: {mode: "x"},
colors: ["#0000FF", "#dba255", "#919733"]
};
$("#grapholder").bind("selected", function (event, area) {
plot = $.plot($("#grapholder"),
[{label: "% coverage", data: percent_array},
{label: "loc tested", data: loctested_array, yaxis: 2},
{label: "loc untested", data: locuntested_array, yaxis: 2}],
$.extend(true, {}, options, {xaxis: {min: area.x1, max: area.x2}}));
});
$("#grapholder").bind("plotclick", function (e, pos, item) {
if (item) {
plot.highlight(item.series, item.datapoint);
buildid = buildids[item.datapoint[0]];
window.location = "build/" + buildid;
}
});
plot = $.plot($("#grapholder"), [{label: "% coverage", data: percent_array},
{label: "loc tested", data: loctested_array, yaxis: 2},
{label: "loc untested", data: locuntested_array, yaxis: 2}], options);
});
</script>
2 changes: 2 additions & 0 deletions routes/web.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,8 @@

Route::any('/ajax/getviewcoverage.php', 'CoverageController@ajaxGetViewCoverage');

Route::any('/ajax/showcoveragegraph.php', 'CoverageController@ajaxShowCoverageGraph');

Route::get('/buildOverview.php', 'BuildController@buildOverview');

Route::get('/buildProperties.php', 'BuildController@buildProperties');
Expand Down

0 comments on commit 8e39fe0

Please sign in to comment.