[UI] Settings routes refactor, avatar and misc settings added.

This commit is contained in:
rainydaysavings 2020-07-22 21:58:23 +01:00 committed by Hugo Sales
parent a4934a4ef3
commit f361a64ab5
6 changed files with 116 additions and 68 deletions

View File

@ -38,6 +38,7 @@ use App\Core\Form;
use function App\Core\I18n\_m;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
use Symfony\Component\Form\Extension\Core\Type\FileType;
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
use Symfony\Component\Form\Extension\Core\Type\TextareaType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
@ -88,23 +89,33 @@ class UserPanel extends AbstractController
[_m('emailnotifyfav'), CheckboxType::class, ['help' => 'Send me email when someone adds my notice as a favorite.', 'label_format' => 'Notify favorites']],
['save', SubmitType::class, ['label' => _m('Save')]], ]);
$acc->handleRequest($request);
if ($acc->isSubmitted()) {
$data = $acc->getData();
if ($prof->isValid()) {
$user = DB::find('\App\Entity\User', ['id' => 2]);
foreach (['outgoing_email', 'password', 'emailnotifysub', 'emailnotifymsg', 'emailnotifyattn', 'emailnotifynudge', 'emailnotifyfav'] as $key) {
$method = "set{$key}";
$user->{$method}($data[_m($key)]);
}
DB::flush();
} else {
// Display error
}
}
return $this->render('settings/account.html.twig', [
'acc' => $acc->createView(),
]);
}
public function avatar(Request $request)
{
$avatar = Form::create([
[_m('avatar'), FileType::class, ['help' => 'You can upload your personal avatar. The maximum file size is 64MB.', 'label_format' => 'Avatar']],
['save', SubmitType::class, ['label' => _m('Submit')]], ]);
return $this->render('settings/avatar.html.twig', [
'avatar' => $avatar->createView(),
]);
}
public function misc(Request $request)
{
$misc = Form::create([
[_m('transport'), TextType::class, ['help' => 'Address used to send and receive notices through IM.', 'label_format' => 'XMPP/Jabber']],
[_m('post_on_status_change'), CheckboxType::class, ['help' => 'Post a notice when my status changes.', 'label_format' => 'Status change']],
[_m('mention'), CheckboxType::class, ['help' => 'Send me replies from people I\'m not subscribed to.', 'label_format' => 'Mentions']],
[_m('posts_by_followed'), CheckboxType::class, ['help' => 'Send me notices.', 'label_format' => 'Notices']],
['save', SubmitType::class, ['label' => _m('Save')]], ]);
return $this->render('settings/misc.html.twig', [
'misc' => $misc->createView(),
]);
}
}

View File

@ -48,12 +48,22 @@ abstract class Main
}
// Settings pages
foreach (['profile', 'avatar'] as $s) {
foreach (['profile', 'avatar', 'misc', 'account'] as $s) {
$r->connect('settings_' . $s, 'settings/' . $s, [C\UserPanel::class, 'profile']);
}
foreach (['account'] as $s) {
$r->connect('settings_' . $s, 'settings/' . $s, [C\UserPanel::class, 'account']);
switch ($s) {
case 'profile':
$r->connect('settings_' . $s, 'settings/' . $s, [C\UserPanel::class, 'profile']);
break;
case 'avatar':
$r->connect('settings_' . $s, 'settings/' . $s, [C\UserPanel::class, 'avatar']);
break;
case 'misc':
$r->connect('settings_' . $s, 'settings/' . $s, [C\UserPanel::class, 'misc']);
break;
case 'account':
$r->connect('settings_' . $s, 'settings/' . $s, [C\UserPanel::class, 'account']);
break;
}
}
}
}

View File

@ -22,7 +22,7 @@
<a href="{{ path('settings_account') }}" class='hover-effect {% if app.request.attributes.get('_route') starts with 'settings_account' %}active{% endif %}'>Account</a>
</li>
<li>
<a href="{{ path('doc_tags') }}" class='hover-effect {% if app.request.attributes.get('_route') starts with 'doc_tags' %}active{% endif %}'>Misc</a>
<a href="{{ path('settings_misc') }}" class='hover-effect {% if app.request.attributes.get('_route') starts with 'settings_misc' %}active{% endif %}'>Misc</a>
</li>
</ul>
</nav>

View File

