Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release PR #387

Merged
merged 5 commits into from
Feb 25, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions app/components/user_card.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php
function UserCard($user, $image = null, $subtitle = null, $actions = null, $user_link = null, $options = [])
{
?>
<article class="user-card">
<!-- Image block -->
<?php if ($image): ?>
<?php $image($user); ?>
<?php else: ?>
<img src="<?= $user->getPicture() ?>">
<?php endif; ?>

<?php if ($user_link):
$user_link();
else: ?>
<a href="/licencies?user=<?= $user->id ?>" <?= UserModal::props($user->id) ?>>
<?= "$user->first_name $user->last_name" ?>
</a>
<?php endif; ?>

<!-- subtitle block -->
<?php $subtitle && $subtitle($user) ?>

<!-- Actions block -->
<?php if ($actions): ?>
<nav>
<ul>
<li>
<?php $actions($user); ?>
</li>
</ul>
</nav>
<?php endif; ?>
</article>
<?php
} ?>
1 change: 1 addition & 0 deletions app/management/club_new.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php
restrict_management();
managementPage("New club");

$v = new Validator(["direct_login" => true]);
Expand Down
83 changes: 74 additions & 9 deletions app/management/club_view.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
<?php
managementPage("View club");
restrict_management();
$slug = Router::getParameter("slug", pattern: '/[\w-]+/');
$s = ClubManagementService::fromSlug($slug) ?? force_404("club not found");
DB::setupForClub($slug);
$s = ClubManagementService::create($slug) ?? force_404("club not found");
$club = $s->getClub();

managementPage("Club - $club->name");

$backupService = new BackupService(dbPath: $s->db->sqlitePath);

$v_backup = new Validator(action: "create_backup");
Expand All @@ -24,13 +27,38 @@

$v = new Validator($club->toForm());
$color = $v->select("color")->options(array_column(ThemeColor::cases(), 'value', 'name'))->label("Couleur de thème");
$name = $v->text("name")->label("Name");
$name = $v->text("name")->label("Name")->required();

if ($v->valid()) {
$r = $s->updateClub($club, $name->value, $color->value);
Toast::fromResult($r);
$r->success && redirect("/mgmt/view/$club->slug");
}

$club_features = FeatureService::listClub($slug, $s);
$v_features = new Validator(action: "features");
$feature_options = [];
foreach (Feature::cases() as $f) {
$feature_options[$f->value] = $f->value;
}
$features = $v_features->select("add_new")->options($feature_options)->label("New feature")->required();

if ($v_features->valid()) {
$newFeature = $club_features[$features->value] ?? new ClubFeature($club, Feature::from($features->value));
$s->db->em()->persist($newFeature);
$s->db->em()->flush();
Toast::success("Feature added");
reload();
}

$v_removeFeature = new Validator(action: "remove_feature");
if ($v_removeFeature->valid() && isset($_POST['remove_name']) && isset($club_features[$_POST['remove_name']])) {
$s->db->em()->remove($club_features[$_POST['remove_name']]);
$s->db->em()->flush();
Toast::error("Feature removed");
reload();
}

?>
<?= actions()->back("/mgmt") ?>
<sl-tab-group>
Expand All @@ -40,9 +68,6 @@
<sl-tab-panel name="general">
<form method="post">
<?= $v ?>
<?php if (!$club->name): ?>
<article class="notice error">Please fill in the club name</article>
<?php endif ?>
<?= $name ?>
<label for="color">Couleurs disponibles</label>
<div class="color-picker">
Expand All @@ -56,13 +81,53 @@
<?= $color ?>
<button>Update</button>
<br><br>
<h3><i>Danger zone</i></h3>
</form>
<section>
<h3>Features</h3>
<ul>
<?php foreach ($club_features as $club_feature): ?>
<li style="display:flex;align-items:center;gap:1rem;padding: 0.5rem">
<?= $club_feature->featureName ?>
<form method="post">
<?= $v_removeFeature ?>
<input type="hidden" name="remove_name" value="<?= $club_feature->featureName ?>">
<button class="destructive">Remove</button>
</form>
</li>
<?php endforeach ?>
</ul>
<form method="post">
<?= $v_features ?>
<?= $features ?>
<button>Add</button>
</form>
</section>
<h3><i>Danger zone</i></h3>
<form method="post">
<button class="destructive" hx-post hx-confirm="Are you sure you want to delete the club?"
<?= $v_delete->hx_action() ?>>Delete</button>
<?= $v_delete->hx_action() ?>>Delete club</button>
</form>
</sl-tab-panel>
<sl-tab-panel name="backups">
<form hx-post="/mgmt/view/<?= $slug ?>/backups" hx-trigger="load,submit" hx-target="this">
</form>
</sl-tab-panel>
</sl-tab-group>
</sl-tab-group>

<style>
.color-dot {
display: flex;
align-items: center;
justify-content: center;
aspect-ratio: 1 / 1;
width: 40px;
border-radius: 50%;
}

.color-picker {
display: flex;
gap: 5px;
flex-wrap: wrap;
padding: 0 0 1rem;
}
</style>
5 changes: 5 additions & 0 deletions app/management/clubs_list.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,12 @@
if (!ClubManagementService::isLoggedIn()) {
redirect("/mgmt/login");
}
restrict_management();
managementPage("Clubs");
/* Workaround to handle the case where a club is selected, so that the color works in layout.php */
if ($club_slug = ClubManagementService::getSelectedClubSlug()) {
DB::setupForClub($club_slug);
}
$clubs = ClubManagementService::listClubs();
?>
<?= actions()->link("/mgmt/new-club", "Add", "fa-plus")->link("/mgmt/logout", "Logout", attributes: ["class" => "destructive"]) ?>
Expand Down
2 changes: 1 addition & 1 deletion app/management/mg_login.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?php
managementPage("MGMT - login", false);
managementPage("MGMT - login");

$v = new Validator;
$password = $v->password("mgmt_pw")->required();
Expand Down
18 changes: 13 additions & 5 deletions app/pages/events/edit/ActivityEditForm.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
<?php
return function ($event_id = null, $activity_id = null, bool $is_simple = false, $post_link = "") {
$event = $event_id ? em()->find(Event::class, $event_id) : null;
if ($event_id) {
$event = em()->find(Event::class, $event_id);
} else {
// the only way this function is called with no event_id is from the creation of a simple event
$event = new Event();
$event->type = EventType::Simple;
}

if ($event_id && !$event) {
return "this event does not exist";
Expand All @@ -15,8 +21,9 @@
return;
}

if ($activity_id || $event?->type == EventType::Simple) {
$activity = em()->find(Activity::class, $activity_id ?? $event?->activities[0]);
//handle the case when you EDIT an activity OR a simple event
if ($activity_id || ($event->type == EventType::Simple && $event_id)) {
$activity = em()->find(Activity::class, $activity_id ?? $event->activities[0]);
$form_values = [
"name" => $activity->name,
"date" => date_format($activity->date, "Y-m-d"),
Expand All @@ -33,7 +40,7 @@
$activity = new Activity();
}

$item_name = ($event && !($event?->type == EventType::Simple)) ? "activité" : "événement";
$item_name = ($event_id && !($event->type == EventType::Simple)) ? "activité" : "événement";

$type_array = ["RACE" => "Course", "TRAINING" => "Entraînement", "OTHER" => "Autre"];

Expand Down Expand Up @@ -91,12 +98,12 @@
}
// With a simple event, we need to edit the event as well
if ($is_simple) {
$event ??= new Event();
$event->set($name->value, $date->value, $date->value, $deadline->value, "");
$event->type = EventType::Simple;
GoogleCalendarService::updateEvent($event);
em()->persist($event);
}
GroupService::processEventGroupChoice($event);
$activity->event = $event;
em()->persist($activity);
em()->flush();
Expand Down Expand Up @@ -127,6 +134,7 @@
</div>
<?php endif ?>
<?= $description->render() ?>
<?= GroupService::renderEventGroupChoice($event) ?>
<div class="col-auto">
<h2>Catégories</h2>
</div>
Expand Down
3 changes: 2 additions & 1 deletion app/pages/events/edit/EventEditForm.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<?php
restrict_access(Access::$ADD_EVENTS);

$event_type = get_query_param("type", false, false);
$event_id = get_route_param("event_id", strict: false);

Expand Down Expand Up @@ -43,6 +42,7 @@
$event->type = EventType::Complex;
$event->description = $description->value;
GoogleCalendarService::updateEvent($event);
GroupService::processEventGroupChoice($event);
em()->persist($event);
em()->flush();
Toast::success("Enregistré");
Expand All @@ -69,5 +69,6 @@
data-intro="Vous pouvez formatter le texte de la description en markdown. N'hésitez pas à aller voir <a href='https://www.markdownguide.org/' target='_blank'>cette ressource</a>">
<?= $description->attributes(["rows" => "8"])->render() ?>
</div>
<?= GroupService::renderEventGroupChoice($event) ?>
</article>
</form>
5 changes: 3 additions & 2 deletions app/pages/events/event_list/RenderEvents.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
<?php
function render_events(EventDto $event)
{

$diff = date_create('now')->diff($event->deadline->add(new DateInterval("PT23H59M59S")));
$limit_class = $tooltip_content = "";
if ($diff->invert) {
Expand All @@ -14,7 +13,8 @@ function render_events(EventDto $event)
$diff->format("Plus que %h heures!") :
$diff->format("Dans %d jour" . ($diff->days == 1 ? "" : "s")))
. "\"";
} ?>
}
$groups = GroupService::getEventGroups($event->id) ?>

<article class="event-article" hx-trigger="click,keyup[key=='Enter'||key==' ']" onkeydown="console.log(event.key)"
hx-get="/evenements/<?= $event->id ?>" hx-target="body" hx-push-url="true" tabindex=0>
Expand All @@ -37,6 +37,7 @@ function render_events(EventDto $event)
<?= $event->name ?>
</b>
</div>
<?= GroupService::renderTags($groups) ?>
<div class="dates">
<span>
<?= format_date($event->start) ?>
Expand Down
2 changes: 2 additions & 0 deletions app/pages/events/view/ActivityView.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@
$activity = em()->find(Activity::class, get_route_param("activity_id"));
}

