refactoring

This commit is contained in:
Simon Vieille 2021-05-30 23:00:08 +02:00
parent 41455d8e39
commit d7154ac6c9
21 changed files with 308 additions and 294 deletions

3
docs/_static/css/extra.css vendored Normal file
View file

@ -0,0 +1,3 @@
.wy-menu p.caption {
margin-top: 10px;
}

View file

Before

Width:  |  Height:  |  Size: 53 KiB

After

Width:  |  Height:  |  Size: 53 KiB

View file

Before

Width:  |  Height:  |  Size: 61 KiB

After

Width:  |  Height:  |  Size: 61 KiB

View file

Before

Width:  |  Height:  |  Size: 74 KiB

After

Width:  |  Height:  |  Size: 74 KiB

View file

Before

Width:  |  Height:  |  Size: 68 KiB

After

Width:  |  Height:  |  Size: 68 KiB

View file

Before

Width:  |  Height:  |  Size: 56 KiB

After

Width:  |  Height:  |  Size: 56 KiB

View file

Before

Width:  |  Height:  |  Size: 52 KiB

After

Width:  |  Height:  |  Size: 52 KiB

View file

Before

Width:  |  Height:  |  Size: 66 KiB

After

Width:  |  Height:  |  Size: 66 KiB

View file

Before

Width:  |  Height:  |  Size: 58 KiB

After

Width:  |  Height:  |  Size: 58 KiB

View file

@ -1,2 +0,0 @@
# Welcome to Murph FR

View file

@ -0,0 +1,2 @@
# Configuration

2
docs/crud/generator.md Normal file
View file

@ -0,0 +1,2 @@
# Generator

2
docs/crud/index.md Normal file
View file

@ -0,0 +1,2 @@
# CRUD

View file

