Commit 1e5b9645 authored by Emma's avatar Emma

add toggle for markdown previews

parent d77a81de
......@@ -24,5 +24,9 @@ function createPreview() {
}
$(function () {
$(document).on('input', '.markdown-input__input', debounce(createPreview, 600));
$(document).on(
'input',
'.js-enable-post-previews .markdown-input__input',
debounce(createPreview, 600)
);
});
......@@ -229,6 +229,13 @@ class User implements UserInterface, EquatableInterface {
*/
private $autoFetchSubmissionTitles = true;
/**
* @ORM\Column(type="boolean", options={"default": true})
*
* @var bool
*/
private $enablePostPreviews = true;
public function __construct(string $username, string $password, \DateTime $created = null) {
$this->setUsername($username);
$this->password = $password;
......@@ -573,6 +580,14 @@ class User implements UserInterface, EquatableInterface {
$this->autoFetchSubmissionTitles = $autoFetchSubmissionTitles;
}
public function enablePostPreviews(): bool {
return $this->enablePostPreviews;
}
public function setEnablePostPreviews(bool $enablePostPreviews): void {
$this->enablePostPreviews = $enablePostPreviews;
}
/**
* Returns the normalized form of the username.
*
......
......@@ -76,6 +76,8 @@ class UserData implements UserInterface {
private $autoFetchSubmissionTitles;
private $enablePostPreviews;
private $admin = false;
public static function fromUser(User $user): self {
......@@ -91,6 +93,7 @@ class UserData implements UserInterface {
$self->openExternalLinksInNewTab = $user->openExternalLinksInNewTab();
$self->biography = $user->getBiography();
$self->autoFetchSubmissionTitles = $user->autoFetchSubmissionTitles();
$self->enablePostPreviews = $user->enablePostPreviews();
$self->admin = $user->isAdmin();
return $self;
......@@ -112,6 +115,7 @@ class UserData implements UserInterface {
$user->setOpenExternalLinksInNewTab($this->openExternalLinksInNewTab);
$user->setBiography($this->biography);
$user->setAutoFetchSubmissionTitles($this->autoFetchSubmissionTitles);
$user->setEnablePostPreviews($this->enablePostPreviews);
$user->setAdmin($this->admin);
}
......@@ -129,6 +133,7 @@ class UserData implements UserInterface {
'preferredTheme',
'openExternalLinksInNewTab',
'autoFetchSubmissionTitles',
'enablePostPreviews',
];
foreach ($settings as $setting) {
......@@ -248,6 +253,14 @@ class UserData implements UserInterface {
$this->autoFetchSubmissionTitles = $autoFetchSubmissionTitles;
}
public function enablePostPreviews(): bool {
return $this->enablePostPreviews;
}
public function setEnablePostPreviews(bool $enablePostPreviews): void {
$this->enablePostPreviews = $enablePostPreviews;
}
public function isAdmin(): bool {
return $this->admin;
}
......
......@@ -51,6 +51,10 @@ final class UserSettingsType extends AbstractType {
'label' => 'label.auto_fetch_submission_titles',
'required' => false,
])
->add('enablePostPreviews', CheckboxType::class, [
'label' => 'label.show_post_previews',
'required' => false,
])
->add('save', SubmitType::class);
}
......
<?php
namespace DoctrineMigrations;
use Doctrine\DBAL\Migrations\AbstractMigration;
use Doctrine\DBAL\Schema\Schema;
class Version20180502160146 extends AbstractMigration {
public function up(Schema $schema) {
$this->abortIf($this->connection->getDatabasePlatform()->getName() !== 'postgresql', 'Migration can only be executed safely on \'postgresql\'.');
$this->addSql('ALTER TABLE users ADD enable_post_previews BOOLEAN DEFAULT TRUE NOT NULL');
}
public function down(Schema $schema) {
$this->abortIf($this->connection->getDatabasePlatform()->getName() !== 'postgresql', 'Migration can only be executed safely on \'postgresql\'.');
$this->addSql('ALTER TABLE users DROP enable_post_previews');
}
}
......@@ -19,7 +19,10 @@
{% block head %}{% endblock %}
</head>
<body class="{% block page_classes '' %} {{ app.user ? 'user-logged-in' : 'user-anonymous' }} {{ (app.user.nightMode ?? false) ? 'night-mode' }}">
<body class="{% block page_classes '' %}
{{ app.user ? 'user-logged-in' : 'user-anonymous' }}
{{ (app.user.nightMode ?? false) ? 'night-mode' }}
{{ (app.user.enablePostPreviews ?? true) ? 'js-enable-post-previews' }}">
{% block site_nav %}
{{ include('_includes/site_nav.html.twig', {forum: forum ?? null}, with_context=false) }}
{% endblock %}
......
{% extends 'base.html.twig' %}
{% block title %}
{{ 'user_settings.title'|trans({'%username%': user.username}) }}
{% endblock %}
{% block title 'user_settings.title'|trans({'%username%': user.username}) %}
{% block page_classes 'user-settings-page' %}
{% block body %}
<h1 class="page-heading">{{ block('title') }}</h1>
......@@ -22,6 +21,8 @@
<legend class="form__group-header">{{ 'label.posting'|trans }}</legend>
{{ form_row(form.autoFetchSubmissionTitles) }}
{{ form_row(form.enablePostPreviews) }}
</fieldset>
<fieldset class="form__group">
......@@ -35,8 +36,3 @@
</fieldset>
{{ form_end(form) }}
{% endblock %}
{% block page_classes %}
user-settings-page
{% endblock %}
......@@ -292,6 +292,7 @@ label:
event.edit_comment: Edit comment
forums_in_this_category: Forums in this category
description: Description
show_post_previews: Show post previews
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