$groups = GroupService::getEventGroups($event->id);
?>

<article>
<?= GroupService::renderTags($groups, delimiter: $groups) ?>
<div class="horizontal">
<div>
<?= IconText($activity->type->toIcon(), $activity->type->toName()) ?>
Expand Down
1 change: 1 addition & 0 deletions app/pages/events/view/event_view.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@
?>
<article>
<header>
<?= GroupService::renderTags($event->groups, delimiter: $event->groups) ?>
<div class="row g-2 center align-center">
<div class="col-12">
<?= RenderTimeline($event, !!$entry?->present) ?>
Expand Down
5 changes: 4 additions & 1 deletion app/pages/files/download_file.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
<?php
restrict_access(Access::$ADD_EVENTS);
restrict_access();
$file_id = $_GET['id'];

$db = DB::getInstance();
$file = $db->em()->find(SharedFile::class, $file_id);
if (in_array($file->permission_level, Access::$ADD_EVENTS)) {
restrict_access(Access::$ADD_EVENTS);
}
$path = Path::uploads($file->path);

if (file_exists($path)) {
Expand Down
34 changes: 34 additions & 0 deletions app/pages/links/link_delete.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php
restrict_access();

$form = new Validator(action: "confirm-delete");

$link_id = get_route_param("link_id");
$link = em()->find(Link::class, $link_id);
if (!$link) {
force_404("the link of id $link_id doesn't exist");
}
if ($form->valid()) {
logger()->info("Link {link_id} deleted by user {currentUserLogin}", ['link_id' => $link_id, 'currentUserLogin' => User::getCurrent()->login]);
em()->remove($link);
em()->flush();
Toast::error("Lien supprimé");
redirect("/liens-utiles");
}

page("Confirmation de suppression");
?>
<form method="post">
<div class="row center">
<?= $form->render_validation() ?>
<p>Sûr de vouloir supprimer le lien
<?= "$link->button_text" ?> ? Il sera définitivement supprimé!!
</p>
<div class="col-auto">
<a class="secondary" role="button" href="/liens-utiles">Annuler</a>
</div>
<div class="col-auto">
<button type="submit" name="delete" value="true" class="destructive">Supprimer</button>
</div>
</div>
</form>
16 changes: 16 additions & 0 deletions app/pages/links/link_line.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

$link = Component::prop("link");
$disable_delete = Component::prop("disable_delete");

?>
<hr>
<div class="link-grid">
<div>
<a href=<?= $link->url ?> target="#blank" role="button"><?= $link->button_text ?></a>
</div>
<div><?= $link->description ?></div>
<?php if (!$disable_delete && check_auth(Access::$EDIT_USERS)): ?>
<a href="/liens-utiles/supprimer/<?= $link->id ?>"><del><i class="fas fa-trash"></i></del></a>
<?php endif ?>
</div>
Loading