Skip to content

Commit

Permalink
ListController: set up sort control before paginating a query
Browse files Browse the repository at this point in the history
  • Loading branch information
Al2Klimov committed May 13, 2015
1 parent 9e3d65e commit ca79b02
Showing 1 changed file with 42 additions and 42 deletions.
84 changes: 42 additions & 42 deletions modules/monitoring/application/controllers/ListController.php
Expand Up @@ -97,6 +97,13 @@ public function hostsAction()
), $this->extraColumns()));
$this->filterQuery($query);
$this->applyRestriction('monitoring/hosts/filter', $query);
$this->setupSortControl(array(
'host_severity' => $this->translate('Severity'),
'host_state' => $this->translate('Current State'),
'host_display_name' => $this->translate('Hostname'),
'host_address' => $this->translate('Address'),
'host_last_check' => $this->translate('Last Check')
), $query);
$this->view->hosts = $query->paginate();

$this->view->stats = $this->backend->select()->from('statusSummary', array(
Expand All @@ -113,13 +120,6 @@ public function hostsAction()

$this->setupLimitControl();
$this->setupPaginationControl($this->view->hosts);
$this->setupSortControl(array(
'host_severity' => $this->translate('Severity'),
'host_state' => $this->translate('Current State'),
'host_display_name' => $this->translate('Hostname'),
'host_address' => $this->translate('Address'),
'host_last_check' => $this->translate('Last Check')
), $query);
}

/**
Expand Down Expand Up @@ -181,10 +181,6 @@ public function servicesAction()
$query = $this->backend->select()->from('serviceStatus', $columns);
$this->filterQuery($query);
$this->applyRestriction('monitoring/services/filter', $query);
$this->view->services = $query->paginate();

$this->setupLimitControl();
$this->setupPaginationControl($this->view->services);
$this->setupSortControl(array(
'service_severity' => $this->translate('Service Severity'),
'service_state' => $this->translate('Current Service State'),
Expand All @@ -196,6 +192,10 @@ public function servicesAction()
'host_address' => $this->translate('Host Address'),
'host_last_check' => $this->translate('Last Host Check')
), $query);
$this->view->services = $query->paginate();

$this->setupLimitControl();
$this->setupPaginationControl($this->view->services);

$this->view->stats = $this->backend->select()->from('statusSummary', array(
'services_total',
Expand Down Expand Up @@ -246,10 +246,6 @@ public function downtimesAction()
'service_display_name'
));
$this->filterQuery($query);
$this->view->downtimes = $query->paginate();

$this->setupLimitControl();
$this->setupPaginationControl($this->view->downtimes);
$this->setupSortControl(array(
'downtime_is_in_effect' => $this->translate('Is In Effect'),
'host_display_name' => $this->translate('Host'),
Expand All @@ -262,6 +258,10 @@ public function downtimesAction()
'downtime_scheduled_end' => $this->translate('Scheduled End'),
'downtime_duration' => $this->translate('Duration')
), $query);
$this->view->downtimes = $query->paginate();

$this->setupLimitControl();
$this->setupPaginationControl($this->view->downtimes);

if ($this->Auth()->hasPermission('monitoring/command/downtime/delete')) {
$this->view->delDowntimeForm = new DeleteDowntimeCommandForm();
Expand Down Expand Up @@ -292,13 +292,13 @@ public function notificationsAction()
'service_display_name'
));
$this->filterQuery($query);
$this->setupSortControl(array(
'notification_start_time' => $this->translate('Notification Start')
), $query);
$this->view->notifications = $query->paginate();

$this->setupLimitControl();
$this->setupPaginationControl($this->view->notifications);
$this->setupSortControl(array(
'notification_start_time' => $this->translate('Notification Start')
), $query);
}

public function contactsAction()
Expand Down Expand Up @@ -326,10 +326,6 @@ public function contactsAction()
'contact_notify_host_downtime',
));
$this->filterQuery($query);
$this->view->contacts = $query->paginate();

$this->setupLimitControl();
$this->setupPaginationControl($this->view->contacts);
$this->setupSortControl(array(
'contact_name' => $this->translate('Name'),
'contact_alias' => $this->translate('Alias'),
Expand All @@ -338,6 +334,10 @@ public function contactsAction()
'contact_notify_service_timeperiod' => $this->translate('Service Notification Timeperiod'),
'contact_notify_host_timeperiod' => $this->translate('Host Notification Timeperiod')
), $query);
$this->view->contacts = $query->paginate();

$this->setupLimitControl();
$this->setupPaginationControl($this->view->contacts);
}

public function eventgridAction()
Expand Down Expand Up @@ -397,6 +397,11 @@ public function contactgroupsAction()
));
$this->filterQuery($query);

$this->setupSortControl(array(
'contactgroup_name' => $this->translate('Contactgroup Name'),
'contactgroup_alias' => $this->translate('Contactgroup Alias')
), $query);

// Fetch and prepare all contact groups:
$contactgroups = $query->getQuery()->fetchAll();
$groupData = array();
Expand All @@ -411,11 +416,6 @@ public function contactgroupsAction()
}
// TODO: Find a better naming
$this->view->groupData = $groupData;

$this->setupSortControl(array(
'contactgroup_name' => $this->translate('Contactgroup Name'),
'contactgroup_alias' => $this->translate('Contactgroup Alias')
), $query);
}

public function commentsAction()
Expand All @@ -438,10 +438,6 @@ public function commentsAction()
'service_display_name'
));
$this->filterQuery($query);
$this->view->comments = $query->paginate();

$this->setupLimitControl();
$this->setupPaginationControl($this->view->comments);
$this->setupSortControl(
array(
'comment_timestamp' => $this->translate('Comment Timestamp'),
Expand All @@ -452,6 +448,10 @@ public function commentsAction()
),
$query
);
$this->view->comments = $query->paginate();

$this->setupLimitControl();
$this->setupPaginationControl($this->view->comments);

if ($this->Auth()->hasPermission('monitoring/command/comment/delete')) {
$this->view->delCommentForm = new DeleteCommentCommandForm();
Expand Down Expand Up @@ -498,10 +498,6 @@ public function servicegroupsAction()
// TODO(el): Can't default to the sort rules of the data view because it's meant for both host groups and
// service groups. We should separate them.
$this->filterQuery($query);
$this->view->servicegroups = $query->paginate();

$this->setupLimitControl();
$this->setupPaginationControl($this->view->servicegroups);
$this->setupSortControl(array(
'services_severity' => $this->translate('Severity'),
'servicegroup_alias' => $this->translate('Service Group Name'),
Expand All @@ -512,6 +508,10 @@ public function servicegroupsAction()
'services_warning' => $this->translate('Services WARNING'),
'services_pending' => $this->translate('Services PENDING')
), $query);
$this->view->servicegroups = $query->paginate();

$this->setupLimitControl();
$this->setupPaginationControl($this->view->servicegroups);
}

public function hostgroupsAction()
Expand Down Expand Up @@ -549,10 +549,6 @@ public function hostgroupsAction()
// TODO(el): Can't default to the sort rules of the data view because it's meant for both host groups and
// service groups. We should separate them.
$this->filterQuery($query);
$this->view->hostgroups = $query->paginate();

$this->setupLimitControl();
$this->setupPaginationControl($this->view->hostgroups);
$this->setupSortControl(array(
'services_severity' => $this->translate('Severity'),
'hostgroup_alias' => $this->translate('Host Group Name'),
Expand All @@ -563,6 +559,10 @@ public function hostgroupsAction()
'services_warning' => $this->translate('Services WARNING'),
'services_pending' => $this->translate('Services PENDING')
), $query);
$this->view->hostgroups = $query->paginate();

$this->setupLimitControl();
$this->setupPaginationControl($this->view->hostgroups);
}

public function eventhistoryAction()
Expand All @@ -588,13 +588,13 @@ public function eventhistoryAction()
));

$this->filterQuery($query);
$this->setupSortControl(array(
'timestamp' => $this->translate('Occurence')
), $query);
$this->view->history = $query->paginate();

$this->setupLimitControl();
$this->setupPaginationControl($this->view->history);
$this->setupSortControl(array(
'timestamp' => $this->translate('Occurence')
), $query);
}

public function servicegridAction()
Expand Down

0 comments on commit ca79b02

Please sign in to comment.