Skip to content

Commit

Permalink
276: Car management 2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Mathieu414 committed Dec 1, 2024
1 parent e3aff55 commit ab99675
Show file tree
Hide file tree
Showing 12 changed files with 175 additions and 141 deletions.
17 changes: 7 additions & 10 deletions app/pages/events/entry_list/entry_list.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,19 @@

$event_id = get_route_param("event_id");
$event_infos = EventService::getEventInfos($event_id);
page($event_infos->name . " : Inscrits")->css("entry_list.css") ?>

<?= actions()
->back("/evenements/$event_id")
->if(
$event_infos->open && check_auth(Access::$ADD_EVENTS),
fn($a) => $a->button("Copier le tableau", attributes: ["onclick" => "selectTable()"])
) ?>
$is_simple = get_query_param("is_simple", false, false);
?>

<?php if ($event_infos->open && check_auth(Access::$ADD_EVENTS)): ?>
<div class="entries-header"><button onclick="selectTable()"> Copier le tableau</button></div>
<?php endif ?>
<?php if (!$event_infos->open): ?>
<p class="center">
<?php "L'évenement de cette course n'est pas encore ouvert 🙃" ?>
<?php "L'évenement n'est pas encore ouvert 🙃" ?>
</p>
<?php else: ?>
<div id="tabs" hx-target="#tabs" hx-swap="innerHTML">
<?= component(__DIR__ . "/entry_list_tabs.php")->render(["event_id" => $event_id]) ?>
<?= $is_simple ? component(__DIR__ . "/entry_list_tab_activity.php")->render(["activity_id" => EventService::getActivityIdList($event_id)[0]->id]) : component(__DIR__ . "/entry_list_tabs.php")->render(["event_id" => $event_id]) ?>
</div>
<script src="/assets/js/select-table.js"></script>
<?php endif ?>
Expand Down
2 changes: 2 additions & 0 deletions app/pages/events/entry_list/entry_list_tab_activity.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<?php
include_once __DIR__ . "/TotalRow.php";

$activityId = Component::prop("activity_id");
$activityEntries = ActivityService::getActivityEntries($activityId);
?>
Expand Down
233 changes: 116 additions & 117 deletions app/pages/events/view/event_view.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,7 @@
restrict_access(Access::$ADD_EVENTS);
}

$vehicles = em()->createQuery('SELECT v FROM Vehicle v WHERE v.event = ?1')->setParameter(
1,
$event->id
)->getResult();
$tab = get_query_param("tab", false, false);

$can_edit = check_auth(Access::$ADD_EVENTS);
$today_date = date_create("today");
Expand All @@ -20,7 +17,7 @@
$totalEntryCount = EventService::getEntryCount($event->id);
$is_simple = $event->type == EventType::Simple;

page($event->name)->css("event_view.css");
page($event->name)->css("event_view.css")->css("entry_list.css");

?>

Expand All @@ -44,120 +41,122 @@

<?= $is_simple ? RenderActivityEntry($event->activities[0], $can_register) : RenderEventEntry($entry, $event, $can_edit) ?>

<?php if ($is_simple) {
require __DIR__ . "/ActivityView.php";
return;
}

$deadline_class = $deadline_in_future ? "" : ($entry?->present ? "completed" : "missed");
$start_class = $event->start_date < $today_date ? $deadline_class : "";
$end_class = $event->end_date < $today_date ? $deadline_class : "";

