Retrieve a list of users who haven’t made any activity in the last x months

I just got an interesting question from an AppGini user:

Is there an SQL query that I can run manually in PhpMyAdmin that will show me a list of all users that haven’t logged into AppGini for the last 6 months please? Even if it is using one of the date fields in the membership_users table to show me a list of all users that haven’t added or changed a record for the last 6 months, that would suffice.

Well, AppGini doesn’t currently (until AppGini 5.72) store the login date/time of users (but we plan to add this in future releases). So, what we can do is run a query to retrieve non-active users (with no insert/edit activity in the last 6 months).

First, we need to create a new view in MySQL to list users’ last activity:

Now, you can use the view ‘members_activity’ that we defined above like you use any table (except it’s not actually a table, but it makes our life easier when performing complex queries). So, to retrieve all users who have no insert/update activity or whose last insert/update activity is more than 6 months old:

But the above query might retrieve new users who joined less than 6 months ago … to exclude those, we should add another condition:

Hiding the nicedit component from a page

AppGini uses nicedit Javascript component for displaying rich text areas, where users can enter formatted input. You might wish to hide/show the rich editor in an AppGini page, or in one of your custom pages. This can be done using JavaScript code.

To hide nicedit components in a page:

To show nicedit components:

 

How to hide a field in child table view?

In many cases, your application might have a child table, like this:

An example child table in an AppGini application. We want to hide some columns from that table.

Let’s say we want to hide the Company and Open columns from that child table. You can add a CSS rule to hide specific columns from the child table. In the generated hooks/footer-extras.php, add code similar to this:

In the above code, replace:

  • child-table with the name of the child table, “quotes” in the above example.
  • lookup-field with the name of the lookup field in the child table that points to the parent table, “company” in the above example.
  • field-to-hide name of the child table field to hide, “company” in the above example

You can repeat the above rule for every column you want to hide. So, to hide the company and open fields:

The result looks as follows:

Company and Open fields now hidden after applying the above CSS rules.

How to allow numbers only in a field?

Let’s say you have a numeric field, maybe a price, a score or some other field that should contain numbers only. If you set the data type of the field in AppGini (or in your database) to be numeric (INT, DECIMAL, FLOAT … etc) that would allow only numbers to be stored in the database.

But you might still wish to alert the user that only numbers are allowed before she saves the record. Here is how to do it in JavaScript:

First, you should place this code in the hooks/footer-extras.php file:

Next, also in the hooks folder, create a file named tablename-dv.js (where tablename is the name of the concerned table) if it’s not already there, and add this code to it:

Change field1 and field2 in the above code to the actual names of the fields that you want to set to accept only numeric values. Add more lines if you have more fields or remove a line if you have only one numeric field.

The above code would remove any non-numeric characters that the user types, on the fly. And it would still allow negative sign and decimal point.

How to hide the seconds in a time field?

If you have a time field in your AppGini application, it displays a time picker in the detail view like this one:

The timepicker includes seconds. If you wish to hide the seconds part, you could do so by editing the tablename_dv hook. Open the generated hooks/tablename_dv.php file in a text editor (where tablename is the name of the concerned table) and look for the dv function, then add this line inside it:

If you refresh the page, the time field would now look like this, showing no seconds:

Auto save a new record without having to click ‘Save as copy’

An AppGini customer told me recently that he has a table containing only one field, a barcode field, that he uses a barcode scanner to populate. He has thousands of items to enter, and wanted to know if there is someway to expedite his workflow, maybe by avoiding to click ‘Save as copy’ everytime he scans a new barcode.

I suggested the following code to him, to be placed in the hooks/tablename-dv.js (where tablename is the name of the concerned table — create that file if it doesn’t already exist).

Change fieldname in line 2 above to the actual name of the barcode field. The above code checks if the concerned barcode field has been changed. If it has been, the ‘Save as copy’ button (using the #insert selector) is clicked.

Programmatically change the value of an image field in the detail view

In the detail view, if you have some ajax request running in the background that should update your detail view form (or if you do this in the tablename_dv hook), you might already know that you can change the data of a normal text field using this JavaScript code:

But if your field is an image field, the above code won’t work. Try this instead:

Of course, change fieldname in the above code to the actual field name.