stash commit 2

This commit is contained in:
Julie Lenaerts 2021-09-23 14:55:54 +02:00
parent 05c5eaa925
commit a28c996164
8 changed files with 391 additions and 231 deletions

View File

@ -4,6 +4,7 @@ declare(strict_types=1);
namespace Chill\AsideActivityBundle\Entity;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
@ -20,8 +21,20 @@ class AsideActivityCategory
*/
private int $id;
/**
* @ORM\Column(type="json", length=255)
*/
private array $title;
/**
* @ORM\OneToMany(targetEntity=AsideActivityCategory::class, mappedBy="parent")
* @ORM\Column(type="boolean")
*/
private bool $isActive = true;
/**
* @ORM\ManyToOne(targetEntity=AsideActivityCategory::class, inversedBy="children")
* @ORM\JoinColumn(nullable=true)
*/
private $parent;
@ -30,15 +43,10 @@ class AsideActivityCategory
*/
private $children;
/**
* @ORM\Column(type="json", length=255)
*/
private array $title;
/**
* @ORM\Column(type="boolean")
*/
private bool $isActive = true;
public function __construct()
{
$this->children = new ArrayCollection();
}
public function getId(): ?int
{

View File

@ -4,19 +4,35 @@ namespace Chill\AsideActivityBundle\Form;
use Chill\AsideActivityBundle\Entity\AsideActivityCategory;
use Chill\MainBundle\Form\Type\TranslatableStringFormType;
use Chill\MainBundle\Templating\TranslatableStringHelper;
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\Form\FormBuilderInterface;
final class AsideActivityCategoryType extends AbstractType
{
protected $translatableStringHelper;
public function __construct(TranslatableStringHelper $translatableStringHelper)
{
$this->translatableStringHelper = $translatableStringHelper;
}
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder->add('title', TranslatableStringFormType::class,
[
'label' => 'Nom',
])
->add('parent', EntityType::class, [
'class' => AsideActivityCategory::class,
'required' => false,
'choice_label' => function (AsideActivityCategory $category){
return $this->translatableStringHelper->localize($category->getTitle());
}
])
->add('isActive', ChoiceType::class,
[
'choices' => [

View File

@ -4,6 +4,7 @@ namespace Chill\AsideActivityBundle\Form;
use Chill\AsideActivityBundle\Entity\AsideActivity;
use Chill\AsideActivityBundle\Entity\AsideActivityCategory;
use Chill\AsideActivityBundle\Templating\Entity\CategoryRender;
use Chill\MainBundle\Entity\User;
use Chill\MainBundle\Form\Type\ChillDateType;
use Chill\MainBundle\Form\Type\ChillTextareaType;
@ -19,22 +20,25 @@ use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Component\Form\FormEvent;
use Symfony\Component\Form\FormEvents;
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
use Symfony\Component\Templating\EngineInterface;
final class AsideActivityFormType extends AbstractType
{
protected array $timeChoices;
private TranslatableStringHelper $translatableStringHelper;
private TokenStorageInterface $storage;
private CategoryRender $categoryRender;
public function __construct (
TranslatableStringHelper $translatableStringHelper,
ParameterBagInterface $parameterBag,
TokenStorageInterface $storage
TokenStorageInterface $storage,
CategoryRender $categoryRender
){
$this->timeChoices = $parameterBag->get('chill_aside_activity.form.time_duration');
$this->translatableStringHelper = $translatableStringHelper;
$this->storage = $storage;
$this->CategoryRender = $categoryRender;
}
public function buildForm(FormBuilderInterface $builder, array $options)
@ -78,7 +82,9 @@ final class AsideActivityFormType extends AbstractType
'class' => AsideActivityCategory::class,
'placeholder' => 'Choose the activity category',
'choice_label' => function (AsideActivityCategory $asideActivityCategory) {
return $this->translatableStringHelper->localize($asideActivityCategory->getTitle());
$options = [];
return $this->categoryRender->renderString($asideActivityCategory, $options);
// return $this->translatableStringHelper->localize($asideActivityCategory->getTitle());
},
])
->add('duration', ChoiceType::class, $durationTimeOptions)

View File

@ -0,0 +1,13 @@
{% set reversed_parents = parents|reverse %}
<span class="chill-entity entity-social-issue">
<span class="badge bg-chill-l-gray text-dark">
{%- for p in reversed_parents %}
<span class="parent-{{ loop.revindex0 }}">
{{ p.title|localize_translatable_string }}{{ options['default.separator'] }}
</span>
{%- endfor -%}
<span class="child">
{{ asideActivityCategory.title|localize_translatable_string }}
</span>
</span>
</span>

View File

@ -0,0 +1,80 @@
<?php
namespace Chill\AsideActivityBundle\Templating\Entity;
use Chill\AsideActivityBundle\Entity\AsideActivityCategory;
use Chill\MainBundle\Templating\Entity\ChillEntityRenderInterface;
use Chill\MainBundle\Templating\TranslatableStringHelper;
use Symfony\Component\Templating\EngineInterface;
final class CategoryRender implements ChillEntityRenderInterface
{
private TranslatableStringHelper $translatableStringHelper;
private EngineInterface $engine;
public const SEPERATOR_KEY = 'default.separator';
public const DEFAULT_ARGS = [
self::SEPERATOR_KEY => ' > '
];
public function __construct(TranslatableStringHelper $translatableStringHelper, EngineInterface $engine)
{
$this->translatableStringHelper = $translatableStringHelper;
$this->engine = $engine;
}
/**
* @param AsideActivityCategory $asideActivityCategory
*/
public function renderString($asideActivityCategory, array $options): string
{
$options = array_merge(self::DEFAULT_ARGS, $options);
$titles[] = $this->translatableStringHelper->localize($asideActivityCategory->getTitle());
while ($asideActivityCategory->hasParent()) {
$asideActivityCategory = $asideActivityCategory->getParent();
$titles[] = $this->translatableStringHelper->localize($asideActivityCategory->getTitle());
}
$titles = array_reverse($titles);
return implode($options[self::SEPERATOR_KEY], $titles);
}
/**
* @param AsideActivityCategory $asideActivityCategory
*/
public function supports($asideActivityCategory, array $options): bool
{
return $asideActivityCategory instanceof AsideActivityCategory;
}
public function buildParents(AsideActivityCategory $asideActivityCategory)
{
$parents = [];
while($asideActivityCategory->hasParent()) {
$asideActivityCategory = $parents[] = $asideActivityCategory->getParent();
}
return $parents;
}
/**
* @param AsideActivityCategory $asideActivityCategory
*/
public function renderBox($asideActivityCategory, array $options): string
{
$options = array_merge(self::DEFAULT_ARGS, $options);
$parents = $this->buildParents($asideActivityCategory);
return $this->engine->render('@ChillAsideActivity/asideActivityCategory/asideActivityCategory.html.twig',
[
'asideActivityCategory' => $asideActivityCategory,
'parents' => $parents,
'options' => $options
]);
}
}

View File

@ -1,5 +1,12 @@
services:
Chill\AsideActivityBundle\DataFixtures\:
resource: './../DataFixtures'
resource: "./../DataFixtures"
autowire: true
autoconfigure: true
Chill\AsideActivityBundle\Templating\Entity\:
autowire: true
autoconfigure: true
resource: "../Templating/Entity"
tags:
- "chill.render_entity"

View File

@ -19,7 +19,9 @@ final class Version20210922182907 extends AbstractMigration
public function up(Schema $schema): void
{
$this->addSql('ALTER TABLE chill_asideactivity.asideactivitycategory ADD parent VARCHAR(255) DEFAULT NULL');
$this->addSql('ALTER TABLE chill_asideactivity.asideactivitycategory ADD parent_id INT DEFAULT NULL');
$this->addSql('ALTER TABLE chill_asideactivity.asideactivitycategory ADD CONSTRAINT FK_7BF90DBE727ACA70 FOREIGN KEY (parent_id) REFERENCES chill_asideactivity.AsideActivityCategory (id) NOT DEFERRABLE INITIALLY IMMEDIATE');
$this->addSql('CREATE INDEX IDX_7BF90DBE727ACA70 ON chill_asideactivity.asideactivitycategory (parent_id)');
}
public function down(Schema $schema): void

View File

@ -28,10 +28,16 @@ div.flex-table {
}
}
h2, h3, h4, dl, p {
h2,
h3,
h4,
dl,
p {
margin: 0;
}
h2, h3, h4 {
h2,
h3,
h4 {
color: $blue;
}
@ -52,23 +58,30 @@ div.flex-bloc {
flex-wrap: wrap;
div.item-bloc {
flex-grow: 0; flex-shrink: 1; flex-basis: auto;
flex-grow: 0;
flex-shrink: 1;
flex-basis: auto;
flex-direction: column;
margin: 0;
hyphens: auto;
div.item-row {
flex-grow: 1; flex-shrink: 1; flex-basis: auto;
flex-grow: 1;
flex-shrink: 1;
flex-basis: auto;
flex-direction: column;
div.item-col {
&:first-child {
flex-grow: 0; flex-shrink: 0; flex-basis: auto;
flex-grow: 0;
flex-shrink: 0;
flex-basis: auto;
}
&:last-child {
flex-grow: 1; flex-shrink: 1; flex-basis: auto;
flex-grow: 1;
flex-shrink: 1;
flex-basis: auto;
@include separator;
ul.record_actions {
@ -94,7 +107,7 @@ div.flex-table {
background-color: $gray-200;
.chill-user-quote {
background-color: shade-color($gray-200, 5%)
background-color: shade-color($gray-200, 5%);
}
}
@ -103,11 +116,15 @@ div.flex-table {
div.item-col {
&:first-child {
flex-grow: 0; flex-shrink: 0; flex-basis: auto;
flex-grow: 0;
flex-shrink: 0;
flex-basis: auto;
}
&:last-child {
flex-grow: 1; flex-shrink: 1; flex-basis: auto;
flex-grow: 1;
flex-shrink: 1;
flex-basis: auto;
justify-content: flex-end;
@include media-breakpoint-down(md) {
@ -205,14 +222,19 @@ div.wrap-header {
&:first-child {
align-items: baseline;
}
&:last-child {}
&:last-child {
}
div.wh-col {
&:first-child {
flex-grow: 0; flex-shrink: 1; flex-basis: auto;
flex-grow: 0;
flex-shrink: 1;
flex-basis: auto;
}
&:last-child {
flex-grow: 1; flex-shrink: 1; flex-basis: auto;
flex-grow: 1;
flex-shrink: 1;
flex-basis: auto;
display: flex;
justify-content: flex-end;
@ -224,12 +246,20 @@ div.wrap-header {
border: 1px solid $black;
div.wh-row {
&:first-child div.wh-col {
&:first-child { background-color: $yellow; }
&:last-child { background-color: $beige; }
&:first-child {
background-color: $yellow;
}
&:last-child {
background-color: $beige;
}
}
&:last-child div.wh-col {
&:first-child { background-color: $orange; }
&:last-child { background-color: $pink; }
&:first-child {
background-color: $orange;
}
&:last-child {
background-color: $pink;
}
}
}
}
@ -243,7 +273,6 @@ div.flex-bloc,
div.flex-table,
div.wrap-list,
div.wrap-header {
div.separator {
@include separator;
}
@ -260,7 +289,6 @@ div.wrap-header {
}
}
/*
* FLOATBUTTON
* p-ê pas convaincant: cet asset est toujours en observation