Skip to content

Commit

Permalink
Allow filtering motion list for To Do items
Browse files Browse the repository at this point in the history
  • Loading branch information
CatoTH committed Jul 15, 2023
1 parent 5db211e commit ded212b
Show file tree
Hide file tree
Showing 18 changed files with 164 additions and 49 deletions.
1 change: 1 addition & 0 deletions History.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
- It can now be set up so that the modified version proposed as part of a proposed procedure is shown inline as part of the motion.
- Besides of exporting all motions as a ZIP-file containing single ODT files, a single ODT file containing all motion texts can now be exported.
- The ODT export now also supports numbered lists.
- The motion list can now be filtered for To Do items (that is, motions/amendments that need to be screened).
- Bugfix: Some edge cases around uploaded logos breaking the PDF export or not being shown on the page were resolved.
- Bugfix: Super-admins could lock themselves out of protected consultations.

Expand Down
4 changes: 4 additions & 0 deletions messages/de/admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@
'index_flush_caches' => 'Alle System-Caches leeren',
'index_flushed_cached' => 'Die Caches wurden geleert',
'index_todo' => 'To Do',
'index_todo_motions' => 'To Do\'s in der Antragsliste anzeigen',
'index_todo_none' => 'Keine Einträge',
'index_site_del' => 'Seite löschen',
'index_pages' => 'Redaktionelle Seiten',
'motion_prefix_collision' => 'Das angegebene Antragskürzel wird bereits von einem anderen Antrag verwendet.',
Expand Down Expand Up @@ -206,6 +208,8 @@
'filter_agenda_item' => 'Tagesordnungspunkt',
'filter_prefix' => 'Antragsnr.',
'filter_responsibility' => 'Zuständigkeit',
'filter_show_replaced' => 'Ersetzte / alte Versionen anzeigen (%NUM%)',
'filter_only_todo' => 'Nur "To Do"\'s anzeigen (%NUM%)',

'con_email_from' => 'Absender-Name',
'con_email_from_place' => 'Standard: "%NAME%"',
Expand Down
4 changes: 4 additions & 0 deletions messages/en/admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@
'index_flush_caches' => 'Flush system caches',
'index_flushed_cached' => 'All caches have been flushed',
'index_todo' => 'To Do',
'index_todo_motions' => 'Show To Do\'s in motion list',
'index_todo_none' => 'No entries',
'index_site_del' => 'Delete site',
'index_pages' => 'Content pages',
'amend_deleted' => 'The amendment has been deleted.',
Expand Down Expand Up @@ -210,6 +212,8 @@
'filter_agenda_item' => 'Agenda item',
'filter_prefix' => 'Signature',
'filter_responsibility' => 'Responsibility',
'filter_show_replaced' => 'Show old / replaced versions (%NUM%)',
'filter_only_todo' => 'Show only "To Do"\'s (%NUM%)',

'con_email_from' => 'From Name',
'con_email_from_place' => 'Standard: "%NAME%"',
Expand Down
44 changes: 26 additions & 18 deletions models/AdminTodoItem.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace app\models;

use app\models\settings\AntragsgruenApp;
Expand All @@ -10,24 +12,20 @@

