[UI][CONTROLLER] Work on tabbed notification settings panel

This commit is contained in:
Hugo Sales 2020-07-30 22:47:47 +00:00 committed by Hugo Sales
parent 4b73024a57
commit e620c20bb4
3 changed files with 45 additions and 10 deletions

View File

@ -33,10 +33,17 @@
namespace App\Controller; namespace App\Controller;
// {{{ Imports
use App\Core\DB\DB;
use App\Core\Event;
use App\Core\Form; use App\Core\Form;
use function App\Core\I18n\_m; use function App\Core\I18n\_m;
use App\Util\Common; use App\Util\Common;
use App\Util\Form\ArrayTransformer; use App\Util\Form\ArrayTransformer;
use Doctrine\DBAL\Types\Types;
use Exception;
use Functional as F;
use Misd\PhoneNumberBundle\Form\Type\PhoneNumberType; use Misd\PhoneNumberBundle\Form\Type\PhoneNumberType;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\Form\Extension\Core\Type\CheckboxType; use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
@ -47,6 +54,8 @@ use Symfony\Component\Form\Extension\Core\Type\TextareaType;
use Symfony\Component\Form\Extension\Core\Type\TextType; use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Request;
// }}} Imports
class UserPanel extends AbstractController class UserPanel extends AbstractController
{ {
public function personal_info(Request $request) public function personal_info(Request $request)
@ -99,13 +108,37 @@ class UserPanel extends AbstractController
public function notifications(Request $request) public function notifications(Request $request)
{ {
$notifications = Form::create([ $schema = DB::getConnection()->getSchemaManager();
[_m('transport'), TextType::class, ['help' => 'Address used to send and receive notices through IM.', 'label_format' => 'XMPP/Jabber']], $platform = $schema->getDatabasePlatform();
[_m('post_on_status_change'), CheckboxType::class, ['help' => 'Post a notice when my status changes.', 'label_format' => 'Status change']], $columns = Common::array_remove_keys($schema->listTableColumns('user_notification_prefs'), ['user_id', 'transport', 'created', 'modified']);
[_m('mention'), CheckboxType::class, ['help' => 'Send me replies from people I\'m not subscribed to.', 'label_format' => 'Mentions']], $form_defs = ['placeholder' => []];
[_m('posts_by_followed'), CheckboxType::class, ['help' => 'Send me notices.', 'label_format' => 'Notices']], foreach ($columns as $name => $col) {
['save', SubmitType::class, ['label' => _m('Save')]], ]); $val = $col->getType()->convertToPHPValue($col->getDefault(), $platform);
switch ($col->getType()) {
case Types::BOOLEAN:
$form_defs['placeholder'][] = [$name, CheckboxType::class, ['data' => $val, 'label' => _m($col->getComment())]];
break;
case Types::INTEGER:
if ($name == 'target_profile_id') {
$form_defs['placeholder'][] = ['target_profiles', TextType::class, ['data' => $val, 'label' => _m($col->getComment())], 'transformer' => ProfileArrayTransformer::class];
break;
}
// fallthrough
// no break
default:
throw new Exception("Structure of table user_notification_prefs changed in a way not accounted to in notification settings ({$name})", 500);
}
}
return ['_template' => 'settings/notifications.html.twig', 'notifications' => $notifications->createView()]; Event::handle('AddNotificationTransport', [&$form_defs]);
unset($form_defs['placeholder']);
$tabbed_forms = [];
foreach ($form_defs as $transport_name => $f) {
$tabbed_forms[$transport_name] = Form::create($f);
}
$tabbed_forms = F\map($tabbed_forms, function ($f) { return $f->createView(); });
return ['_template' => 'settings/notifications.html.twig', 'tabbed_forms' => $tabbed_forms];
} }
} }

View File

@ -202,7 +202,7 @@ class UserNotificationPrefs
'user_id' => ['type' => 'int', 'not null' => true], 'user_id' => ['type' => 'int', 'not null' => true],
'transport' => ['type' => 'varchar', 'length' => 191, 'not null' => true, 'description' => 'transport (ex email. xmpp, aim)'], 'transport' => ['type' => 'varchar', 'length' => 191, 'not null' => true, 'description' => 'transport (ex email. xmpp, aim)'],
'target_profile_id' => ['type' => 'int', 'default' => null, 'description' => 'If not null, settings are specific only to a given profiles'], 'target_profile_id' => ['type' => 'int', 'default' => null, 'description' => 'If not null, settings are specific only to a given profiles'],
'notice_by_followed' => ['type' => 'bool', 'not null' => true, 'default' => true, 'description' => 'Notify when a new notice by someone we follow is made'], 'activity_by_followed' => ['type' => 'bool', 'not null' => true, 'default' => true, 'description' => 'Notify when a new activity by someone we follow is made'],
'mention' => ['type' => 'bool', 'not null' => true, 'default' => true, 'description' => 'Notify when mentioned by someone we do not follow'], 'mention' => ['type' => 'bool', 'not null' => true, 'default' => true, 'description' => 'Notify when mentioned by someone we do not follow'],
'reply' => ['type' => 'bool', 'not null' => true, 'default' => true, 'description' => 'Notify when someone replies to a notice made by us'], 'reply' => ['type' => 'bool', 'not null' => true, 'default' => true, 'description' => 'Notify when someone replies to a notice made by us'],
'follow' => ['type' => 'bool', 'not null' => true, 'default' => true, 'description' => 'Notify someone follows us'], 'follow' => ['type' => 'bool', 'not null' => true, 'default' => true, 'description' => 'Notify someone follows us'],

View File

@ -10,9 +10,11 @@
{% endblock primary_nav %} {% endblock primary_nav %}
{% block form %} {% block form %}
<div class='form-single'> {% for transport, form in tabbed_forms %}
{{ form(notifications) }} <div id="form_{{ transport }}" class='form'>
{{ form(form) }}
</div> </div>
{% endfor %}
{% endblock form %} {% endblock form %}
</div> </div>