× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.



I'm playing around a lot more with Node.js and Jade using Express on the
IBM i.

I'm just curious how others are handing condition logic, more importantly,
where.

As an example lets say you're listing customer order details. We can of
course limit records we get in a result set using the SQL. We can also
order things, etc..

Once you have the result set, are you doing any additional programming in
node or the jade template?

Here's an example...

I have a generic routine that returns a result set. I have another that
returns the field headings from the file...: (not checked for syntax.. )

var sql = "select RRN(a) as RRN, a.* from %s.%s a where CDEMAIL = '%s'";
sql = util.format(sql, Library, Table, email);

var customerDetailList = myStuff.getResultSet(sql);
var columns = myStuff.getFieldDescriptions();

I then pass these into my jade template as such:

res.render('viewCustomerDetail', {resultSet: customerDetailList,
columnList: columns});

My jade template then has some logic to replace certain headings if
required (like if they're too long). It also has logic so that certain
rows won't be shown... for example:

block content
- var dontShow = ['CDEMAIL', 'RRN', 'CDREGNET', 'CDMNTAX', 'CDDSTC']
- var replaceHeadings = {CDCREQ: 'Requested', CDDAYS: 'Days'}

each fieldValue, fieldKey in resultSet[0]
if (dontShow.indexOf(fieldKey) < 0)
th.small1(align="left")
if (!replaceHeadings[fieldKey])
=columnList[fieldKey]
else
=replaceHeadings[fieldKey]

This works really slick and is moving all the display logic to the
template. But, is this considered ok or is it better to do this type of
logic in the node.js? Manipulate the returned lists, replace headings,
remove columns if we don't want to display them, etc.

Doing things this way I find my templates are generic for lists. I just
need to update the dontShow and replaceHeadings objects for each specific
page. I understand I can limit the columns display using the SQL statement
but right now this is how I am doing things while playing around.

It also means I can update my display without needing to stop and restart
my server (very nice!). If I needed to remove or add a column and use the
SQL statement to select the columns I'd need to update the node route and
restart the server.

Just throwing out some ideas... thanks!

Brad
www.bvstools.com

As an Amazon Associate we earn from qualifying purchases.

This thread ...

Follow-Ups:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.