Skip to content

Conversation

@lukasluecke
Copy link
Contributor

#3352

2020-07-13 17 17 03

// There needs to be a CrudController handling the target entity, as we display the corresponding INDEX view here.
EmbedField::new('associationName');

It supports most of the functionality, including async initial load, sort, pagination, search and actions (with a custom referrer that redirects you straight back to the embed field).

Currently the "reverse" relation field is automatically removed, if it was part of the target index view (because all values would be the current detail view entity).

@lukasluecke
Copy link
Contributor Author

lukasluecke commented Jul 13, 2020

I would like to add a way to further customize the view (e.g. change columns, different default sort, page size), but all customization options should be part of the EmbedField options, and not the target CrudController. This is currently not easily possible, but I got a solution almost ready 🙂

Edit
Waiting on #3550 (see #3551 for an example on the usage, which is quite similar to this)

@lukasluecke
Copy link
Contributor Author

lukasluecke commented Jul 13, 2020

Filters are not yet working correctly, their code is even more complicated to make "reusable". I might end up just having to extract all these "inline" scripts to proper functions that get called in any view where they are required, but that will be a bigger change than what I originally intended (and I might do that separately, before finishing up this PR).

Edit
I got the filters working with a single embed on the page - will try to make it a bit more flexible next..

@javiereguiluz javiereguiluz added this to the 3.x milestone Jul 13, 2020
This was referenced Jul 13, 2020
@seb-jean
Copy link
Contributor

Should we add an item create button? (Action::NEW)

@lukasluecke
Copy link
Contributor Author

@seb-jean I‘m not sure yet how exactly I want to handle Actions in general here - maybe something like #3519, and by default render the actions defined for the index view (which in most cases is NEW).

My end goal is a kind of fully integrated experience, which probably will involve AJAX modals for create (and possibly edit), amongst other things - but I will try to get the basic functionality in before that 🙂

@seb-jean
Copy link
Contributor

Okay, great :). I wish you good luck @lukasluecke.

javiereguiluz added a commit to javiereguiluz/EasyAdminBundle that referenced this pull request Jul 15, 2020
This PR was merged into the 3.0.x-dev branch.

Discussion
----------

Extract ControllerFactory service

This is a pre-requisite for EasyCorp#3476 (MR EasyCorp#3551) and EasyCorp#3352 (see EasyCorp#3543 (comment) for details).

Also deduplicated a bit of the shared logic between CrudController and DashboardController creation.

Commits
-------

ed63197 Extract ControllerFactory service
@WeTurkstra
Copy link

Can this pr be merged into the master?

@ghost
Copy link

ghost commented Sep 24, 2020

I hope this feature will be merged soon 💯

@sharkFace146
Copy link

Wow this feature is exactly what i want 😍.
Hope it will be merged soon 🚀.

@bfavrel
Copy link

bfavrel commented Nov 16, 2020

Thanks for this very useful feature ! Hope it will be merged soon !
I've tested it and I've detected 2 issues :

  • Filter button doesn't work. It's open a new page with the filters fields inside
  • BooleanField that appears in table, cannot be updated (enable or disable). It seems to miss an ajax action to update the entity.

Copy link

@bfavrel bfavrel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This code enable custom switches for BooleanField in list.

if(searchQuery) {
$(embedContent).find('table tbody td:not(.actions)').highlight($.merge([searchQuery], searchQuery.split(' ')));
}

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// custom switches
const customSwitches = document.querySelectorAll('td.field-boolean .custom-control.custom-switch input[type="checkbox"]');
for (i = 0; i < customSwitches.length; i++) {
customSwitches[i].addEventListener('change', function () {
const customSwitch = this;
const newValue = this.checked;
const oldValue = !newValue;
const fieldName = this.closest('.custom-switch').dataset.fieldname;
const target = "{{ ea_url()
.unset('entityId')
.unset('referrer')
.unset('menuIndex')
.unset('submenuIndex')
.setCrudId(crud_id)
.setAction('edit')|raw }}";
const toggleUrl = target
+ "&entityId=" + this.closest('[data-id]').dataset.id
+ "&fieldName=" + fieldName
+ "&newValue=" + newValue.toString();
let toggleRequest = $.ajax({ type: "GET", url: toggleUrl, data: {} });
toggleRequest.done(function(result) {});
toggleRequest.fail(function() {
// in case of error, restore the original value and disable the toggle
customSwitch.checked = oldValue;
customSwitch.disabled = true;
customSwitch.closest('.custom-switch').classList.add('disabled');
});
});
}

@lukasluecke
Copy link
Contributor Author

Thanks for your feedback and contribution. I'm currently very busy in another project which does not use EasyAdmin, but hope that I can find some time to finish this PR and some others around christmas time 🤞

If anyone else wants to pick this up in the meantime feel free to take this over in a new PR as well 🙂

@finnef
Copy link

finnef commented Jan 6, 2021

Hmm patch needs reroll for EA 3.2 it seems.

@Mancusoj
Copy link

I would like to add a list of this type for a collection, does it work in easyadmin 4?

@wontroba666
Copy link

does it work in easyadmin 4? this is great

@User12312412412
Copy link

Can this please be implemented? To provide you with a use case for this it's when you need to display a complex entity with one to many relationships in a tab.

Say a Subscription being the primary entity and so you create a tab that has Members (OneToMany).
The usecase here is that we're able to display the OneToMany relationship as a paginated and filterable table.

Some subscription records for example have 1000s of records and doing CollectionField::new('members') simple does not work due to the volume of fields it has to display.

@msphn
Copy link

msphn commented Feb 21, 2024

I'd be willing to invest into this and port this for EA 4 but I have concerns about the acceptance of PRs in general atm. Would that change get accepted or would it be better to create a bundle containing this feature?

@NicoHaase
Copy link

Are there any news on this topic?

@psihius
Copy link
Contributor

psihius commented Jul 15, 2024

I can confirm that this one does not work on EA4 and needs updates quite a bit.
I've adapted for my project for some of the functionality to work, but there have been major changes in how the system works so the grid needs to be split into blocks and probably work via horizontal reuse instead of pure inheritance or just need to maintain 2 grid templates - one regular and one for embedded.
This needs buy-in from stakeholders, because while not too big, still a sizeable addition to the amount of code to maintain.
@javiereguiluz and please tag whoever else needs to be in the loop - is this something that would be accepted? Or should I just maintain my own patch and not bother submitting upstream?

@psihius
Copy link
Contributor

psihius commented Jul 25, 2024

I've made a new PR because changes to this for 4.x are extensive and I had to redo some things, there's a lot more work to be done, so I do not see a point keeping this one open any more. 4.x series has a lot more complicated interactions and way it is doing things.

@javiereguiluz
Copy link
Collaborator

Let's close this in favor of #6384 where @psihius is trying to implement this feature in the 4.x branch 💪

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.