@ -1,259 +0,0 @@
# Settings
## Global settings
![](/img/settings/02.png)
### Create settings
The creation of settings is based on events.
Using an event subscriber, you can create settings and define how to edit them.
A setting's value is stored in json so a value could be a string, a boolean, an array, etc.
See the example below.
```
// src/EventSuscriber/SettingEventSubscriber.php
namespace App\EventSuscriber;
use App\Core\Event\Setting\SettingEvent;
use App\Core\EventSuscriber\SettingEventSubscriber as EventSubscriber;
use App\Core\Setting\SettingManager;
use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
use Symfony\Component\Form\Extension\Core\Type\ColorType;
class SettingEventSubscriber extends EventSubscriber
{
protected SettingManager $manager;
public function __construct(SettingManager $manager)
{
$this->manager = $manager;
}
public function onInit(SettingEvent $event)
{
$this->manager->init('app_font_color', 'Font color', 'Design', '#fff');
$this->manager->init('app_background_color', 'Background color', 'Design', '#333');
$this->manager->init('app_maintenance_enabled', 'Maintenance', 'System', false);
}
public function onFormInit(SettingEvent $event)
{
$data = $event->getData();
$builder = $data['builder'];
$entity = $data['entity'];
if (in_array($entity->getCode(), ['app_font_color', 'app_background_color'])) {
$builder->add(
'value',
ColorType::class,
[
'label' => $entity->getLabel(),
]
);
}
if (in_array($entity->getCode(), ['app_maintenance_enabled'])) {
$builder->add(
'value',
CheckboxType::class,
[
'label' => $entity->getLabel(),
]
);
}
}
}
```
### Access settings
Settings are accessible using `App\Core\Setting\SettingManager` which is a service.
```
// src/Controller/FooController.php
namespace App\Controller;
use App\Core\Setting\SettingManager;
use Symfony\Component\HttpFoundation\Response;
class FooController
{
public function foo(SettingManager $settingManager): Response
{
$fontColor = $settingManager->get('app_font_color');
$backgroundColor = $settingManager->get('app_background_color');
$maintenanceEnabled = $settingManager->get('app_maintenance_enabled');
// ...
}
}
```
In a template, you can use the function `setting`:
```
Font color: {{ setting('app_font_color') }}<br>
Background color: {{ setting('app_background_color') }}<br>
Maintenance enabled: {{ setting('app_maintenance_enabled') ? 'Yes' : 'No' }}<br>
```
### Update settings
Settings are accessible using `App\Core\Setting\SettingManager` which is a service.
```
// src/Controller/FooController.php
namespace App\Controller;
use App\Core\Setting\SettingManager;
use Symfony\Component\HttpFoundation\Response;
class FooController
{
public function foo(SettingManager $settingManager): Response
{
$settingManager->set('app_font_color', '#f00');
$settingManager->set('app_background_color', '#00f');
$settingManager->set('app_maintenance_enabled', true);
// ...
}
}
```
You can also edit them from UI:
![](/img/settings/01.png)
## Navigation settings
![](/img/settings/03.png)
### Create settings
The creation of settings is based on events.
Using an event subscriber, you can create settings and define how to edit them.
A setting's value is stored in json so a value could be a string, a boolean, an array, etc.
See the example below.
```
// src/EventSuscriber/NavigationSettingEventSubscriber.php
namespace App\EventSuscriber;
use App\Core\Event\Setting\NavigationSettingEvent;
use App\Core\EventSuscriber\NavigationSettingEventSubscriber as EventSubscriber;
use App\Core\Setting\NavigationSettingManager;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\Extension\Core\Type\EmailType;
class NavigationSettingEventSubscriber extends EventSubscriber
{
protected NavigationSettingManager $manager;
public function __construct(NavigationSettingManager $manager)
{
$this->manager = $manager;
}
public function onInit(NavigationSettingEvent $event)
{
$data = $event->getData();
$navigation = $data['navigation'];
$this->manager->init($navigation, 'nav_tracker_code', 'Stats', 'Tracker', '');
$this->manager->init($navigation, 'nav_contact_email', 'Contact', 'Email', 'foo@example.com');
}
public function onFormInit(NavigationSettingEvent $event)
{
$data = $event->getData();
$builder = $data['builder'];
$entity = $data['entity'];
if (in_array($entity->getCode(), ['nav_tracker_code'])) {
$builder->add(
'value',
TextType::class,
[
'label' => $entity->getLabel(),
]
);
}
if (in_array($entity->getCode(), ['nav_contact_email'])) {
$builder->add(
'value',
EmailType::class,
[
'label' => $entity->getLabel(),
]
);
}
}
}
```
### Access settings
Settings are accessible using `App\Core\Setting\NavigationSettingManager` which is a service.
```
// src/Controller/FooController.php
namespace App\Controller;
use App\Core\Setting\NavigationSettingManager;
use App\Core\Site\SiteRequest;
use Symfony\Component\HttpFoundation\Response;
class FooController
{
public function foo(NavigationSettingManager $settingManager, SiteRequest $siteRequest): Response
{
$trackerCode = $settingManager->get($siteRequest->getNavigation(), 'nav_tracker_code');
$contactEmail = $settingManager->get($siteRequest->getNavigation(), 'nav_contact_email');
// ...
}
}
```
In a template, you can use the function `navigation_setting`:
```
Tracker code: {{ navigation_setting(_navigation, 'nav_tracker_code') }}<br>
Contact email: {{ navigation_setting('my_nav', 'nav_contact_email') }}<br>
```
### Update settings
Settings are accessible using `App\Core\Setting\NavigationSettingManager` which is a service.
```
// src/Controller/FooController.php
namespace App\Controller;
use App\Core\Setting\NavigationSettingManager;
use App\Core\Site\SiteRequest;
use Symfony\Component\HttpFoundation\Response;
class FooController
{
public function foo(NavigationSettingManager $settingManager, SiteRequest $siteRequest): Response
{
$settingManager->set($siteRequest->getNavigation(), 'nav_tracker_code', '...');
$settingManager->set('my_nav', 'nav_contact_email', '...');
// ...
}
}
```
You can also edit them from UI:
![](/img/settings/04.png)

127
docs/settings/global.md Normal file
View file

