how to manipulate record count in homepage?

If you're a new user of AppGini, feel free to ask general usage questions, or look for answers here.
Post Reply
User avatar
onoehring
AppGini Super Hero
AppGini Super Hero
Posts: 1161
Joined: 2019-05-21 22:42
Location: Germany
Contact:

how to manipulate record count in homepage?

Post by onoehring » 2020-11-13 19:20

Hi,

I need to adjust the value shown as record count in the homepage.
reccount.png
reccount.png (2.82 KiB) Viewed 1630 times
I have the JS selector path

Code: Select all

document.querySelector("#tablename-tile > div > div > div.btn-group > a:nth-child(1) > span").textContent='MY_VALUE'
The value shows the total number of record in the table - I want it to show only the record count of those matching certain criteria.
Thus I think I will need to combine PHP with JS:
Use PHP to get the count I want and dynamically add this to the JS.

So my question is: Where do I add the code so that injects (or changes the badge contents before displaying the number)?

Thanks already
Olaf

pbottcher
AppGini Super Hero
AppGini Super Hero
Posts: 1638
Joined: 2018-04-01 10:12

Re: how to manipulate record count in homepage?

Post by pbottcher » 2020-11-13 19:37

Hi Olaf,

add the code to the hooks/header-extras.php, check if you are in the index.php page and off you go.
Any help offered comes with the best of intentions. Use it at your own risk. In any case, please make a backup of your existing environment before applying any changes.

User avatar
onoehring
AppGini Super Hero
AppGini Super Hero
Posts: 1161
Joined: 2019-05-21 22:42
Location: Germany
Contact:

Re: how to manipulate record count in homepage?

Post by onoehring » 2020-11-14 08:43

Hi pbötcher,

thank you. It worked like a charm.
The code I placed in header-extras:

Code: Select all

$position = stripos($_SERVER['REQUEST_URI'], 'index.php');
if ($position === 1){	
	//we are on INDEX / MAIN / LOGIN
} else {
	//we are SOMEWHERE ELSE
}
?>
Olaf

User avatar
onoehring
AppGini Super Hero
AppGini Super Hero
Posts: 1161
Joined: 2019-05-21 22:42
Location: Germany
Contact:

Re: how to manipulate record count in homepage?

Post by onoehring » 2020-11-14 09:24

Hi again,

actually this does not work as expected: If I have another user with different table permissions, the JS path seems to change and my code thus fails to update a badge that does not exist on another table :-(

Olaf

User avatar
onoehring
AppGini Super Hero
AppGini Super Hero
Posts: 1161
Joined: 2019-05-21 22:42
Location: Germany
Contact:

Re: how to manipulate record count in homepage?

Post by onoehring » 2020-11-14 09:35

Hi,
I suppose the reason is, that as admin I have an extra "+" on the button, so it's rendered as a button-group. The other user however can not add to that table, so there is no "+" and no button group.

Olaf

User avatar
onoehring
AppGini Super Hero
AppGini Super Hero
Posts: 1161
Joined: 2019-05-21 22:42
Location: Germany
Contact:

Re: how to manipulate record count in homepage?

Post by onoehring » 2020-11-14 09:48

Hi

just reporting back. Problem seems to be solved.
I am checking the permissions of the logged in user. If he has INSERT permission, I need another JS path than without.

Code: Select all

<?php//Check user permission on table Jobs. If user can add to jobs it's a button group
$permission = getTablePermissions('ecomo_jobs');
if ($permission['insert'] != 0) {
?>document.querySelector("#tablename-tile > div > div > div.btn-group > a:nth-child(1) > span").textContent='<?php echo $myValue; ?>';
<?php
} else {
?>document.querySelector("#tablename-tile > div > div > a > span").textContent='<?php echo $myValue; ?>';
<?php
}
?>
Not: This code goes into the are of the position check which says "//we are on INDEX / MAIN / LOGIN" and, as it's JS, it needs to be placed inside <script>...</script> tags (which I do not show here as there is more code).

Thanks again.
Olaf

Post Reply