Skip to content
Open
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
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

* [PR-25](https://github.com/itk-dev/itk-projects/pull/25)
Add a Topic field to initiatives, naming the wider programme an initiative is
part of. Shown under the title on the form and on the initiative page, covered
by the free-text filter, and included in the CSV export.

## [0.2.0] - 2026-06-30

* [PR-23](https://github.com/itk-dev/itk-projects/pull/23)
Expand Down
26 changes: 26 additions & 0 deletions migrations/Version20260814131716.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

declare(strict_types=1);

namespace DoctrineMigrations;

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

final class Version20260814131716 extends AbstractMigration
{
public function getDescription(): string
{
return 'Add the topic column to initiative.';
}

public function up(Schema $schema): void
{
$this->addSql('ALTER TABLE initiative ADD topic LONGTEXT DEFAULT NULL');
}

public function down(Schema $schema): void
{
$this->addSql('ALTER TABLE initiative DROP topic');
}
}
4 changes: 3 additions & 1 deletion src/Controller/InitiativeController.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@ public function export(Request $request, InitiativeRepository $initiatives, Tran
$response = new StreamedResponse(function () use ($rows, $translator, $translate): void {
$csv = Writer::createFromStream(fopen('php://output', 'w'));
$csv->insertOne([
'id', $translator->trans('initiative.title'), $translator->trans('initiative.status'),
'id', $translator->trans('initiative.title'), $translator->trans('initiative.topic'),
$translator->trans('initiative.status'),
$translator->trans('initiative.area'), $translator->trans('initiative.initiative_type'),
$translator->trans('initiative.organizational_anchoring'), $translator->trans('initiative.endorsement'),
$translator->trans('initiative.endorsement_author'), $translator->trans('initiative.budget'),
Expand All @@ -80,6 +81,7 @@ public function export(Request $request, InitiativeRepository $initiatives, Tran
$csv->insertOne([
(string) $row->getId(),
$row->getTitle(),
$row->getTopic(),
$translate($row->getStatus()),
$row->getArea()?->getName(),
$translate($row->getInitiativeType()),
Expand Down
11 changes: 11 additions & 0 deletions src/DataFixtures/AppFixtures.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@ class AppFixtures extends Fixture
private const array STRATEGIES = ['Klimaplan 2030', 'Erhvervsplan', 'Børn- og ungepolitik', 'Mobilitetsplan', 'Digitaliseringsstrategi', 'Sundhedspolitik'];
private const array DEPARTMENTS = ['ITK Development', 'CFIA', 'Aarhus CityLab', 'Stab', 'OS2', 'AI Lab', 'IOT Lab', 'GTM', 'Fut Lab'];
private const array AREAS = ['Klima og miljø', 'Mobilitet', 'Velfærd', 'Kultur og fritid', 'Uddannelse', 'Erhverv', 'Digitalisering', 'Byudvikling'];
private const array TOPICS = [
'Digital Europe Blueprint for Data Space for smart and sustainable cities and communities.',
'Horizon Europe — Climate-neutral and smart cities mission.',
'Den fællesoffentlige digitaliseringsstrategi 2022–2026.',
'Interreg Øresund-Kattegat-Skagerrak.',
];

public function __construct(private readonly UserPasswordHasherInterface $hasher)
{
Expand Down Expand Up @@ -127,6 +133,11 @@ public function load(ObjectManager $manager): void
->setBudget(mt_rand(1, 40) * 50000);
$initiative->setCreatedBy($users[array_rand($users)]);

// Not every initiative belongs to a wider programme.
if (0 !== $index % 3) {
$initiative->setTopic(self::TOPICS[$index % \count(self::TOPICS)]);
}

if (0 !== $index % 4) {
$initiative->setEndorsementAuthor($endorsers[array_rand($endorsers)]);
}
Expand Down
20 changes: 20 additions & 0 deletions src/Entity/Initiative.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,14 @@ class Initiative extends AbstractEntity
#[ORM\Column(length: 255)]
private ?string $title = null;

/**
* Which wider programme the initiative is a part of — the title names this
* project, the topic places it ("DS4SSCC" → "Digital Europe Blueprint for
* Data Space for smart and sustainable cities and communities").
*/
#[ORM\Column(type: Types::TEXT, nullable: true)]
private ?string $topic = null;

#[ORM\ManyToOne(targetEntity: Area::class)]
#[ORM\JoinColumn(onDelete: 'SET NULL')]
private ?Area $area = null;
Expand Down Expand Up @@ -134,6 +142,18 @@ public function setTitle(?string $title): static
return $this;
}

public function getTopic(): ?string
{
return $this->topic;
}

public function setTopic(?string $topic): static
{
$this->topic = $topic;

return $this;
}

public function getArea(): ?Area
{
return $this->area;
Expand Down
6 changes: 6 additions & 0 deletions src/Form/InitiativeType.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,12 @@ public function buildForm(FormBuilderInterface $builder, array $options): void
'label' => 'initiative.title',
'help' => 'initiative.title_help',
])
->add('topic', TextareaType::class, [
'label' => 'initiative.topic',
'required' => false,
'attr' => ['rows' => 4],
'help' => 'initiative.topic_help',
])
->add('area', EntityType::class, [
'label' => 'initiative.area',
'class' => Area::class,
Expand Down
1 change: 1 addition & 0 deletions src/Repository/InitiativeRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ public function search(InitiativeFilter $filter): QueryBuilder

$ors = [
'LOWER(i.title) LIKE :q',
'LOWER(i.topic) LIKE :q',
'LOWER(i.description) LIKE :q',
'LOWER(i.statusAdditional) LIKE :q',
// Related names, matched without joining the root query so the
Expand Down
1 change: 1 addition & 0 deletions templates/initiative/_form.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
{% set title_attr = {'data-action': 'input->title-mirror#update', 'data-autosave-required': true} %}
{% if not initiative.id %}{% set title_attr = title_attr|merge({autofocus: true}) %}{% endif %}
{{ form_row(form.title, {attr: title_attr}) }}
{{ form_row(form.topic) }}
<div class="form-grid">
{{ form_row(form.area) }}
{{ form_row(form.initiativeType) }}
Expand Down
4 changes: 4 additions & 0 deletions templates/initiative/show.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@
<twig:Card:Header :title="'initiative.show.details'|trans" />
<div class="card__body">
{% if initiative.description %}<p class="prose">{{ initiative.description }}</p>{% else %}<p class="muted">—</p>{% endif %}
{% if initiative.topic %}
<h3 class="detail-subhead">{{ 'initiative.topic'|trans }}</h3>
<p class="prose">{{ initiative.topic }}</p>
{% endif %}
{% if initiative.statusAdditional %}
<h3 class="detail-subhead">{{ 'initiative.status_additional'|trans }}</h3>
<p class="prose">{{ initiative.statusAdditional }}</p>
Expand Down
31 changes: 31 additions & 0 deletions tests/Controller/InitiativeControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,37 @@ public function testNewPersistsInitiativeWithInlineContactAndDropsEmptyMedia():
$em->flush();
}

public function testTopicIsSavedShownSearchableAndExported(): void
{
$this->loginAsAdmin();
$topic = 'Digital Europe Blueprint '.uniqid();

$crawler = $this->client->request('GET', '/initiatives/new');
$token = (string) $crawler->filter('input[name="initiative[_token]"]')->attr('value');
$this->client->request('POST', '/initiatives/new', [
'initiative' => ['title' => 'Topic initiative', 'topic' => $topic, '_token' => $token],
]);
$this->assertResponseRedirects();

$initiative = $this->initiatives()->findOneBy(['title' => 'Topic initiative']);
self::assertInstanceOf(Initiative::class, $initiative);
self::assertSame($topic, $initiative->getTopic());
$id = (string) $initiative->getId();

$crawler = $this->client->request('GET', '/initiatives/'.$id);
self::assertStringContainsString($topic, $crawler->filter('.card__body')->first()->text());

// The free-text filter searches the topic alongside title and description.
$crawler = $this->client->request('GET', '/initiatives?q='.urlencode($topic));
self::assertStringContainsString('Topic initiative', $crawler->filter('#initiative-results')->text());

$this->client->request('GET', '/initiatives/export?q='.urlencode($topic));
$csv = (string) $this->client->getInternalResponse()->getContent();
self::assertStringContainsString($topic, $csv);

$this->removeInitiative($id);
}

public function testEditUpdatesInitiative(): void
{
$this->loginAsAdmin();
Expand Down
2 changes: 2 additions & 0 deletions tests/Unit/Entity/InitiativeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ public function testScalarAccessors(): void

$initiative = (new Initiative())
->setTitle('Grøn omstilling')
->setTopic('Digital Europe Blueprint for Data Space')
->setArea($area)
->setDescription('Beskrivelse')
->setInitiativeType(InitiativeType::Project)
Expand All @@ -61,6 +62,7 @@ public function testScalarAccessors(): void
->setTimePeriodEnd($end);

self::assertSame('Grøn omstilling', $initiative->getTitle());
self::assertSame('Digital Europe Blueprint for Data Space', $initiative->getTopic());
self::assertSame($area, $initiative->getArea());
self::assertSame('Beskrivelse', $initiative->getDescription());
self::assertSame(InitiativeType::Project, $initiative->getInitiativeType());
Expand Down
2 changes: 2 additions & 0 deletions translations/messages.da.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,8 @@ dashboard:
initiative:
title: Titel
title_help: Et kort, sigende navn på initiativet.
topic: Emne
topic_help: Det overordnede program, initiativet er en del af.
area: Område
area_help: Det tematiske område initiativet hører under.
description: Kort beskrivelse
Expand Down
2 changes: 2 additions & 0 deletions translations/messages.en.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,8 @@ dashboard:
initiative:
title: Title
title_help: A short, descriptive name for the initiative.
topic: Topic
topic_help: The wider programme this initiative is part of.
area: Area
area_help: The thematic area the initiative belongs to.
description: Short description
Expand Down
Loading