?>
<article>
<header>
<div class="row g-2 center align-center">
<div class="col-12">
<?= RenderTimeline($event, !!$entry?->present) ?>
</div>
<div class="col-12">
<div class="row g-2 center">
<?php if ($event->bulletin_url): ?>
<div class="col-12 col-lg-auto">
<a role="button" href="<?= $event->bulletin_url ?>" target="_blank"> <i
class="fa fa-paperclip"></i>
Bulletin
<i class="fa fa-external-link"></i></a>
<sl-tab-group>
<sl-tab slot="nav" panel="information" <?= $tab ? "" : "active" ?>>
Informations
</sl-tab>
<sl-tab slot="nav" panel="entry-list" hx-trigger="load"
hx-post="/evenements/<?= $event->id ?>/participants<?= $is_simple ? "?is_simple=true" : "" ?>"
hx-target="#entry-list" <?= ($tab == "participants") ? "active" : "" ?>>
Participants
</sl-tab>
<sl-tab slot="nav" panel="vehicles" hx-trigger="load" hx-post="/evenements/<?= $event->id ?>/vehicules"
hx-target="#vehicles" <?= ($tab == "vehicules") ? "active" : "" ?>>
Véhicules
</sl-tab>

<sl-tab-panel name="information">
<?php if ($is_simple) {
require __DIR__ . "/ActivityView.php";
} else {

$deadline_class = $deadline_in_future ? "" : ($entry?->present ? "completed" : "missed");
$start_class = $event->start_date < $today_date ? $deadline_class : "";
$end_class = $event->end_date < $today_date ? $deadline_class : "";

?>
<article>
<header>
<div class="row g-2 center align-center">
<div class="col-12">
<?= RenderTimeline($event, !!$entry?->present) ?>
</div>
<?php endif ?>
<?php if ($event->open && $totalEntryCount): ?>
<div class="col-12 col-lg-auto">
<a role="button" href="/evenements/<?= $event->id ?>/participants" class="secondary">
<i class="fas fa-users"></i> Participants
<?= "($totalEntryCount)" ?>
</a>
</div>
<?php endif ?>
</div>
</div>
</div>
</header>
<section>
<?php if (count($event->activities)): ?>
<h3>Activités</h3>
<?php foreach ($event->activities as $i => $activity):
$activity_entry = $activity->entries[0] ?? null; ?>
<details>
<summary>
<?= ConditionalIcon($activity_entry && $activity_entry->present) . " " ?>
<?= $activity->name ?>
<i class="fa <?= $activity->type->toIcon() ?>" title=<?= $activity->type->toName() ?>></i>
</summary>
<?= RenderActivityEntry($activity) ?>
<p class="grid">
<span><i class="fa fa-calendar fa-fw"></i>
<?= format_date($activity->date) ?>
</span>
<?php if ($activity->location_label): ?>
<span>
<i class="fa fa-location-dot fa-fw"></i>
<?php if ($activity->location_url): ?>
<a href=<?= $activity->location_url ?> target="_blank"><?= $activity->location_label ?></a>
<?php else: ?>
<?= $activity->location_label ?>
<div class="col-12">
<div class="row g-2 center">
<?php if ($event->bulletin_url): ?>
<div class="col-12 col-lg-auto">
<a role="button" href="<?= $event->bulletin_url ?>" target="_blank"> <i
class="fa fa-paperclip"></i>
Bulletin
<i class="fa fa-external-link"></i></a>
</div>
<?php endif ?>
</span>
<?php endif ?>
</p>
<div class="buttons-grid">
<a role="button" class="outline secondary"
href='/evenements/<?= $event->id ?>/activite/<?= $activity->id ?>'>
<i class="fa fa-circle-info"></i>
Détails</a>
<?php if ($can_edit): ?>
<a role="button" class="outline secondary"
href='/evenements/<?= $event->id ?>/activite/<?= $activity->id ?>/modifier'>
<i class="fa fa-pen"></i>
Modifier</a>
<a role="button" class="outline error"
href="/evenements/<?= $event->id ?>/activite/<?= $activity->id ?>/supprimer">
<i class="fa fa-trash"></i>
Supprimer
</a>

<?php endif ?>
</div>
</div>
</div>
</details>
<hr>
<?php endforeach; ?>
<?php endif; ?>


<?php if ($can_edit): ?>
<p>
<a role=button class="secondary" href="/evenements/<?= $event->id ?>/activite/nouveau">
<i class="fas fa-plus"></i> Ajouter une activité</a>
</p>
<?php endif ?>
</section>
<?php if ($event->description): ?>
<br>
<section>
<h3>Description</h3>
<?= (new Parsedown)->text($event->description) ?>
</section>
<?php endif ?>
</article>

<h2><i class="fas fa-car"></i> Véhicules</h2>

<?php foreach ($vehicles as $vehicle): ?>
<div hx-get="/evenements/<?= $event->id ?>/vehicule/<?= $vehicle->id ?>/inscription/<?= $user_id ?>" hx-trigger="load"
hx-target="this">
</div>
<?php endforeach ?>

<a role=button class="secondary" href="/evenements/<?= $event->id ?>/vehicule/nouveau">
<i class="fas fa-plus"></i> Ajouter un véhicule</a>
</header>
<section>
<?php if (count($event->activities)): ?>
<h3>Activités</h3>
<?php foreach ($event->activities as $i => $activity):
$activity_entry = $activity->entries[0] ?? null; ?>
<details>
<summary>
<?= ConditionalIcon($activity_entry && $activity_entry->present) . " " ?>
<?= $activity->name ?>
<i class="fa <?= $activity->type->toIcon() ?>" title=<?= $activity->type->toName() ?>></i>
</summary>
<?= RenderActivityEntry($activity) ?>
<p class="grid">
<span><i class="fa fa-calendar fa-fw"></i>
<?= format_date($activity->date) ?>
</span>
<?php if ($activity->location_label): ?>
<span>
<i class="fa fa-location-dot fa-fw"></i>
<?php if ($activity->location_url): ?>
<a href=<?= $activity->location_url ?> target="_blank"><?= $activity->location_label ?></a>
<?php else: ?>
<?= $activity->location_label ?>
<?php endif ?>
</span>
<?php endif ?>
</p>
<div class="buttons-grid">
<a role="button" class="outline secondary"
href='/evenements/<?= $event->id ?>/activite/<?= $activity->id ?>'>
<i class="fa fa-circle-info"></i>
Détails</a>
<?php if ($can_edit): ?>
<a role="button" class="outline secondary"
href='/evenements/<?= $event->id ?>/activite/<?= $activity->id ?>/modifier'>
<i class="fa fa-pen"></i>
Modifier</a>
<a role="button" class="outline error"
href="/evenements/<?= $event->id ?>/activite/<?= $activity->id ?>/supprimer">
<i class="fa fa-trash"></i>
Supprimer
</a>

<?php endif ?>
</div>
</details>
<hr>
<?php endforeach; ?>
<?php endif; ?>


<?php if ($can_edit): ?>
<p>
<a role=button class="secondary" href="/evenements/<?= $event->id ?>/activite/nouveau">
<i class="fas fa-plus"></i> Ajouter une activité</a>
</p>
<?php endif ?>
<?php if ($event->description): ?>
<br>
<section>
<h3>Description</h3>
<?= (new Parsedown)->text($event->description) ?>
</section>
<?php else: ?>
Pas encore de description pour cet événement 🪶
<?php endif ?>
</section>
</article>
<?php } ?>
</sl-tab-panel>
<sl-tab-panel name="entry-list" id="entry-list"></sl-tab-panel>
<sl-tab-panel name="vehicles" id="vehicles"></sl-tab-panel>
</sl-tab-group>

