Skip to content

Commit 737bc6e

Browse files
Merge pull request #32 from stephanediondev/theme
Theme editor
2 parents c300d45 + 5e2e555 commit 737bc6e

File tree

206 files changed

+701
-455
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

206 files changed

+701
-455
lines changed

.env.dist

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,4 @@ SECRET_REGISTER=
3333
VAPID_PUBLIC_KEY=
3434
VAPID_PRIVATE_KEY=
3535
SENDER_ADDRESS=
36-
#light theme
37-
#THEME_NAVBAR='navbar sticky-top navbar-expand-lg navbar-light bg-light'
38-
#THEME_CARD='shadow p-3 mb-4 bg-light rounded'
39-
#THEME_TABLE='table table-light table-hover table-sm'
40-
#THEME_LINK_PRIMARY='text-primary'
41-
#THEME_LINK_SECONDARY='text-dark'
42-
#THEME_JUMBOTRON='jumbotron mt-3 bg-secondary text-light border border-light'
43-
#THEME_COLOR_1='light'
44-
#THEME_COLOR_2='dark'
4536
###< app ###

assets/js/app.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ if('serviceWorker' in navigator && 'https:' == window.location.protocol) {
9696
}
9797

9898
$(document).ready(function () {
99-
$('label.required').append(' <small class="badge bg-' + themeColor2 + ' text-' + themeColor1 + ' ml-1">' + trans_required + '</small>');
99+
$('label.required').append(' <small class="form-required ' + theme_form_required +'">' + trans_required + '</small>');
100100

101101
$(document).on('click', '.dashboard-table-expand', function(event) {
102102
event.preventDefault();

config/packages/twig.yaml

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,3 @@
11
twig:
22
default_path: '%kernel.project_dir%/templates'
33
form_themes: ['bootstrap_5_layout.html.twig']
4-
globals:
5-
themeNavbar: '%env(THEME_NAVBAR)%'
6-
themeCard: '%env(THEME_CARD)%'
7-
themeTable: '%env(THEME_TABLE)%'
8-
themeLinkPrimary: '%env(THEME_LINK_PRIMARY)%'
9-
themeLinkSecondary: '%env(THEME_LINK_SECONDARY)%'
10-
themeJumbotron: '%env(THEME_JUMBOTRON)%'
11-
themeColor1: '%env(THEME_COLOR_1)%'
12-
themeColor2: '%env(THEME_COLOR_2)%'

config/services.yaml

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,6 @@
44
# Put parameters here that don't need to change on each machine where the app is deployed
55
# https://symfony.com/doc/current/best_practices/configuration.html#application-related-configuration
66
parameters:
7-
env(THEME_NAVBAR): 'navbar sticky-top navbar-expand-lg navbar-dark bg-dark'
8-
env(THEME_CARD): 'shadow p-3 mb-4 bg-dark rounded'
9-
env(THEME_TABLE): 'table table-dark table-hover table-sm'
10-
env(THEME_LINK_PRIMARY): 'text-info'
11-
env(THEME_LINK_SECONDARY): 'text-light'
12-
env(THEME_JUMBOTRON): 'jumbotron mt-3 bg-secondary text-light border border-light'
13-
env(THEME_COLOR_1): 'dark'
14-
env(THEME_COLOR_2): 'light'
157

168
services:
179
# default configuration for services in *this* file

src/Controller/AbstractAppController.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
use App\Manager\CallManager;
77
use App\Manager\ElasticsearchClusterManager;
88
use App\Manager\PaginatorManager;
9+
use App\Manager\AppThemeManager;
910
use App\Model\CallRequestModel;
1011
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
1112
use Symfony\Component\HttpFoundation\Request;
@@ -31,6 +32,14 @@ public function setClusterManager(ElasticsearchClusterManager $elasticsearchClus
3132
$this->elasticsearchClusterManager = $elasticsearchClusterManager;
3233
}
3334

35+
/**
36+
* @required
37+
*/
38+
public function setAppThemeManager(AppThemeManager $appThemeManager)
39+
{
40+
$this->appThemeManager = $appThemeManager;
41+
}
42+
3443
/**
3544
* @required
3645
*/
@@ -49,6 +58,14 @@ public function setTranslator(TranslatorInterface $translator)
4958

5059
public function renderAbstract(Request $request, string $view, array $parameters = [], Response $response = null): Response
5160
{
61+
$twig = $this->container->get('twig');
62+
63+
$saved = $request->cookies->get('theme') ? json_decode($request->cookies->get('theme'), true) : [];
64+
$predefined = $this->appThemeManager->getPredefined('dark');
65+
foreach ($predefined as $k => $v) {
66+
$twig->addGlobal('theme_'.$k, $saved[$k] ?? $v);
67+
}
68+
5269
if (false === isset($parameters['firewall'])) {
5370
$parameters['firewall'] = true;
5471
}

src/Controller/AppThemeController.php

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
<?php
2+
3+
namespace App\Controller;
4+
5+
use App\Controller\AbstractAppController;
6+
use App\Form\Type\AppThemeType;
7+
use Symfony\Component\Routing\Annotation\Route;
8+
use Symfony\Component\HttpFoundation\Cookie;
9+
use Symfony\Component\HttpFoundation\Request;
10+
use Symfony\Component\HttpFoundation\Response;
11+
use Symfony\Component\HttpFoundation\RedirectResponse;
12+
13+
/**
14+
* @Route("/admin")
15+
*/
16+
class AppThemeController extends AbstractAppController
17+
{
18+
/**
19+
* @Route("/theme-editor", name="app_theme_editor")
20+
*/
21+
public function index(Request $request): Response
22+
{
23+
$theme = [];
24+
25+
$saved = $request->cookies->get('theme') ? json_decode($request->cookies->get('theme'), true) : [];
26+
$predefined = $this->appThemeManager->getPredefined('dark');
27+
foreach ($predefined as $k => $v) {
28+
$theme[$k] = $saved[$k] ?? $v;
29+
}
30+
31+
$form = $this->createForm(AppThemeType::class, $theme, [
32+
]);
33+
34+
$form->handleRequest($request);
35+
36+
if ($form->isSubmitted() && $form->isValid()) {
37+
try {
38+
$cookie = Cookie::create('theme', json_encode($form->getData()), 2147483647, '/', null, true, false, false, Cookie::SAMESITE_LAX);
39+
$response = new RedirectResponse($request->getUri());
40+
$response->headers->setCookie($cookie);
41+
42+
$this->addFlash('info', 'theme_saved');
43+
44+
return $response;
45+
} catch (CallException $e) {
46+
$this->addFlash('danger', $e->getMessage());
47+
}
48+
}
49+
50+
return $this->renderAbstract($request, 'Modules/app_theme/app_theme_editor.html.twig', [
51+
'form' => $form->createView(),
52+
'predefined' => $this->appThemeManager->predefinedList(),
53+
]);
54+
}
55+
}

src/Form/Type/AppThemeType.php

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
<?php
2+
3+
namespace App\Form\Type;
4+
5+
use App\Manager\AppThemeManager;
6+
use Symfony\Component\HttpFoundation\Response;
7+
use Symfony\Component\Form\AbstractType;
8+
use Symfony\Component\Form\FormBuilderInterface;
9+
use Symfony\Component\Form\Extension\Core\Type\TextType;
10+
use Symfony\Component\OptionsResolver\OptionsResolver;
11+
use Symfony\Component\Validator\Constraints\NotBlank;
12+
use Symfony\Contracts\Translation\TranslatorInterface;
13+
14+
class AppThemeType extends AbstractType
15+
{
16+
public function __construct(AppThemeManager $appThemeManager, TranslatorInterface $translator)
17+
{
18+
$this->appThemeManager = $appThemeManager;
19+
$this->translator = $translator;
20+
}
21+
22+
public function buildForm(FormBuilderInterface $builder, array $options)
23+
{
24+
$keys = $this->appThemeManager->keys();
25+
26+
$i = 1;
27+
foreach ($keys as $key) {
28+
$builder->add($key, TextType::class, [
29+
'label' => 'theme_'.$key,
30+
'required' => true,
31+
'constraints' => [
32+
new NotBlank(),
33+
],
34+
'attr' => [
35+
'data-break-after' => 4 == $i || 8 == $i ? 'yes' : 'no',
36+
],
37+
]);
38+
$i++;
39+
}
40+
}
41+
42+
public function configureOptions(OptionsResolver $resolver)
43+
{
44+
$resolver->setDefaults([
45+
//'data_class' => AppUserModel::class,
46+
]);
47+
}
48+
49+
public function getBlockPrefix()
50+
{
51+
return 'data';
52+
}
53+
}

src/Manager/AppThemeManager.php

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
<?php
2+
3+
namespace App\Manager;
4+
5+
use App\Manager\AbstractAppManager;
6+
7+
class AppThemeManager extends AbstractAppManager
8+
{
9+
private $predefined = [
10+
'dark' => [
11+
'body' => 'bg-dark text-light',
12+
'navbar' => 'sticky-top navbar-expand-lg navbar-dark bg-dark',
13+
'nav_link' => 'text-light',
14+
'dropdown_menu' => 'dropdown-menu-dark border border-secondary',
15+
'block' => 'shadow p-3 mb-4 bg-dark rounded',
16+
'modal_content' => 'bg-dark',
17+
'form_control' => 'bg-dark text-light',
18+
'form_required' => 'badge bg-light text-dark ml-1',
19+
'table' => 'table-dark table-hover table-sm',
20+
'link_primary' => 'text-info',
21+
'link_secondary' => 'text-light',
22+
'jumbotron' => 'mt-3 bg-secondary text-light border border-light',
23+
'color_1' => 'dark',
24+
'color_2' => 'light',
25+
],
26+
'light' => [
27+
'body' => 'bg-light text-dark',
28+
'navbar' => 'sticky-top navbar-expand-lg navbar-light bg-light',
29+
'nav_link' => 'text-dark',
30+
'dropdown_menu' => 'dropdown-menu-light border border-secondary',
31+
'block' => 'shadow p-3 mb-4 bg-light rounded',
32+
'modal_content' => 'bg-light',
33+
'form_control' => 'bg-light text-dark',
34+
'form_required' => 'badge bg-dark text-light ml-1',
35+
'table' => 'table-light table-hover table-sm',
36+
'link_primary' => 'text-primary',
37+
'link_secondary' => 'text-dark',
38+
'jumbotron' => 'mt-3 bg-secondary text-light border border-light',
39+
'color_1' => 'light',
40+
'color_2' => 'dark',
41+
],
42+
];
43+
44+
public function keys(): array
45+
{
46+
return [
47+
'body',
48+
'navbar',
49+
'nav_link',
50+
'dropdown_menu',
51+
'block',
52+
'modal_content',
53+
'form_control',
54+
'form_required',
55+
'table',
56+
'link_primary',
57+
'link_secondary',
58+
'jumbotron',
59+
'color_1',
60+
'color_2',
61+
];
62+
}
63+
64+
public function predefinedList(): array
65+
{
66+
return $this->predefined;
67+
}
68+
69+
public function getPredefined(string $theme): array
70+
{
71+
return $this->predefined[$theme];
72+
}
73+
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<div class="{{ themeCard }}">
1+
<div class="block {{ theme_block }}">
22
{% block content %}
33
{% endblock %}
44
</div>

templates/Embed/shard_reroute_cluster_embed.html.twig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
<div class="modal fade" id="modal{{ modalReference }}" tabindex="-1" role="dialog" aria-labelledby="modalLabel{{ modalReference }}" aria-hidden="true">
88
<div class="modal-dialog" role="document">
9-
<div class="modal-content bg-{{ themeColor1 }}">
9+
<div class="modal-content {{ theme_modal_content }}">
1010
<form action="{{ form_action }}">
1111
<div class="modal-header">
1212
<h5 class="modal-title" id="modalLabel{{ modalReference }}">{{ title }}</h5>

0 commit comments

Comments
 (0)