Commit ba1894fd authored by Emma's avatar Emma 🏳🌈

add user preference for hiding/showing thumbnails

parent 34a1c77b
Pipeline #51864544 passed with stages
in 9 minutes and 2 seconds
......@@ -252,6 +252,13 @@ class User implements UserInterface, EquatableInterface {
*/
private $enablePostPreviews = true;
/**
* @ORM\Column(type="boolean", options={"default": true})
*
* @var bool
*/
private $showThumbnails = true;
public function __construct(string $username, string $password, \DateTime $created = null) {
$this->setUsername($username);
$this->password = $password;
......@@ -631,6 +638,14 @@ class User implements UserInterface, EquatableInterface {
$this->enablePostPreviews = $enablePostPreviews;
}
public function showThumbnails(): bool {
return $this->showThumbnails;
}
public function setShowThumbnails(bool $showThumbnails): void {
$this->showThumbnails = $showThumbnails;
}
/**
* Returns the normalized form of the username.
*
......
......@@ -78,6 +78,8 @@ class UserData implements UserInterface {
private $enablePostPreviews;
private $showThumbnails;
private $admin = false;
public static function fromUser(User $user): self {
......@@ -94,6 +96,7 @@ class UserData implements UserInterface {
$self->biography = $user->getBiography();
$self->autoFetchSubmissionTitles = $user->autoFetchSubmissionTitles();
$self->enablePostPreviews = $user->enablePostPreviews();
$self->showThumbnails = $user->showThumbnails();
$self->admin = $user->isAdmin();
return $self;
......@@ -116,6 +119,7 @@ class UserData implements UserInterface {
$user->setBiography($this->biography);
$user->setAutoFetchSubmissionTitles($this->autoFetchSubmissionTitles);
$user->setEnablePostPreviews($this->enablePostPreviews);
$user->setShowThumbnails($this->showThumbnails);
$user->setAdmin($this->admin);
}
......@@ -134,6 +138,7 @@ class UserData implements UserInterface {
'openExternalLinksInNewTab',
'autoFetchSubmissionTitles',
'enablePostPreviews',
'showThumbnails',
];
foreach ($settings as $setting) {
......@@ -261,6 +266,14 @@ class UserData implements UserInterface {
$this->enablePostPreviews = $enablePostPreviews;
}
public function showThumbnails() {
return $this->showThumbnails;
}
public function setShowThumbnails($showThumbnails): void {
$this->showThumbnails = $showThumbnails;
}
public function isAdmin(): bool {
return $this->admin;
}
......
......@@ -84,6 +84,10 @@ final class UserSettingsType extends AbstractType {
'label' => 'label.show_post_previews',
'required' => false,
])
->add('showThumbnails', CheckboxType::class, [
'label' => 'label.show_thumbnails',
'required' => false,
])
->add('save', SubmitType::class);
}
......
<?php
namespace DoctrineMigrations;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;
final class Version20190314141009 extends AbstractMigration {
public function getDescription(): string {
return 'Add preference for hiding/showing thumbnails';
}
public function up(Schema $schema): void {
$this->abortIf($this->connection->getDatabasePlatform()->getName() !== 'postgresql', 'Migration can only be executed safely on \'postgresql\'.');
$this->addSql('ALTER TABLE users ADD show_thumbnails BOOLEAN DEFAULT TRUE NOT NULL');
}
public function down(Schema $schema): void {
$this->abortIf($this->connection->getDatabasePlatform()->getName() !== 'postgresql', 'Migration can only be executed safely on \'postgresql\'.');
$this->addSql('ALTER TABLE users DROP show_thumbnails');
}
}
......@@ -29,14 +29,14 @@
{%- block submission -%}
{%- from '_macros/icon.html.twig' import icon -%}
{%- from 'vote/_macros.html.twig' import vote -%}
{%- set open_external = submission.url is not empty and (app.user.openExternalLinksInNewTab ?? false) -%}
{%- set open_external = submission.url is not empty and open_external_links_in_new_tab -%}
<article class="{{ block('submission_classes') }}">
<div class="submission-row">
<div class="submission-vote">
{{- vote(submission, 'submission_vote') -}}
</div>
{% if submission.image %}
{% if submission.image and show_thumbnails %}
<div class="submission-image-container">
<a href="{{ block('submission_url') }}" class="submission-image" {% if submission.url %}rel="nofollow noreferrer noopener" {% if open_external %}target="_blank"{% endif %}{% endif %}>
<img src="{{ submission.image|imagine_filter('submission_thumbnail_1x') }}"
......
......@@ -2,8 +2,10 @@
{%- macro submission(submission, options) -%}
{%- with {
open_external_links_in_new_tab: options.open_external_links_in_new_tab ?? app.user.openExternalLinksInNewTab ?? false,
show_body: options.show_body ?? false,
show_forum_name: options.show_forum_name ?? true,
show_thumbnails: options.show_thumbnails ?? app.user.showThumbnails ?? true,
submission: submission
} only -%}
{{ block('submission') }}
......
......@@ -15,6 +15,8 @@
{{ form_row(form.front_page) }}
{{ form_row(form.openExternalLinksInNewTab) }}
{{ form_row(form.showThumbnails) }}
</fieldset>
<fieldset class="form__group">
......
......@@ -314,6 +314,7 @@ label:
user_associated_with_ip: User associated with IP
let_forums_override_preferred_theme: Let forums override preferred theme
search: Search for a post...
show_thumbnails: Show thumbnails
log:
comment_deletion: '%user% deleted comment by %author% in "%submission%"'
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment