Implement snip content names
This commit is contained in:
parent
62136a0ca0
commit
5ae5db985b
35
migrations/Version20250513103236.php
Normal file
35
migrations/Version20250513103236.php
Normal 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);
|
||||
}
|
||||
}
|
@ -104,7 +104,11 @@ class SnipController extends AbstractController
|
||||
]);
|
||||
}
|
||||
$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));
|
||||
|
||||
|
@ -35,6 +35,9 @@ class SnipContent
|
||||
#[ORM\Column(nullable: true)]
|
||||
private ?array $diff = null;
|
||||
|
||||
#[ORM\Column(length: 255, nullable: true)]
|
||||
private ?string $name = null;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->children = new ArrayCollection();
|
||||
@ -122,4 +125,16 @@ class SnipContent
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getName(): ?string
|
||||
{
|
||||
return $this->name;
|
||||
}
|
||||
|
||||
public function setName(?string $name): static
|
||||
{
|
||||
$this->name = $name;
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
|
@ -6,7 +6,9 @@ use App\Entity\Snip;
|
||||
use App\Service\SnipParser\ParserFactory;
|
||||
use Symfony\Component\Form\AbstractType;
|
||||
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\TextType;
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||
|
||||
@ -31,6 +33,10 @@ class SnipType extends AbstractType
|
||||
->add('tags', TagsType::class)
|
||||
->add('public', SwitchType::class)
|
||||
->add('visible', SwitchType::class)
|
||||
->add('contentName', TextType::class, [
|
||||
'label' => 'Change description (optional)',
|
||||
'mapped' => false,
|
||||
])
|
||||
;
|
||||
}
|
||||
|
||||
|
@ -13,18 +13,19 @@ readonly class SnipContentService
|
||||
private EntityManagerInterface $em,
|
||||
) {}
|
||||
|
||||
public function update(Snip $snip, string $snipContents): void
|
||||
public function update(Snip $snip, string $contents, ?string $contentName): void
|
||||
{
|
||||
$parentContent = $snip->getActiveVersion();
|
||||
if (self::rebuildText($parentContent) === $snipContents) {
|
||||
if (self::rebuildText($parentContent) === $contents) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Create new snipContent entity with previous one as parent
|
||||
$content = new SnipContent();
|
||||
$content
|
||||
->setText($snipContents)
|
||||
->setText($contents)
|
||||
->setSnip($snip)
|
||||
->setName($contentName)
|
||||
;
|
||||
if ($parentContent !== null) {
|
||||
$content->setParent($parentContent);
|
||||
|
1
templates/generic/datetime.badge.html.twig
Normal file
1
templates/generic/datetime.badge.html.twig
Normal file
@ -0,0 +1 @@
|
||||
<span class="badge text-bg-secondary">{{ date|date('Y-m-d H:i:s') }}</span>
|
@ -54,10 +54,7 @@
|
||||
<p class="card-text text-muted">
|
||||
Current version: {{ snip.activeVersion.id }}
|
||||
{% if snip.activeVersion == snip.latestVersion %}(latest){% endif %}
|
||||
|
||||
Created at {{ snip.activeVersion.id.dateTime|date('Y-m-d H:i:s') }}
|
||||
|
||||
|
||||
Created at {{ include('generic/datetime.badge.html.twig', {date: snip.activeVersion.id.dateTime}) }}
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
|
@ -15,8 +15,13 @@
|
||||
<br><br>
|
||||
<div class="list-group">
|
||||
{% 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}) }}">
|
||||
{{ version.id.dateTime|date('Y-m-d H:i:s') }} - {{ version.id }}
|
||||
<a class="list-group-item {% if version.id == snip.activeVersion.id %}list-group-item-success{% endif %} d-flex justify-content-between"
|
||||
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>
|
||||
{% endfor %}
|
||||
</div>
|
||||
|
Loading…
x
Reference in New Issue
Block a user