<?= UserModal::renderRoot() ?>
4 changes: 2 additions & 2 deletions app/pages/vehicle/vehicle_delete.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
em()->remove($vehicle);
em()->flush();
Toast::error("Véhicule supprimé");
redirect("/evenements/$event_id");
redirect("/evenements/$event_id?tab=vehicules");
}

page("Confirmation de suppression");
Expand All @@ -30,7 +30,7 @@
<?= "$vehicle->id" ?> ? Il sera définitivement supprimé!!
</p>
<div class="col-auto">
<a class="secondary" role="button" href="/evenements/<?= $event_id ?>">Annuler</a>
<a class="secondary" role="button" href="/evenements/<?= $event_id ?>?tab=vehicules">Annuler</a>
</div>
<div class="col-auto">
<button type="submit" name="delete" value="true" class="destructive">Supprimer</button>
Expand Down
2 changes: 1 addition & 1 deletion app/pages/vehicle/vehicle_edit.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
?>

<form method="post">
<?= actions()?->back("/evenements/$event_id", "Annuler")->submit($vehicle_id ? "Modifier" : "Ajouter") ?>
<?= actions()?->back("/evenements/$event_id?tab=vehicules", "Annuler")->submit($vehicle_id ? "Modifier" : "Ajouter") ?>
<article>
<div class="row">
<?= $v->render_validation() ?>
Expand Down
20 changes: 20 additions & 0 deletions app/pages/vehicle/vehicle_view.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php
restrict_access();
$user_id = User::getCurrent()->id;
$event = EventService::getEventWithAllData(get_route_param('event_id'), $user_id);