@ -0,0 +1,127 @@
# Global settings
![](/_static/img/settings/02.png)
## Create settings
The creation of settings is based on events.
Using an event subscriber, you can create settings and define how to edit them.
A setting's value is stored in json so a value could be a string, a boolean, an array, etc.
See the example below.
```
// src/EventSuscriber/SettingEventSubscriber.php
namespace App\EventSuscriber;
use App\Core\Event\Setting\SettingEvent;
use App\Core\EventSuscriber\SettingEventSubscriber as EventSubscriber;
use App\Core\Setting\SettingManager;
use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
use Symfony\Component\Form\Extension\Core\Type\ColorType;
class SettingEventSubscriber extends EventSubscriber
{
protected SettingManager $manager;
public function __construct(SettingManager $manager)
{
$this->manager = $manager;
}
public function onInit(SettingEvent $event)
{
$this->manager->init('app_font_color', 'Font color', 'Design', '#fff');
$this->manager->init('app_background_color', 'Background color', 'Design', '#333');
$this->manager->init('app_maintenance_enabled', 'Maintenance', 'System', false);
}
public function onFormInit(SettingEvent $event)
{
$data = $event->getData();
$builder = $data['builder'];
$entity = $data['entity'];
if (in_array($entity->getCode(), ['app_font_color', 'app_background_color'])) {
$builder->add(
'value',
ColorType::class,
[
'label' => $entity->getLabel(),
]
);
}
if (in_array($entity->getCode(), ['app_maintenance_enabled'])) {
$builder->add(
'value',
CheckboxType::class,
[
'label' => $entity->getLabel(),
]
);
}
}
}
```
## Access settings
Settings are accessible using `App\Core\Setting\SettingManager` which is a service.
```
// src/Controller/FooController.php
namespace App\Controller;
use App\Core\Setting\SettingManager;
use Symfony\Component\HttpFoundation\Response;
class FooController
{
public function foo(SettingManager $settingManager): Response
{
$fontColor = $settingManager->get('app_font_color');
$backgroundColor = $settingManager->get('app_background_color');
$maintenanceEnabled = $settingManager->get('app_maintenance_enabled');
// ...
}
}
```
In a template, you can use the function `setting`:
```
Font color: {{ setting('app_font_color') }}<br>
Background color: {{ setting('app_background_color') }}<br>
Maintenance enabled: {{ setting('app_maintenance_enabled') ? 'Yes' : 'No' }}<br>
```
## Update settings
Settings are accessible using `App\Core\Setting\SettingManager` which is a service.
```
// src/Controller/FooController.php
namespace App\Controller;
use App\Core\Setting\SettingManager;
use Symfony\Component\HttpFoundation\Response;
class FooController
{
public function foo(SettingManager $settingManager): Response
{
$settingManager->set('app_font_color', '#f00');
$settingManager->set('app_background_color', '#00f');
$settingManager->set('app_maintenance_enabled', true);
// ...
}
}
```
You can also edit them from UI:
![](/_static/img/settings/01.png)

128
docs/settings/navigation.md Normal file
View file

@ -0,0 +1,128 @@
# Navigation settings
![](/_static/img/settings/03.png)
## Create settings
The creation of settings is based on events.
Using an event subscriber, you can create settings and define how to edit them.
A setting's value is stored in json so a value could be a string, a boolean, an array, etc.
See the example below.
```
// src/EventSuscriber/NavigationSettingEventSubscriber.php
namespace App\EventSuscriber;
use App\Core\Event\Setting\NavigationSettingEvent;
use App\Core\EventSuscriber\NavigationSettingEventSubscriber as EventSubscriber;
use App\Core\Setting\NavigationSettingManager;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\Extension\Core\Type\EmailType;
class NavigationSettingEventSubscriber extends EventSubscriber
{
protected NavigationSettingManager $manager;
public function __construct(NavigationSettingManager $manager)
{
$this->manager = $manager;
}
public function onInit(NavigationSettingEvent $event)
{
$data = $event->getData();
$navigation = $data['navigation'];
$this->manager->init($navigation, 'nav_tracker_code', 'Stats', 'Tracker', '');
$this->manager->init($navigation, 'nav_contact_email', 'Contact', 'Email', 'foo@example.com');
}
public function onFormInit(NavigationSettingEvent $event)
{
$data = $event->getData();
$builder = $data['builder'];
$entity = $data['entity'];
if (in_array($entity->getCode(), ['nav_tracker_code'])) {
$builder->add(
'value',
TextType::class,
[
'label' => $entity->getLabel(),
]
);
}
if (in_array($entity->getCode(), ['nav_contact_email'])) {
$builder->add(
'value',
EmailType::class,
[
'label' => $entity->getLabel(),
]
);
}
}
}
```
## Access settings
Settings are accessible using `App\Core\Setting\NavigationSettingManager` which is a service.
```
// src/Controller/FooController.php
namespace App\Controller;
use App\Core\Setting\NavigationSettingManager;
use App\Core\Site\SiteRequest;
use Symfony\Component\HttpFoundation\Response;
class FooController
{
public function foo(NavigationSettingManager $settingManager, SiteRequest $siteRequest): Response
{
$trackerCode = $settingManager->get($siteRequest->getNavigation(), 'nav_tracker_code');
$contactEmail = $settingManager->get($siteRequest->getNavigation(), 'nav_contact_email');
// ...
}
}
```
In a template, you can use the function `navigation_setting`:
```
Tracker code: {{ navigation_setting(_navigation, 'nav_tracker_code') }}<br>
Contact email: {{ navigation_setting('my_nav', 'nav_contact_email') }}<br>
```
## Update settings
Settings are accessible using `App\Core\Setting\NavigationSettingManager` which is a service.
```
// src/Controller/FooController.php
namespace App\Controller;
use App\Core\Setting\NavigationSettingManager;
use App\Core\Site\SiteRequest;
use Symfony\Component\HttpFoundation\Response;
class FooController
{
public function foo(NavigationSettingManager $settingManager, SiteRequest $siteRequest): Response
{
$settingManager->set($siteRequest->getNavigation(), 'nav_tracker_code', '...');
$settingManager->set('my_nav', 'nav_contact_email', '...');
// ...
}
}
```
You can also edit them from UI:
![](/_static/img/settings/04.png)

