diff --git a/src/Twig/Components/MonitorList.php b/src/Twig/Components/MonitorList.php index b5a04ce..6484675 100644 --- a/src/Twig/Components/MonitorList.php +++ b/src/Twig/Components/MonitorList.php @@ -16,6 +16,9 @@ final class MonitorList extends AbstractController use PaginateTrait; + #[LiveProp(writable: true)] + public string $type; + #[LiveProp(writable: true)] public bool $isWidget = true; @@ -24,8 +27,34 @@ final class MonitorList extends AbstractController ) {} #[LiveAction] - public function getUserMonitors() + public function getMonitors() { - return $this->monitorRepository->getUserMonitorsPaginated($this->getUser(), $this->pageNumber, $this->perPage); + if ($this->type === "active") { + return $this->getActiveUserMonitors(); + } elseif ($this->type === "complete") { + return $this->getCompleteUserMonitors(); + } + + return []; + } + + #[LiveAction] + public function getActiveUserMonitors() + { + return $this->asPaginator($this->monitorRepository->createQueryBuilder('m') + ->andWhere('m.status IN (:statuses)') + ->setParameter('statuses', ['New', 'In Progress']) + ->getQuery() + ); + } + + #[LiveAction] + public function getCompleteUserMonitors() + { + return $this->asPaginator($this->monitorRepository->createQueryBuilder('m') + ->andWhere('m.status = :status') + ->setParameter('status', 'Complete') + ->getQuery() + ); } } diff --git a/templates/components/MonitorList.html.twig b/templates/components/MonitorList.html.twig index aea1e68..cd43a49 100644 --- a/templates/components/MonitorList.html.twig +++ b/templates/components/MonitorList.html.twig @@ -26,8 +26,8 @@ - {% if this.userMonitors.items|length > 0 %} - {% for monitor in this.userMonitors.items %} + {% if this.monitors.items|length > 0 %} + {% for monitor in this.monitors.items %} {{ monitor.title }} @@ -61,7 +61,7 @@ {% endfor %} - {% if this.isWidget and this.userMonitors.items|length > 5 %} + {% if this.isWidget and this.monitors.items|length > 5 %} View All Monitors @@ -79,8 +79,8 @@ {% if this.isWidget == false %} - {% if this.userMonitors.items|length > 0 %} - {% set paginator = this.userMonitors %} + {% if this.monitors.items|length > 0 %} + {% set paginator = this.monitors %} {% include 'partial/paginator.html.twig' %} {% endif %} {% endif %} diff --git a/templates/index/index.html.twig b/templates/index/index.html.twig index 82e0f75..dc4ef22 100644 --- a/templates/index/index.html.twig +++ b/templates/index/index.html.twig @@ -16,7 +16,7 @@
- +
diff --git a/templates/monitor/index.html.twig b/templates/monitor/index.html.twig index d463a2e..078cf1d 100644 --- a/templates/monitor/index.html.twig +++ b/templates/monitor/index.html.twig @@ -5,8 +5,14 @@ {% block body %}
- - + + + +
+ +
+ +
{% endblock %}