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

Use POST for /runs/delete_all and add a confirmation form #252

Merged
merged 1 commit into from
Jan 5, 2019
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
7 changes: 6 additions & 1 deletion src/Xhgui/Controller/Run.php
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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