@ -6,52 +6,40 @@
<link rel='stylesheet' type='text/css' href="{{ asset('assets/css/settings/settings_small.css') }}" media="screen and (max-width: 750px)">
{% endblock %}
{% block nav %}
<nav class='set-nav'>
<ul>
<li>
<a href="{{ path('settings_profile') }}" class='hover-effect {% if app.request.attributes.get('_route') starts with 'settings_' %}active{% endif %}'>Settings</a>
</li>
<li>
<a href="{{ path('account_settings') }}" class='hover-effect {% if app.request.attributes.get('_route') starts with 'account_settings' %}active{% endif %}'>Account</a>
</li>
<li>
<a href="{{ path('doc_tags') }}" class='hover-effect {% if app.request.attributes.get('_route') starts with 'doc_tags' %}active{% endif %}'>Misc</a>
</li>
</ul>
</nav>
<nav class='set-nav2'>
<ul>
<li>
<a href="{{ path('settings_profile') }}" class='hover-effect {% if app.request.attributes.get('_route') starts with 'settings_profile' %}active{% endif %}'>Profile</a>
</li>
<li>
<a href="{{ path('settings_avatar') }}" class='hover-effect {% if app.request.attributes.get('_route') starts with 'settings_avatar' %}active{% endif %}'>Avatar</a>
</li>
</ul>
<hr>
</nav>
{% endblock %}
{% block title %}Avatar Settings{% endblock %}
{% block header %}{{ parent() }}{% endblock %}
{% block body %}
<div class='content'>
<div id='nickname'>
<div class='label'> {{ form_label(prof.Nickname) }} </div> {{ form_widget(prof.Nickname) }}
</div>
<div id='name'>
<div class='label'> {{ form_label(prof.FullName) }} </div> {{ form_widget(prof.FullName) }}
</div>
<div id='homepage'>
<div class='label'> {{ form_label(prof.Homepage) }} </div> {{ form_widget(prof.Homepage) }}
</div>
<div id='bio'>
<div class='label'> {{ form_label(prof.Bio) }} </div> {{ form_widget(prof.Bio) }}
</div>
<div id='location'>
<div class='label'> {{ form_label(prof.Location) }} </div> {{ form_widget(prof.Location) }}
</div>
<div id='save'>
{{ form_widget(prof.save) }}
</div>
<nav class='set-nav'>
<ul>
<li>
<a href="{{ path('settings_profile') }}" class='hover-effect {% if (app.request.attributes.get('_route') starts with 'settings_profile') or (app.request.attributes.get('_route') starts with 'settings_avatar')%}active{% endif %}'>Settings</a>
</li>
<li>
<a href="{{ path('settings_account') }}" class='hover-effect {% if app.request.attributes.get('_route') starts with 'settings_account' %}active{% endif %}'>Account</a>
</li>
<li>
<a href="{{ path('settings_misc') }}" class='hover-effect {% if app.request.attributes.get('_route') starts with 'settings_misc' %}active{% endif %}'>Misc</a>
</li>
</ul>
</nav>
<nav class='set-nav2'>
<ul>
<li>
<a href="{{ path('settings_profile') }}" class='hover-effect {% if app.request.attributes.get('_route') starts with 'settings_profile' %}active{% endif %}'>Profile</a>
</li>
<li>
<a href="{{ path('settings_avatar') }}" class='hover-effect {% if app.request.attributes.get('_route') starts with 'settings_avatar' %}active{% endif %}'>Avatar</a>
</li>
</ul>
</nav>
{% block form %}
<div class='form'>
{{ form(avatar) }}
</div>
{% endblock %}
</div>
{% endblock %}

View File

@ -0,0 +1,39 @@
{% extends 'base.html.twig' %}
{% block stylesheets %}
{{ parent() }}
<link rel='stylesheet' type='text/css' href="{{ asset('assets/css/settings/settings.css') }}" media="screen and (min-width: 1300px)">
<link rel='stylesheet' type='text/css' href="{{ asset('assets/css/settings/settings_mid.css') }}" media="screen and (max-width: 1300px)">
<link rel='stylesheet' type='text/css' href="{{ asset('assets/css/settings/settings_small.css') }}" media="screen and (max-width: 750px)">
{% endblock %}
{% block title %}Misc Settings{% endblock %}
{% block header %}{{ parent() }}{% endblock %}
{% block body %}
<div class='content'>
<nav class='set-nav'>
<ul>
<li>
<a href="{{ path('settings_profile') }}" class='hover-effect {% if (app.request.attributes.get('_route') starts with 'settings_profile') or (app.request.attributes.get('_route') starts with 'settings_avatar')%}active{% endif %}'>Settings</a>
</li>
<li>
<a href="{{ path('settings_account') }}" class='hover-effect {% if app.request.attributes.get('_route') starts with 'settings_account' %}active{% endif %}'>Account</a>
</li>
<li>
<a href="{{ path('settings_misc') }}" class='hover-effect {% if app.request.attributes.get('_route') starts with 'settings_misc' %}active{% endif %}'>Misc</a>
</li>
</ul>
</nav>
{% block form %}
<div class='form-single'>
{{ form(misc) }}
</div>
{% endblock %}
</div>
{% endblock %}

View File

@ -22,7 +22,7 @@
<a href="{{ path('settings_account') }}" class='hover-effect {% if app.request.attributes.get('_route') starts with 'settings_account' %}active{% endif %}'>Account</a>
</li>
<li>
<a href="{{ path('doc_tags') }}" class='hover-effect {% if app.request.attributes.get('_route') starts with 'doc_tags' %}active{% endif %}'>Misc</a>
<a href="{{ path('settings_misc') }}" class='hover-effect {% if app.request.attributes.get('_route') starts with 'settings_misc' %}active{% endif %}'>Misc</a>
</li>
</ul>
</nav>