From a94d7503c28eac8f440d9057d2cef36aab9fcb49 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20L=C5=93uillet?= Date: Tue, 13 Jun 2023 15:02:48 +0200 Subject: [PATCH 1/6] Added new setting to show / hide articles thumbnails --- .../Version20230613121354.php | 30 +++++++++++++++++++ app/config/services.yml | 1 + app/config/wallabag.yml | 1 + .../DataFixtures/ConfigFixtures.php | 3 ++ .../DependencyInjection/Configuration.php | 3 ++ .../WallabagCoreExtension.php | 1 + src/Wallabag/CoreBundle/Entity/Config.php | 29 ++++++++++++++++++ .../CoreBundle/Form/Type/ConfigType.php | 6 ++++ .../Resources/views/Config/index.html.twig | 13 ++++++++ .../views/Entry/_card_full_image.html.twig | 2 ++ .../views/Entry/_card_list.html.twig | 2 ++ .../views/Entry/_card_preview.html.twig | 4 ++- .../EventListener/CreateConfigListener.php | 5 +++- translations/messages.en.yml | 2 ++ 14 files changed, 100 insertions(+), 2 deletions(-) create mode 100644 app/DoctrineMigrations/Version20230613121354.php diff --git a/app/DoctrineMigrations/Version20230613121354.php b/app/DoctrineMigrations/Version20230613121354.php new file mode 100644 index 000000000..07a70a182 --- /dev/null +++ b/app/DoctrineMigrations/Version20230613121354.php @@ -0,0 +1,30 @@ +getTable($this->getTable('config')); + + $this->skipIf($configTable->hasColumn('display_thumbnails'), 'It seems that you already played this migration.'); + + $configTable->addColumn('display_thumbnails', 'integer', [ + 'default' => 1, + 'notnull' => false, + ]); + } + + public function down(Schema $schema): void + { + $configTable = $schema->getTable($this->getTable('config')); + $configTable->dropColumn('display_thumbnails'); + } +} diff --git a/app/config/services.yml b/app/config/services.yml index d63413d48..eb5d0e4e2 100644 --- a/app/config/services.yml +++ b/app/config/services.yml @@ -300,6 +300,7 @@ services: $readingSpeed: "%wallabag_core.reading_speed%" $actionMarkAsRead: "%wallabag_core.action_mark_as_read%" $listMode: "%wallabag_core.list_mode%" + $displayThumbnails: "%wallabag_core.display_thumbnails%" Wallabag\UserBundle\EventListener\AuthenticationFailureListener: tags: diff --git a/app/config/wallabag.yml b/app/config/wallabag.yml index 7643d06ac..8339348fe 100644 --- a/app/config/wallabag.yml +++ b/app/config/wallabag.yml @@ -30,6 +30,7 @@ wallabag_core: cache_lifetime: 10 action_mark_as_read: 1 list_mode: 0 + display_thumbnails: 1 fetching_error_message_title: 'No title found' fetching_error_message: | wallabag can't retrieve contents for this article. Please troubleshoot this issue. diff --git a/src/Wallabag/CoreBundle/DataFixtures/ConfigFixtures.php b/src/Wallabag/CoreBundle/DataFixtures/ConfigFixtures.php index a8a1a78ae..77809f95b 100644 --- a/src/Wallabag/CoreBundle/DataFixtures/ConfigFixtures.php +++ b/src/Wallabag/CoreBundle/DataFixtures/ConfigFixtures.php @@ -23,6 +23,7 @@ class ConfigFixtures extends Fixture implements DependentFixtureInterface $adminConfig->setPocketConsumerKey('xxxxx'); $adminConfig->setActionMarkAsRead(0); $adminConfig->setListMode(0); + $adminConfig->setDisplayThumbnails(0); $manager->persist($adminConfig); @@ -35,6 +36,7 @@ class ConfigFixtures extends Fixture implements DependentFixtureInterface $bobConfig->setPocketConsumerKey(null); $bobConfig->setActionMarkAsRead(1); $bobConfig->setListMode(1); + $bobConfig->setDisplayThumbnails(1); $manager->persist($bobConfig); @@ -47,6 +49,7 @@ class ConfigFixtures extends Fixture implements DependentFixtureInterface $emptyConfig->setPocketConsumerKey(null); $emptyConfig->setActionMarkAsRead(0); $emptyConfig->setListMode(0); + $emptyConfig->setDisplayThumbnails(0); $manager->persist($emptyConfig); diff --git a/src/Wallabag/CoreBundle/DependencyInjection/Configuration.php b/src/Wallabag/CoreBundle/DependencyInjection/Configuration.php index fa31ecda4..91ea7a326 100644 --- a/src/Wallabag/CoreBundle/DependencyInjection/Configuration.php +++ b/src/Wallabag/CoreBundle/DependencyInjection/Configuration.php @@ -46,6 +46,9 @@ class Configuration implements ConfigurationInterface ->scalarNode('list_mode') ->defaultValue(1) ->end() + ->scalarNode('display_thumbnails') + ->defaultValue(1) + ->end() ->scalarNode('api_limit_mass_actions') ->defaultValue(10) ->end() diff --git a/src/Wallabag/CoreBundle/DependencyInjection/WallabagCoreExtension.php b/src/Wallabag/CoreBundle/DependencyInjection/WallabagCoreExtension.php index 648595a7c..0eabaa075 100644 --- a/src/Wallabag/CoreBundle/DependencyInjection/WallabagCoreExtension.php +++ b/src/Wallabag/CoreBundle/DependencyInjection/WallabagCoreExtension.php @@ -22,6 +22,7 @@ class WallabagCoreExtension extends Extension $container->setParameter('wallabag_core.cache_lifetime', $config['cache_lifetime']); $container->setParameter('wallabag_core.action_mark_as_read', $config['action_mark_as_read']); $container->setParameter('wallabag_core.list_mode', $config['list_mode']); + $container->setParameter('wallabag_core.display_thumbnails', $config['display_thumbnails']); $container->setParameter('wallabag_core.fetching_error_message', $config['fetching_error_message']); $container->setParameter('wallabag_core.fetching_error_message_title', $config['fetching_error_message_title']); $container->setParameter('wallabag_core.api_limit_mass_actions', $config['api_limit_mass_actions']); diff --git a/src/Wallabag/CoreBundle/Entity/Config.php b/src/Wallabag/CoreBundle/Entity/Config.php index 9b47c23a8..854335d0d 100644 --- a/src/Wallabag/CoreBundle/Entity/Config.php +++ b/src/Wallabag/CoreBundle/Entity/Config.php @@ -117,6 +117,15 @@ class Config */ private $listMode; + /** + * @var int + * + * @ORM\Column(name="display_thumbnails", type="integer", nullable=true) + * + * @Groups({"config_api"}) + */ + private $displayThumbnails; + /** * @ORM\OneToOne(targetEntity="Wallabag\UserBundle\Entity\User", inversedBy="config") */ @@ -362,6 +371,26 @@ class Config return $this; } + /** + * @return bool + */ + public function getDisplayThumbnails(): ?bool + { + return $this->displayThumbnails; + } + + /** + * @param bool $displayThumbnails + * + * @return Config + */ + public function setDisplayThumbnails(bool $displayThumbnails) + { + $this->displayThumbnails = $displayThumbnails; + + return $this; + } + /** * @return Config */ diff --git a/src/Wallabag/CoreBundle/Form/Type/ConfigType.php b/src/Wallabag/CoreBundle/Form/Type/ConfigType.php index ae8714084..8f63551fc 100644 --- a/src/Wallabag/CoreBundle/Form/Type/ConfigType.php +++ b/src/Wallabag/CoreBundle/Form/Type/ConfigType.php @@ -3,6 +3,7 @@ namespace Wallabag\CoreBundle\Form\Type; use Symfony\Component\Form\AbstractType; +use Symfony\Component\Form\Extension\Core\Type\CheckboxType; use Symfony\Component\Form\Extension\Core\Type\ChoiceType; use Symfony\Component\Form\Extension\Core\Type\IntegerType; use Symfony\Component\Form\Extension\Core\Type\SubmitType; @@ -29,6 +30,11 @@ class ConfigType extends AbstractType 'label' => 'config.form_settings.items_per_page_label', 'property_path' => 'itemsPerPage', ]) + ->add('display_thumbnails', CheckboxType::class, [ + 'label' => 'config.form_settings.display_thumbnails_label', + 'property_path' => 'displayThumbnails', + 'required' => false, + ]) ->add('reading_speed', IntegerType::class, [ 'label' => 'config.form_settings.reading_speed.label', 'property_path' => 'readingSpeed', diff --git a/src/Wallabag/CoreBundle/Resources/views/Config/index.html.twig b/src/Wallabag/CoreBundle/Resources/views/Config/index.html.twig index 134e623d6..ddee13faa 100644 --- a/src/Wallabag/CoreBundle/Resources/views/Config/index.html.twig +++ b/src/Wallabag/CoreBundle/Resources/views/Config/index.html.twig @@ -38,6 +38,19 @@ +
+
+ {{ form_errors(form.config.display_thumbnails) }} + {{ form_widget(form.config.display_thumbnails) }} + {{ form_label(form.config.display_thumbnails) }} +
+ +
+
{{ form_errors(form.config.reading_speed) }} diff --git a/src/Wallabag/CoreBundle/Resources/views/Entry/_card_full_image.html.twig b/src/Wallabag/CoreBundle/Resources/views/Entry/_card_full_image.html.twig index 6ca075576..2624ae451 100644 --- a/src/Wallabag/CoreBundle/Resources/views/Entry/_card_full_image.html.twig +++ b/src/Wallabag/CoreBundle/Resources/views/Entry/_card_full_image.html.twig @@ -6,9 +6,11 @@
  • {{ tag.label }}
  • {% endfor %} + {% if app.user.config.displayThumbnails %} + {% endif %}
    {% include "@WallabagCore/Entry/Card/_content.html.twig" with {'entry': entry} only %}
    diff --git a/src/Wallabag/CoreBundle/Resources/views/Entry/_card_list.html.twig b/src/Wallabag/CoreBundle/Resources/views/Entry/_card_list.html.twig index dfad1279c..78e97ea37 100644 --- a/src/Wallabag/CoreBundle/Resources/views/Entry/_card_list.html.twig +++ b/src/Wallabag/CoreBundle/Resources/views/Entry/_card_list.html.twig @@ -1,11 +1,13 @@
    {% include "@WallabagCore/Entry/Card/_mass_checkbox.html.twig" with {'entry': entry} only %} + {% if app.user.config.displayThumbnails %} + {% endif %} {% include "@WallabagCore/Entry/Card/_content.html.twig" with {'entry': entry, 'withMetadata': true, 'subClass': 'metadata'} only %}