Option List Customization

The recommended method of customizing your AppGini-generated application is through hooks. But sometimes you might need to add functionality not accessible through hooks. You can discuss this here.
Post Reply
sathukorala
AppGini Super Hero
AppGini Super Hero
Posts: 121
Joined: 2020-02-16 16:29

Option List Customization

Post by sathukorala » 2020-11-27 07:43

I want to get option list of the current week and 7 weeks prior to this week to be auto-populated and the user to select, any help?
Like this?
1.png
1.png (18.97 KiB) Viewed 4007 times

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

Re: Option List Customization

Post by jsetzer » 2020-11-27 09:33

Alternative (1): JQuery plugin

Integrate a date range picker like this one:
https://www.jqueryscript.net/demo/Multi ... er-Plugin/

Scroll down to the example named "Batch mode ( week )" which automatically selects a whole week when selecting a date.

This is not out of the box. For integrating such a plugin you will need some programming knowlegdge in JQuery and Javascript.

There are more date range picker plugins available on the market, for example this one:
https://www.cssscript.com/date-range-picker-lightpick/
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.10 Revision 1579 + all AppGini Helper tools

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

Re: Option List Customization

Post by jsetzer » 2020-11-27 09:41

Alternative (2): Additional "weeks" table

Create an additional table for weeks and populate it by PHP+SQL code. For example automatically insert all weeks till the end of the current yeay (or for the next 10 years or for the next three months ...).

Use that "weeks" table as lookup.

This solution could become be very flexible and can be integrated using built-in AppGini functions without any additional libraries or tools.

Example:

weeks
  • id
  • start {date, required, unique}
  • end {date, required, unique}
  • year {int, *}
  • month {int, *}
  • week {int, *}
* Year, month and week are optional by may (!) be very helpful later on for example for filtering using your lookup/Advanced SQL code.

Insert can be done using PHP+SQL being called by a CRON job or after login or in an _init hook.
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.10 Revision 1579 + all AppGini Helper tools

sathukorala
AppGini Super Hero
AppGini Super Hero
Posts: 121
Joined: 2020-02-16 16:29

Re: Option List Customization

Post by sathukorala » 2020-11-27 14:55

jsetzer wrote:
2020-11-27 09:41
Alternative (2): Additional "weeks" table

Create an additional table for weeks and populate it by PHP+SQL code. For example automatically insert all weeks till the end of the current yeay (or for the next 10 years or for the next three months ...).

Use that "weeks" table as lookup.

This solution could become be very flexible and can be integrated using built-in AppGini functions without any additional libraries or tools.

Example:

weeks
  • id
  • start {date, required, unique}
  • end {date, required, unique}
  • year {int, *}
  • month {int, *}
  • week {int, *}
* Year, month and week are optional by may (!) be very helpful later on for example for filtering using your lookup/Advanced SQL code.

Insert can be done using PHP+SQL being called by a CRON job or after login or in an _init hook.
The list will be a huge one, how can we have only few weeks around current date?

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

Re: Option List Customization

Post by jsetzer » 2020-11-27 15:10

... very helpful later on for example for filtering using your lookup/Advanced SQL code ...
Just click [Advanced] button in lookup configuration and change the SQL code which controls fetching lookup data.
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.10 Revision 1579 + all AppGini Helper tools

sathukorala
AppGini Super Hero
AppGini Super Hero
Posts: 121
Joined: 2020-02-16 16:29

Re: Option List Customization

Post by sathukorala » 2020-11-28 04:58

jsetzer wrote:
2020-11-27 15:10
... very helpful later on for example for filtering using your lookup/Advanced SQL code ...
Just click [Advanced] button in lookup configuration and change the SQL code which controls fetching lookup data.

Can't we use a code block like following to the DV.php and get the values at the form level?

Code: Select all

<?php 
	$PeriodWeekly = 8;
	$monday = strtotime("last monday");
	$monday = date('w', $monday)==date('w') ? $monday+7*86400 : $monday;
	$sunday = strtotime(date("Y-m-d",$monday)." +6 days");
	
	for($i=0; $i<=$PeriodWeekly;$i++){
	$n = $i*7;
	$start_date = date("Y-m-d",strtotime(date("Y-m-d",$monday)." -$n days"));
	$end_date = date("Y-m-d",strtotime(date("Y-m-d",$sunday)." -$n days"));
	
	<option value="<?php echo "$start_date to $end_date"; ?>"><?php echo "$start_date to $end_date"; ?></option>
	
	 }?>


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

