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

2025-01: Frontend enhancements #460

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
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 module/Database/migrations/Version20250126144021.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php

declare(strict_types=1);

namespace Database\Migrations;

use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;

/**
* Auto-generated Migration: Please modify to your needs!
*/
final class Version20250126144021 extends AbstractMigration
{
public function getDescription(): string
{
return 'Introduce query categories';
}

public function up(Schema $schema): void
{
// phpcs:disable SlevomatCodingStandard.Functions.RequireMultiLineCall.RequiredMultiLineCall
$this->addSql('ALTER TABLE savedquery ADD category VARCHAR(255)');
$this->addSql('UPDATE savedquery SET category = trim(split_part(name, \':\', 1)), name = trim(split_part(name, \':\', -1))');

Check warning on line 24 in module/Database/migrations/Version20250126144021.php

View workflow job for this annotation

GitHub Actions / php-codesniffer / PHP_CodeSniffer (8.3)

Line exceeds 120 characters; contains 133 characters
$this->addSql('ALTER TABLE savedquery ALTER COLUMN category SET NOT NULL');
// phpcs:enable SlevomatCodingStandard.Functions.RequireMultiLineCall.RequiredMultiLineCall
}

public function down(Schema $schema): void
{
// phpcs:disable SlevomatCodingStandard.Functions.RequireMultiLineCall.RequiredMultiLineCall
$this->addSql('UPDATE savedquery SET name = concat(category, \': \', name)');
$this->addSql('ALTER TABLE SavedQuery DROP category');
// phpcs:enable SlevomatCodingStandard.Functions.RequireMultiLineCall.RequiredMultiLineCall
}
}
3 changes: 3 additions & 0 deletions module/Database/src/Form/Fieldset/MemberFunction.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ public function __construct(
'label' => 'Functie',
'value_options' => InstallationFunctions::getFunctionsArray($translator, $withmember, $withLegacy),
],
'attributes' => [
'value' => InstallationFunctions::Member->value,
],
]);
}

Expand Down
6 changes: 6 additions & 0 deletions module/Database/src/Form/QueryExport.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace Database\Form;

use Laminas\Form\Element\Hidden;
use Laminas\Form\Element\Select;
use Laminas\InputFilter\InputFilterProviderInterface;
use Laminas\Mvc\I18n\Translator;
Expand All @@ -14,6 +15,11 @@ public function __construct(private readonly Translator $translator)
{
parent::__construct($this->translator);

$this->add([
'name' => 'name',
'type' => Hidden::class,
]);

$this->add([
'name' => 'type',
'type' => Select::class,
Expand Down
10 changes: 9 additions & 1 deletion module/Database/src/Form/QuerySave.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,14 @@ public function __construct(private readonly Translator $translator)
{
parent::__construct($this->translator);

$this->add([
'name' => 'category',
'type' => Text::class,
'options' => [
'label' => $this->translator->translate('Category'),
],
]);

$this->add([
'name' => 'name',
'type' => Text::class,
Expand All @@ -29,7 +37,7 @@ public function __construct(private readonly Translator $translator)
'type' => Submit::class,
'attributes' => [
'label' => $this->translator->translate('Save'),
'value' => $this->translator->translate('Save'),
'value' => 'save',
],
]);
}
Expand Down
2 changes: 1 addition & 1 deletion module/Database/src/Mapper/SavedQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public function findByName(string $name): ?SavedQueryModel
public function findAll(): array
{
$qb = $this->getRepository()->createQueryBuilder('q');
$qb->add('orderBy', 'lower(q.name) ASC');
$qb->add('orderBy', 'lower(q.category), lower(q.name) ASC');

return $qb->getQuery()->getResult();
}
Expand Down
22 changes: 22 additions & 0 deletions module/Database/src/Model/SavedQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@ class SavedQuery
#[GeneratedValue(strategy: 'AUTO')]
protected ?int $id = null;

/**
* Category.
*/
#[Column(type: 'string')]
protected string $category;

/**
* Name.
*/
Expand Down Expand Up @@ -69,6 +75,22 @@ public function setName(string $name): void
$this->name = $name;
}

/**
* Get the category.
*/
public function getCategory(): string
{
return $this->category;
}

/**
* Set the category.
*/
public function setCategory(string $category): void
{
$this->category = $category;
}

/**
* Set the query.
*/
Expand Down
4 changes: 3 additions & 1 deletion module/Database/src/Service/FrontPage.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ public function getFrontpageData(): array

public function getNotificationCount(): int
{
return $this->memberService->getPendingUpdateCount() + (int) $this->apiService->isSyncPaused();
return $this->memberService->getPendingUpdateCount() +
(int) $this->apiService->isSyncPaused() +
$this->memberService->getPaidProspectivesCount();
}
}
9 changes: 9 additions & 0 deletions module/Database/src/Service/Member.php
Original file line number Diff line number Diff line change
Expand Up @@ -997,6 +997,15 @@ public function getPendingUpdateCount(): int
return $this->getMemberUpdateMapper()->getRepository()->count([]);
}

