Skip to content

Commit

Permalink
Merge pull request #252 from Krinkle/post-deleteall
Browse files Browse the repository at this point in the history
Use POST for /runs/delete_all and add a confirmation form
  • Loading branch information
markstory committed Jan 5, 2019
2 parents 0f10bfc + ebde052 commit 9b4bb8d
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 6 deletions.
7 changes: 6 additions & 1 deletion src/Xhgui/Controller/Run.php
Expand Up @@ -124,7 +124,12 @@ public function delete()
$this->app->redirect($redirect);
}

public function deleteAll()
public function deleteAllForm()
{
$this->_template = 'runs/delete-all-form.twig';
}

public function deleteAllSubmit()
{
$request = $this->app->request();

Expand Down
9 changes: 7 additions & 2 deletions src/routes.php
Expand Up @@ -35,8 +35,13 @@
})->name('run.delete');

$app->get('/run/delete_all', function () use ($di, $app) {
$di['runController']->deleteAll();
})->name('run.deleteAll');
$app->controller = $di['runController'];
$app->controller->deleteAllForm();
})->name('run.deleteAll.form');

$app->post('/run/delete_all', function () use ($di, $app) {
$di['runController']->deleteAllSubmit();
})->name('run.deleteAll.submit');

$app->get('/url/view', function () use ($di, $app) {
$app->controller = $di['runController'];
Expand Down
18 changes: 18 additions & 0 deletions src/templates/runs/delete-all-form.twig
@@ -0,0 +1,18 @@
{% extends 'layout/base.twig' %}
{% import 'macros/helpers.twig' as helpers %}

{% block title %}
- Delete all runs
{% endblock %}

{% block content %}
<h1>Delete all runs</h1>

<form class="form-stacked" action="{{ url('run.deleteAll.submit') }}" method="post">
<div class="hero-unit">
<p>Are you sure you want to delete all runs?</p>
<input class="btn btn-large btn-danger" type="submit" value="Delete all" />
</div>
</form>

{% endblock %}
2 changes: 1 addition & 1 deletion src/templates/runs/list.twig
Expand Up @@ -10,7 +10,7 @@

{% if runs|length or has_search %}
<div class="searchbar clearfix">
<a href="{{ url('run.deleteAll') }}" class="pull-right btn btn-small delete-all" title="Delete all">
<a href="{{ url('run.deleteAll.form') }}" class="pull-right btn btn-small delete-all" title="Delete all">
<i class="icon-trash"></i> Delete all
</a>

Expand Down
4 changes: 2 additions & 2 deletions tests/Controller/RunTest.php
Expand Up @@ -193,7 +193,7 @@ public function testDelete()
$this->assertCount(4, $result['results']);
}

public function testDeleteAll()
public function testDeleteAllSubmit()
{
loadFixture($this->profiles, XHGUI_ROOT_DIR . '/tests/fixtures/results.json');

Expand All @@ -212,7 +212,7 @@ public function testDeleteAll()
$result = $this->profiles->getAll();
$this->assertCount(5, $result['results']);

$this->runs->deleteAll();
$this->runs->deleteAllSubmit();

$result = $this->profiles->getAll();
$this->assertCount(0, $result['results']);
Expand Down

0 comments on commit 9b4bb8d

Please sign in to comment.