class AdminTodoItem
{
/** @var string */
public string $todoId;
public string $title;
public string $action;
public string $link;
public string $description;
public ?string $titlePrefix;
public int $timestamp;

public function __construct(string $todoId, string $title, string $action, string $link, int $timestamp, string $description, ?string $titlePrefix)
{
$this->todoId = $todoId;
$this->link = $link;
$this->title = $title;
$this->action = $action;
$this->timestamp = $timestamp;
$this->description = $description;
$this->titlePrefix = $titlePrefix;
public const TARGET_MOTION = 1;
public const TARGET_AMENDMENT = 2;

public function __construct(
public string $todoId,
public string $title,
public string $action,
public string $link,
public int $timestamp,
public string $description,
public ?int $targetType,
public ?int $targetId,
public ?string $titlePrefix
) {
}

private static array $todoCache = [];
Expand Down Expand Up @@ -57,6 +55,8 @@ private static function addMissingStatutesItem(Consultation $consultation, array
0,
$description,
null,
null,
null,
);
}
}
Expand Down Expand Up @@ -84,6 +84,8 @@ private static function addScreeningMotionsItems(Consultation $consultation, arr
UrlHelper::createUrl(['/admin/motion/update', 'motionId' => $motion->id]),
Tools::dateSql2timestamp($motion->dateCreation),
$description,
self::TARGET_MOTION,
$motion->id,
$motion->getFormattedTitlePrefix(),
);
}
Expand Down Expand Up @@ -111,6 +113,8 @@ private static function addScreeningAmendmentItems(Consultation $consultation, a
UrlHelper::createUrl(['/admin/amendment/update', 'amendmentId' => $amend->id]),
Tools::dateSql2timestamp($amend->dateCreation),
$description,
self::TARGET_AMENDMENT,
$amend->id,
$amend->getFormattedTitlePrefix(),
);
}
Expand Down Expand Up @@ -138,6 +142,8 @@ private static function addScreeningMotionComments(Consultation $consultation, a
$comment->getLink(),
Tools::dateSql2timestamp($comment->dateCreation),
$description,
self::TARGET_MOTION,
$comment->motionId,
$comment->getIMotion()->getFormattedTitlePrefix(),
);
}
Expand Down Expand Up @@ -165,6 +171,8 @@ private static function addScreeningAmendmentComments(Consultation $consultation
$comment->getLink(),
Tools::dateSql2timestamp($comment->dateCreation),
$description,
self::TARGET_AMENDMENT,
$comment->amendmentId,
$comment->getIMotion()->getFormattedTitlePrefix(),
);
}
Expand Down
81 changes: 63 additions & 18 deletions models/forms/AdminMotionFilterForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@

namespace app\models\forms;

use app\models\settings\AntragsgruenApp;
use app\models\settings\PrivilegeQueryContext;
use app\models\settings\Privileges;
use app\models\AdminTodoItem;
use app\models\settings\{AntragsgruenApp, PrivilegeQueryContext, Privileges};
use app\components\{Tools, UrlHelper};
use app\models\db\{Amendment, AmendmentSupporter, Consultation, ConsultationSettingsTag, IMotion, ISupporter, Motion, MotionSupporter, User};
use yii\helpers\Html;
Expand Down Expand Up @@ -35,29 +34,27 @@ class AdminMotionFilterForm
public ?string $title = null;
public ?string $prefix = null;

/** @var Motion [] */
public array $allMotions;

/** @var Amendment[] */
public array $allAmendments;
public Consultation $consultation;

public int $sort = self::SORT_TITLE_PREFIX;
protected bool $showScreening;

public bool $showReplaced = false;
public bool $onlyTodo = false;
public int $numReplaced;
public int $numTodo;

/** @var string[] */
protected array $route;

/**
* @param Motion[] $allMotions
*/
public function __construct(Consultation $consultation, array $allMotions, bool $showScreening)
{
$this->showScreening = $showScreening;
$this->consultation = $consultation;
public function __construct(
public Consultation $consultation,
public array $allMotions,
protected bool $showScreening
) {
$this->allMotions = [];
$this->allAmendments = [];
foreach ($allMotions as $motion) {
Expand Down Expand Up @@ -112,6 +109,7 @@ public function setAttributes(array $values): void
}

$this->showReplaced = isset($values['showReplaced']) && $values['showReplaced'] === '1';
$this->onlyTodo = isset($values['onlyTodo']) && $values['onlyTodo'] === '1';
}

private ?array $versionNames = null;
Expand Down Expand Up @@ -468,6 +466,40 @@ private function calcAndFilterReplacedMotions(array $motions): array
return $out;
}