Re: Option List Customization

Post by pbottcher » 2020-11-28 20:31

Hi,

just a thought, you could use your code actually in the hooks/TABLENAME_init function to create the TABLENAME.FIELDNAME.csv file in the hooks folder, (see https://bigprof.com/appgini/help/advanc ... agic-files )

Like that you will always have the expected selection available.

One drawback, if you have an exiting record with a date selected that is not available in the newly created list (as it is already older than 7 weeks), the data will still be displayed in the tableview, but not in the detailview, as the reference to the possible selections will not be available any more.
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.

sathukorala
AppGini Super Hero
AppGini Super Hero
Posts: 121
Joined: 2020-02-16 16:29

Re: Option List Customization

Post by sathukorala » 2020-11-29 01:29

pböttcher wrote:
2020-11-28 20:31
Hi,

just a thought, you could use your code actually in the hooks/TABLENAME_init function to create the TABLENAME.FIELDNAME.csv file in the hooks folder, (see https://bigprof.com/appgini/help/advanc ... agic-files )

Like that you will always have the expected selection available.

One drawback, if you have an exiting record with a date selected that is not available in the newly created list (as it is already older than 7 weeks), the data will still be displayed in the tableview, but not in the detailview, as the reference to the possible selections will not be available any more.
hooks/TABLENAME_init function is an excelent idea....

sathukorala
AppGini Super Hero
AppGini Super Hero
Posts: 121
Joined: 2020-02-16 16:29

Re: Option List Customization

Post by sathukorala » 2020-11-29 04:01

This is the code which should be put in hooks/table_name.php for init function
It will auto-populate the CSV file and that will be taken to option list

Code: Select all

function COVID_cases_init(&$options, $memberInfo, &$args) {
		
	$PeriodWeekly = 8;
	$file = '.\hooks\tablename.fieldname.csv';
	file_put_contents('.\hooks\tablename.fieldname.csv', "");
	
	$monday = strtotime("last monday");
	$monday = date('w', $monday)==date('w') ? $monday+7*86400 : $monday;
	$sunday = strtotime(date("Y-m-d",$monday)." +6 days");
	
	for($i=0; $i<=$PeriodWeekly;$i++){
	$n = $i*7;
	$start_date = date("Y-m-d",strtotime(date("Y-m-d",$monday)." -$n days"));
	$end_date = date("Y-m-d",strtotime(date("Y-m-d",$sunday)." -$n days"));
	
	$current = $start_date . " to " . $end_date . ";;";
	$current = file_get_contents($file);
	$current .= $start_date . " to " . $end_date . ";;";
	file_put_contents($file, $current);
	
	}

		return TRUE;
	}
1.png
1.png (12.7 KiB) Viewed 3840 times

sathukorala
AppGini Super Hero
AppGini Super Hero
Posts: 121
Joined: 2020-02-16 16:29

Re: Option List Customization

Post by sathukorala » 2020-11-29 04:23

To make the dates descending change the common.js.php below section
"return b.text > a.text;" instead of "return a.text > b.text;"

Code: Select all

/* function to sort select2 search results by relevence */
AppGini.sortSelect2ByRelevence = function(res, cont, qry) {
	return res.sort(function(a, b) {
		if(qry.term) {
			var aStart = a.text.match(new RegExp("^" + qry.term, "i")) !== null;
			var bStart = b.text.match(new RegExp("^" + qry.term, "i")) !== null;
			if(aStart && !bStart) return false;
			if(!aStart && bStart) return true;
		}
		return b.text > a.text;
	});
}
1.png
1.png (12.22 KiB) Viewed 3839 times


pfrumkin
Veteran Member
Posts: 157
Joined: 2020-02-18 17:58
Location: Albuquerque, New Mexico USA

Re: Option List Customization

Post by pfrumkin » 2020-12-07 17:50

Does this happen every time someone lands on the form?

I assume the list is always Monday to Sunday, so this list would change weekly as opposed to daily.

Thanks.
~Paul

sathukorala
AppGini Super Hero
AppGini Super Hero
Posts: 121
Joined: 2020-02-16 16:29

Re: Option List Customization

Post by sathukorala » 2020-12-08 04:12

pfrumkin wrote:
2020-12-07 17:50
Does this happen every time someone lands on the form?

I assume the list is always Monday to Sunday, so this list would change weekly as opposed to daily.

Thanks.
~Paul
Yes the list will be auto generated each time you load the detail view. Date ranges will be generated based on the current date

Post Reply