$vehicles = em()->createQuery('SELECT v FROM Vehicle v WHERE v.event = ?1')->setParameter(
1,
$event->id
)->getResult();

?>

<?php foreach ($vehicles as $vehicle): ?>
<div hx-get="/evenements/<?= $event->id ?>/vehicule/<?= $vehicle->id ?>/inscription/<?= $user_id ?>" hx-trigger="load"
hx-target="this">
</div>
<?php endforeach ?>

<a role=button class="secondary" href="/evenements/<?= $event->id ?>/vehicule/nouveau">
<i class="fas fa-plus"></i> Ajouter un véhicule</a>
9 changes: 8 additions & 1 deletion app/template/shoelace.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,16 @@
// These scripts load shoelace from CDN. The files should be cached forever so it is very convenient.

?>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@shoelace-style/[email protected]/cdn/themes/light.css" />
<link rel="stylesheet" media="(prefers-color-scheme:light)"
href="https://cdn.jsdelivr.net/npm/@shoelace-style/[email protected]/cdn/themes/light.css" />
<link rel="stylesheet" media="(prefers-color-scheme:dark)"
href="https://cdn.jsdelivr.net/npm/@shoelace-style/[email protected]/cdn/themes/dark.css"
onload="document.documentElement.classList.add('sl-theme-dark');" />
<script type="module">
// Import all shoelace components here
import 'https://cdn.jsdelivr.net/npm/@shoelace-style/[email protected]/cdn/components/copy-button/copy-button.js';
import 'https://cdn.jsdelivr.net/npm/@shoelace-style/[email protected]/cdn/components/tooltip/tooltip.js';
import 'https://cdn.jsdelivr.net/npm/@shoelace-style/[email protected]/cdn/components/tab-group/tab-group.js';
import 'https://cdn.jsdelivr.net/npm/@shoelace-style/[email protected]/cdn/components/tab/tab.js';
import 'https://cdn.jsdelivr.net/npm/@shoelace-style/[email protected]/cdn/components/tab-panel/tab-panel.js';
</script>
11 changes: 7 additions & 4 deletions assets/css/entry_list.css
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
.tab-list {
border-bottom: solid var(--contrast) 2px;
white-space: nowrap;
overflow-x: auto;
}
.tab-list > button {
margin: 0;
border-radius: 1rem 1rem 0 0;
border-bottom: none;
margin: 0.1rem;
border-radius: 1.5rem;
}
.filter-panel {
padding: 1rem;
}

.entries-header {
display: grid;
justify-items: end;
}
5 changes: 5 additions & 0 deletions assets/css/event_view.css
Original file line number Diff line number Diff line change
Expand Up @@ -72,3 +72,8 @@ details summary:focus:not([role="button"]) {
gap: 10px;
flex-wrap: wrap;
}

sl-tab-group {
--indicator-color: var(--primary);
--sl-color-primary-600: var(--primary);
}
Loading

0 comments on commit ab99675

Please sign in to comment.