/**
* @param IMotion[] $imotions
* @return IMotion[]
*/
private function calcAndFilterTodoItems(array $imotions): array
{
$todoMotionIds = [];
$todoAmendmentIds = [];
foreach (AdminTodoItem::getConsultationTodos($this->consultation) as $item) {
if ($item->targetType === AdminTodoItem::TARGET_MOTION) {
$todoMotionIds[] = $item->targetId;
}
if ($item->targetType === AdminTodoItem::TARGET_AMENDMENT) {
$todoAmendmentIds[] = $item->targetId;
}
}

$this->numTodo = count($todoMotionIds) + count($todoAmendmentIds);

if ($this->onlyTodo) {
return array_values(array_filter($imotions, function (IMotion $imotion) use ($todoMotionIds, $todoAmendmentIds): bool {
if (is_a($imotion, Motion::class)) {
return in_array($imotion->id, $todoMotionIds);
}
if (is_a($imotion, Amendment::class)) {
return in_array($imotion->id, $todoAmendmentIds);
}
return false;
}));
} else {
return $imotions;
}
}

/**
* @return Motion[]
*/
Expand Down Expand Up @@ -520,7 +552,10 @@ public function getFilteredMotions(): array
}
}

return $this->calcAndFilterReplacedMotions($out);
$out = $this->calcAndFilterReplacedMotions($out);
$out = $this->calcAndFilterTodoItems($out);

return $out;

Check failure on line 558 in models/forms/AdminMotionFilterForm.php

View workflow job for this annotation

GitHub Actions / evaluate-pr

Method app\models\forms\AdminMotionFilterForm::getFilteredMotions() should return array<app\models\db\Motion> but returns array<app\models\db\IMotion>.
}


Expand Down Expand Up @@ -803,11 +838,21 @@ public function getFilterFormFields(bool $responsibilities): string

$str .= '</div>';

