Skip to content

Commit

Permalink
Merge pull request #239 from dumityty/delete-all-runs
Browse files Browse the repository at this point in the history
Add link to delete all  run from the main paginated list page
  • Loading branch information
markstory authored May 29, 2018
2 parents bfefcf8 + 223b15c commit b9abf78
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/Xhgui/Controller/Run.php
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,21 @@ public function delete()
$this->app->redirect($redirect);
}

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

// Delete all profile runs.
$delete = $this->profiles->truncate();

$this->app->flash('success', 'Deleted all profiles');

$referrer = $request->getReferrer();
// In case route is accessed directly the referrer is not set.
$redirect = isset($referrer) ? $referrer : $this->app->urlFor('home');
$this->app->redirect($redirect);
}

public function url()
{
$request = $this->app->request();
Expand Down
4 changes: 4 additions & 0 deletions src/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@
$di['runController']->delete();
})->name('run.delete');

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

$app->get('/url/view', function () use ($di, $app) {
$app->controller = $di['runController'];
$app->controller->url();
Expand Down
4 changes: 4 additions & 0 deletions src/templates/runs/list.twig
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@

{% 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">
<i class="icon-trash"></i> Delete all
</a>

<a href="#" class="pull-right btn btn-small search-expand" title="Show search form">
<i class="icon-search"></i> Search
</a>
Expand Down
25 changes: 25 additions & 0 deletions tests/Controller/RunTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -192,4 +192,29 @@ public function testDelete()
$result = $this->profiles->getAll();
$this->assertCount(4, $result['results']);
}

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

Environment::mock(array(
'SCRIPT_NAME' => 'index.php',
'PATH_INFO' => '/run/delete_all',
));

$this->app->expects($this->once())
->method('urlFor')
->with('home');

$this->app->expects($this->once())
->method('redirect');

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

$this->runs->deleteAll();

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

0 comments on commit b9abf78

Please sign in to comment.