[Feature request] Admin fields relation with other tables/fields #452

Closed
opened 2019-08-06 14:11:05 +00:00 by jcodewalker · 11 comments
jcodewalker commented 2019-08-06 14:11:05 +00:00 (Migrated from github.com)

Hi Llewellyn,
Working with a relational database is very common (in my own projects, at least) to have no redundant data. Being so, usually users data (for example) are not copied into other db tables so I always have to join users table if I want get user's data in a list view.
Doing that, it would be nice to have $main_table_users_id.' '.$joined_user_table_users_name listed in a column via the admin fields relation.
Is it possible to add another form/subform to set field relation to other tables/fields?
Something like the attached image?
Where:
Join Table is a drop down menu with all database tables
Join Field is a drop down field list autopopulated as soon as a table is selected
Join Field to let JCB know how I set the join query and how the field will be retrieved.

In alternative, would be possible to get the custom admin view with view.html.php and the model compiled exactly like the standard admin view (an option as alternative to the current mode)? If you see the view and models files are compiled in a way different mode. The ones related to standard admin view have complete functionality compiled (like the function populateState for the model, to say just one, but you know there are many others), while the custom ones not. As the custom view are linked to a dynamicGet, which is linked to either a component table or a database table (or custom, but it's not possible with custom I suppose), JCB has the data to build the view(s) and model(s) files for both list and edit to make a copy of the standard admin files (excepts for the display templates, of course).
If this would be possible, we could make a custom admin view, edit only the templates where needed without caring the functionality still compiled by JCB. The join query would be made in the dynamicGet and the relation field would be made manually in the customized templates. This, for little customization not worthing a long work to re-make something JCB already does very well, would be fantastic.

Which option is possible? Honestly I would prefer the second one, much more flexible.

Thanks in advance.

advanced-admin-fields-relation

Hi Llewellyn, Working with a relational database is very common (in my own projects, at least) to have no redundant data. Being so, usually users data (for example) are not copied into other db tables so I always have to join users table if I want get user's data in a list view. Doing that, it would be nice to have $main_table_users_id.' '.$joined_user_table_users_name listed in a column via the admin fields relation. Is it possible to add another form/subform to set field relation to other tables/fields? Something like the attached image? Where: Join Table is a drop down menu with all database tables Join Field is a drop down field list autopopulated as soon as a table is selected Join Field to let JCB know how I set the join query and how the field will be retrieved. In alternative, would be possible to get the custom admin view with view.html.php and the model compiled exactly like the standard admin view (an option as alternative to the current mode)? If you see the view and models files are compiled in a way different mode. The ones related to standard admin view have complete functionality compiled (like the function populateState for the model, to say just one, but you know there are many others), while the custom ones not. As the custom view are linked to a dynamicGet, which is linked to either a component table or a database table (or custom, but it's not possible with custom I suppose), JCB has the data to build the view(s) and model(s) files for both list and edit to make a copy of the standard admin files (excepts for the display templates, of course). If this would be possible, we could make a custom admin view, edit only the templates where needed without caring the functionality still compiled by JCB. The join query would be made in the dynamicGet and the relation field would be made manually in the customized templates. This, for little customization not worthing a long work to re-make something JCB already does very well, would be fantastic. Which option is possible? Honestly I would prefer the second one, much more flexible. Thanks in advance. ![advanced-admin-fields-relation](https://user-images.githubusercontent.com/49115855/62543858-fe09c300-b85e-11e9-8658-bd4c92f86c62.jpg)

hmmm I would normally achieve this with some custom code, instead of adding another layer of complexity to an already crazy feature 👍

So I would build a helper function in the components main-admin helper class, or some custom code in the model/view... does not matter, and then get the related value here and use it with the helper method to get the data, and model it ready for display. Then if I see that I am going to do this in more components, then I will move that custom code to the custom code are and add it everywhere with customcode-placeholder. This is already very doable in JCB, and really the way to go...

Let me know if you would like a little video tutorial of what i just explained... as I think that way your components remains unique and you get to do things exactly the way you like.

hmmm I would normally achieve this with some custom code, instead of adding another layer of complexity to an already crazy feature :+1: So I would build a helper function in the components main-admin helper class, or some custom code in the model/view... does not matter, and then get the related value here and use it with the helper method to get the data, and model it ready for display. Then if I see that I am going to do this in more components, then I will move that custom code to the custom code are and add it everywhere with customcode-placeholder. This is already very doable in JCB, and really the way to go... Let me know if you would like a little video tutorial of what i just explained... as I think that way your components remains unique and you get to do things exactly the way you like.
jcodewalker commented 2019-08-06 17:45:27 +00:00 (Migrated from github.com)

Hello Llewellyn,
thanks for your fast reply.

Hmmm :-)
Let me see if I can understand from the video already available (https://www.youtube.com/watch?v=8Yl4lAAAWMQ&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&index=71) I suppose is this one.
Custom code is something I still have to learn. Tomorrow I'm going to have a look at those videos and if I'm not able to get what I want I will kindly ask you some help.

Thanks for you disposal!

Hello Llewellyn, thanks for your fast reply. Hmmm :-) Let me see if I can understand from the video already available (https://www.youtube.com/watch?v=8Yl4lAAAWMQ&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&index=71) I suppose is this one. Custom code is something I still have to learn. Tomorrow I'm going to have a look at those videos and if I'm not able to get what I want I will kindly ask you some help. Thanks for you disposal!
jcodewalker commented 2019-08-07 07:35:39 +00:00 (Migrated from github.com)

Hello Llewellyn,

I think custom code is exactly what I was looking for, for both the solution above described.

Watching the video, if I'm not wrong, I can inject (Hash automation) my custom code in the file I want, starting from the line I want.

I just set a test column custom code, set everything (obviously with my own file path and starting line #) like your video (timecode: 8:36), saved, compiled and installed, but:

  1. The custom code is not injected (I even checked in the php file)
  2. the Start Hash Target code is not generated

What am I missing?

If I'm not wrong, I can't use a placeholder like [CUSTOMCODE=myCodeName], as the default_head.php file is generated on the fly by JCB and, as far as I know, there is not a custom area for that.

Any hint?
Thanks in advance!

Hello Llewellyn, I think custom code is exactly what I was looking for, for both the solution above described. Watching the video, if I'm not wrong, I can inject (Hash automation) my custom code in the file I want, starting from the line I want. I just set a <th>test column</th> custom code, set everything (obviously with my own file path and starting line #) like your video (timecode: 8:36), saved, compiled and installed, but: 1. The custom code is not injected (I even checked in the php file) 2. the Start Hash Target code is not generated What am I missing? If I'm not wrong, I can't use a placeholder like [CUSTOMCODE=myCodeName], as the default_head.php file is generated on the fly by JCB and, as far as I know, there is not a custom area for that. Any hint? Thanks in advance!
jcodewalker commented 2019-08-07 09:21:25 +00:00 (Migrated from github.com)

Hello Llewellyn,
I've watched this other video (https://www.youtube.com/watch?v=DFMfIl-VkSk&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&index=32&t=0s) and now I'm a bit confused...

This video (https://www.youtube.com/watch?v=8Yl4lAAAWMQ&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&index=71) AND this video (https://www.youtube.com/watch?v=DFMfIl-VkSk&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&index=32&t=0s) are intended to work together (in this case why they are not linked together?) or we can use one OR the other way?

Using only the first one (https://www.youtube.com/watch?v=8Yl4lAAAWMQ&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&index=71) I get absolutely nothing. It means no error message while compiling the component, no code inserted.

Using both or just the second mode (https://www.youtube.com/watch?v=DFMfIl-VkSk&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&index=32&t=0s) (just the second mode means disabling the custom code I set in "Editing the Custom Code" section of JCB) I get the following error message after compiling the component:
Custom code could not be added to admin/views/comments/tmpl/default_head.php please review the file at line 40. This could be due to a change to lines above the custom code.
Custom code could not be added to admin/views/comments/tmpl/default_head.php please review the file at line 41. This could be due to a change to lines above the custom code.
Custom code could not be added to admin/views/comments/tmpl/default_head.php please review the file at line 44. This could be due to a change to lines above the custom code.

The default_head.php with the insertion code is as the attached image.
The code of "Editing the Custom Code" section of JCB is as attached image.

It doesn't matter what line I set in the "Editing the Custom Code" section of JCB, I always get these error messages.

Zero based line I think should starts from zero, while the editor starts from 1. In my logic, I should subtract 1 from the line I have in my editor and set it in "Editing the Custom Code" section of JCB.
But it seems doesn't work.

Any hint?
Thanks in advance.
Schermata 2019-08-07 alle 11 13 24
Schermata 2019-08-07 alle 11 13 52

Hello Llewellyn, I've watched this other video (https://www.youtube.com/watch?v=DFMfIl-VkSk&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&index=32&t=0s) and now I'm a bit confused... This video (https://www.youtube.com/watch?v=8Yl4lAAAWMQ&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&index=71) AND this video (https://www.youtube.com/watch?v=DFMfIl-VkSk&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&index=32&t=0s) are intended to work together (in this case why they are not linked together?) or we can use one OR the other way? Using only the first one (https://www.youtube.com/watch?v=8Yl4lAAAWMQ&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&index=71) I get absolutely nothing. It means no error message while compiling the component, no code inserted. Using both or just the second mode (https://www.youtube.com/watch?v=DFMfIl-VkSk&list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE&index=32&t=0s) (just the second mode means disabling the custom code I set in "Editing the Custom Code" section of JCB) I get the following error message after compiling the component: Custom code could not be added to admin/views/comments/tmpl/default_head.php please review the file at line 40. This could be due to a change to lines above the custom code. Custom code could not be added to admin/views/comments/tmpl/default_head.php please review the file at line 41. This could be due to a change to lines above the custom code. Custom code could not be added to admin/views/comments/tmpl/default_head.php please review the file at line 44. This could be due to a change to lines above the custom code. The default_head.php with the insertion code is as the attached image. The code of "Editing the Custom Code" section of JCB is as attached image. It doesn't matter what line I set in the "Editing the Custom Code" section of JCB, I always get these error messages. Zero based line I think should starts from zero, while the editor starts from 1. In my logic, I should subtract 1 from the line I have in my editor and set it in "Editing the Custom Code" section of JCB. But it seems doesn't work. Any hint? Thanks in advance. ![Schermata 2019-08-07 alle 11 13 24](https://user-images.githubusercontent.com/49115855/62610973-04eb1100-b905-11e9-8fde-faf7cf031c7c.png) ![Schermata 2019-08-07 alle 11 13 52](https://user-images.githubusercontent.com/49115855/62610974-04eb1100-b905-11e9-8c59-c8a9db02f31b.png)
jcodewalker commented 2019-08-07 11:07:32 +00:00 (Migrated from github.com)

So, now I reached a bad result. Compiling the component with whatever inserted code I get the following error:
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 5

The compiler works without any custom code.
Any hint?

Schermata 2019-08-07 alle 13 06 29

So, now I reached a bad result. Compiling the component with whatever inserted code I get the following error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 5 The compiler works without any custom code. Any hint? ![Schermata 2019-08-07 alle 13 06 29](https://user-images.githubusercontent.com/49115855/62618317-3919fe00-b914-11e9-9270-10e6b3f11009.png)

There are currently four custom code concepts in JCB and all four of them work simultaneously, with various measures to avoid conflict between them. Unintentionally they got the same wording in the tutorials and in the GUI and we are at the point where renaming them will possibly be needed.

Resolving this issue of yours in the way I described makes use of the GUI placeholder use of customcode, and not the IDE way. It is kind of hard to explain much of these ideas, but a hint is that it is to good to be true, and so most of the time developers don't try the use case since they can't think JCB is that advance 👍

That said, I will make a little tutorial to show the workflow, and hopefully that will help you manage the implementation with less confusion. (give me a few days to get that done :)

When you look at the JCB website you see this iceberg... and this is really the case. What you see in the tutorials are just the tip of the iceberg of what JCB can do under the hood.

There are currently four custom code concepts in JCB and all four of them work simultaneously, with various measures to avoid conflict between them. Unintentionally they got the same wording in the tutorials and in the GUI and we are at the point where renaming them will possibly be needed. Resolving this issue of yours in the way I described makes use of the GUI placeholder use of customcode, and not the IDE way. It is kind of hard to explain much of these ideas, but a hint is that it is to good to be true, and so most of the time developers don't try the use case since they can't think JCB is that advance :+1: That said, I will make a little tutorial to show the workflow, and hopefully that will help you manage the implementation with less confusion. (give me a few days to get that done :) When you look at the JCB website you see this iceberg... and this is really the case. What you see in the tutorials are just the tip of the iceberg of what JCB can do under the hood.

The line zero based is in relation to the file where the code is added and not in relation the the GUI editor.

The line zero based is in relation to the file where the code is added and not in relation the the GUI editor.

Then the way to add code in via the IDE is from the IDE... not from the GUI like you are trying. But again this is when we are talking about the custom code option from the IDE. Also called round trip development.

Then the way to add code in via the IDE is from the IDE... not from the GUI like you are trying. But again this is when we are talking about the custom code option from the IDE. Also called round trip development.
jcodewalker commented 2019-08-07 16:10:28 +00:00 (Migrated from github.com)

Yes, thanks, I believe I need a video tutorial and for sure I can wait your time.
Thanks in advance!

Yes, thanks, I believe I need a video tutorial and for sure I can wait your time. Thanks in advance!
jcodewalker commented 2019-08-08 12:22:56 +00:00 (Migrated from github.com)

Hello Llewellyn,

In a brand new installation I was able to use both insert and replace custom code (in IDE) and both work fine.
So, for me you don't have to do the video tutorial...
Thanks anyway for the support!

Hello Llewellyn, In a brand new installation I was able to use both insert and replace custom code (in IDE) and both work fine. So, for me you don't have to do the video tutorial... Thanks anyway for the support!

I need to make a few new tutorials anyway... there has been some huge improvements to JCB, all still in the staging branch not yet in the stable (master) branch. But the fact is it just got even smarter, so be on the lookout for the new tutorials, they will explain even some the things I mentioned above, that has never been seen in JCB before.

I need to make a few new tutorials anyway... there has been some huge improvements to JCB, all still in the staging branch not yet in the stable (master) branch. But the fact is it just got even smarter, so be on the lookout for the new tutorials, they will explain even some the things I mentioned above, that has never been seen in JCB before.
Sign in to join this conversation.
No Milestone
No project
No Assignees
1 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: joomla/Component-Builder#452
No description provided.