some data get lost in my table on tabulator with symfony

Viewed 10

I'm going to explain my problem that makes me want to throw my computer into a wall.

When I send the data of my history table on Twig by encoding as specified in the first block and that I parse the data in Json on the other side (GestionHistorique.html.twig) The recording, the deletion and the modification are not displayed in my array whereas they are well present in db in my table actionHistory on pgAdmin4. I tried different solutions without solving the problem. I show you just below the concerned lines of code .

GestionHistoryController

 <?php

namespace App\Controller;

use App\Entity\ActionHistorique;
use App\Entity\Users;
use App\Entity\Projet;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\RequestStack;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
use App\Services\HistoriqueLogs;
use Doctrine\Persistence\ManagerRegistry;



class GestionHistoriqueController extends AbstractController
{
    /**
     * @var HistoriqueLogs
     */
    private $logHistorique;
    /**
     * @var ManagerRegistry
     */
    private $doctrine;

    public function __construct(
        HistoriqueLogs $logHistorique,
        ManagerRegistry $doctrine
    ) {
        $this->logHistorique = $logHistorique;
        $this->doctrine = $doctrine;
    }
    /**
     * @Route("/gestion/historique",
     * name="app_gestion_historique")
     */
    public function dashboardAdmin(RequestStack $requestStack): Response
    {
        $params = $requestStack->getSession();
        $projet =  $params->get('projet');
        $modules = $params->get('modules');
        $fonctionnalites = $params->get('fonctionnalites');
        $adresseWeb = $this->getParameter('adresse_web');

        $actionHistoriques = $this->doctrine->getRepository(ActionHistorique::class)->findby(array('projetId'=>$projet->getId()));
        
        $dataJson = array();
        $projet = $this->doctrine->getRepository(Projet::class)->find($projet->getId());

        $listUtilisateur = $projet->getUsers();

        foreach ($listUtilisateur as $user) {
            foreach ($actionHistoriques as $actionHistorique) {
                if ($actionHistorique->getUsersId() == $user->getId() && $actionHistorique->getProjetId() == $projet->getId()) {
                    $mesDonnes = array(
                                    "nom"=> $user->getNom(),
                                    "prenom"=> $user->getPrenom(),
                                    "projet"=> $projet->getProjet(),
                                    "date"=> $actionHistorique->getDate()->format('d/m/Y'),
                                    "actionEffectuée"=> $actionHistorique->getAction(),
                                    "CodeST/TI/PT/LT/BP/BA"=> $actionHistorique->getCode(),
                                    "nomCode"=> $actionHistorique->getNom(),
                    );
                    $dataJson[] = $mesDonnes;
                }
            }
        }



        return $this->render('Historique/gestionHistorique.html.twig', [
            'user' => $user,
            'projet' => $projet,
            'modules' => $modules,
            'fonctionnalites'=> $fonctionnalites,
            'adresseWeb'=> $adresseWeb,
            'actionHistorique'=> json_encode($dataJson),
        ]);
    }
}

History Logs

    <?php

/**************************************************************************************************************************************************************************************************
 ***
 *** service de gestion d'historique d'action lié à Easy Exploit V1
 ***
/**************************************************************************************************************************************************************************************************/

namespace App\Services;

use App\Entity\ActionHistorique;
use Doctrine\Persistence\ManagerRegistry;
use Exception;
use DateTime;
use Symfony\Component\HttpFoundation\RequestStack;

class HistoriqueLogs
{
    private $requestStack;
    private $managerRegistry;


    /**************************************************************************************************************************************************************************************************
     ***
     *** Construt de la classe, historique connexion pour intercepter les actions de changements.
     ***
     **************************************************************************************************************************************************************************************************/
    public function __construct(RequestStack $requestStack, ManagerRegistry $managerRegistry)
    {
        $this->managerRegistry = $managerRegistry;
        $this->requestStack = $requestStack;
    }

    public function addHistoryConnection($projet, $user, $action, $code = null, $nom = null, $divers = null): void
    {
        //On crée la variable action historique qui permettra de récupererer les actions faites sur Easy Exploit

        $actionHistorique = new ActionHistorique();
        $date = new DateTime(); //this returns the current date time
        //Création de l'historique 
        $actionHistorique->setUsersId($user);
        $actionHistorique->setDate($date);
        $actionHistorique->setProjetId($projet);
        $actionHistorique->setDivers($divers);
        $actionHistorique->setCode($code);
        $actionHistorique->setNom($nom);
        $actionHistorique->setAction($action);

        // Sauvegarde 
        $manager = $this->managerRegistry->getManager();
        $manager->persist($actionHistorique);
        $manager->flush();
        $this->managerRegistry->resetManager();
    }
}

