Merge Monitoring_ListController::hasBetterUrl() into Icinga\Web\Controller::init()

refs #9220
This commit is contained in:
Alexander A. Klimov 2015-05-11 13:36:58 +02:00
parent cf8376f478
commit 152c6a8f7f
2 changed files with 22 additions and 65 deletions

View File

@ -15,6 +15,27 @@ use Icinga\Web\Widget\Limiter;
*/ */
class Controller extends ModuleActionController class Controller extends ModuleActionController
{ {
/**
* @see ActionController::init
*/
public function init()
{
parent::init();
$request = $this->getRequest();
$url = Url::fromRequest();
if ($request->isPost() && ($sort = $request->getPost('sort'))) {
$url->setParam('sort', $sort);
if ($dir = $request->getPost('dir')) {
$url->setParam('dir', $dir);
} else {
$url->removeParam('dir');
}
$this->redirectNow($url);
}
}
/** /**
* Create a SortBox widget at the `sortBox' view property * Create a SortBox widget at the `sortBox' view property
* *

View File

@ -20,6 +20,7 @@ class Monitoring_ListController extends Controller
*/ */
public function init() public function init()
{ {
parent::init();
$this->createTabs(); $this->createTabs();
} }
@ -41,25 +42,6 @@ class Monitoring_ListController extends Controller
return $query; return $query;
} }
protected function hasBetterUrl()
{
$request = $this->getRequest();
$url = Url::fromRequest();
if ($this->getRequest()->isPost()) {
if ($request->getPost('sort')) {
$url->setParam('sort', $request->getPost('sort'));
if ($request->getPost('dir')) {
$url->setParam('dir', $request->getPost('dir'));
} else {
$url->removeParam('dir');
}
return $url;
}
}
return false;
}
/** /**
* Overwrite the backend to use (used for testing) * Overwrite the backend to use (used for testing)
* *
@ -75,10 +57,6 @@ class Monitoring_ListController extends Controller
*/ */
public function hostsAction() public function hostsAction()
{ {
if ($url = $this->hasBetterUrl()) {
return $this->redirectNow($url);
}
// Handle soft and hard states // Handle soft and hard states
if (strtolower($this->params->shift('stateType', 'soft')) === 'hard') { if (strtolower($this->params->shift('stateType', 'soft')) === 'hard') {
$stateColumn = 'host_hard_state'; $stateColumn = 'host_hard_state';
@ -149,10 +127,6 @@ class Monitoring_ListController extends Controller
*/ */
public function servicesAction() public function servicesAction()
{ {
if ($url = $this->hasBetterUrl()) {
return $this->redirectNow($url);
}
// Handle soft and hard states // Handle soft and hard states
if (strtolower($this->params->shift('stateType', 'soft')) === 'hard') { if (strtolower($this->params->shift('stateType', 'soft')) === 'hard') {
$stateColumn = 'service_hard_state'; $stateColumn = 'service_hard_state';
@ -247,10 +221,6 @@ class Monitoring_ListController extends Controller
*/ */
public function downtimesAction() public function downtimesAction()
{ {
if ($url = $this->hasBetterUrl()) {
return $this->redirectNow($url);
}
$this->addTitleTab('downtimes', $this->translate('Downtimes'), $this->translate('List downtimes')); $this->addTitleTab('downtimes', $this->translate('Downtimes'), $this->translate('List downtimes'));
$this->setAutorefreshInterval(12); $this->setAutorefreshInterval(12);
@ -304,10 +274,6 @@ class Monitoring_ListController extends Controller
*/ */
public function notificationsAction() public function notificationsAction()
{ {
if ($url = $this->hasBetterUrl()) {
return $this->redirectNow($url);
}
$this->addTitleTab( $this->addTitleTab(
'notifications', 'notifications',
$this->translate('Notifications'), $this->translate('Notifications'),
@ -337,10 +303,6 @@ class Monitoring_ListController extends Controller
public function contactsAction() public function contactsAction()
{ {
if ($url = $this->hasBetterUrl()) {
return $this->redirectNow($url);
}
$this->addTitleTab('contacts', $this->translate('Contacts'), $this->translate('List contacts')); $this->addTitleTab('contacts', $this->translate('Contacts'), $this->translate('List contacts'));
$query = $this->backend->select()->from('contact', array( $query = $this->backend->select()->from('contact', array(
@ -380,9 +342,6 @@ class Monitoring_ListController extends Controller
public function eventgridAction() public function eventgridAction()
{ {
if ($url = $this->hasBetterUrl()) {
return $this->redirectNow($url);
}
$this->addTitleTab('eventgrid', $this->translate('Event Grid'), $this->translate('Show the Event Grid')); $this->addTitleTab('eventgrid', $this->translate('Event Grid'), $this->translate('Show the Event Grid'));
$form = new StatehistoryForm(); $form = new StatehistoryForm();
@ -422,10 +381,6 @@ class Monitoring_ListController extends Controller
public function contactgroupsAction() public function contactgroupsAction()
{ {
if ($url = $this->hasBetterUrl()) {
return $this->redirectNow($url);
}
$this->addTitleTab( $this->addTitleTab(
'contactgroups', 'contactgroups',
$this->translate('Contact Groups'), $this->translate('Contact Groups'),
@ -465,10 +420,6 @@ class Monitoring_ListController extends Controller
public function commentsAction() public function commentsAction()
{ {
if ($url = $this->hasBetterUrl()) {
return $this->redirectNow($url);
}
$this->addTitleTab('comments', $this->translate('Comments'), $this->translate('List comments')); $this->addTitleTab('comments', $this->translate('Comments'), $this->translate('List comments'));
$this->setAutorefreshInterval(12); $this->setAutorefreshInterval(12);
@ -509,10 +460,6 @@ class Monitoring_ListController extends Controller
public function servicegroupsAction() public function servicegroupsAction()
{ {
if ($url = $this->hasBetterUrl()) {
return $this->redirectNow($url);
}
$this->addTitleTab( $this->addTitleTab(
'servicegroups', 'servicegroups',
$this->translate('Service Groups'), $this->translate('Service Groups'),
@ -568,10 +515,6 @@ class Monitoring_ListController extends Controller
public function hostgroupsAction() public function hostgroupsAction()
{ {
if ($url = $this->hasBetterUrl()) {
return $this->redirectNow($url);
}
$this->addTitleTab('hostgroups', $this->translate('Host Groups'), $this->translate('List host groups')); $this->addTitleTab('hostgroups', $this->translate('Host Groups'), $this->translate('List host groups'));
$this->setAutorefreshInterval(12); $this->setAutorefreshInterval(12);
@ -623,10 +566,6 @@ class Monitoring_ListController extends Controller
public function eventhistoryAction() public function eventhistoryAction()
{ {
if ($url = $this->hasBetterUrl()) {
return $this->redirectNow($url);
}
$this->addTitleTab( $this->addTitleTab(
'eventhistory', 'eventhistory',
$this->translate('Event Overview'), $this->translate('Event Overview'),
@ -659,9 +598,6 @@ class Monitoring_ListController extends Controller
public function servicegridAction() public function servicegridAction()
{ {
if ($url = $this->hasBetterUrl()) {
return $this->redirectNow($url);
}
$this->addTitleTab('servicegrid', $this->translate('Service Grid'), $this->translate('Show the Service Grid')); $this->addTitleTab('servicegrid', $this->translate('Service Grid'), $this->translate('Show the Service Grid'));
$this->setAutorefreshInterval(15); $this->setAutorefreshInterval(15);
$query = $this->backend->select()->from('serviceStatus', array( $query = $this->backend->select()->from('serviceStatus', array(