bug 3343 : Completed revision of ADL to support explicit ordering (incl reverse ordering) of lists

This commit is contained in:
sb 2010-01-12 17:20:16 +00:00
parent 574e4d346f
commit 63a94d8ce1
13 changed files with 147 additions and 149 deletions

View file

@ -9,15 +9,15 @@
Transform ADL into (partial) controller classes
$Author: sb $
$Revision: 1.43 $
$Date: 2009-05-12 15:43:18 $
$Revision: 1.44 $
$Date: 2010-01-12 17:20:17 $
-->
<!-- WARNING WARNING WARNING: Do NOT reformat this file!
Whitespace (or lack of it) is significant! -->
<xsl:stylesheet version="1.0"
xmlns="http://libs.cygnets.co.uk/adl/1.3/"
xmlns:adl="http://libs.cygnets.co.uk/adl/1.3/"
xmlns="http://libs.cygnets.co.uk/adl/1.4/"
xmlns:adl="http://libs.cygnets.co.uk/adl/1.4/"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:exsl="urn:schemas-microsoft-com:xslt"
extension-element-prefixes="exsl">
@ -72,7 +72,7 @@
//
// Automatically generated abstract super class for controllers for the
// <xsl:value-of select="/adl:application/@name"/> application; generated using
// adl2controllerclasses.xslt version <xsl:value-of select="substring( '$Revision: 1.43 $', 10)"/>
// adl2controllerclasses.xslt version <xsl:value-of select="substring( '$Revision: 1.44 $', 10)"/>
//
// <xsl:value-of select="/adl:application/@revision"/>
//
@ -182,7 +182,7 @@
//
// Controller for auto-generated forms for editing <xsl:value-of select="@name"/>s
// Automatically generated from application description using
// adl2controllerclasses.xslt version <xsl:value-of select="substring( '$Revision: 1.43 $', 10)"/>
// adl2controllerclasses.xslt version <xsl:value-of select="substring( '$Revision: 1.44 $', 10)"/>
//
// This file is automatically generated; DO NOT EDIT IT.
//
@ -677,10 +677,8 @@
} /* if ( ! HasNoErrors()) */
<xsl:value-of select="concat( 'this.',adl:form[position()=1]/@name)"/>( record);
}
</xsl:if>
<xsl:if test="adl:form">
<!-- unless there's at least one form, we won't generate a 'delete' method -->
<!-- unless there's at least one form, we won't generate a 'delete' method -->
/// &lt;summary&gt;
/// Actually delete the selected record
/// &lt;/summary&gt;
@ -726,77 +724,9 @@
}
</xsl:if>
<xsl:apply-templates select="adl:form"/>
<xsl:apply-templates select="adl:list"/>
<xsl:if test="adl:list">
<xsl:variable name="listname" select="adl:list[position()=1]/@name"/>
<xsl:apply-templates select="adl:list"/>
/// &lt;summary&gt;
/// list all instances of this entity to allow the user to select one for editing
/// this method invokes the default list view - which is probably what you want unless
/// you've a special reason for doing something different
/// &lt;/summary&gt;
public void InternalShowList()
{
InternalShowList( "<xsl:value-of select="$listname"/>");
}
/// &lt;summary&gt;
/// list all instances of this entity to allow the user to select one for editing
/// &lt;/summary&gt;
/// &lt;param name="view"&gt;The name of the list view to show&lt;/param&gt;
public void InternalShowList( String view)
{
AssertUserCanRead();
ISession hibernator = GetDBSession();
ICriteria search =
hibernator.CreateCriteria(typeof(<xsl:value-of select="concat( $entityns, '.', @name)"/>));
Boolean withSearchCriteria = false;
<xsl:for-each select="adl:property">
<xsl:variable name="base-type">
<xsl:call-template name="base-type">
<xsl:with-param name="property" select="."/>
</xsl:call-template>
</xsl:variable>
<xsl:choose>
<xsl:when test="$base-type='boolean'"/>
<xsl:when test="$base-type='link'"/>
<xsl:when test="$base-type='list'"/>
<xsl:otherwise>
if ( ! String.IsNullOrEmpty( Params[ "<xsl:value-of select="concat( 'search_', @name)"/>"])) {
search<xsl:call-template name="add-hibernate-expression-like">
<xsl:with-param name="property" select="."/>
<xsl:with-param name="value">Params["<xsl:value-of select="concat( 'search_', @name)"/>"]</xsl:with-param>
</xsl:call-template>;
PropertyBag["<xsl:value-of select="concat( 'search_', @name)"/>"] = Params[ "<xsl:value-of select="concat( 'search_', @name)"/>"];
withSearchCriteria = true;
}
</xsl:otherwise>
</xsl:choose>
</xsl:for-each>
<xsl:for-each select="adl:property[@distinct='user' or @distinct='all']">
search.AddOrder(<xsl:value-of select="concat( ' new Order( &#34;', @name, '&#34;, true)')"/>);
</xsl:for-each>
IList&lt;<xsl:value-of select="concat( $entityns, '.', @name)"/>&gt; instances = search.List&lt;<xsl:value-of select="concat( $entityns, '.', @name)"/>&gt;();
/* bug 2921: suppress pagination when searching, as we can't fold the search params into the pagination */
/* if no instances, set showRecords to one else we get a division by zero error */
int showRecords = instances.Count > 0? instances.Count: 1;
if ( ! withSearchCriteria) {
showRecords = <xsl:value-of select="$records-per-page"/>;
}
PropertyBag["instances"] =
PaginationHelper.CreatePagination( this, instances, showRecords);
RenderViewWithFailover(view + ".vm", view + ".auto.vm");
}
</xsl:if>
/// &lt;summary&gt;
/// &lt;summary&gt;
/// Check whether values for all my keys are available in the form fields
/// &lt;/summary&gt;
protected bool AllKeys() {
@ -1015,11 +945,80 @@
/// this method invokes the named view.
/// &lt;/summary&gt;
public void <xsl:value-of select="@name"/>()
{
InternalShowList( "<xsl:value-of select="@name"/>");
}
{
AssertUserCanRead();
string view = "<xsl:value-of select="@name"/>";
ISession hibernator = GetDBSession();
ICriteria search =
hibernator.CreateCriteria(typeof(<xsl:value-of select="concat( $entityns, '.', ancestor::adl:entity/@name)"/>));
Boolean withSearchCriteria = false;
</xsl:template>
<xsl:for-each select="adl:field">
<xsl:variable name="fieldprop" select="@property"/>
<xsl:variable name="property" select="ancestor::adl:entity//adl:property[@name=$fieldprop]"/>
<xsl:variable name="base-type">
<xsl:call-template name="base-type">
<xsl:with-param name="property" select="$property"/>
</xsl:call-template>
</xsl:variable>
/* <xsl:value-of select="@property"/> */
<xsl:choose>
<xsl:when test="$base-type='boolean'"/>
<xsl:when test="$base-type='link'"/>
<xsl:when test="$base-type='list'"/>
<xsl:otherwise>
if ( ! String.IsNullOrEmpty( Params[ "<xsl:value-of select="concat( 'search_', $property/@name)"/>"])) {
search<xsl:call-template name="add-hibernate-expression-like">
<xsl:with-param name="property" select="$property"/>
<xsl:with-param name="value">
Params["<xsl:value-of select="concat( 'search_', $property/@name)"/>"]
</xsl:with-param>
</xsl:call-template>;
PropertyBag["<xsl:value-of select="concat( 'search_', $property/@name)"/>"] = Params[ "<xsl:value-of select="concat( 'search_', $property/@name)"/>"];
withSearchCriteria = true;
}
</xsl:otherwise>
</xsl:choose>
</xsl:for-each>
<xsl:choose>
<xsl:when test="adl:order">
/* explicit ordering */
<xsl:apply-templates select="adl:order"/>
</xsl:when>
<xsl:otherwise>
/* no explicit ordering */
<xsl:for-each select="ancestor::adl:entity//adl:property[@distinct='user' or @distinct='all']">
search.AddOrder(<xsl:value-of select="concat( ' new Order( &#34;', @name, '&#34;, true)')"/>);
</xsl:for-each>
</xsl:otherwise>
</xsl:choose>
IList&lt;<xsl:value-of select="concat( $entityns, '.', ancestor::adl:entity/@name)"/>&gt; instances = search.List&lt;<xsl:value-of select="concat( $entityns, '.', ancestor::adl:entity/@name)"/>&gt;();
/* if no instances, set showRecords to one else we get a division by zero error */
int showRecords = instances.Count > 0? instances.Count: 1;
if ( ! withSearchCriteria) {
showRecords = <xsl:value-of select="$records-per-page"/>;
}
PropertyBag["instances"] =
PaginationHelper.CreatePagination( this, instances, showRecords);
RenderViewWithFailover(view + ".vm", view + ".auto.vm");
}
</xsl:template>
<xsl:template match="adl:order">
search.AddOrder( new Order( "<xsl:value-of select="@property"/>",
<xsl:choose>
<xsl:when test="@sequence='reverse-canonical'">false</xsl:when>
<xsl:otherwise>true</xsl:otherwise>
</xsl:choose>));
</xsl:template>
<xsl:template match="adl:documentation">
/* <xsl:apply-templates/> */
@ -1102,22 +1101,22 @@
<xsl:variable name="propname" select="@property"/>
<xsl:choose>
<xsl:when test="parent::adl:auxlist"/>
<xsl:when test="$form/ancestor::adl:entity/adl:property[@name=$propname and @type='entity']">
/* produce a list of <xsl:value-of select="$form/ancestor::adl:entity/adl:property[@name=$propname]/@entity"/> to populate the select for <xsl:value-of select="$propname"/> */
<xsl:when test="$form/ancestor::adl:entity//adl:property[@name=$propname and @type='entity']">
/* produce a list of <xsl:value-of select="$form/ancestor::adl:entity//adl:property[@name=$propname]/@entity"/> to populate the select for <xsl:value-of select="$propname"/> */
<xsl:call-template name="menu">
<xsl:with-param name="property" select="$form/ancestor::adl:entity/adl:property[@name=$propname]"/>
<xsl:with-param name="property" select="$form/ancestor::adl:entity//adl:property[@name=$propname]"/>
</xsl:call-template>
</xsl:when>
<xsl:when test="$form/ancestor::adl:entity/adl:property[@name=$propname and @type='link']">
/* produce a list of <xsl:value-of select="$form/ancestor::adl:entity/adl:property[@name=$propname]/@entity"/> to populate the LHS of the shuffle for <xsl:value-of select="$propname"/> */
<xsl:when test="$form/ancestor::adl:entity//adl:property[@name=$propname and @type='link']">
/* produce a list of <xsl:value-of select="$form/ancestor::adl:entity//adl:property[@name=$propname]/@entity"/> to populate the LHS of the shuffle for <xsl:value-of select="$propname"/> */
<xsl:call-template name="menu">
<xsl:with-param name="property" select="$form/ancestor::adl:entity/adl:property[@name=$propname]"/>
<xsl:with-param name="property" select="$form/ancestor::adl:entity//adl:property[@name=$propname]"/>
</xsl:call-template>
</xsl:when>
<xsl:when test="$form/ancestor::adl:entity/adl:property[@name=$propname and @type='list']">
/* produce a list of <xsl:value-of select="$form/ancestor::adl:entity/adl:property[@name=$propname]/@entity"/> to populate the multi-select for <xsl:value-of select="@name"/> */
<xsl:when test="$form/ancestor::adl:entity//adl:property[@name=$propname and @type='list']">
/* produce a list of <xsl:value-of select="$form/ancestor::adl:entity//adl:property[@name=$propname]/@entity"/> to populate the multi-select for <xsl:value-of select="@name"/> */
<xsl:call-template name="menu">
<xsl:with-param name="property" select="$form/ancestor::adl:entity/adl:property[@name=$propname]"/>
<xsl:with-param name="property" select="$form/ancestor::adl:entity//adl:property[@name=$propname]"/>
</xsl:call-template>
</xsl:when>
</xsl:choose>
@ -1133,11 +1132,8 @@
/* there's no way I can find of producing a set of just those entities
* we'll need menus for. So we set up variables for all the menus we might
* need, and then only instantiate those we do need. */
<!-- xsl:for-each select="//adl:entity">
IList&lt;<xsl:value-of select="concat( $entityns, '.', @name)"/>&gt; <xsl:value-of select="concat( 'all', @name)"/> = null;
</xsl:for-each -->
<xsl:for-each select="$entity//adl:property[@type='entity']">
<!-- $entity//adl:property because it is possible to have type='entity' in the key -->
<xsl:for-each select="$entity/adl:property[@type='entity']">
<!-- $entity/adl:property because it is possible to have type='entity' in the key -->
<xsl:call-template name="menu">
<xsl:with-param name="property" select="."/>
</xsl:call-template>
@ -1278,7 +1274,7 @@
ADL: Error: properties of type <xsl:value-of select="$basetype"/> cannot yet be used
in equality tests
</xsl:message>
</xsl:otherwise>
</xsl:otherwise>
</xsl:choose>)
</xsl:template>
@ -1294,11 +1290,11 @@
</xsl:variable>
<xsl:choose>
<xsl:when test="$basetype='string' or $basetype='text'">
Expression.Like( "<xsl:value-of select="@name"/>", "%"+<xsl:value-of select="$value"/>+"%")
Expression.Like( "<xsl:value-of select="$property/@name"/>", "%"+<xsl:value-of select="$value"/>+"%")
</xsl:when>
<xsl:when test="$basetype='real'">
/* match to four significant places */
Expression.Between( "<xsl:value-of select="@name"/>",
Expression.Between( "<xsl:value-of select="$property/@name"/>",
Double.Parse( <xsl:value-of select="$value"/>) * 1.0001,
Double.Parse( <xsl:value-of select="$value"/>) * 0.9999)
</xsl:when>