/**
* Paid prospective members (separately from frontpage data to reduce number
* of database queries)
*/
public function getPaidProspectivesCount(): int
{
return count($this->getProspectiveMemberMapper()->search('', 'paid'));
}

/**
* Get a list of all pending member updates.
*
Expand Down
2 changes: 2 additions & 0 deletions module/Database/src/Service/Query.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ public function save(array $data): ?SavedQueryModel
{
$form = $this->getQuerySaveForm();

// This is an intentional choice to find the query by name
// (we require unique names even across categories)
$query = $this->getSavedQueryMapper()->findByName($data['name']);
if (null !== $query) {
$form->bind($query);
Expand Down
98 changes: 56 additions & 42 deletions module/Database/view/database/index/index.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ use Laminas\View\Renderer\PhpRenderer;
* @var int $totalCount
*/

$twoColumnMode = $totalCount > 0;
?>
<div class="row">
<div class="col-md-12">
Expand All @@ -25,7 +24,7 @@ $twoColumnMode = $totalCount > 0;
</div>
</div>
<div class="row">
<div class="<?= $twoColumnMode ? 'col-md-8' : 'col-md-12'?>">
<div class="col-md-8">
<p>
<?= sprintf(
$this->translate('GEWIS currently has <a href="%s">%d members</a> (+%d expired) and <a href="%s">%d prospective members (%d paid, %d unpaid)</a>. <a href="%s">Click here</a> to create a meeting or <a href="%s">perform a query</a>.'),
Expand All @@ -47,55 +46,70 @@ $twoColumnMode = $totalCount > 0;
) ?>
</p>
</div>
<div class="col-md-4">
<?php if (0 < $updates): ?>
<div class="col-md-4">
<div class="panel panel-info">
<div class="panel-heading"><?= $this->translate('Pending member updates') ?></div>
<div class="panel-body">
<p>
<?= sprintf(
$this->translatePlural(
'There is currently <a href="%s">%d update</a> pending approval.',
'There are currently <a href="%s">%d updates</a> pending approval.',
$updates,
),
$this->url('member/updates'),
<div class="panel panel-info">
<div class="panel-heading"><?= $this->translate('Pending member updates') ?></div>
<div class="panel-body">
<p>
<?= sprintf(
$this->translatePlural(
'There is currently <a href="%s">%d update</a> pending approval.',
'There are currently <a href="%s">%d updates</a> pending approval.',
$updates,
) ?>
</p>
</div>
),
$this->url('member/updates'),
$updates,
) ?>
</p>
</div>
</div>
<?php endif; ?>
<?php if ($syncPaused && null !== $syncPausedUntil): ?>
<div class="col-md-4">
<div class="panel panel-info">
<div class="panel-heading"><?= $this->translate('Synchronisation paused') ?></div>
<div class="panel-body">
<p>
<?php
$syncPausedDifference = $syncPausedUntil->getTimestamp() - (new DateTime())->getTimestamp();
if ($syncPausedDifference > 3600) {
echo sprintf(
$this->translate(
'Synchronisation with other systems is paused until %s.',
),
$syncPausedUntil->format(DateTimeInterface::ATOM),
);
} else {
echo sprintf(
$this->translate(
'Synchronisation with other systems is paused and will resume in %d minutes.',
),
(int) $syncPausedDifference/60,
);
}
?>
</p>
</div>
<div class="panel panel-info">
<div class="panel-heading"><?= $this->translate('Synchronisation paused') ?></div>
<div class="panel-body">
<p>
<?php
$syncPausedDifference = $syncPausedUntil->getTimestamp() - (new DateTime())->getTimestamp();
if ($syncPausedDifference > 3600) {
echo sprintf(
$this->translate(
'Synchronisation with other systems is paused until %s.',
),
$syncPausedUntil->format(DateTimeInterface::ATOM),
);
} else {
echo sprintf(
$this->translate(
'Synchronisation with other systems is paused and will resume in %d minutes.',
),
(int) $syncPausedDifference/60,
);
}
?>
</p>
</div>
</div>
<?php endif; ?>
<?php if (0 < $prospectives['paid']): ?>
<div class="panel panel-warning">
<div class="panel-heading"><?= $this->translate('Prospective Members') ?></div>
<div class="panel-body">
<p>
<?php
echo sprintf(
$this->translate(
'%s prospective member(s) have paid and are pending approval.',
),
$prospectives['paid'],
);
?>
</p>
</div>
</div>
<?php endif; ?>
</div>
</div>
<div class="row">
<div class="col-md-12">
Expand Down
42 changes: 23 additions & 19 deletions module/Database/view/database/query/index.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ $this->headScript()->appendFile($this->basePath() . '/js/codemirror-compressed.j
<?php
/* These are part of the QuerySave form */ ?>
<div class="form-group">
<input type="text" class="form-control input-small" name="category" placeholder="<?= $this->translate('Category') ?>">
<input type="text" class="form-control input-small" name="name" placeholder="<?= $this->translate('Name') ?>">
</div>
<button class="btn btn-success" name="submit_save" type="submit">
Expand All @@ -68,38 +69,41 @@ $this->headScript()->appendFile($this->basePath() . '/js/codemirror-compressed.j
<?php
$prefix = null;
foreach ($saved as $query):
if ($prefix !== strtoupper(explode(":", $query->getName(), 2)[0])):
$prefix = strtoupper(explode(":", $query->getName(), 2)[0]);
if ($prefix !== $query->getCategory()):
$prefix = $query->getCategory();
?>
</ul>
</li>
<li><b><?= $prefix ?></b>
<ul>
<?php endif; ?>
<li>
<a href="<?= $this->url('query/show', ['query' => $query->getId()]) ?>">
<?=
explode(
":",
$query->getName(),
2,
)[1] ?>
</a>
</li>
</ul>
</li>
<li><b><?= $prefix ? $prefix : $this->translate('No category') ?></b>
<ul>
<?php endif; ?>
<li>
<a href="<?= $this->url('query/show', ['query' => $query->getId()]) ?>">
<?= $query->getName() ?>
</a>
</li>
<?php endforeach; ?>
</ul>
</li>
</ul>

<?=
<p>
<?= $this->translate('Saving a query with a previously used name will overwrite the previously saved query and update its category.') ?>
</p>

<p>
<?=
sprintf(
$this->translate('For an overview of how you can use the Doctrine Query Language (DQL) please refer to %sits documentation%s.'),
'<a href="https://www.doctrine-project.org/projects/doctrine-orm/en/current/reference/dql-doctrine-query-language.html">',
'</a>',
)
?>
?>
</p>

<p>
<?= $this->translate('The entities that you can use:') ?>
</p>
<ul>
<?php foreach ($entities as $entity): ?>
<li><?= $entity; ?></li>
Expand Down
Loading