GithubHelp home page GithubHelp logo

Comments (34)

 avatar commented on May 21, 2024

you cant define random id couse you need to know it when grid is saving data to session ... dont know if there is way how to have same id for grid in all requests

from apydatagridbundle.

Abhoryo avatar Abhoryo commented on May 21, 2024

Why not generate an id with all the options defined in a grid ?
Controller, source, columns, action...

from apydatagridbundle.

 avatar commented on May 21, 2024

yes its possible but maybe faster way is one static variable which will be incrementing when you call grids constructor

from apydatagridbundle.

Abhoryo avatar Abhoryo commented on May 21, 2024

I've already think about that but what if for some reason one grid is not displayed the next filter?
For instance, between 1h00 and 3h00 a grid is not displayed.
Or a grid is only show for Admin and the user rules is changed between two filters.

from apydatagridbundle.

 avatar commented on May 21, 2024

hmmm ... then he will be need to set id manually ... i've created experimental branch with implementation with static variable

from apydatagridbundle.

 avatar commented on May 21, 2024

hashing all object is a bit problematic, i've tried spl_object_hash and so on no one worked like i should, we will need to hash all objects manually, do know if its right way

from apydatagridbundle.

 avatar commented on May 21, 2024

can you look at last commit in branch auto_id_generator its building hash based on controller column and source hash

from apydatagridbundle.

Abhoryo avatar Abhoryo commented on May 21, 2024

I'll take a look.

from apydatagridbundle.

Abhoryo avatar Abhoryo commented on May 21, 2024

Not tested yet, but sometimes I use two identical grids.
The first grid shows enabled objects and the second shows the desabled objects.
The hash is identical in these two grid.

Perhaps you can hash the source with its queryBuilder ?

I think that if grids are very similar, a user have to define himself the identifier of the grids.

from apydatagridbundle.

Abhoryo avatar Abhoryo commented on May 21, 2024

Oh, why $grid->setId is no longer used ?

from apydatagridbundle.

Abhoryo avatar Abhoryo commented on May 21, 2024

Hum, nothing works :D

I use a simple grid and I have this error :

An exception has been thrown during the rendering of a template ("DateTime::__construct() [<a href='datetime.--construct'>datetime.--construct</a>]: Failed to parse time string (a:1:{i:0;s:17:&quot;ROLE_PROFILE_EDIT&quot;;}) at position 1 (:): Unexpected character") in "SorienDataGridBundle::blocks.html.twig" at line 65.

from apydatagridbundle.

 avatar commented on May 21, 2024

grid need to have prepared columns before creating query it means you can't hash querybuilder, i can readd setId ... which way seems to be better for you, hash or static var?

from apydatagridbundle.

Abhoryo avatar Abhoryo commented on May 21, 2024

I think generate an auto hash is great but we have to keep the setId way for some case.
When you generate the hash, add the Id to the end of the hash.

controller+column+source+id

(id default=empty)

from apydatagridbundle.

 avatar commented on May 21, 2024

I'm still not sure ... static var is a bit problematic when some grid is ignored and generate hash will cause unexpected odd errors like 2 same grids but filtered for different data with querybuilder callback (you just copy a code but there will be some strange error and you don't know why)... maybe combination static and hash can solve all problems it will take a best of all implementations

from apydatagridbundle.

 avatar commented on May 21, 2024

check last implementation it is using hash generation and static counter ... you can have n same grids and hide filters ... there is just one problem when you are hiding one of same filters there can be situation where second will use data from first

from apydatagridbundle.

Abhoryo avatar Abhoryo commented on May 21, 2024

I told you to use a hash + an id. Not a counter.

It's not common to have the same grid. A user should know when an identifier for a grid is mandatory.

Maybe you can implement a grid manager that controls these problems.

Example of usage:

<?php
$grid_manager = $this->get('grid.manager');

$grid1 = $grid_manager->create(); // return a grid object
$source1 = new Entity('Entity:User');
$grid1->setSource($source1);

$grid2 = $grid_manager->create();
$source2 = new Entity('Entity:User');
$grid2->setSource($source2);

// The grid manager handle the redirection for all grids create during the request
// If the grid manager detect the same hash for two grid, a exception is thrown
// We have to create a grid with a id: $grid2 = $grid_manager->create('my_grid_2');
if ($grid_manager->isReadyForRedirect())
{
    //data are stored, do redirect
    return new RedirectResponse($this->generateUrl('grid'));
}
else
{
    // to obtain data for template you need to call prepare function
    return $this->render('Bundle::grid.html.twig', array('data' => $grid1,  'data2' => $grid2));
}

from apydatagridbundle.

 avatar commented on May 21, 2024

re:"I told you to use a hash + an id. Not a counter." i know that, i'm just trying to find best solution

problem is that I'm not satisfied with static nor hash+id implementation, it's reason why it's not in master ... and grid manager can't solve all problems too, grid manager is same like static implementation but all logic is moved to another class

i was checking another grid implementations and no of them is trying to autogenerate id, they are forcing user to set proper id

from apydatagridbundle.

Abhoryo avatar Abhoryo commented on May 21, 2024

Do you read my comments in the code?

A grid_manager can easily manage identifier colision, isReadyForRedirect and new features like export data for all grids implement with the manager. We can call it grid.factory if you want.

What's wrong with this solution. Do you want me to implement my solution to test it?

from apydatagridbundle.

 avatar commented on May 21, 2024

