Fixes API sorting and filtering. Closes #1489
This commit is contained in:
committed by
James Brooks
parent
98550c31c9
commit
919c7127e7
@@ -161,12 +161,6 @@ abstract class AbstractApiController extends Controller
|
||||
|
||||
$items = $paginator->getCollection();
|
||||
|
||||
if ($sortBy = $request->get('sort')) {
|
||||
$direction = $request->has('order') && $request->get('order') == 'desc';
|
||||
|
||||
$items = $items->sortBy($sortBy, SORT_REGULAR, $direction);
|
||||
}
|
||||
|
||||
return $this->setMetaData($pagination)->setData(AutoPresenter::decorate($items->values()))->respond();
|
||||
}
|
||||
|
||||
|
||||
@@ -37,7 +37,15 @@ class ComponentController extends AbstractApiController
|
||||
$components = Component::enabled();
|
||||
}
|
||||
|
||||
return $this->paginator($components->paginate(Binput::get('per_page', 20)), Request::instance());
|
||||
if ($sortBy = Binput::get('sort')) {
|
||||
$direction = Binput::has('order') && Binput::get('order') == 'desc';
|
||||
|
||||
$components->sort($sortBy, $direction);
|
||||
}
|
||||
|
||||
$components = $components->paginate(Binput::get('per_page', 20));
|
||||
|
||||
return $this->paginator($components, Request::instance());
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -29,7 +29,15 @@ class ComponentGroupController extends AbstractApiController
|
||||
*/
|
||||
public function getGroups()
|
||||
{
|
||||
$groups = ComponentGroup::paginate(Binput::get('per_page', 20));
|
||||
$groups = ComponentGroup::whereRaw('1=1');
|
||||
|
||||
if ($sortBy = Binput::get('sort')) {
|
||||
$direction = Binput::has('order') && Binput::get('order') == 'desc';
|
||||
|
||||
$groups->sort($sortBy, $direction);
|
||||
}
|
||||
|
||||
$groups = $groups->paginate(Binput::get('per_page', 20));
|
||||
|
||||
return $this->paginator($groups, Request::instance());
|
||||
}
|
||||
|
||||
@@ -32,7 +32,15 @@ class IncidentController extends AbstractApiController
|
||||
{
|
||||
$incidentVisibility = app(Guard::class)->check() ? 0 : 1;
|
||||
|
||||
$incidents = Incident::where('visible', '>=', $incidentVisibility)->paginate(Binput::get('per_page', 20));
|
||||
$incidents = Incident::where('visible', '>=', $incidentVisibility);
|
||||
|
||||
if ($sortBy = Binput::get('sort')) {
|
||||
$direction = Binput::has('order') && Binput::get('order') == 'desc';
|
||||
|
||||
$incidents->sort($sortBy, $direction);
|
||||
}
|
||||
|
||||
$incidents = $incidents->paginate(Binput::get('per_page', 20));
|
||||
|
||||
return $this->paginator($incidents, Request::instance());
|
||||
}
|
||||
|
||||
@@ -29,7 +29,15 @@ class MetricController extends AbstractApiController
|
||||
*/
|
||||
public function getMetrics()
|
||||
{
|
||||
$metrics = Metric::paginate(Binput::get('per_page', 20));
|
||||
$metrics = Metric::whereRaw('1=1');
|
||||
|
||||
if ($sortBy = Binput::get('sort')) {
|
||||
$direction = Binput::has('order') && Binput::get('order') == 'desc';
|
||||
|
||||
$metrics->sort($sortBy, $direction);
|
||||
}
|
||||
|
||||
$metrics = $metrics->paginate(Binput::get('per_page', 20));
|
||||
|
||||
return $this->paginator($metrics, Request::instance());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user