How to Display Recent Child Records in Modal Add New separate display DV

Discussions related to customizing hooks. Hooks are documented at http://bigprof.com/appgini/help/advanced-topics/hooks/
Post Reply
joshianjvj83
Posts: 21
Joined: 2024-05-12 10:13

How to Display Recent Child Records in Modal Add New separate display DV

Post by joshianjvj83 » 2024-10-22 05:11

I'm working on a document tracking system, and I need some help with customizing the "Add New" modal for child tables. Specifically, I would like to display the three most recently encoded records from the child table within the modal. This would allow users to see the latest entries as they add new records, helping them decide what actions to take without needing to close the modal to check the preview tracking information.

I’ve already tried using the Detail view settings to NOT check the separate display, but this approach restricts the number of records I can view per page in my "Routing" table and also may provide furthermore customizations.
Attachments
Screenshot 2024-10-22 125427.png
Screenshot 2024-10-22 125427.png (129.11 KiB) Viewed 528 times

User avatar
jsetzer
AppGini Super Hero
AppGini Super Hero
Posts: 1883
Joined: 2018-07-06 06:03
Location: Kiel, Germany
Contact:

Re: How to Display Recent Child Records in Modal Add New separate display DV

Post by jsetzer » 2024-10-22 07:32

First idea which came into my mind as a starting point:

Inject an iframe:

src = TABLENAME_view.php?Embedded=1&parameter_for_filtering=123

In TABLENAME_init() hook check for parameter and use $options for filtering.

This will show an embedded Table View without any header/menu/footer and list the filtered records. This will already consider user permissions.
Kind regards,
<js />

My AppGini Blog:
https://appgini.bizzworxx.de/blog

You can help us helping you:
Please always put code fragments inside [code]...[/code] blocks for better readability

AppGini 24.14 Revision 1665 + all AppGini Helper tools

User avatar
D Oliveira
AppGini Super Hero
AppGini Super Hero
Posts: 353
Joined: 2018-03-04 09:30
Location: David

Re: How to Display Recent Child Records in Modal Add New separate display DV

Post by D Oliveira » 2024-10-23 17:03

jsetzer wrote:
2024-10-22 07:32
First idea which came into my mind as a starting point:

Inject an iframe:

src = TABLENAME_view.php?Embedded=1&parameter_for_filtering=123

In TABLENAME_init() hook check for parameter and use $options for filtering.

This will show an embedded Table View without any header/menu/footer and list the filtered records. This will already consider user permissions.

Brilliant!

joshianjvj83
Posts: 21
Joined: 2024-05-12 10:13

Re: How to Display Recent Child Records in Modal Add New separate display DV

Post by joshianjvj83 » 2024-10-24 02:21

sorry I can't seem to follow, could I get furthermore guidance? and again huge thanks for helping

1st problem. with <iframe src="RoutingActionInformation_view.php?Embedded=1&filter_field=value" style="width: 100%; height: 600px; border: none;"></iframe>
I tried this to embed the HTML above the modal however this also adds in the Table View of the RoutingActionInformation, so I end up 2 RoutingActionInformation Table View