dunno if its not too late to detect a collision in isreadyforredirect couse wrong data been stored in setSource ...

it will not working for
if ($time < 0:00){
$grid = $grid_manager->create();
$grid->setSource('FooFaa');
}else{
$grid = $grid_manager->create();
$grid->setSource('FiiFoo');
}

the same problem like with static variable // its not able to check colision couse there is not any and grid filtering can be broken

from apydatagridbundle.

Abhoryo avatar Abhoryo commented on May 21, 2024

Hmmm, I see what you said. Dammit !

Maybe we can move fetchAndSaveColumnData, executeMassActions and fetchAndSaveGridData + prepare and call them inside a new function.

$grid_manager = $this->get('grid.manager');

$grid1 = $grid_manager->create(); // return a grid object
$source1 = new Entity('Entity:User');
$grid1->setSource($source1);

$grid2 = $grid_manager->create();
$source2 = new Entity('Entity:User');
$grid2->setSource($source2);

/* 
 * If the grid manager detect the same hash for two grid, a exception is thrown.
 * fetchAndSaveColumnData, executeMassActions, fetchAndSaveGridData and prepare are call after the colision detection
 */
$grid_manager->prepare(); 

/*
 * The grid manager handle the redirection for all grids create during the request
 */
if ($grid_manager->isReadyForRedirect())
{
    //data are stored, do redirect
    return new RedirectResponse($this->generateUrl('grid'));
}
else
{
    // to obtain data for template you need to call prepare function
    return $this->render('Bundle::grid.html.twig', array('data' => $grid1,  'data2' => $grid2));
}

from apydatagridbundle.

Abhoryo avatar Abhoryo commented on May 21, 2024

Hi, I finish my own bundle and post-it on github.

After I'll try what I've proposed in my previous post.

from apydatagridbundle.

 avatar commented on May 21, 2024

don't need to hurry up :)

from apydatagridbundle.

Abhoryo avatar Abhoryo commented on May 21, 2024

Tada ! my first bundle

from apydatagridbundle.

Abhoryo avatar Abhoryo commented on May 21, 2024

My fork

I've started this branch from yours.

I commit an evol with a grid manager.

Generate auto id isn't really possible. This grid manager generates an exception if grids have the same hash and proposes to define an identifier for grids.

$gridManager = $this->get('grid.manager');
$source = new Entity('MyProjectMyBundle:User');
$grid = $gridManager->createGrid($source);
$grid->setSource($source);

$source2 = new Entity('MyProjectMyBundle:User');
$grid2 = $gridManager->createGrid($source2);
$grid2->setSource($source2);

if ($gridManager->isReadyForRedirect()) { // Generate an exception
    return new RedirectResponse($this->generateUrl('grid'));
}
else
{
    return $this->render('MyProjectMyBundle::grid.html.twig', array('data' => $grid->prepare(),  'data2' => $grid2->prepare()));
}

In addition, I add a method that handles other aspects of grids as the redirection after filtering but also the export of grids for instance.

$gridManager = $this->get('grid.manager');
$source = new Entity('MyProjectMyBundle:User');
$grid = $gridManager->createGrid($source);
$grid->setId("grid1");
$grid->setSource($source);

$source2 = new Entity('MyProjectMyBundle:User');
$grid2 = $gridManager->createGrid($source2);
$grid2->setSource($source2);

if (($manageReturn = $gridManager->manageGrids()) !== false)
{
    return $manageReturn;
}
else
{
    return $this->render('MyProjectMyBundle::grid.html.twig', array('data' => $grid->prepare(),  'data2' => $grid2->prepare()));
}

from apydatagridbundle.

 avatar commented on May 21, 2024

I'm too busy right now, hope that I'll look at it during a weekend

from apydatagridbundle.

Abhoryo avatar Abhoryo commented on May 21, 2024

No prob.

from apydatagridbundle.

 avatar commented on May 21, 2024

its a step forward and solving few problems but i'm not sure if i want to have 2 different ways how to create manage/grids

from apydatagridbundle.

Abhoryo avatar Abhoryo commented on May 21, 2024

Ok, use only the manager to create a grid :D One way!

I just don't want to have this later in each controller:

if (grid1->expor() || grid2->expor() || grid3->expor())
   ->export
else if (grid1->redirect() || grid2->redirect() || grid3->redirect())
   ->redirect
else if ...
else if ...
else 
   -> draw grids

from apydatagridbundle.

 avatar commented on May 21, 2024

one questions how many grids do you have on one page ... i have almost finished shop system for my company and i don't have more then 1 grid per page.

from apydatagridbundle.

Abhoryo avatar Abhoryo commented on May 21, 2024

Ah good question.
I have a "shop" website too and in the user account, there are 5 grids to show objects, one per state. (draft, wait for validation, In progress, finish, cancel)

from apydatagridbundle.

 avatar commented on May 21, 2024

hmm, ok, i'll marge it but please can you make pr and add some docs (1 example + some comment)

from apydatagridbundle.

Abhoryo avatar Abhoryo commented on May 21, 2024

Ok no prob, I'll do a PR and change the documentation.

from apydatagridbundle.

 avatar commented on May 21, 2024

pls do not change all samples just add one to "how to manage multiple grids" and mark it as preferred way

from apydatagridbundle.

Abhoryo avatar Abhoryo commented on May 21, 2024

Yeah, it's what I want to do. Don't worry, I do the PR and you'll merged it.

from apydatagridbundle.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.