Added ability to edit benchmarks
This commit is contained in:
parent
23cfbc2efa
commit
4f0cb54190
@ -60,4 +60,32 @@ class BenchmarkController extends Controller {
|
||||
->withStatus(302);
|
||||
}
|
||||
|
||||
public function getEdit(Request $request, Response $response, array $args): Response {
|
||||
$benchmark = Benchmark::where('id', $args['benchmark_id'])->first();
|
||||
|
||||
$view = Twig::fromRequest($request);
|
||||
return $view->render($response, 'benchmark/edit.twig', [
|
||||
'benchmark' => $benchmark,
|
||||
]);
|
||||
}
|
||||
|
||||
public function postEdit(Request $request, Response $response, array $args): Response {
|
||||
$benchmark = Benchmark::where('id', $args['benchmark_id'])->first();
|
||||
|
||||
$params = (array)$request->getParsedBody();
|
||||
|
||||
$benchmark->name = $params['benchmark_name'];
|
||||
$benchmark->description = $params['benchmark_description'];
|
||||
$benchmark->scoring = $params['benchmark_scoring'];
|
||||
|
||||
$benchmark->save();
|
||||
|
||||
// redirect the user back to the home page
|
||||
$routeContext = RouteContext::fromRequest($request);
|
||||
$routeParser = $routeContext->getRouteParser();
|
||||
return $response
|
||||
->withHeader('Location', $routeParser->urlFor('benchmark.view', ['benchmark_id' => $benchmark->id]))
|
||||
->withStatus(302);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -9,7 +9,13 @@ $app->group('/benchmark', function(RouteCollectorProxy $group) {
|
||||
$group->get('/list', '\\BitGoblin\\Colossus\\Controllers\\BenchmarkController:getList')->setName('benchmark.list');
|
||||
$group->get('/add', '\\BitGoblin\\Colossus\\Controllers\\BenchmarkController:getAdd')->setName('benchmark.add');
|
||||
$group->post('/add', '\\BitGoblin\\Colossus\\Controllers\\BenchmarkController:postAdd');
|
||||
$group->get('/{benchmark_id}', '\\BitGoblin\\Colossus\\Controllers\\BenchmarkController:getView')->setName('benchmark.view');
|
||||
|
||||
$group->group('/{benchmark_id}', function(RouteCollectorProxy $benchmark) {
|
||||
$benchmark->get('', '\\BitGoblin\\Colossus\\Controllers\\BenchmarkController:getView')->setName('benchmark.view');
|
||||
|
||||
$benchmark->get('/edit', '\\BitGoblin\\Colossus\\Controllers\\BenchmarkController:getEdit')->setName('benchmark.edit');
|
||||
$benchmark->post('/edit', '\\BitGoblin\\Colossus\\Controllers\\BenchmarkController:postEdit');
|
||||
});
|
||||
});
|
||||
|
||||
$app->group('/component', function(RouteCollectorProxy $group) {
|
||||
|
46
views/benchmark/edit.twig
Normal file
46
views/benchmark/edit.twig
Normal file
@ -0,0 +1,46 @@
|
||||
{% extends 'layout.twig' %}
|
||||
|
||||
{% block title %}Editing Benchmark: {{ benchmark.name }}{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
|
||||
<div class="row">
|
||||
<div class="twelve columns">
|
||||
<h1>Editing Benchmark: {{ benchmark.name }}</h1>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="row">
|
||||
<div class="twelve columns">
|
||||
<form action="{{ url_for('benchmark.edit', { benchmark_id: benchmark.id }) }}" method="POST" class="u-full-width">
|
||||
<div class="row">
|
||||
<div class="nine columns">
|
||||
<label for="benchmark_name">Benchmark name:</label>
|
||||
<input type="text" id="benchmark_name" class="u-full-width" name="benchmark_name" value="{{ benchmark.name }}">
|
||||
</div>
|
||||
|
||||
<div class="three columns">
|
||||
<label>
|
||||
Scoring type
|
||||
<select class="u-full-width" name="benchmark_scoring">
|
||||
<option value="fps" {% if benchmark.scoring == 'fps' %}selected{% endif %}>Frames per Second (fps)</option>
|
||||
<option value="ms" {% if benchmark.scoring == 'ms' %}selected{% endif %}>Frame Time (ms)</option>
|
||||
<option value="pts" {% if benchmark.scoring == 'pts' %}selected{% endif %}>Total Points</option>
|
||||
</select>
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="row">
|
||||
<div class="twelve columns">
|
||||
<label for="benchmark_description">Description</label>
|
||||
<textarea class="u-full-width" name="benchmark_description" id="benchmark_description" rows="5" placeholder="Describe this benchmark...">{{ benchmark.description }}</textarea>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<input class="button button-primary u-full-width" type="submit" value="Submit">
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{% endblock %}
|
@ -6,6 +6,7 @@
|
||||
<div class="row">
|
||||
<div class="twelve columns">
|
||||
<h1>{{ benchmark.name }}</h1>
|
||||
<p><a href="{{ url_for('benchmark.edit', { benchmark_id: benchmark.id }) }}">Edit</a></p>
|
||||
<p>{{ benchmark.description }}</p>
|
||||
</div>
|
||||
</div>
|
||||
|
Loading…
x
Reference in New Issue
Block a user