12
docs/tree/index.md Normal file
View file

@ -0,0 +1,12 @@
# Tree manager
Murph manages contents this way:
* You define navigations
* For each navigation, you define menus
* For each menu, you define elements (nodes)
* and for each element, you define:
- an optional page
- the routing
- some attributes
- a sitemap configuration

10
docs/tree/menu.md Normal file
View file

@ -0,0 +1,10 @@
# Menu
To create a menu, go to `Trees`, select the navigation and click on `Add a menu`. Then fill the form and save.
* The `label` is the label displayed whenever necessary (eg: `Top menu`)
* The `code` is an unique technical identifier (in the given navigation) and it is useful in templating, routing and settings (eg: `top`)
When a menu is created then an element is automatically generated.
![](/_static/img/tree/02.png)

View file

@ -1,17 +1,4 @@
# Tree manager
Murph manages contents this way:
* You define navigations
* For each navigation, you define menus
* For each menu, you define elements (nodes)
* and for each element, you define:
- an optional page
- the routing
- some attributes
- a sitemap configuration
## Navigation
# Navigation
To create a navigation, go to `Navigations` and click on `New`. Then fill the form and save.
@ -24,15 +11,4 @@ To create a navigation, go to `Navigations` and click on `New`. Then fill the fo
If several navigations share the same domain, then the locale will by used to prefix routes.
But if a navigation uses a single domain then the local will not prefix routes.
![](/img/tree/01.png)
## Menu
To create a menu, go to `Trees`, select the navigation and click on `Add a menu`. Then fill the form and save.
* The `label` is the label displayed whenever necessary (eg: `Top menu`)
* The `code` is an unique technical identifier (in the given navigation) and it is useful in templating, routing and settings (eg: `top`)
When a menu is created then an element is automatically generated.
![](/img/tree/02.png)
![](/_static/img/tree/01.png)

View file

@ -1,2 +1,2 @@
# Welcome to Murph FR
# Users

View file

@ -1,10 +1,23 @@
site_name: Murph documentation
theme: readthedocs
theme:
name: readthedocs
extra_css:
- /_static/css/extra.css
nav:
- Overview: index.md
- Installation: install.md
- Tree manager: tree.md
- CRUD: crud.md
- Settings: settings.md
- Users: users.md
- Tasks: tasks.md
- 'Tree manager':
- Overview: tree/index.md
- Navigation: tree/navigation.md
- Menu: tree/menu.md
- CRUD:
- Overview: crud/index.md
- Generator: crud/generator.md
- Configuration: crud/configuration.md
- Settings:
- 'Global settings': settings/global.md
- 'Navigation settings': settings/navigation.md
- Users:
- Users: users.md
- Others:
- Tasks: tasks.md