Updated the reports page to use the new API endpoints
This commit is contained in:
parent
1b4fd8dec9
commit
6e67d58a8b
@ -1,15 +1,19 @@
|
|||||||
$ ->
|
$ ->
|
||||||
console.log('ready.')
|
console.log('ready.')
|
||||||
|
|
||||||
$('#report-benchmarks').on('change', ->
|
$('#report-benchmarks').on 'change', ->
|
||||||
url = '/api/benchmark/' + $('#report-benchmarks').val() + '/tests'
|
try
|
||||||
$.get(url, (data) ->
|
benchmarkSearchParams = new URLSearchParams
|
||||||
|
benchmark_id: $('#report-benchmarks').val()
|
||||||
|
benchmarkRes = await fetch("/api/v1/benchmark/tests?#{benchmarkSearchParams}")
|
||||||
|
benchmarkData = await benchmarkRes.json()
|
||||||
|
|
||||||
# clear old contents from the selector
|
# clear old contents from the selector
|
||||||
$('#report-tests').empty()
|
$('#report-tests').empty()
|
||||||
# add new elements to the selector
|
# add new elements to the selector
|
||||||
addOption(test) for test in data
|
addOption(test) for test in benchmarkData
|
||||||
)
|
catch error
|
||||||
)
|
console.error 'An error occurred while fetching benchmark results.', error
|
||||||
|
|
||||||
addOption = (test) ->
|
addOption = (test) ->
|
||||||
$('#report-tests').append(
|
$('#report-tests').append(
|
||||||
|
@ -22,7 +22,8 @@ class ApiController extends Controller {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function getBenchmarkTests(Request $request, Response $response, array $args): Response {
|
public function getBenchmarkTests(Request $request, Response $response, array $args): Response {
|
||||||
$benchmark = Benchmark::where('id', $args['benchmark_id'])->first();
|
$urlParams = $request->getQueryParams();
|
||||||
|
$benchmark = Benchmark::where('id', $urlParams['benchmark_id'])->first();
|
||||||
|
|
||||||
$payload = json_encode($benchmark->tests);
|
$payload = json_encode($benchmark->tests);
|
||||||
|
|
||||||
|
@ -1,37 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace BitGoblin\Colossus\Controllers;
|
|
||||||
|
|
||||||
use Psr\Http\Message\ResponseInterface as Response;
|
|
||||||
use Psr\Http\Message\ServerRequestInterface as Request;
|
|
||||||
use Slim\Routing\RouteContext;
|
|
||||||
use Slim\Views\Twig;
|
|
||||||
use BitGoblin\Colossus\Models\Result;
|
|
||||||
use BitGoblin\Colossus\Models\Test;
|
|
||||||
|
|
||||||
class ResultController extends Controller {
|
|
||||||
|
|
||||||
public function postAdd(Request $request, Response $response): Response {
|
|
||||||
$params = (array)$request->getParsedBody();
|
|
||||||
|
|
||||||
$result = new Result;
|
|
||||||
$result->test_id = $params['result_test'];
|
|
||||||
$result->component_id = $params['result_component'];
|
|
||||||
$result->benchmark_id = $params['result_benchmark'];
|
|
||||||
$result->average = $params['result_avg'];
|
|
||||||
$result->minimum = $params['result_min'] ?? null;
|
|
||||||
$result->maximum = $params['result_max'] ?? null;
|
|
||||||
|
|
||||||
$result->save();
|
|
||||||
|
|
||||||
// redirect the user back to the home page
|
|
||||||
$routeContext = RouteContext::fromRequest($request);
|
|
||||||
$routeParser = $routeContext->getRouteParser();
|
|
||||||
return $response
|
|
||||||
->withHeader('Location', $routeParser->urlFor('test.view', [
|
|
||||||
'test_id' => $result->test_id
|
|
||||||
]))
|
|
||||||
->withStatus(302);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -27,10 +27,6 @@ $app->group('/test', function(RouteCollectorProxy $group) {
|
|||||||
$group->get('/{test_id}', '\\BitGoblin\\Colossus\\Controllers\\TestController:getView')->setName('test.view');
|
$group->get('/{test_id}', '\\BitGoblin\\Colossus\\Controllers\\TestController:getView')->setName('test.view');
|
||||||
});
|
});
|
||||||
|
|
||||||
$app->group('/result', function(RouteCollectorProxy $group) {
|
|
||||||
$group->post('/add', '\\BitGoblin\\Colossus\\Controllers\\ResultController:postAdd')->setName('result.add');
|
|
||||||
});
|
|
||||||
|
|
||||||
$app->group('/reports', function(RouteCollectorProxy $group) {
|
$app->group('/reports', function(RouteCollectorProxy $group) {
|
||||||
$group->get('/generate', '\\BitGoblin\\Colossus\Controllers\ReportController:getGenerate')->setName('reports.generate');
|
$group->get('/generate', '\\BitGoblin\\Colossus\Controllers\ReportController:getGenerate')->setName('reports.generate');
|
||||||
});
|
});
|
||||||
|
@ -14,7 +14,7 @@
|
|||||||
|
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="twelve columns">
|
<div class="twelve columns">
|
||||||
<form id="result-form" class="u-full-width" action="{{ url_for('result.add') }}" method="POST">
|
<form id="result-form" class="u-full-width" action="{{ url_for('api.resultAdd') }}" method="POST">
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="four columns">
|
<div class="four columns">
|
||||||
<select class="u-full-width" name="result_benchmark">
|
<select class="u-full-width" name="result_benchmark">
|
||||||
|
Loading…
x
Reference in New Issue
Block a user