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

Various improvements #386

Merged
merged 1 commit 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
12 changes: 5 additions & 7 deletions app/components/user_card.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,19 @@ function UserCard($user, $image = null, $subtitle = null, $actions = null, $user
<img src="<?= $user->getPicture() ?>">
<?php endif; ?>

<?php if ($user_link): ?>
<?php $user_link() ?>
<?php else: ?>
<?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 if ($subtitle): ?>
<?php $subtitle($user); ?>
<?php endif; ?>
<?php $subtitle && $subtitle($user) ?>

<!-- Actions block -->
<?php if (isset($actions)): ?>
<?php if ($actions): ?>
<nav>
<ul>
<li>
Expand Down
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
29 changes: 23 additions & 6 deletions app/management/club_view.php
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
<?php
managementPage("View club");
restrict_management();
$slug = Router::getParameter("slug", pattern: '/[\w-]+/');
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 @@ -25,7 +27,7 @@

$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);
Expand Down Expand Up @@ -66,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 Down Expand Up @@ -113,4 +112,22 @@
<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>
1 change: 1 addition & 0 deletions app/management/clubs_list.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
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()) {
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
2 changes: 1 addition & 1 deletion app/services/ClubManagementService.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ static function clubExists($slug)
return file_exists(club_data_path($slug));
}

public function getClub()
public function getClub(): Club
{
$results = $this->db->em()->createQuery("SELECT c FROM Club c")->getResult();
if (!$results) {
Expand Down
4 changes: 2 additions & 2 deletions app/template/layout.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?php
$page = Page::getInstance(); ?>
$page = Page::getInstance();
$clubColor = array_key_exists("selected_club", $_SESSION) ? ClubManagementService::create()->getClubColor($_SESSION["selected_club"] ?? null) : null; ?>
<!doctype html>
<html lang="en">

Expand All @@ -22,7 +23,6 @@
<link rel="stylesheet" href="/assets/css/theme-toggle.css">

<!-- Pico.css -->
<?php $clubColor = array_key_exists("selected_club", $_SESSION) ? ClubManagementService::create()->getClubColor($_SESSION["selected_club"] ?? null) : null; ?>
<?php if ($clubColor != null): ?>
<link rel="stylesheet" href="/assets/css/pico.<?= $clubColor ?>.min.css">
<?php else: ?>
Expand Down
25 changes: 0 additions & 25 deletions assets/css/main.css
Original file line number Diff line number Diff line change
Expand Up @@ -720,31 +720,6 @@ sl-tab-group {
--sl-color-primary-600: var(--pico-primary);
}

.color-dot {
display: flex;
align-items: center;
justify-content: center;
aspect-ratio: 1 / 1;
border-radius: 50%;
}
.color-picker {
grid-gap: var(--pico-block-spacing-horizontal);
display: grid;
grid-template-columns: repeat(5, 1fr);
overflow: hidden;
border-top-right-radius: var(--pico-border-radius);
border-top-left-radius: var(--pico-border-radius);
margin-bottom: var(--pico-block-spacing-vertical);
}

@media (min-width: 768px) {
.color-picker {
grid-gap: calc(var(--pico-block-spacing-horizontal) * 0.5);
grid-template-columns: repeat(10, 1fr);
margin-bottom: var(--pico-block-spacing-vertical);
}
}

.tag {
display: inline-flex;
align-items: center;
Expand Down
1 change: 0 additions & 1 deletion engine/helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,6 @@ function page(string $title)

function managementPage(string $title, $restrict = true)
{
$restrict && restrict_management();
return page($title)->disableNav()->boost();
}

Expand Down
29 changes: 3 additions & 26 deletions engine/validation/fields/UploadField.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,32 +53,8 @@ class UploadField extends Field
'application/vnd.ms-powerpoint.addin.macroEnabled.12',
'application/vnd.openxmlformats-officedocument.presentationml.slide',
'application/vnd.oasis.opendocument.presentation',
]
];
/** @var array<array> */
public static array $IMAGE_MIME = [
'image' => [
'image/webp',
'image/tiff',
'image/png',
'image/jpeg',
'image/gif',
'image/x-ms-bmp',
'image/x-bmp',
'image/x-portable-bitmap',
'image/vnd.adobe.photoshop',
'image/x-eps',
'application/postscript',
'application/dicom',
'application/pcx',
'application/x-pcx',
'image/pcx',
'image/x-pc-paintbrush',
'image/x-pcx',
'zz-application/zz-winassoc-pcx',
'image/jp2',
'image/heif'
]
],
'zip' => ['application/zip'],
];
function set_type(): void
{
Expand Down Expand Up @@ -155,6 +131,7 @@ function mime(array $mimes): static
$this->allowed_mime = $mimes;
// Allow certain file formats
$finfo = new finfo(FILEINFO_MIME_TYPE);
logger()->debug("finfo", ["info" => $finfo->file($_FILES[$this->key]['tmp_name'])]);
// Flatten the array
$flatArray = array_reduce($this->allowed_mime, 'array_merge', []);
if (
Expand Down
2 changes: 1 addition & 1 deletion routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@
Router::add('/licencies/$user_id', __DIR__ . '/app/pages/users/user_view_modal.php');
Router::add('/licencies/$user_id/desactiver', __DIR__ . '/app/pages/users/user_deactivation_confirm.php');
Router::add('/licencies/$user_id/supprimer', __DIR__ . '/app/pages/users/user_delete_confirm.php');
Router::add('/licencies/$user_id/creer-famille', __DIR__ . '/app/pages/users/family_create.php');
Router::add('/licencies/$user_id/creer-famille', __DIR__ . '/app/pages/users/family/family_create.php');
Router::add('/licencies/$user_id/debug', __DIR__ . '/app/pages/users/user_debug.php');
// Familles
Router::add('/familles', __DIR__ . '/app/pages/users/family/family_list.php');
Expand Down