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 showcoveragegraph.php AJAX endpoint to controller #1521

Merged
merged 1 commit into from
Jun 28, 2023
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
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 @@ -15346,22 +15346,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