deanlaw / cfcgenerator

Automatically exported from code.google.com/p/cfcgenerator
8 stars 6 forks source link

Order DSN list alpha order #23

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Brian,

I am looking for a good code generator, and I’m very impressed with yours
so far. 

2 quick suggestions: 

1.  When creating files, it would be nice to be able to use an absolute
path instead of a relative path.  We would run this program from a central
domain, but the results would be stored in numerous other domains, so the
system root folder does not equal the export folder.  I couldn’t find where
this was set.  I don’t have flex yet, and I’ve already burned my flex
builder demo, so I couldn’t look too far into this one.

2.  We have a very large number of DSNs, and the default listing in the
dropdown is not in a predictable order.

I added the following two functions to  com.cf.model.adminAPI.adminAPIFacade

One of my own:    

<cffunction name="sortDatasources" access="public" output="false">

                                    <cfset var sortedArray = ArrayNew(1)>

                                    <cfset var returnArray = ArrayNew(1)>

                                    <cfset var i="">

                                    <!--- Store a 2 value structure with
name and id in a temporary array. --->

                                    <cfloop from="1"
to="#arrayLen(variables.arrDSNs)#" index="i">

                                                <cfset sortedArray[i] =
StructNew()>

                                                <cfset
sortedArray[i].dsnName = variables.arrDSNs[i].getDsnName()>

                                                <cfset
sortedArray[i].originalID = i>

                                    </cfloop>

                                    <!--- Sort the new array by dsnName --->

                                    <cfset sortedArray = 
arrayOfStructsSort(sortedArray,"dsnName","asc","Text")>

                                    <!--- Loop through sorted list, and
build a return array with

                                    original objects in the new sorted
order. --->

                                    <cfloop from="1"
to="#arrayLen(sortedArray)#" index="i">

                                                <cfset returnArray[i] =
variables.arrDSNs[sortedArray[i].originalID]>

                                    </cfloop>

                                    <cfset variables.arrDSNs = returnArray>

                        </cffunction>

The other is from cflib.org

<cfscript>

/**

 * Sorts an array of structures based on a key in the structures.

 *

 * @param aofS              Array of structures.

 * @param key  Key to sort by.

 * @param sortOrder       Order to sort by, asc or desc.

 * @param sortType        Text, textnocase, or numeric.

 * @param delim             Delimiter used for temporary data storage. Must
not exist in data. Defaults to a period.

 * @return Returns a sorted array.

 * @author Nathan Dintenfass (nathan@changemedia.com)

 * @version 1, December 10, 2001

 */

function arrayOfStructsSort(aOfS,key){

                        //by default we'll use an ascending sort

                        var sortOrder = "asc";                

                        //by default, we'll use a textnocase sort

                        var sortType = "textnocase";

                        //by default, use ascii character 30 as the delim

                        var delim = ".";

                        //make an array to hold the sort stuff

                        var sortArray = arraynew(1);

                        //make an array to return

                        var returnArray = arraynew(1);

                        //grab the number of elements in the array (used in
the loops)

                        var count = arrayLen(aOfS);

                        //make a variable to use in the loop

                        var ii = 1;

                        //if there is a 3rd argument, set the sortOrder

                        if(arraylen(arguments) GT 2)

                                    sortOrder = arguments[3];

                        //if there is a 4th argument, set the sortType

                        if(arraylen(arguments) GT 3)

                                    sortType = arguments[4];

                        //if there is a 5th argument, set the delim

                        if(arraylen(arguments) GT 4)

                                    delim = arguments[5];

                        //loop over the array of structs, building the
sortArray

                        for(ii = 1; ii lte count; ii = ii + 1)

                                    sortArray[ii] = aOfS[ii][key] & delim & ii;

                        //now sort the array

                        arraySort(sortArray,sortType,sortOrder);

                        //now build the return array

                        for(ii = 1; ii lte count; ii = ii + 1)

                                    returnArray[ii] =
aOfS[listLast(sortArray[ii],delim)];

                        //return the array

                        return returnArray;

}

</cfscript> 

Then I added  <cfset sortDatasources()> to the bottom of the existing
setDatasources() function.  There may be a better way to do it, but this
was the quick solution I came up with.  Our DSN list is impossible to
navigate if not in alpha order.

Program looks great.

Gabriel Hyter

Website Design and Development

Original issue reported on code.google.com by brian.ri...@gmail.com on 11 Mar 2007 at 12:12

GoogleCodeExporter commented 9 years ago
I mode the change to the adminAPIFacade.cfc to handle this. It only required a 
few
additional lines tilizing the structSort() function on the adminAPI 
getDatasources()
call. This change is in SVN and downloads should be updated shortly.

Original comment by brian.ri...@gmail.com on 11 Mar 2007 at 12:32