if ($this->numReplaced > 0) {
$str .= '<div class="filtersBottom"><label>';
$str .= Html::checkbox('Search[showReplaced]', $this->showReplaced, ['value' => '1', 'id' => 'filterShowReplaced']);
$str .= ' ' . str_replace('%NUM%', (string)$this->numReplaced, 'Ersetzte / alte Versionen anzeigen (%NUM%)');
$str .= '</label></div>';
if ($this->numReplaced > 0 || $this->numTodo > 0) {
$str .= '<div class="filtersBottom">';
if ($this->numReplaced > 0) {
$str .= '<label>';
$str .= Html::checkbox('Search[showReplaced]', $this->showReplaced, ['value' => '1', 'id' => 'filterShowReplaced']);
$str .= ' ' . str_replace('%NUM%', (string)$this->numReplaced, \Yii::t('admin', 'filter_show_replaced'));
$str .= '</label> &nbsp; ';
}
if ($this->numTodo > 0) {
$str .= '<label>';
$str .= Html::checkbox('Search[onlyTodo]', $this->onlyTodo, ['value' => '1', 'id' => 'filterOnlyTodo']);
$str .= ' ' . str_replace('%NUM%', (string)$this->numTodo, \Yii::t('admin', 'filter_only_todo'));
$str .= '</label>';
}
$str .= '</div>';
}

return $str;
Expand Down
12 changes: 6 additions & 6 deletions plugins/dbwv/commands/SetupController.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class SetupController extends Controller
private const AGENDA_ITEMS_SACHGEBIETE = [
[
'title' => 'Sachgebiet I - Sicherheits- und Verteidigungspolitik; Einsätze und Missionen; Europa',
'motionPrefix' => 'I / ',
'motionPrefix' => 'I/',
'position' => 1,
'themengebiete' => [
[
Expand All @@ -43,31 +43,31 @@ class SetupController extends Controller
],
[
'title' => 'Sachgebiet II',
'motionPrefix' => 'II / ',
'motionPrefix' => 'II/',
'position' => 2,
'themengebiete' => [],
],
[
'title' => 'Sachgebiet III - Dienst- und Laufbahnrecht',
'motionPrefix' => 'III / ',
'motionPrefix' => 'III/',
'position' => 3,
'themengebiete' => [],
],
[
'title' => 'Sachgebiet IV',
'motionPrefix' => 'IV / ',
'motionPrefix' => 'IV/',
'position' => 4,
'themengebiete' => [],
],
[
'title' => 'Sachgebiet V',
'motionPrefix' => 'V / ',
'motionPrefix' => 'V/',
'position' => 5,
'themengebiete' => [],
],
[
'title' => 'Sachgebiet VI',
'motionPrefix' => 'VI / ',
'motionPrefix' => 'VI/',
'position' => 6,
'themengebiete' => [],
],
Expand Down
4 changes: 4 additions & 0 deletions plugins/dbwv/workflow/Step1.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ public static function getAdminTodo(Motion $motion): ?AdminTodoItem
UrlHelper::createMotionUrl($motion),
Tools::dateSql2timestamp($motion->dateCreation),
$motion->getInitiatorsStr(),
AdminTodoItem::TARGET_MOTION,
$motion->id,
$motion->getFormattedTitlePrefix(),
);
}
Expand All @@ -39,6 +41,8 @@ public static function getAdminTodo(Motion $motion): ?AdminTodoItem
UrlHelper::createMotionUrl($motion),
Tools::dateSql2timestamp($motion->dateCreation),
$motion->getInitiatorsStr(),
AdminTodoItem::TARGET_MOTION,
$motion->id,
$motion->getFormattedTitlePrefix(),
);
}
Expand Down
4 changes: 4 additions & 0 deletions plugins/dbwv/workflow/Step2.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ public static function getAdminTodo(Motion $motion): ?AdminTodoItem
UrlHelper::createUrl(['/admin/motion-list/index']),
Tools::dateSql2timestamp($motion->dateCreation),
$description,
AdminTodoItem::TARGET_MOTION,
$motion->id,
$motion->getFormattedTitlePrefix(),
);
}
Expand All @@ -42,6 +44,8 @@ public static function getAdminTodo(Motion $motion): ?AdminTodoItem
UrlHelper::createMotionUrl($motion),
Tools::dateSql2timestamp($motion->dateCreation),
$motion->getInitiatorsStr(),
AdminTodoItem::TARGET_MOTION,
$motion->id,
$motion->getFormattedTitlePrefix(),
);
}
Expand Down
8 changes: 6 additions & 2 deletions plugins/dbwv/workflow/Step3.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,25 +20,29 @@ public static function getAdminTodo(Motion $motion): ?AdminTodoItem
if (MotionNumbering::findMotionInHistoryOfVersion($motion, Workflow::STEP_V4)) {
return null;
}
if (Workflow::canSetRecommendationV2($motion) && $motion->proposalVisibleFrom === null) {
if (Workflow::canSetRecommendationV2($motion) && !$motion->isProposalPublic()) {
return new AdminTodoItem(
'todoDbwvSetPp' . $motion->id,
$motion->getTitleWithPrefix(),
'Verfahrensvorschlag veröffentlichen',
UrlHelper::createMotionUrl($motion),
Tools::dateSql2timestamp($motion->dateCreation),
$motion->getInitiatorsStr(),
AdminTodoItem::TARGET_MOTION,
$motion->id,
$motion->getFormattedTitlePrefix(),
);
}
if (Workflow::canSetResolutionV3($motion) && $motion->proposalVisibleFrom !== null) {
if (Workflow::canSetResolutionV3($motion) && $motion->isProposalPublic()) {
return new AdminTodoItem(
'todoDbwvSetPp' . $motion->id,
$motion->getTitleWithPrefix(),
'Beschluss erarbeiten',
UrlHelper::createMotionUrl($motion),
Tools::dateSql2timestamp($motion->dateCreation),
$motion->getInitiatorsStr(),
AdminTodoItem::TARGET_MOTION,
$motion->id,
$motion->getFormattedTitlePrefix(),
);
}
Expand Down
Loading

0 comments on commit ded212b

Please sign in to comment.