Implement snip content names

This commit is contained in:
Tim 2025-05-13 13:47:33 +02:00
parent 62136a0ca0
commit 5ae5db985b
8 changed files with 74 additions and 10 deletions

View File

@ -0,0 +1,35 @@
<?php
declare(strict_types=1);
namespace DoctrineMigrations;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;
/**
* Auto-generated Migration: Please modify to your needs!
*/
final class Version20250513103236 extends AbstractMigration
{
public function getDescription(): string
{
return '';
}
public function up(Schema $schema): void
{
// this up() migration is auto-generated, please modify it to your needs
$this->addSql(<<<'SQL'
ALTER TABLE snip_content ADD name VARCHAR(255) DEFAULT NULL
SQL);
}
public function down(Schema $schema): void
{
// this down() migration is auto-generated, please modify it to your needs
$this->addSql(<<<'SQL'
ALTER TABLE snip_content DROP name
SQL);
}
}

View File

@ -104,7 +104,11 @@ class SnipController extends AbstractController
]); ]);
} }
$this->repository->save($snip); $this->repository->save($snip);
$contentService->update($snip, $form->get('content')->getData()); $contentService->update(
$snip,
$form->get('content')->getData(),
$form->get('contentName')->getData()
);
$this->addFlash('success', sprintf('Snip "%s" saved', $snip)); $this->addFlash('success', sprintf('Snip "%s" saved', $snip));

View File

@ -35,6 +35,9 @@ class SnipContent
#[ORM\Column(nullable: true)] #[ORM\Column(nullable: true)]
private ?array $diff = null; private ?array $diff = null;
#[ORM\Column(length: 255, nullable: true)]
private ?string $name = null;
public function __construct() public function __construct()
{ {
$this->children = new ArrayCollection(); $this->children = new ArrayCollection();
@ -122,4 +125,16 @@ class SnipContent
return $this; return $this;
} }
public function getName(): ?string
{
return $this->name;
}
public function setName(?string $name): static
{
$this->name = $name;
return $this;
}
} }

View File

@ -6,7 +6,9 @@ use App\Entity\Snip;
use App\Service\SnipParser\ParserFactory; use App\Service\SnipParser\ParserFactory;
use Symfony\Component\Form\AbstractType; use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType; use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
use Symfony\Component\Form\Extension\Core\Type\TextareaType; use Symfony\Component\Form\Extension\Core\Type\TextareaType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\FormBuilderInterface; use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver; use Symfony\Component\OptionsResolver\OptionsResolver;
@ -31,6 +33,10 @@ class SnipType extends AbstractType
->add('tags', TagsType::class) ->add('tags', TagsType::class)
->add('public', SwitchType::class) ->add('public', SwitchType::class)
->add('visible', SwitchType::class) ->add('visible', SwitchType::class)
->add('contentName', TextType::class, [
'label' => 'Change description (optional)',
'mapped' => false,
])
; ;
} }

View File

@ -13,18 +13,19 @@ readonly class SnipContentService
private EntityManagerInterface $em, private EntityManagerInterface $em,
) {} ) {}
public function update(Snip $snip, string $snipContents): void public function update(Snip $snip, string $contents, ?string $contentName): void
{ {
$parentContent = $snip->getActiveVersion(); $parentContent = $snip->getActiveVersion();
if (self::rebuildText($parentContent) === $snipContents) { if (self::rebuildText($parentContent) === $contents) {
return; return;
} }
// Create new snipContent entity with previous one as parent // Create new snipContent entity with previous one as parent
$content = new SnipContent(); $content = new SnipContent();
$content $content
->setText($snipContents) ->setText($contents)
->setSnip($snip) ->setSnip($snip)
->setName($contentName)
; ;
if ($parentContent !== null) { if ($parentContent !== null) {
$content->setParent($parentContent); $content->setParent($parentContent);

View File

@ -0,0 +1 @@
<span class="badge text-bg-secondary">{{ date|date('Y-m-d H:i:s') }}</span>

View File

@ -54,10 +54,7 @@
<p class="card-text text-muted"> <p class="card-text text-muted">
Current version: {{ snip.activeVersion.id }} Current version: {{ snip.activeVersion.id }}
{% if snip.activeVersion == snip.latestVersion %}(latest){% endif %} {% if snip.activeVersion == snip.latestVersion %}(latest){% endif %}
Created at {{ include('generic/datetime.badge.html.twig', {date: snip.activeVersion.id.dateTime}) }}
Created at {{ snip.activeVersion.id.dateTime|date('Y-m-d H:i:s') }}
</p> </p>
</div> </div>
</div> </div>

View File

@ -15,8 +15,13 @@
<br><br> <br><br>
<div class="list-group"> <div class="list-group">
{% for version in snip.snipContents|reverse %} {% for version in snip.snipContents|reverse %}
<a class="list-group-item {% if version.id == snip.activeVersion.id %}list-group-item-success{% endif %}" href="{{ path('version_set', {version: version.id, snip: snip.id}) }}"> <a class="list-group-item {% if version.id == snip.activeVersion.id %}list-group-item-success{% endif %} d-flex justify-content-between"
{{ version.id.dateTime|date('Y-m-d H:i:s') }} - {{ version.id }} href="{{ path('version_set', {version: version.id, snip: snip.id}) }}">
<span>
{{ include('generic/datetime.badge.html.twig', {date: version.id.dateTime}) }}
{% if version.name %}{{ version.name }}{% endif %}
</span>
<span class="text-muted">{{ version.id }}</span>
</a> </a>
{% endfor %} {% endfor %}
</div> </div>