Skip to content

Commit

Permalink
Fix #14
Browse files Browse the repository at this point in the history
  • Loading branch information
tito10047 committed Sep 27, 2024
1 parent 463a108 commit 911ac1c
Show file tree
Hide file tree
Showing 8 changed files with 55 additions and 12 deletions.
3 changes: 0 additions & 3 deletions config/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,6 @@
->add('bug_catcher.dashboard.index', '/')
->controller(DashboardController::class . "::index")
->methods(['GET'])
->add('bug_catcher.dashboard.status', '/status/{status}')
->controller(DashboardController::class . "::index")
->methods(['GET'])
->add('bug_catcher.dashboard.detail', '/detail/{record}')
->controller(DashboardController::class . "::detail")
->methods(['GET']);
Expand Down
22 changes: 21 additions & 1 deletion src/Controller/DashboardController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,16 @@

namespace BugCatcher\Controller;

use BugCatcher\Entity\Project;
use BugCatcher\Repository\ProjectRepository;
use Doctrine\ORM\EntityManagerInterface;
use Exception;
use BugCatcher\Entity\Record;
use Symfony\Component\DependencyInjection\Attribute\Autowire;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Attribute\MapQueryParameter;
use Symfony\Component\Uid\Uuid;

final class DashboardController extends AbstractController
{
Expand All @@ -18,9 +24,23 @@ public function __construct(
) {}

public function index(
EntityManagerInterface $em,
Request $request,
#[MapQueryParameter]
string $project = 'all',
#[MapQueryParameter]
string $status = 'new'
): Response {
return $this->render('@BugCatcher/dashboard/index.html.twig', [
if ($project == 'all') {
$project = null;
} else {
$project = $em->getReference(Project::class, new Uuid($project));
}
$request->attributes->set('project', $project);
$request->attributes->set('status', $status);

return $this->render('@BugCatcher/dashboard/index.html.twig', [
"project" => $project,
"status" => $status,
"components" => $this->components,
"refreshInterval" => $this->refreshInterval,
Expand Down
8 changes: 8 additions & 0 deletions src/Repository/RecordPingRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,15 @@ public function save(RecordPing $entity, bool $flush = false): void
}


public function getQBWith(Project $project): QueryBuilder
{
$qb = $this->createQueryBuilder('r');

$qb->andWhere('r.project = :project')
->setParameter('project', $project->getId(), UuidType::NAME);

return $qb;
}

public function getLastRecord(Project $project, string $maxLife = '-1 hour'): ?RecordPing
{
Expand Down
10 changes: 9 additions & 1 deletion src/Twig/Components/LogList.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ final class LogList extends AbstractController
#[LiveProp]
public string $status;

#[LiveProp]
public ?Project $project = null;

#[LiveProp]
public string $id;
/** @var Record[] */
Expand Down Expand Up @@ -52,6 +55,11 @@ public function init(): void
$discriminatorMap = array_flip($discriminatorMap);
$keys = array_map(fn($class) => $discriminatorMap[$class] ?? null, $this->classes);

if ($this->project) {
$projects = [$this->project];
} else {
$projects = $this->getUser()->getActiveProjects()->toArray();
}
/** @var Record[] $records */
$records = $this->recordRepo->createQueryBuilder("record")
->where("record.status like :status")
Expand All @@ -60,7 +68,7 @@ public function init(): void
->setParameter("status", $this->status . '%')
->setParameter("class", $keys)
->setParameter('projects',
array_map(fn(Project $p) => $p->getId()->toBinary(), $this->getUser()->getActiveProjects()->toArray())
array_map(fn(Project $p) => $p->getId()->toBinary(), $projects)
)
->orderBy("record.date", "DESC")
->setMaxResults(100)
Expand Down
6 changes: 4 additions & 2 deletions templates/base.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,10 @@
<a class="dropdown-item" href="{{ path('bug_catcher.admin') }}">Administration</a>
{% endif %}
<hr class="dropdown-divider">
<a class="dropdown-item" href="{{ path('bug_catcher.dashboard.status',{status:'archived'}) }}">Archived logs</a>
<a class="dropdown-item" href="{{ path('bug_catcher.dashboard.status',{status:'withheld'}) }}">Withheld logs</a>
<a class="dropdown-item" href="{{ path('bug_catcher.dashboard.index',{status:'archived'}) }}">Archived
logs</a>
<a class="dropdown-item" href="{{ path('bug_catcher.dashboard.index',{status:'withheld'}) }}">Withheld
logs</a>
<a class="dropdown-item" href="{{ path('bug_catcher.dashboard.index') }}">New logs</a>
<hr class="dropdown-divider">
<a class="dropdown-item" href="{{ path('bug_catcher.security.change-password') }}">Change password</a>
Expand Down
8 changes: 7 additions & 1 deletion templates/components/LogList.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,20 @@
{% set logs = this.logs %}
{% if logs|length %}
<div class="nav justify-content-end pb-1">
{% if app.request.attributes.get("project") is not null %}
<a href="{{ path('bug_catcher.dashboard.index') }}" class="btn btn-primary btn-sm mx-1">
<twig:ux:icon name="lucide:filter-x" width="20px" height="20px"/>
{{ 'Clear filter'|trans }}
</a>
{% endif %}
<button class="btn btn-outline-secondary btn-sm" aria-current="page"
data-action="live#action"
data-live-action-param="clearAll"
data-live-from-param="{{ this.to|date('Y-m-d-H-i-s') }}"
data-live-to-param="{{ this.from|date('Y-m-d-H-i-s') }}"
>
<twig:ux:icon name="game-icons:magic-broom" width="20px" height="20px"/>
Fix all
{{ 'Fix all'|trans }}
</button>
</div>
<ul class="list-group">
Expand Down
9 changes: 5 additions & 4 deletions templates/components/LogList/RecordLog.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@
{% endif %}
<div>
<span class="badge text-bg-secondary ">{{ log.date|date('d.m.Y H:i:s') }}</span>
<span class="badge text-bg-primary ">{{ log.project.name }}</span>
<a href="{{ path('bug_catcher.dashboard.index',{project:log.project.id,status:this.status}) }}"
class="badge text-bg-primary text-decoration-none">{{ log.project.name }}</a>
<span class="badge text-bg-{{ status }} ">{{ log.count }}</span>
<div class="d-inline text-break">{{ log.message }}</div>
</div>
Expand All @@ -29,22 +30,22 @@
data-action="live#action"
data-live-action-param="clearOne"
data-live-status-param="resolved"
title="Fix it"
title="{{ 'Fix it'|trans }}"
>
<twig:ux:icon name="game-icons:magic-broom" width="20px" height="20px"/>
</button>
<a href="{{ path('bug_catcher.dashboard.detail',{"record":log.id}) }}"
class="btn btn-outline-success btn-sm"
target="_blank"
title="Detail"
title="{{ 'Detail'|trans }}"
>
<twig:ux:icon name="covid:virus-lab-research-magnifier-1" width="20px" height="20px"/>
</a>
<button type="button" class="btn btn-outline-info btn-sm"
data-action="live#action"
data-live-action-param="clearOne"
data-live-status-param="archived"
title="Archive it"
title="{{ 'Archive it'|trans }}"
>
<twig:ux:icon name="clarity:archive-line" width="20px" height="20px"/>
</button>
Expand Down
1 change: 1 addition & 0 deletions templates/dashboard/index.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
{% for dashboardComponent in components %}
{{ component(dashboardComponent,{
status:status,
project:project,
'data-poll':"delay("~refreshInterval~"000)|$render"
}) }}
{% endfor %}
Expand Down

0 comments on commit 911ac1c

Please sign in to comment.