2nd problem. with function RoutingActionInformation_init(&$options, $memberInfo, &$args) { //logic etc.
its here Im also struggling to make the filter/logic work to only show the child-table-routingactioninformation that is equals to its parent table-documents controlnumber. I would like it to only show the 3 recent encoded of routingactioninformation of the document

User avatar
jsetzer
AppGini Super Hero
AppGini Super Hero
Posts: 1883
Joined: 2018-07-06 06:03
Location: Kiel, Germany
Contact:

Re: How to Display Recent Child Records in Modal Add New separate display DV

Post by jsetzer » 2024-10-24 04:08

2nd problem. [...] make the filter/logic work
First things first: You should start with the filtering logic.

According to docs, there are different ways for filtering TV data. This is how I do it which gives me maximum flexibility and control:

It is just a working example. Replace tasks by your table name and replace SQL conditions accordingly. You may also change parameter name custom_filter to something different.

Code: Select all

function tasks_init(&$options, $memberInfo, &$args)
{
	// TEST filtering
	$my_filter = Request::val("custom_filter");
	switch ($my_filter) {
		case 'closed':
			$options->QueryWhere = "WHERE task_states1.is_finished";
			break;
		case 'open':
			$options->QueryWhere = "WHERE NOT task_states1.is_finished";
			break;
	}
}
Now, in your browser load the tableview and pass parameter custom_filter=open or custom_filter=closed as URL. This should return the filtered records, only.

https://YOURSERVER/YOURAPP/tasks_view.php?custom_filter=closed

chrome_07UrOVXvz0.png
chrome_07UrOVXvz0.png (70.46 KiB) Viewed 467 times

As soon as it works with a simple filter, extend your logic. For example add more filters like &custom_filter_parent_id=999 or whatever your need and, extend $options->QueryWhere SQL conditions accordingly.

Caution
There may be cases where $options->QueryWhere already contains SQL conditions. In these cases, do not concat "WHERE ..." but concat "AND ...", otherwise you will get SQL errors.

As soon as your filtering works as expected, we can start working on embedding a table view into another detail view.
Kind regards,
<js />

My AppGini Blog:
https://appgini.bizzworxx.de/blog

You can help us helping you:
Please always put code fragments inside [code]...[/code] blocks for better readability

AppGini 24.14 Revision 1665 + all AppGini Helper tools

joshianjvj83
Posts: 21
Joined: 2024-05-12 10:13

Re: How to Display Recent Child Records in Modal Add New separate display DV

Post by joshianjvj83 » 2024-11-04 08:50

SLR I just got back from the weekends, and atm couldn't still make it work (not that good at programming) or am I not getting something right

/Hooks/RountingActionInformation.php

<iframe src="http://localhost/v4update/RoutingAction ... er=matched" style="width: 100%; height: 600px;"> </iframe>

<?php
function RoutingActionInformation_init(&$options, $memberInfo, &$args) {
// TEST filtering
$my_filter = Request::val("custom_filter");

switch ($my_filter) {
case 'matched':
$options->QueryWhere = "WHERE RoutingActionInformation.ControlNumber = Documents.ControlNumber";
break;
case 'unmatched':
$options->QueryWhere = "WHERE RoutingActionInformation.ControlNumber != Documents.ControlNumber";
break;
}

}

I couldn't figure out on why my iframe src is not filtered, is in an almost infinity loop of view and it's showing the entire (with header and footer) view of the address. The help is always significantly grateful

User avatar
jsetzer
AppGini Super Hero
AppGini Super Hero
Posts: 1883
Joined: 2018-07-06 06:03
Location: Kiel, Germany
Contact:

Re: How to Display Recent Child Records in Modal Add New separate display DV

Post by jsetzer » 2024-11-04 09:45

...?custom_filter=matched
As mentioned before, I highly recommend testing your filtering-logic in browser, first, before you start with embeding an <iframe/>.
  1. Check this URL in your browser: http://localhost/v4update/RoutingActionInformation_view.php?custom_filter=matched
    Does it work at all?
  2. If not, add some debugging, for example:

    Code: Select all

    function RoutingActionInformation_init(&$options, $memberInfo, &$args) {
      // TEST filtering
      $my_filter = Request::val("custom_filter");
      var_dump($my_filter);
    
      switch ($my_filter) {
        case 'matched':
          $options->QueryWhere = "WHERE RoutingActionInformation.ControlNumber = Documents.ControlNumber";
          break;
        case 'unmatched':
          $options->QueryWhere = "WHERE RoutingActionInformation.ControlNumber != Documents.ControlNumber";
          break;
      }
      var_dump($options->QueryWhere);
      exit();
    }
    
    Reload your browser and check if there is matched and WHERE RoutingActionInformation.ControlNumber = Documents.ControlNumber in output.
  3. If so, remove the debugging-lines (var_dump(...), exit()), reload page, then, in Admin Area, check for failed SQL queries. We don't know your table names nor do we know your column-names. Perhaps there is a typo or different column-naming.
  4. If there are failed SQL queries, double check your column names and your $options->QueryWhere statement, then, in Admin Area clear error-queries, in Users Area reload your table view page, go back to Admin Area and check if there are new error-queries.
  5. As soon as your table view filter works, go on with embedding <iframe/>.
    Tip: add &Embedded=1 to your URL. As already mentioned, this will remove header from your embedded table view.
---
not that good at programming
We are trying to help you. But please read carefully when we give advice to you.
When posting here, please take the time to put your code fragments in <code>...</code> for better readability.
Kind regards,
<js />

My AppGini Blog:
https://appgini.bizzworxx.de/blog

You can help us helping you:
Please always put code fragments inside [code]...[/code] blocks for better readability

AppGini 24.14 Revision 1665 + all AppGini Helper tools

joshianjvj83
Posts: 21
Joined: 2024-05-12 10:13

Re: How to Display Recent Child Records in Modal Add New separate display DV

Post by joshianjvj83 » 2024-11-05 08:33

1. kinda? its shows string(7) "matched"
2. I added the debugging, and yes it shows in output string(7) "matched" string(70) "WHERE RoutingActionInformation.ControlNumber = Documents.ControlNumber"
3.I checked the admin/query logs for any failed SQL queries but did not find any. For context, my database consists of two tables: 'Documents' and 'RoutingActionInformation'. The 'Documents' table has a primary key field called 'ControlNumber', which is also used as a foreign key in the 'RoutingActionInformation' table.

Thank you so much for your consistent support and guidance, truly appreciate it.
Attachments
Screenshot 2024-11-05 163115.jpg
Screenshot 2024-11-05 163115.jpg (23.55 KiB) Viewed 246 times
Screenshot 2024-11-05 162921.jpg
Screenshot 2024-11-05 162921.jpg (45.82 KiB) Viewed 246 times
Screenshot 2024-11-05 161829.jpg
Screenshot 2024-11-05 161829.jpg (22.96 KiB) Viewed 246 times

User avatar
jsetzer
AppGini Super Hero
AppGini Super Hero
Posts: 1883
Joined: 2018-07-06 06:03
Location: Kiel, Germany
Contact:

Re: How to Display Recent Child Records in Modal Add New separate display DV

Post by jsetzer » 2024-11-05 09:03

Thanks for naming the tables.

Just guessing:
Can you please retry with Documents1.ControlNumber instead of Documents.ControlNumber

Code: Select all

$options->QueryWhere = "WHERE RoutingActionInformation.ControlNumber = Documents1.ControlNumber";

When you var_dump($options->QueryFrom); you should see inner joins FROM RoutingActionInformation on Documents table, having an alias 'Documents1'. So, your SQL query conditions should refer to Documents1, not to Documents.

Hope this is the reason.
Kind regards,
<js />

My AppGini Blog:
https://appgini.bizzworxx.de/blog

You can help us helping you:
Please always put code fragments inside [code]...[/code] blocks for better readability

AppGini 24.14 Revision 1665 + all AppGini Helper tools

joshianjvj83
Posts: 21
Joined: 2024-05-12 10:13

Re: How to Display Recent Child Records in Modal Add New separate display DV

Post by joshianjvj83 » 2024-11-05 09:49

The issues seem to be the same for having it as Documents1: string(7) "matched" string(71) "WHERE RoutingActionInformation.ControlNumber = Documents1.ControlNumber"

<iframe src="http://localhost/v4update/RoutingAction ... er=matched" style="width: 100%; height: 600px;"> </iframe>
<?php
function RoutingActionInformation_init(&$options, $memberInfo, &$args) {
// TEST filtering
$my_filter = Request::val("custom_filter");
var_dump($my_filter);

switch ($my_filter) {
case 'matched':
$options->QueryWhere = "WHERE RoutingActionInformation.ControlNumber = Documents1.ControlNumber";
break;
case 'unmatched':
$options->QueryWhere = "WHERE RoutingActionInformation.ControlNumber != Documents1.ControlNumber";
break;
}
var_dump($options->QueryWhere);
exit();
}
Attachments
Screenshot 2024-11-05 174701.jpg
Screenshot 2024-11-05 174701.jpg (51.48 KiB) Viewed 242 times

User avatar
jsetzer
AppGini Super Hero
AppGini Super Hero
Posts: 1883
Joined: 2018-07-06 06:03
Location: Kiel, Germany
Contact:

Re: How to Display Recent Child Records in Modal Add New separate display DV

Post by jsetzer » 2024-11-05 10:26

Do not write any <iframe/>-HTML-code in hooks file directly!

As you can see, this messes up everything and this will not work. Hook files have a defined set of PHP-functions, identified by naming conventions. You cannot just put any HTML there!

Once again:
Please test the filtering logic in pure plain table view, first.

And please, when posting here, always put code fragments inside [code]...[/code] blocks for better readability.
Kind regards,
<js />

My AppGini Blog:
https://appgini.bizzworxx.de/blog

You can help us helping you:
Please always put code fragments inside [code]...[/code] blocks for better readability

AppGini 24.14 Revision 1665 + all AppGini Helper tools

joshianjvj83
Posts: 21
Joined: 2024-05-12 10:13

Re: How to Display Recent Child Records in Modal Add New separate display DV

Post by joshianjvj83 » 2024-11-06 01:30

Oh, I see. Understood! If I'm not supposed to add my <iframe /> in the hooks, where should I add it?

Code: Select all

<iframe src="http://localhost/v4update/RoutingActionInformation_view.php?&Embedded=1&custom_filter=matched" style="width: 100%; height: 600px;"> </iframe>
Additionally, the filter I am trying to use compares the ControlNumber of both Documents and RoutingActionInformation. If they match, I want to display the RoutingActionInformation entries. Is there something wrong with my query?

Code: Select all

WHERE RoutingActionInformation.ControlNumber = Documents.ControlNumber
Noted: I'll used the

Code: Select all

 fragments.

User avatar
jsetzer
AppGini Super Hero
AppGini Super Hero
Posts: 1883
Joined: 2018-07-06 06:03
Location: Kiel, Germany
Contact:

Re: How to Display Recent Child Records in Modal Add New separate display DV

Post by jsetzer » 2024-11-06 02:47

Filtering Table View Data

Still, it is important that opening a browser-tab with this URL http://localhost/v4update/RoutingActionInformation_view.php?custom_filter=matched returns the filtered table you expect.

If filtering logic in plain table view still does not work I recommend more debugging like so:
  • In TABLENAME_init() hook function, var_dump($options->QueryFrom); and var_dump($options->QueryWhere);
  • Check both outputs to see obvious errors like different table names or misspelled aliases
  • If, after resolving obvious SQL errors, table view still does not work as expected, let AppGini build your final SQL query and check the results in your favourite SQL tool (for example Adminer or PhpMyAdmin):

    Change table names and where-clause accordingly:

    Code: Select all

    function TABLENAME_init(&$options, $memberInfo, &$args)
    {
    	// your filtering logic here
    	// change QueryWhere depending on custom filter parameters
    	// Replace QueryWhere according to YOUR specific condition(s)
    	$options->QueryWhere = "WHERE `TABLENAME`.`id` IN (1, 2, 3, 5, 8, 13, 21, 34, 55)";
    
    	// enable debugging: true|false
    	$debug = true;
    
    	if ($debug) {
    		$sql = $options->buildQuery($options->QueryFieldsTV);
    		echo "<p>Clipboard-copy and test the following SQL command in your SQL tool:</p>";
    		echo "<code>{$sql}</code>";
    		exit;
    	}
    	
    	// ...
    }
    
    This is the dumped SQL statement in my scenario:
    chrome_naaO8gdYAS.png
    chrome_naaO8gdYAS.png (73.6 KiB) Viewed 208 times
  • Open your SQL tool, paste the dumped SQL command, run the query and check the results. As long as your SQL tool cannot run your query, AppGini generated code cannot run your query neither. Your SQL tool may give more detailed information about the error.
  • If you cannot find the mistake by yourself, post outputs from var_dump($options->QueryFrom);, var_dump($options->QueryWhere); and especially $sql here, maybe we can see it.
  • As mentioned before, there are situations in which QueryWhere already contains content due to permissions. Then do not concat " WHERE ..." but " AND ..."
Injecting HTML code
[...] <iframe /> [...], where should I add it?
First things first, but you will not stop asking, right?
Anyway, there are different ways for embedding HTML. You can prepend quoted HTML-code to $html variable in TABLERNAME_dv() hook function. Caution: check $selectedID variable, which may be empty in insert-mode and may be necessary for your filtering logic.
Kind regards,
<js />

My AppGini Blog:
https://appgini.bizzworxx.de/blog

You can help us helping you:
Please always put code fragments inside [code]...[/code] blocks for better readability

AppGini 24.14 Revision 1665 + all AppGini Helper tools

joshianjvj83
Posts: 21
Joined: 2024-05-12 10:13

Re: How to Display Recent Child Records in Modal Add New separate display DV

Post by joshianjvj83 » 2024-11-12 07:01

I just realized—is there a way to iframe only the children of the Document component? What I need is to display only the RoutingactionInformation, which is a child of Document. Could someone elaborate on this approach for the forum?

User avatar
jsetzer
AppGini Super Hero
AppGini Super Hero
Posts: 1883
Joined: 2018-07-06 06:03
Location: Kiel, Germany
Contact:

Re: How to Display Recent Child Records in Modal Add New separate display DV

Post by jsetzer » 2024-11-12 08:23

Question: does it work now? Any feedback welcome.
Kind regards,
<js />

My AppGini Blog:
https://appgini.bizzworxx.de/blog

You can help us helping you:
Please always put code fragments inside [code]...[/code] blocks for better readability

AppGini 24.14 Revision 1665 + all AppGini Helper tools

joshianjvj83
Posts: 21
Joined: 2024-05-12 10:13

Re: How to Display Recent Child Records in Modal Add New separate display DV

Post by joshianjvj83 » 2024-11-12 09:16

sadly no,

Note back to the hooks/RoutingActioninformation.php, I still havent figured out and yes me entering the iframe in the table_templateDV.html looks just right but without the filter

Code: Select all

<?php
function RoutingActionInformation_init(&$options, $memberInfo, &$args)
{
	// TEST filtering
	$my_filter = Request::val("custom_filter");
	switch ($my_filter) {
		case 'match':
			$options->QueryWhere = "WHERE RoutingActionInformation.ControlNumber = Documents.RoutingActionInformation";
			break;
		case 'unmatch':
			$options->QueryWhere = "WHERE RoutingActionInformation.ControlNumber != Documents.RoutingActionInformation";
			break;
	}
}
and resulting I tried using this alternative as it already serves the filter that I want

Code: Select all

<iframe src="http://localhost/v4update/children-RoutingActionInformation?&Embedded=1" style="width: 100%; height: 200px;"> </iframe>
isnt possible as it prompting No direct access allowed. is there a way to negate this?

Code: Select all

 I tried removing the 	if(!isset($Translation)) die('No direct access allowed.');

User avatar
jsetzer
AppGini Super Hero
AppGini Super Hero
Posts: 1883
Joined: 2018-07-06 06:03
Location: Kiel, Germany
Contact:

Re: How to Display Recent Child Records in Modal Add New separate display DV

Post by jsetzer » 2024-11-12 10:14

Question: does it work now? Any feedback welcome.
Sorry, my question was not precise enough: I wanted to ask if your table view filters are working now.

---
I have never seen such filename and I do not know that kind of file which you are using as src in your <iframe/>:

children-RoutingActionInformation?&Embedded=1

It is not a PHP-script. Did you forget the .php file extension? Your src-attribute does not match any default AppGini naming convention for table views nor detail views, and I do not know if you have configured any custom .htaccess redirection for handing such sources.

Here are a few standard script-names for AppGini:
  • TABLENAME_view.php
    Opens a table view for TABLENAME
  • TABLENAME_view.php?SelectedID=1
    Opens a detail view for TABLENAME, showing record, identified by primary key (AKA id) =1, if exists.
  • TABLENAME_view.php?SelectedID=1&Embedded=1
    Same as above but in Embedded-mode without navbar
As a beginner, I once again and for the last time recommend your should get your table view filters working before you continue struggling with <iframe/>. Due to security reasons <iframe/> restrictions are quite complex. You could read and try to understand AppGini generated source code for <ifame/> and learn from how BigProf handles it.

---

For me it looks like I am not able to give any helpful information to you for a little progress on your filters-request.

Anyway, as soon as you have your filters running, it is not complicated, just two lines of PHP code in /hooks/TABLENAME.php produce such result:

CqpdFvd7Mk.png
CqpdFvd7Mk.png (87.65 KiB) Viewed 64 times
Nothing fancy:

Code: Select all

if (!$selectedID) 
  $html .= '<iframe src="TABLENAME_view.php?Embedded=1" width="100%" height="300"></iframe>';
And then there is only little Javascript for moving the <iframe/> to the top.
Kind regards,
<js />

My AppGini Blog:
https://appgini.bizzworxx.de/blog

You can help us helping you:
Please always put code fragments inside [code]...[/code] blocks for better readability

AppGini 24.14 Revision 1665 + all AppGini Helper tools

Post Reply