|
Just my opinion of course, although you will find articles supporting--
the argument, you are better off doing this sort of thing on the
client. Let's say you have a result set that you have obtained
asynchronously on the server, but you want to manipulate/sort it
further before it's useful, then let the client do it. If you get into
the habit of doing it in your server side node.js code you are
effectively blocking the event loop. You may not notice with a handful
of clients attached, but ramp that up a notch or two and you soon have
client requests waiting to be serviced for no good reason. Your server
side code should be optimised to get that response back asap, so if
you must do it server-side you need to hand it off to a child process to do it asynchronously.
Sent from my iPad
On 12 Apr 2016, at 01:15, Bradley Stone <bvstone@xxxxxxxxx> wrote:importantly,
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
where.statement
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
but right now this is how I am doing things while playing around.the
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
SQL statement to select the columns I'd need to update the nodelist
route and restart the server.
Just throwing out some ideas... thanks!
Brad
www.bvstools.com
--
This is the Web Enabling the IBM i (AS/400 and iSeries) (WEB400)
mailing
To post a message email: WEB400@xxxxxxxxxxxx To subscribe,
unsubscribe, or change list options,
visit: http://lists.midrange.com/mailman/listinfo/web400
or email: WEB400-request@xxxxxxxxxxxx Before posting, please take a
moment to review the archives at http://archive.midrange.com/web400.
___________________________________________
This email has been scanned by iomartcloud.
http://www.iomartcloud.com/
________________________________
NOTICE: The information in this electronic mail transmission is
intended by CoralTree Systems Ltd for the use of the named individuals
or entity to which it is directed and may contain information that is
privileged or otherwise confidential. If you have received this
electronic mail transmission in error, please delete it from your
system without copying or forwarding it, and notify the sender of the
error by reply email or by telephone, so that the sender's address records can be corrected.
----------------------------------------------------------------------
----------
CoralTree Systems Limited
25 Barnes Wallis Road
Segensworth East, Fareham
PO15 5TT
Company Registration Number 5021022.
Registered Office:
12-14 Carlton Place
Southampton, UK
SO15 2EA
VAT Registration Number 834 1020 74.
--
This is the Web Enabling the IBM i (AS/400 and iSeries) (WEB400)
mailing list To post a message email: WEB400@xxxxxxxxxxxx To
subscribe, unsubscribe, or change list options,
visit: http://lists.midrange.com/mailman/listinfo/web400
or email: WEB400-request@xxxxxxxxxxxx
Before posting, please take a moment to review the archives at
http://archive.midrange.com/web400.
As an Amazon Associate we earn from qualifying purchases.
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.