Better default field formatting & configuration rules

Post Reply
andonovar
User
Posts: 4

Better default field formatting & configuration rules

Post by andonovar »

  1. I want to assign appropriate default field formatting rules based on the database field type. e.g.
    For every number, assign number field format, right align
    For every date, make it a date
    For text fields, stop mangling it as a textarea

  2. There are global options i just want to set a certain way e.g.
    I never want Column Wrap.
    I always want my Preview Overlay options specified a certain way

Just generally, if I have a standard way I want to deal with certain entities, then the required process is that I have to go through every field of my configuration through the GUI and manually apply it.
When you've got a massive project, this is ridiculous work.

I've since written a perl script that actually goes through the .pmp file, and rewrites these settings based on rules that I specify.
It would be great if PHPMaker could do this kind of thing internally (i.e. allow you to create these kinds of rules to set various settings).

I've included the relevant code below in case you want to reproduce something like this, and to act as a guide as to what I'm proposing.
It does things such as the following:

Turns off ColumnWrap on every field
For all numbers: Set to number type, right align
For all integers: set Number of Digits to zero
For all floats/numerics: Set number of digits to 2
If the field name contains certain strings (e.g. amount): set type to Currency
If the field name contains %: set Type to Percent, 2 digits
For dates, set to date format,turn on the popupcalendar.
Text fields: PHPMaker mangles postgres text fields, which should be treated similarly to varchars. For these, change textareas to text, make them visible etc.
For a particular field (id_booking), automatically make them into hyperlinks

foreach my $line (@$lines) {
	my $orig = $line;
	$line =~ s/"Id":"PreviewOverlay","Type":"Boolean","Value":"0"/"Id":"PreviewOverlay","Type":"Boolean","Value":"1"/;
	$line =~ s/{"Id":"PreviewRow","Type":"Boolean","Value":"1"}/{"Id":"PreviewRow","Type":"Boolean","Value":"0"}/;
	$line =~ s/TblDetailShowCount="0"/TblDetailShowCount="1"/;
	$line =~ s/TblShowMultipleDetails="1"/TblShowMultipleDetails="0"/; 
	
	if ($line =~ /<Table TblSchema="(.+?)" TblName="(.+?)" TblType="(.+?)" TblGen="(.+?)"/) {
		($schema,$table,$type,$gen) = ($1,$2,$3,$4);
		#wprint("$schema:$table:$type:$gen\n");
	}
	if($line =~m|</Table>|) {
		$table = '';
		$type = '';
	}
	
	if ($line =~ /FldName="(.+?)"/) {
		my $name = $1;
		$line =~ s/FldColumnWrap="1"/FldColumnWrap="0"/ unless $path =~ /issues/;
		$line = set_line($line,{'FldSrchOpr'=>'USER SELECT'});
		
		# Numbers
		if($line =~ /(FldValidate="FLOAT|INTEGER")/) {
			$line =~ s/FldAlign=".*?"/FldAlign="right"/;
			
			if($line =~ /(FldTypeName="int\d")/) {
				$line =~ s/FldValidate="FLOAT"/FldValidate="INTEGER"/;
			}
			if($line =~ /(FldValidate="INTEGER")/) {
				$line =~ s/FldFmtType=".*?"/FldFmtType="Number"/;
				$line =~ s/FldNumDigits=".*?"/FldNumDigits="0"/;
			}
			elsif($line =~ /(FldValidate="FLOAT")/) {
				$line =~ s/FldNumDigits=".*?"/FldNumDigits="2"/;
				if ($name =~ /%$/) {
					$line =~ s/FldFmtType=".*?"/FldFmtType="Percent"/;
				}
				elsif ($name =~ /price|fee|net|revenue|rate|total|value|aud|amount|margin|profit|paid|balance|allocated|matched|maybe|not/) {
					$line =~ s/FldFmtType=".*?"/FldFmtType="Currency"/;
				}
				else {
					$line =~ s/FldFmtType=".*?"/FldFmtType="Number"/;
				}
			}
		}
		# DATES
		elsif ($line =~ /FldTypeName="date"/) {
			$line = set_line($line,{'FldDtFormat'=>5,'FldPopCalendar'=>1,'FldSrchOpr'=>'USER SELECT'});
		}
		elsif ($line =~ /FldTypeName="timestamp/) {
			$line = set_line($line,{'FldDtFormat'=>9,'FldPopCalendar'=>1,'FldSrchOpr'=>'USER SELECT'});
		}
		## TEXTAREA
		elsif($line =~ /(FldTypeName="text")/ || $line =~ /FldHtmlTag="TEXTAREA"/) {
			$line =~ s/FldList="0"/FldList="1"/;
			$line =~ s/FldExport="0"/FldExport="1"/;
			$line =~ s/FldHtmlTag="TEXTAREA"/FldHtmlTag="TEXT"/;
		}
		# Turn id_booking field into hyperlink
		if($line =~ /FldName="id_booking"/) {
			$line =~ s|FldTagATarget=""|FldTagATarget="_blank/"|;
			
			my $prefix = "/scripts/foobar?id_booking=";
			$prefix =~ s|&|&|g;
			$line =~ s|FldTagAPrefix=".+?"|FldTagAPrefix="$prefix"|;
			$line =~ s|FldBold="0"|FldBold="1"|;
			$line =~ s|FldHrefFld=""|FldHrefFld="id_booking"|;
			$line =~ s/FldHrefFldOrig="0"/FldHrefFldOrig="1"/;
			$line =~ s/FldFmtType=".*?"/FldFmtType="String"/;
		}
	}

Post Reply