I've been trying my best to get into the use of hooks in Appgini. I have a good understanding of data models and SQL, but php and jscript for now remain beyond my comfortable knowledge. I've had some success despite this and thanks to the great resources in the community, but I'm struggling with things like this, even after trying the Udemy course to pick up some tips and tricks.
So my problem statement is fairly simple.
I have a Companies table which allows my users to add companies that they have to do checks on.
I have a Documents_Checklist tab (one of several) which is pre-filled with a checklist of documents to be checked by the users (so that they do not forget to check for each type of document).
The Documents_Checklist tab shows a counter by default in the sub tab for the parent record of ALL records in the view, which was added by Appgini some time ago.
I want to customise what is being counted.
I have tried to leverage the learnings from this page:
https://blog.appgini.com/appgini/displa ... tab-title/
and apply them to my script. I have also tried to use an AI to help me get the syntax right for the SQL element, but I'm not sure if I haven't made more of a hash of things with it.
I have the following that I have tried to add into footer_extras.php:
Code: Select all
<?php $is_homepage = (basename($_SERVER['PHP_SELF']) === 'index.php' && !isset($_REQUEST['signIn'])); if ($is_homepage) //pretty sure this is entirely wrong
<script>
$j(function() {
setInterval(function() {
// Target the specific tab based on its ID
var tabId = 'tab_Documents_Checklist-Company_ID'; //found this using inspect element on the first of the tabs
// Use PHP to execute the SQL query to count incomplete records
<?php
$counter = SQL("SELECT COUNT(*) FROM Documents_Checklist WHERE status <> 'Complete'"); //i know i need to add an ID limiter for the count per record, but I want to get the basic syntax right first
?>
// Update the badge within the specified tab
if (!$j('#' + tabId + ' .badge').length) {
$j('<span class="badge hspacer-md"></span>').appendTo('#' + tabId);
}
$j('#' + tabId + ' .badge').html(<?php echo $counter; ?>);
}, 1000);
});
</script>
Any advice would be welcome. I've searched and searched for existing posts with more guidance on this, but I haven't found one, nor the use case I'm after in the various youtube videos. Thanks!