HistoryGestionTwig

{% extends 'base.html.twig' %}

{% block stylesheets %}
    {{ parent() }}
    {{encore_entry_link_tags('tabulator')}}

{% endblock %}
    {% block sudalysBody %}
    <section>
      <div id="singleTab" class="box box-info">
        <div class="box-header with-border">
    <h2 class="box-title">Historique Easy Exploit</h2>
        </div>
        <div id="infos">
<div>
</div>
          <div id="monTable"></div>
        </div>
      </div>
    </section>
        
    {% endblock %}

{% block javascripts %}
    {{ parent() }}

<script>
 var gestionHistorique = '{{actionHistorique | e('js') | raw}}';
gestionHistorique = JSON.parse(gestionHistorique);
   console.log(gestionHistorique);
  
// });
  $(document).ready(function() {

//custom max min header filter
var minMaxFilterEditor = function(cell, onRendered, success, cancel, editorParams){

    var end;

    var container = document.createElement("span");

    //create and style inputs
    var start = document.createElement("input");
    start.setAttribute("type", "date");
    start.setAttribute("placeholder", "Min");
    start.style.padding = "6px";
    start.style.width = "50%";
    start.style.boxSizing = "border-box";

    start.value = cell.getValue();

    function buildValues(){
        success({
            start:start.value,
            end:end.value,
        });
    }

    function keypress(e){
        if(e.keyCode == 13){
            buildValues();
        }

        if(e.keyCode == 27){
            cancel();
        }
    }

    end = start.cloneNode();
    end.setAttribute("placeholder", "Max");

    start.addEventListener("change", buildValues);
    start.addEventListener("blur", buildValues);
    start.addEventListener("keydown", keypress);

    end.addEventListener("change", buildValues);
    end.addEventListener("blur", buildValues);
    end.addEventListener("keydown", keypress);


    container.appendChild(start);
    container.appendChild(end);

    return container;
 }

//custom max min filter function

function 
minMaxFilterFunction(headerValue,rowValue,rowData,filterParams) {
//headerValue - the value of the header filter element
//rowValue - the value of the column in this row
//rowData - the data for the row being filtered
//filterParams - params object passed to the headerFilterFuncParams property
//convert strings into dates

    if (headerValue.start != "") {
        headerValue.start = new Date(headerValue.start);
    }

    if (headerValue.end != "") {
        headerValue.end = new Date(headerValue.end);
    }

    if(rowValue){
        const [day, month, year] = rowValue.split('/');
        const result = [year, month, day].join('-');
        var rowValue1 = new Date(result);

        if(headerValue.start != ""){
            if(headerValue.end != ""){
                if(rowValue1 >= headerValue.start && rowValue1 <= headerValue.end){
                        return true;
                }else{
                    return false;
                }
            }else{
                if(rowValue1 >= headerValue.start){
                    return true;
                }else{
                    return false;
                }
            }
        }else{
            if(headerValue.end != ""){
                if(rowValue1 >= headerValue.end){
                    return true;
                }else{
                    return false;
                }
            }
        }
    }
    return true; 
//must return a boolean, true if it passes the filter.
}
//Define variables for input element
var table = new Tabulator("#monTable", {
     
          layout: "fitColumns",
          data: gestionHistorique,
          pagination: "local",
          paginationSize: 20,
          paginationSizeSelector: [20, 40, 60, 100],
          paginationCounter: "rows",
          paginationCounter: "rows",
    columns:[
        {title:"Nom", field:"nom",hozAlign:"center", headerFilter:"input"},
        {title:"Prénom", field:"prenom",hozAlign:"center",headerFilter:"input"},
        {title:"Projet", field:"projet",hozAlign:"center"},
        {title:"Date", field:"date", sorter:"datetime",hozAlign:"center",formatter:"datetime", formatterParams:{
                inputFormat:"dd/MM/yyyy",
                outputFormat:"dd/MM/yyyy",
                invalidPlaceholder:"(invalid date)",
            },  headerFilter:minMaxFilterEditor, headerFilterFunc:minMaxFilterFunction, headerFilterLiveFilter:false},
         {title:"Action effectuée",field:"actionEffectuée",hozAlign:"center",headerFilter:"input"},
        {title:"Code Objet", field:"CodeST/TI/PT/LT/BP/BA",hozAlign:"center",headerFilter:"input"},
        {title:"Nom Objet", field:"nomCode",hozAlign:"center",headerFilter:"input"},
    ],
    });
});
console.log (Tabulator);
</script>
  
{% endblock %}
0 Answers
Related