```
✨ feat(devis): Améliore la sélection des produits et options avec modales de recherche
Supprime la relation Product->DevisLine, ajoute des composants de recherche modale pour produits/options dans les devis.
```
This commit is contained in:
@@ -1,11 +1,12 @@
|
||||
import './admin.scss';
|
||||
import * as Sentry from "@sentry/browser";
|
||||
import * as Turbo from "@hotwired/turbo";
|
||||
import TomSelect from "tom-select";
|
||||
|
||||
import { RepeatLine } from "./libs/RepeatLine.js";
|
||||
import { DevisManager } from "./libs/DevisManager.js";
|
||||
import { initTomSelect } from "./libs/initTomSelect.js";
|
||||
import { SearchProduct,SearchOptions } from "./libs/SearchProduct.js";
|
||||
import { SearchProductDevis,SearchOptionsDevis } from "./libs/SearchProductDevis.js";
|
||||
// --- INITIALISATION SENTRY ---
|
||||
Sentry.init({
|
||||
dsn: "https://803814be6540031b1c37bf92ba9c0f79@sentry.esy-web.dev/24",
|
||||
@@ -70,6 +71,13 @@ function initAdminLayout() {
|
||||
if (!customElements.get('search-options')) {
|
||||
customElements.define('search-options', SearchOptions, { extends: 'button' });
|
||||
}
|
||||
if (!customElements.get('search-productdevis')) {
|
||||
customElements.define('search-productdevis', SearchProductDevis, { extends: 'button' });
|
||||
}
|
||||
if (!customElements.get('search-optionsdevis')) {
|
||||
customElements.define('search-optionsdevis', SearchOptionsDevis, { extends: 'button' });
|
||||
}
|
||||
// S
|
||||
// Sidebar & UI
|
||||
const sidebar = document.getElementById('sidebar');
|
||||
const overlay = document.getElementById('sidebar-overlay');
|
||||
|
||||
288
assets/libs/SearchProductDevis.js
Normal file
288
assets/libs/SearchProductDevis.js
Normal file
@@ -0,0 +1,288 @@
|
||||
export class SearchOptionsDevis extends HTMLButtonElement {
|
||||
constructor() {
|
||||
super();
|
||||
this.allOptions = [];
|
||||
}
|
||||
|
||||
connectedCallback() {
|
||||
this.addEventListener('click', () => this.openModal());
|
||||
}
|
||||
|
||||
async openModal() {
|
||||
let modal = document.getElementById('modal-search-options');
|
||||
if (!modal) {
|
||||
modal = this.createModalStructure();
|
||||
document.body.appendChild(modal);
|
||||
this.setupSearchEvent(modal);
|
||||
}
|
||||
|
||||
modal.classList.remove('hidden');
|
||||
const container = modal.querySelector('#results-container-options');
|
||||
const searchInput = modal.querySelector('#modal-search-input-options');
|
||||
|
||||
searchInput.value = '';
|
||||
container.innerHTML = '<div class="text-white p-8 text-center animate-pulse tracking-widest text-[10px] uppercase font-black">Chargement des options...</div>';
|
||||
|
||||
try {
|
||||
const response = await fetch('/crm/options/json');
|
||||
this.allOptions = await response.json();
|
||||
this.renderOptions(this.allOptions, container, modal);
|
||||
searchInput.focus();
|
||||
} catch (error) {
|
||||
container.innerHTML = '<div class="text-red-400 p-8 text-center">Erreur catalogue options.</div>';
|
||||
}
|
||||
}
|
||||
|
||||
createModalStructure() {
|
||||
const div = document.createElement('div');
|
||||
div.id = 'modal-search-options';
|
||||
div.className = 'fixed inset-0 z-[100] flex items-center justify-center p-4 bg-slate-950/90 backdrop-blur-md hidden animate-in fade-in duration-300';
|
||||
div.innerHTML = `
|
||||
<div class="bg-slate-900 border border-white/10 w-full max-w-2xl max-h-[85vh] rounded-[3rem] shadow-2xl overflow-hidden flex flex-col scale-in-center">
|
||||
<div class="p-8 border-b border-white/5 bg-white/5 space-y-6">
|
||||
<div class="flex justify-between items-center">
|
||||
<h3 class="text-white font-black uppercase tracking-[0.3em] text-[11px] flex items-center">
|
||||
<span class="w-2 h-2 bg-blue-500 rounded-full mr-3 animate-pulse"></span>
|
||||
Sélection Option
|
||||
</h3>
|
||||
<button type="button" onclick="this.closest('#modal-search-options').classList.add('hidden')" class="p-2 text-slate-400 hover:text-white transition-colors">
|
||||
<svg class="w-6 h-6" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M6 18L18 6M6 6l12 12"/></svg>
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<div class="relative">
|
||||
<input type="text" id="modal-search-input-options" placeholder="RECHERCHER UNE OPTION..."
|
||||
class="w-full bg-slate-950/50 border border-white/10 rounded-2xl py-4 pl-12 pr-5 text-white text-xs font-black tracking-widest focus:ring-blue-500/20 focus:border-blue-500 transition-all uppercase placeholder:text-slate-600">
|
||||
<svg class="w-5 h-5 absolute left-4 top-3.5 text-slate-500" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M21 21l-6-6m2-5a7 7 0 11-14 0 7 7 0 0114 0z"/>
|
||||
</svg>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div id="results-container-options" class="overflow-y-auto p-6 space-y-2 custom-scrollbar flex-grow min-h-[300px]"></div>
|
||||
|
||||
<div class="p-4 bg-white/5 text-center">
|
||||
<p class="text-[9px] text-slate-500 font-black uppercase tracking-widest line-clamp-1">Appuyez sur Échap pour fermer</p>
|
||||
</div>
|
||||
</div>
|
||||
`;
|
||||
return div;
|
||||
}
|
||||
|
||||
setupSearchEvent(modal) {
|
||||
const input = modal.querySelector('#modal-search-input-options');
|
||||
const container = modal.querySelector('#results-container-options');
|
||||
|
||||
input.oninput = () => {
|
||||
const query = input.value.toLowerCase().trim();
|
||||
const filtered = this.allOptions.filter(o =>
|
||||
o.name.toLowerCase().includes(query)
|
||||
);
|
||||
this.renderOptions(filtered, container, modal);
|
||||
};
|
||||
|
||||
window.addEventListener('keydown', (e) => {
|
||||
if (e.key === 'Escape') modal.classList.add('hidden');
|
||||
});
|
||||
}
|
||||
|
||||
renderOptions(options, container, modal) {
|
||||
container.innerHTML = '';
|
||||
|
||||
if (options.length === 0) {
|
||||
container.innerHTML = '<div class="text-slate-600 p-12 text-center text-[10px] font-black uppercase tracking-[0.2em]">Aucune option trouvée</div>';
|
||||
return;
|
||||
}
|
||||
|
||||
options.forEach(option => {
|
||||
const card = document.createElement('div');
|
||||
card.className = 'flex items-center gap-5 p-4 bg-white/5 border border-white/5 rounded-2xl hover:bg-blue-500/10 hover:border-blue-500/40 transition-all cursor-pointer group animate-in fade-in slide-in-from-bottom-2';
|
||||
|
||||
const imgHtml = option.image
|
||||
? `<img src="${option.image}" class="w-14 h-14 rounded-xl object-cover shadow-lg group-hover:scale-110 transition-transform" onerror="this.src='/provider/images/favicon.png'">`
|
||||
: `<div class="w-14 h-14 bg-slate-950 rounded-xl flex items-center justify-center text-[8px] text-slate-700 font-black border border-white/5">OPT</div>`;
|
||||
|
||||
card.innerHTML = `
|
||||
${imgHtml}
|
||||
<div class="flex-grow">
|
||||
<div class="text-white font-black text-xs uppercase tracking-wider mb-1">${option.name}</div>
|
||||
<div class="flex gap-4">
|
||||
<span class="text-blue-400 text-[10px] font-mono">PRIX HT: ${option.price}€</span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="w-10 h-10 rounded-full bg-blue-500/0 group-hover:bg-blue-500/20 flex items-center justify-center text-blue-500 transition-all">
|
||||
<svg class="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="3" d="M12 6v6m0 0v6m0-6h6m-6 0H6"/></svg>
|
||||
</div>
|
||||
`;
|
||||
|
||||
card.onclick = () => {
|
||||
this.fillOptionLine(option);
|
||||
modal.classList.add('hidden');
|
||||
};
|
||||
container.appendChild(card);
|
||||
});
|
||||
}
|
||||
|
||||
fillOptionLine(option) {
|
||||
// On cherche la ligne parente (ajuste le sélecteur si différent de celui des produits)
|
||||
const row = this.closest('.form-repeater__row');
|
||||
if (row) {
|
||||
// Mapping selon ta structure de DevisOption
|
||||
const nameInput = row.querySelector('input[name*="[product]"]');
|
||||
const priceInput = row.querySelector('input[name*="[price_ht]"]');
|
||||
|
||||
if(nameInput) nameInput.value = option.name;
|
||||
if(priceInput) priceInput.value = option.price;
|
||||
|
||||
// Feedback visuel (Bleu pour les options)
|
||||
const fieldset = row.querySelector('fieldset');
|
||||
if (fieldset) {
|
||||
fieldset.classList.add('border-blue-500/50', 'bg-blue-500/5');
|
||||
setTimeout(() => fieldset.classList.remove('border-blue-500/50', 'bg-blue-500/5'), 800);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export class SearchProductDevis extends HTMLButtonElement {
|
||||
constructor() {
|
||||
super();
|
||||
this.allProducts = []; // Stockage local pour la recherche
|
||||
}
|
||||
|
||||
connectedCallback() {
|
||||
this.addEventListener('click', () => this.openModal());
|
||||
}
|
||||
|
||||
async openModal() {
|
||||
let modal = document.getElementById('modal-search-product');
|
||||
if (!modal) {
|
||||
modal = this.createModalStructure();
|
||||
document.body.appendChild(modal);
|
||||
this.setupSearchEvent(modal);
|
||||
}
|
||||
|
||||
modal.classList.remove('hidden');
|
||||
const container = modal.querySelector('#results-container');
|
||||
const searchInput = modal.querySelector('#modal-search-input');
|
||||
|
||||
searchInput.value = ''; // Reset recherche
|
||||
container.innerHTML = '<div class="text-white p-8 text-center animate-pulse tracking-widest text-[10px] uppercase font-black">Synchronisation catalogue...</div>';
|
||||
|
||||
try {
|
||||
const response = await fetch('/crm/products/json');
|
||||
this.allProducts = await response.json();
|
||||
this.renderProducts(this.allProducts, container, modal);
|
||||
searchInput.focus();
|
||||
} catch (error) {
|
||||
container.innerHTML = '<div class="text-red-400 p-8 text-center">Erreur catalogue.</div>';
|
||||
}
|
||||
}
|
||||
|
||||
createModalStructure() {
|
||||
const div = document.createElement('div');
|
||||
div.id = 'modal-search-product';
|
||||
div.className = 'fixed inset-0 z-[100] flex items-center justify-center p-4 bg-slate-950/90 backdrop-blur-md hidden animate-in fade-in duration-300';
|
||||
div.innerHTML = `
|
||||
<div class="bg-slate-900 border border-white/10 w-full max-w-2xl max-h-[85vh] rounded-[3rem] shadow-2xl overflow-hidden flex flex-col scale-in-center">
|
||||
<div class="p-8 border-b border-white/5 bg-white/5 space-y-6">
|
||||
<div class="flex justify-between items-center">
|
||||
<h3 class="text-white font-black uppercase tracking-[0.3em] text-[11px] flex items-center">
|
||||
<span class="w-2 h-2 bg-purple-500 rounded-full mr-3 animate-pulse"></span>
|
||||
Sélection Produit
|
||||
</h3>
|
||||
<button type="button" onclick="this.closest('#modal-search-product').classList.add('hidden')" class="p-2 text-slate-400 hover:text-white transition-colors">
|
||||
<svg class="w-6 h-6" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M6 18L18 6M6 6l12 12"/></svg>
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<div class="relative">
|
||||
<input type="text" id="modal-search-input" placeholder="RECHERCHER UN NOM, UNE RÉFÉRENCE..."
|
||||
class="w-full bg-slate-950/50 border border-white/10 rounded-2xl py-4 pl-12 pr-5 text-white text-xs font-black tracking-widest focus:ring-purple-500/20 focus:border-purple-500 transition-all uppercase placeholder:text-slate-600">
|
||||
<svg class="w-5 h-5 absolute left-4 top-3.5 text-slate-500" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M21 21l-6-6m2-5a7 7 0 11-14 0 7 7 0 0114 0z"/>
|
||||
</svg>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div id="results-container" class="overflow-y-auto p-6 space-y-2 custom-scrollbar flex-grow min-h-[300px]"></div>
|
||||
|
||||
<div class="p-4 bg-white/5 text-center">
|
||||
<p class="text-[9px] text-slate-500 font-black uppercase tracking-widest line-clamp-1">Appuyez sur Échap pour fermer</p>
|
||||
</div>
|
||||
</div>
|
||||
`;
|
||||
return div;
|
||||
}
|
||||
|
||||
setupSearchEvent(modal) {
|
||||
const input = modal.querySelector('#modal-search-input');
|
||||
const container = modal.querySelector('#results-container');
|
||||
|
||||
input.oninput = () => {
|
||||
const query = input.value.toLowerCase().trim();
|
||||
const filtered = this.allProducts.filter(p =>
|
||||
p.name.toLowerCase().includes(query)
|
||||
);
|
||||
this.renderProducts(filtered, container, modal);
|
||||
};
|
||||
|
||||
// Fermeture sur Echap
|
||||
window.addEventListener('keydown', (e) => {
|
||||
if (e.key === 'Escape') modal.classList.add('hidden');
|
||||
});
|
||||
}
|
||||
|
||||
renderProducts(products, container, modal) {
|
||||
container.innerHTML = '';
|
||||
|
||||
if (products.length === 0) {
|
||||
container.innerHTML = '<div class="text-slate-600 p-12 text-center text-[10px] font-black uppercase tracking-[0.2em]">Aucun produit trouvé</div>';
|
||||
return;
|
||||
}
|
||||
|
||||
products.forEach(product => {
|
||||
const card = document.createElement('div');
|
||||
card.className = 'flex items-center gap-5 p-4 bg-white/5 border border-white/5 rounded-2xl hover:bg-purple-500/10 hover:border-purple-500/40 transition-all cursor-pointer group animate-in fade-in slide-in-from-bottom-2';
|
||||
|
||||
const imgHtml = product.image
|
||||
? `<img src="${product.image}" class="w-14 h-14 rounded-xl object-cover shadow-lg group-hover:scale-110 transition-transform">`
|
||||
: `<div class="w-14 h-14 bg-slate-950 rounded-xl flex items-center justify-center text-[8px] text-slate-700 font-black border border-white/5">IMG</div>`;
|
||||
|
||||
card.innerHTML = `
|
||||
${imgHtml}
|
||||
<div class="flex-grow">
|
||||
<div class="text-white font-black text-xs uppercase tracking-wider mb-1">${product.name}</div>
|
||||
<div class="flex gap-4">
|
||||
<span class="text-purple-400 text-[10px] font-mono">1J: ${product.price1day}€</span>
|
||||
<span class="text-slate-500 text-[10px] font-mono">SUP: ${product.priceSup}€</span>
|
||||
<span class="text-amber-500/80 text-[10px] font-mono">CAUTION: ${product.caution}€</span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="w-10 h-10 rounded-full bg-purple-500/0 group-hover:bg-purple-500/20 flex items-center justify-center text-purple-500 transition-all">
|
||||
<svg class="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="3" d="M12 6v6m0 0v6m0-6h6m-6 0H6"/></svg>
|
||||
</div>
|
||||
`;
|
||||
|
||||
card.onclick = () => {
|
||||
this.fillFormLine(product);
|
||||
modal.classList.add('hidden');
|
||||
};
|
||||
container.appendChild(card);
|
||||
});
|
||||
}
|
||||
|
||||
fillFormLine(product) {
|
||||
const row = this.closest('.form-repeater__row');
|
||||
if (row) {
|
||||
row.querySelector('input[name*="[product]"]').value = product.name;
|
||||
row.querySelector('input[name*="[price_ht]"]').value = product.price1day;
|
||||
row.querySelector('input[name*="[price_sup_ht]"]').value = product.priceSup;
|
||||
|
||||
const fieldset = row.querySelector('fieldset');
|
||||
fieldset.classList.add('border-emerald-500/50', 'bg-emerald-500/5');
|
||||
setTimeout(() => fieldset.classList.remove('border-emerald-500/50', 'bg-emerald-500/5'), 800);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
38
migrations/Version20260127091504.php
Normal file
38
migrations/Version20260127091504.php
Normal file
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace DoctrineMigrations;
|
||||
|
||||
use Doctrine\DBAL\Schema\Schema;
|
||||
use Doctrine\Migrations\AbstractMigration;
|
||||
|
||||
/**
|
||||
* Auto-generated Migration: Please modify to your needs!
|
||||
*/
|
||||
final class Version20260127091504 extends AbstractMigration
|
||||
{
|
||||
public function getDescription(): string
|
||||
{
|
||||
return '';
|
||||
}
|
||||
|
||||
public function up(Schema $schema): void
|
||||
{
|
||||
// this up() migration is auto-generated, please modify it to your needs
|
||||
$this->addSql('ALTER TABLE devis_line DROP CONSTRAINT fk_9ec6d5294584665a');
|
||||
$this->addSql('DROP INDEX idx_9ec6d5294584665a');
|
||||
$this->addSql('ALTER TABLE devis_line ADD product VARCHAR(255) NOT NULL');
|
||||
$this->addSql('ALTER TABLE devis_line DROP product_id');
|
||||
}
|
||||
|
||||
public function down(Schema $schema): void
|
||||
{
|
||||
// this down() migration is auto-generated, please modify it to your needs
|
||||
$this->addSql('CREATE SCHEMA public');
|
||||
$this->addSql('ALTER TABLE devis_line ADD product_id INT DEFAULT NULL');
|
||||
$this->addSql('ALTER TABLE devis_line DROP product');
|
||||
$this->addSql('ALTER TABLE devis_line ADD CONSTRAINT fk_9ec6d5294584665a FOREIGN KEY (product_id) REFERENCES product (id) NOT DEFERRABLE INITIALLY IMMEDIATE');
|
||||
$this->addSql('CREATE INDEX idx_9ec6d5294584665a ON devis_line (product_id)');
|
||||
}
|
||||
}
|
||||
189
src/Command/DeployConfigCommand.php
Normal file
189
src/Command/DeployConfigCommand.php
Normal file
@@ -0,0 +1,189 @@
|
||||
<?php
|
||||
|
||||
namespace App\Command;
|
||||
|
||||
use Symfony\Component\Console\Attribute\AsCommand;
|
||||
use Symfony\Component\Console\Command\Command;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
use Symfony\Component\Console\Style\SymfonyStyle;
|
||||
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
|
||||
use Symfony\Component\Filesystem\Filesystem;
|
||||
use Symfony\Contracts\HttpClient\HttpClientInterface;
|
||||
|
||||
#[AsCommand(
|
||||
name: 'app:deploy:config',
|
||||
description: 'Initialise et déploie la configuration système en extrayant les infos de l\'inventaire Ansible.',
|
||||
)]
|
||||
class DeployConfigCommand extends Command
|
||||
{
|
||||
private const LIBRARY_RULE_NAME = "EsyCMS Library Cache";
|
||||
private const PDF_RULE_NAME = "EsyCMS Disable PDF Cache";
|
||||
private const CACHE_PHASE = 'http_request_cache_settings';
|
||||
|
||||
public function __construct(
|
||||
private readonly ParameterBagInterface $parameterBag,
|
||||
private readonly HttpClientInterface $httpClient
|
||||
) {
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
protected function execute(InputInterface $input, OutputInterface $output): int
|
||||
{
|
||||
$io = new SymfonyStyle($input, $output);
|
||||
|
||||
$hostIntranet = "intranet.ludikevent.fr";
|
||||
$hostReservation = "reservation.ludikevent.fr";
|
||||
$mainHost = "ludikevent.fr";
|
||||
|
||||
$host = parse_url($mainHost, PHP_URL_HOST) ?: $mainHost;
|
||||
$parts = explode('.', $host);
|
||||
$fqdn = count($parts) >= 2 ? implode('.', array_slice($parts, -2)) : $host;
|
||||
|
||||
$io->success(sprintf('Hôte principal détecté : %s', $mainHost));
|
||||
|
||||
// 1. Gestion du cache local
|
||||
$io->section('Gestion du cache local');
|
||||
$filesystem = new Filesystem();
|
||||
$cachePath = sys_get_temp_dir() . '/esycms-cache';
|
||||
|
||||
if ($filesystem->exists($cachePath)) {
|
||||
$filesystem->remove($cachePath);
|
||||
$io->note('Dossier esycms-cache local supprimé.');
|
||||
}
|
||||
|
||||
// 2. Configuration Cloudflare
|
||||
$io->section('Configuration Cloudflare (Rulesets)');
|
||||
$cfToken = $_ENV['CLOUDFLARE_DEPLOY'] ?? null;
|
||||
|
||||
if (!$cfToken) {
|
||||
$io->error('La clé API Cloudflare (CLOUDFLARE_DEPLOY) est manquante.');
|
||||
return Command::FAILURE;
|
||||
}
|
||||
|
||||
try {
|
||||
// A. Récupération de la Zone
|
||||
$response = $this->httpClient->request('GET', 'https://api.cloudflare.com/client/v4/zones', [
|
||||
'headers' => ['Authorization' => 'Bearer ' . $cfToken],
|
||||
'query' => ['name' => $fqdn, 'status' => 'active'],
|
||||
]);
|
||||
|
||||
$data = $response->toArray();
|
||||
if (empty($data['result'])) {
|
||||
$io->error(sprintf('Zone introuvable pour : %s', $fqdn));
|
||||
return Command::FAILURE;
|
||||
}
|
||||
|
||||
$zoneId = $data['result'][0]['id'];
|
||||
|
||||
// B. Récupération/Création du Ruleset
|
||||
$rulesetsResponse = $this->httpClient->request('GET', "https://api.cloudflare.com/client/v4/zones/$zoneId/rulesets", [
|
||||
'headers' => ['Authorization' => 'Bearer ' . $cfToken]
|
||||
]);
|
||||
|
||||
$rulesets = $rulesetsResponse->toArray()['result'] ?? [];
|
||||
$rulesetId = null;
|
||||
foreach ($rulesets as $rs) {
|
||||
if ($rs['phase'] === self::CACHE_PHASE) {
|
||||
$rulesetId = $rs['id'];
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!$rulesetId) {
|
||||
$createResponse = $this->httpClient->request('POST', "https://api.cloudflare.com/client/v4/zones/$zoneId/rulesets", [
|
||||
'headers' => ['Authorization' => 'Bearer ' . $cfToken, 'Content-Type' => 'application/json'],
|
||||
'json' => [
|
||||
'name' => 'EsyCMS Cache Ruleset',
|
||||
'kind' => 'zone',
|
||||
'phase' => self::CACHE_PHASE
|
||||
]
|
||||
]);
|
||||
$rulesetId = $createResponse->toArray()['result']['id'];
|
||||
}
|
||||
|
||||
// C. Récupération des règles actuelles pour nettoyage
|
||||
$rulesResponse = $this->httpClient->request('GET', "https://api.cloudflare.com/client/v4/zones/$zoneId/rulesets/$rulesetId", [
|
||||
'headers' => ['Authorization' => 'Bearer ' . $cfToken]
|
||||
]);
|
||||
$currentRules = $rulesResponse->toArray()['result']['rules'] ?? [];
|
||||
|
||||
// D. Nettoyage des anciennes règles gérées par ce script
|
||||
$sanitizedRules = [];
|
||||
foreach ($currentRules as $rule) {
|
||||
$desc = $rule['description'] ?? '';
|
||||
if ($desc === self::LIBRARY_RULE_NAME || $desc === self::PDF_RULE_NAME) {
|
||||
continue;
|
||||
}
|
||||
$sanitizedRules[] = [
|
||||
'expression' => $rule['expression'],
|
||||
'description' => $rule['description'] ?? '',
|
||||
'action' => $rule['action'],
|
||||
'action_parameters' => $rule['action_parameters'] ?? null,
|
||||
'enabled' => $rule['enabled'] ?? true,
|
||||
];
|
||||
}
|
||||
|
||||
$hostPart = sprintf('(http.host in {"%s", "%s"})', $hostIntranet, $hostReservation);
|
||||
|
||||
// --- RÈGLE 1 : DESACTIVER LE CACHE POUR LES PDF ---
|
||||
$sanitizedRules[] = [
|
||||
'expression' => "$hostPart and (http.request.uri.path.extension eq \"pdf\")",
|
||||
'description' => self::PDF_RULE_NAME,
|
||||
'action' => 'set_cache_settings',
|
||||
'action_parameters' => [
|
||||
'cache' => false // Désactive explicitement le cache
|
||||
],
|
||||
'enabled' => true
|
||||
];
|
||||
|
||||
// --- RÈGLE 2 : CACHE LONGUE DURÉE POUR MÉDIAS (Images/Vidéos) ---
|
||||
$paths = ['/storage', '/media', '/image', '/provider'];
|
||||
$pathPrefixes = array_map(fn($p) => "starts_with(http.request.uri.path, \"$p/\")", $paths);
|
||||
$pathPart = "(" . implode(" or ", $pathPrefixes) . ")";
|
||||
|
||||
$extensions = [
|
||||
'jpg', 'jpeg', 'png', 'gif', 'webp', 'avif', 'svg', 'ico',
|
||||
'mp4', 'webm', 'ogg', 'mov', 'm4v'
|
||||
];
|
||||
$extensionPart = '(http.request.uri.path.extension in {"' . implode('", "', $extensions) . '"})';
|
||||
|
||||
$sanitizedRules[] = [
|
||||
'expression' => "$hostPart and $pathPart and $extensionPart",
|
||||
'description' => self::LIBRARY_RULE_NAME,
|
||||
'action' => 'set_cache_settings',
|
||||
'action_parameters' => [
|
||||
'cache' => true,
|
||||
'edge_ttl' => [
|
||||
'mode' => 'override_origin',
|
||||
'default' => 31536000
|
||||
],
|
||||
'browser_ttl' => [
|
||||
'mode' => 'override_origin',
|
||||
'default' => 31536000
|
||||
]
|
||||
],
|
||||
'enabled' => true
|
||||
];
|
||||
|
||||
// F. Mise à jour Cloudflare
|
||||
$this->httpClient->request('PUT', "https://api.cloudflare.com/client/v4/zones/$zoneId/rulesets/$rulesetId", [
|
||||
'headers' => [
|
||||
'Authorization' => 'Bearer ' . $cfToken,
|
||||
'Content-Type' => 'application/json',
|
||||
],
|
||||
'json' => [
|
||||
'rules' => $sanitizedRules
|
||||
]
|
||||
]);
|
||||
|
||||
$io->success('Configuration Cloudflare déployée : Cache désactivé pour les PDF, activé 1 an pour les médias.');
|
||||
|
||||
} catch (\Exception $e) {
|
||||
$io->error('Erreur Cloudflare : ' . $e->getMessage());
|
||||
return Command::FAILURE;
|
||||
}
|
||||
|
||||
return Command::SUCCESS;
|
||||
}
|
||||
}
|
||||
@@ -197,7 +197,7 @@ class DevisController extends AbstractController
|
||||
'form' => $form->createView(),
|
||||
'lines' => [
|
||||
[
|
||||
'product_id' => '',
|
||||
'product' => '',
|
||||
'days'=>'',
|
||||
'price_ht' => '',
|
||||
'price_sup_ht' =>''
|
||||
@@ -205,7 +205,7 @@ class DevisController extends AbstractController
|
||||
],
|
||||
'options' => [
|
||||
[
|
||||
'product_id' => '',
|
||||
'product' => '',
|
||||
'price_ht' => '',
|
||||
]
|
||||
]
|
||||
|
||||
@@ -65,9 +65,6 @@ class Devis
|
||||
#[ORM\Column(length: 255, nullable: true)]
|
||||
private ?string $signatureId = null;
|
||||
|
||||
/**
|
||||
* @var Collection<int, DevisLine>
|
||||
*/
|
||||
#[ORM\OneToMany(targetEntity: DevisLine::class, mappedBy: 'devi')]
|
||||
private Collection $devisLines;
|
||||
|
||||
|
||||
@@ -30,8 +30,8 @@ class DevisLine
|
||||
private ?int $day = null;
|
||||
|
||||
|
||||
#[ORM\ManyToOne(inversedBy: 'devisLines')]
|
||||
private ?Product $product = null;
|
||||
#[ORM\Column]
|
||||
private string $product = "";
|
||||
|
||||
public function getId(): ?int
|
||||
{
|
||||
@@ -99,12 +99,12 @@ class DevisLine
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getProduct(): ?Product
|
||||
public function getProduct(): ?string
|
||||
{
|
||||
return $this->product;
|
||||
}
|
||||
|
||||
public function setProduct(?Product $product): static
|
||||
public function setProduct(?string $product): static
|
||||
{
|
||||
$this->product = $product;
|
||||
|
||||
|
||||
@@ -54,12 +54,6 @@ class Product
|
||||
#[ORM\Column(length: 255, nullable: true)]
|
||||
private ?string $productId = null;
|
||||
|
||||
/**
|
||||
* @var Collection<int, DevisLine>
|
||||
*/
|
||||
#[ORM\OneToMany(targetEntity: DevisLine::class, mappedBy: 'product')]
|
||||
private Collection $devisLines;
|
||||
|
||||
/**
|
||||
* @var Collection<int, ProductReserve>
|
||||
*/
|
||||
@@ -89,7 +83,6 @@ class Product
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->devisLines = new ArrayCollection();
|
||||
$this->productReserves = new ArrayCollection();
|
||||
$this->productDocs = new ArrayCollection();
|
||||
}
|
||||
@@ -234,35 +227,6 @@ class Product
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Collection<int, DevisLine>
|
||||
*/
|
||||
public function getDevisLines(): Collection
|
||||
{
|
||||
return $this->devisLines;
|
||||
}
|
||||
|
||||
public function addDevisLine(DevisLine $devisLine): static
|
||||
{
|
||||
if (!$this->devisLines->contains($devisLine)) {
|
||||
$this->devisLines->add($devisLine);
|
||||
$devisLine->setProduct($this);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function removeDevisLine(DevisLine $devisLine): static
|
||||
{
|
||||
if ($this->devisLines->removeElement($devisLine)) {
|
||||
// set the owning side to null (unless already changed)
|
||||
if ($devisLine->getProduct() === $this) {
|
||||
$devisLine->setProduct(null);
|
||||
}
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Collection<int, ProductReserve>
|
||||
|
||||
@@ -113,16 +113,15 @@
|
||||
<div class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-12 gap-5 items-end">
|
||||
{# 1. PRODUIT #}
|
||||
<div class="lg:col-span-5">
|
||||
<label class="{{ label_class }}">Produit / Prestation</label>
|
||||
<select data-load="product" name="lines[{{ key }}][product_id]" class="{{ input_class }}" required>
|
||||
{% if line.id is not defined%}
|
||||
<option value="">Sélectionner...</option>
|
||||
{% else %}
|
||||
{% for product in products %}
|
||||
<option {% if product.id == line.product_id %}selected{% endif %} value="{{ product.id }}">{{ product.name }} - {{ product.ref }}</option>
|
||||
{% endfor %}
|
||||
{% endif %}
|
||||
</select>
|
||||
<label class="text-[9px] font-black text-slate-500 uppercase tracking-widest ml-1 mb-2 block">Produit / Prestation</label>
|
||||
<div class="relative flex items-center">
|
||||
<input type="text" name="lines[{{ key }}][product]" value="{{ line.product }}" required class="w-full bg-slate-950/50 border-white/5 rounded-2xl text-white focus:ring-purple-500/20 focus:border-purple-500 transition-all py-3 pl-5 pr-12 text-sm">
|
||||
|
||||
{# BOUTON RECHERCHER #}
|
||||
<button is="search-productdevis" type="button" class="absolute right-2 p-2 bg-purple-500/10 hover:bg-purple-500 text-purple-400 hover:text-white rounded-xl transition-all duration-300 group/search" title="Rechercher un produit">
|
||||
Rechercher un produit
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{# 3. PRIX HT J1 #}
|
||||
@@ -174,16 +173,15 @@
|
||||
{% endif %}
|
||||
{# 1. PRODUIT #}
|
||||
<div class="lg:col-span-9">
|
||||
<label class="{{ label_class }}">Options</label>
|
||||
<select data-load="options" name="options[{{ key }}][product_id]" class="{{ input_class }}" required >
|
||||
{% if option.id is not defined%}
|
||||
<option value="">Sélectionner...</option>
|
||||
{% else %}
|
||||
{% for optionItem in optionsList %}
|
||||
<option {% if optionItem.id == option.product_id %}selected{% endif %} value="{{ optionItem.id }}">{{ optionItem.name }}</option>
|
||||
{% endfor %}
|
||||
{% endif %}
|
||||
</select>
|
||||
<label class="text-[9px] font-black text-slate-500 uppercase tracking-widest ml-1 mb-2 block">Produit / Prestation</label>
|
||||
<div class="relative flex items-center">
|
||||
<input type="text" name="lines[{{ key }}][product]" value="{{ option.product }}" required class="w-full bg-slate-950/50 border-white/5 rounded-2xl text-white focus:ring-purple-500/20 focus:border-purple-500 transition-all py-3 pl-5 pr-12 text-sm">
|
||||
|
||||
{# BOUTON RECHERCHER #}
|
||||
<button is="search-optionsdevis" type="button" class="absolute right-2 p-2 bg-purple-500/10 hover:bg-purple-500 text-purple-400 hover:text-white rounded-xl transition-all duration-300 group/search" title="Rechercher un produit">
|
||||
Rechercher une option
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
{# 3. PRIX HT J1 #}
|
||||
<div class="lg:col-span-2">
|
||||
|
||||
Reference in New Issue
Block a user