Commit ebe13f85 by Damien Moulard

Products families admin with conditionnal display on tav env

parent 333a3529
......@@ -70,7 +70,7 @@ $(document).ready(function() {
});
});
// Hide or display Cotisation or Profils de Cotisation submenu depending on TAV env
// Hide or display Cotisation, Profils de Cotisation and Products Families submenu depending on TAV env
const tav_env = document.getElementsByName('is-tav-env')[0].getAttribute('content');
let linksToCotisationAdherent = $('a[href="/admin/cotisation_adherent/list"]');
......@@ -91,6 +91,12 @@ $(document).ready(function() {
linksToProfilDeCotisation[i].parentNode.style.display = (tav_env === "1") ? "" : "none";
}
}
let linksToProductsFamily = $('a[href="/admin/app/productfamily/list"]');
for(let i = 0 ; i < linksToProductsFamily.length ; i++) {
if(linksToProductsFamily[i].innerText === "Familles de produits") {
linksToProductsFamily[i].parentNode.style.display = (tav_env === "1") ? "" : "none";
}
}
var MutationObserver = window.MutationObserver || window.WebKitMutationObserver || window.MozMutationObserver;
......
......@@ -331,6 +331,14 @@ sonata_admin:
icon: '<i class="fa fa-upload"></i>'
items:
- admin.import
sonata.admin.productsFamily:
keep_open: false
on_top: true
label: "Familles de produits"
label_catalogue: SonataAdminBundle
icon: '<i class="fa fa-shopping-basket"></i>'
items:
- admin.productsFamily
sonata.admin.group.globalparameter:
keep_open: false
on_top: true
......
......@@ -660,6 +660,16 @@ services:
show_mosaic_button: false
public: true
admin.productsFamily:
class: App\Admin\ProductFamilyAdmin
arguments: [~, App\Entity\ProductFamily, ~]
tags:
- name: sonata.admin
manager_type: orm
group: "Familles de Produits"
label: "Familles de Produits"
public: true
sonata.media.provider.csv:
class: App\Admin\ImportProvider
tags:
......
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
......@@ -12,7 +12,7 @@
"admin": {
"js": [
"/build/runtime.6ad5c9da.js",
"/build/admin.cee4d78d.js"
"/build/admin.86a2d986.js"
],
"css": [
"/build/admin.5dc0eea7.css"
......
......@@ -2,7 +2,7 @@
"build/app.css": "/build/app.02f81748.css",
"build/app.js": "/build/app.e49db714.js",
"build/admin.css": "/build/admin.5dc0eea7.css",
"build/admin.js": "/build/admin.cee4d78d.js",
"build/admin.js": "/build/admin.86a2d986.js",
"build/runtime.js": "/build/runtime.6ad5c9da.js",
"build/images/fa-solid-900.svg": "/build/images/fa-solid-900.a838c42a.svg",
"build/images/fa-brands-400.svg": "/build/images/fa-brands-400.05d20183.svg",
......
<?php
namespace App\Admin;
use Sonata\AdminBundle\Admin\AbstractAdmin;
use Sonata\AdminBundle\Datagrid\DatagridMapper;
use Sonata\AdminBundle\Datagrid\ListMapper;
use Sonata\AdminBundle\Form\FormMapper;
use Sonata\AdminBundle\Show\ShowMapper;
use Symfony\Component\Form\Extension\Core\Type\TextType;
/**
* Administration des familles de produits.
*
* KOHINOS : Outil de gestion de Monnaie Locale Complémentaire
*/
class ProductFamilyAdmin extends AbstractAdmin
{
protected function configureFormFields(FormMapper $form): void
{
$form->add('name', TextType::class, [
'label' => 'Nom'
]);
}
protected function configureDatagridFilters(DatagridMapper $datagrid): void
{
$datagrid->add('name', null, [
'label' => 'Nom'
]);
}
protected function configureListFields(ListMapper $list): void
{
$list->addIdentifier('name', null, [
'label' => 'Nom'
]);
}
}
\ No newline at end of file
<?php
declare(strict_types=1);
namespace App\Command;
use App\Entity\ProductFamily;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Style\SymfonyStyle;
/**
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
*/
class CreateProductFamiliesCommand extends Command
{
private const PRODUCTS_FAMILIES = [
"Féculents, céréales, farines",
"Légumineuses",
"Tubercules",
"Fruits et légumes",
"Champignons",
"Graines à germer",
"Viande et charcuterie",
"Œufs et produits laitiers",
"Poisson et produits de la mer",
"Miel et sucre",
"Pain du monde",
"Conserve",
"Fruits à coque",
"Huiles",
"Condiment et épices",
"Café, thé, cacao, chocolat, chicorée et tisanes"
];
protected static $defaultName = 'kohinos:tav:create-products-families';
protected $em;
protected $io;
public function __construct(
EntityManagerInterface $em
) {
$this->em = $em;
parent::__construct();
}
protected function configure()
{
$this
->setDescription('Insert product families into the database.')
;
}
protected function execute(InputInterface $input, OutputInterface $output): int
{
$this->io = new SymfonyStyle($input, $output);
$this->io->title('--- INSERTION DES FAMILLES DE PRODUITS ---');
$this->insertProductFamilies();
$this->io->success('--- FIN DE L\'INSERTION DES FAMILLES DE PRODUITS ---');
return 0;
}
private function insertProductFamilies()
{
foreach (self::PRODUCTS_FAMILIES as $productFamilyName) {
// Create all products families if don't exist
if (null == $this->em->getRepository(ProductFamily::class)->findOneBy(['name' => $productFamilyName])) {
$productFamily = new ProductFamily();
$productFamily->setName($productFamilyName);
$this->em->persist($productFamily);
}
$this->em->flush();
}
}
}
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