Archive for the ‘Cube Life’ Category

Adding Polish and the First Production Deployment

Monday, April 27th, 2009

WebDevel.jpg

Well... it's been another great day. I added a lot of polish to the second web page of the site, and now it can plot normalized greeks - normalized by the thresholds for the selected Portfolio. It makes them all out of 100, assuming they don't breach the thresholds. It was a nice little addition and I know they are really going to like it.

Also, the support crew finally got the production box working, and it's running just fine. Great news, because now I can update Test to include all the additions I've made to the system - the new JavaScript drop-down menus, the ability to link to the base data I'm displaying, and of course, help and how to contact us. It's going to be great.

Then I'll tag it and write up some release notes so that they can keep track of things the way they normally want to. It's all very fair, I just didn't know I needed these things, so this first release was a little 'sketchy'. The next one will be better.

So a good day, and lots of good style improvements on the pages. It's looking like a real site now. Can't wait to do the next page.

JavaScript Drop-Down Menus – Free and Commercial

Sunday, April 26th, 2009

WebDevel.jpg

Today I was spending a little time looking for a simple, yet easy-to-use JavaScript drop-down menu code for my web app at work. I have a feeling that I'm going to need it with the number of pages we'll be writing, it's going to make sense to have something like we had back at my previous job. Actually, I want something a lot nicer than we had back there, so I started digging now.

What I found was a lot of JavaScript menu systems for sale. Now I can see the value of commercial software - I just didn't expect it to be this menu. One of the nicer free solutions was this guy I found. It's simple, seems to work just fine, and I should be able to make it work for what I need.

However, there are limitations. First, there's no multiple level menus. Second, the menu structure has to include a bit of JavaScript in it - not horrible, but not as clean as simple UL and LI list items. That's where this commercial offering really makes a difference.

This one takes nothing more than UL and LI lists, embedded within each other, and a few class tags, and builds a very nice menu. Very nice indeed. Different themes as well as different animation techniques makes it a very nice menu.

But it's $200. Not exactly inexpensive when all I really need will be served by the free alternative. I'm going to have to run this by the purchasing folks and see if they'll swing for it. If they do, that would be great. But I can certainly see their point if they say no. After all... the free alternative is fine for what we need.

We'll see what they say on Monday.

Interesting Issue with eval() and JavaScript JSON

Thursday, April 23rd, 2009

SquirrelFish.jpg

I was enhancing my web app today based on a request that someone voiced about making it easier to have a user see everything all the time. Face it, there are a good chunk of users that are in the Risk Management group that are going to need to see everything all the time. If I made a permissioning scheme based on an enumerated list, then when I added a new portfolio, I'd have to update these users. Sort of a hassle.

So the request was to have a wildcard for the portfolio list, and when a user had this, they would be able to see all portfolios regardless of how many there were. It's a good idea, I just hadn't thought of it.

But that's not the issue.

What I realized was that there were likely going to be a lot more changes to the permissioning scheme, and in that case, my semi-colon-delimited list of values was not going to do. What I needed was to be able to pass in a fully created JavaScript object and then let the page be able to interrogate it as necessary.

For example, if my validation applet was given a parameter out of json then it might return the following JSON output:

  { username: 'beatyr',
    page: 'PnLTool',
    approved: true,
    portfolios: ['Indexes', 'Nasdaq'] }

then when parsed, I should be able to say things like:

  if (!userInfo.approved) {
  }

Nice.

All this seems well and good, and I should be able to simply say:

  var userInfo = eval(xhr.responseText);

but that won't work. Why? The fact lies in the interpretation of the initial '{' in the string value. The parser in eval() thinks it's the start of a block of code, not a JSON value, so you have to force eval() to get into object evaluation mode by wrapping the JSON in '()'. Like:

  var userInfo = eval('(' + xhr.responseText + ')');

When you put this into the script, it works like a charm. Perfectly understandable from the point of eval(), but a little tricky if you forget about it.

Adding User Permissioning with AJAX

Wednesday, April 22nd, 2009

AJAX.jpg

I got a request for my web app to add in user-based permissioning. Basically, the management wanted to restrict the data any one person in the Shop might see based on their login name. Since I'd already done the user authentication with a signed Java applet, it seemed like a natural extension to add in the portfolios that the individual user could see. I simply change the JavaScript code to parse the response and then went back to the java servlet and added in the database lookup of a new column of data from the database table with the list of usernames.

I decided that it was easiest, for now, to just have a semi-colon-separated list of values, the first would be the YES or NO of the approval, and if YES, then the remainder would be the names of the allowed portfolios for this user. This was taken straight out of the database column.

Like I said, simple.

As I get more requests, I'll probably try to make it JSON and have that allow for the map-like capabilities of the basic JavaScript object. At that time, I'll move to returning JavaScript and then running eval(xhr.responseTest) in the return method. That will make it easier to extend in the future. The only wrinkle is that I'll have to assume that there's a standard variable that the response is coded to, but that's not horrible.

When I got the servlet working, and the simple parsing of the results, I then set about to allow the user to see only that portion of the data that was contained in the portfolio list I'd just parsed. This, as it turns out, was pretty easy.

The first thing I did was to get rid of the repetition in the HTML and JavaScript for all the individual portfolios. There were check boxes, checks on the data, etc. All those needed to be automated and made expandable simply. When I looked at the code, it was pretty simple. Leave all the checkboxes as-is, and create a simple JavaScript array of the names of the portfolios. Then, in the initialChecks() call, use document.getElementById() where the id was the name of the portfolio. Simple.

The tougher part was making the checkboxes disappear when the user shouldn't be able to see their data. The answer was really rather simple: make a div that surrounds the checkbox and name it "div_Portfolio". That way I can make an array of them and get their references by again using document.getElementById('div_' + portfolio). Then, I can make them invisible by:

  // get all the references of the checkboxes and enclosing divs
  var portfolioChecks = [];
  var portfolioDivs = [];
  for (var i = 0; i < portfolioNames.length; ++i) {
    portfolioChecks[i] = document.getElementById(portfolioNames[i]);
    portfolioDivs[i] = document.getElementById('div_' + portfolioNames[i]);
  }
 
  // ...get the list of the available portfolios
 
  // remove the portfolios that the user can't see
  for (var i = 0; i < portfolioNames.length; ++i) {
    if (response.indexOf(portfolioNames[i]) < 0) {
      portfolioChecks[i].checked = false;
      portfolioDivs[i].style.display = 'none';
    }
  }

with this 'turn off, then remove' code, I was able to leave the large part of the app unchanged and it just worked. I was very pleased with the way it turned out.

Now I have something that looks good for all users, and they can see only the data the management wants them to see. Lovely.

Exciting How Easy AJAX Really is to Work With

Tuesday, April 21st, 2009

WebDevel.jpg

I was working on my web app and I needed to have a simple AJAX call to a servlet to hit the back-end database and verify that the provided username was in a table of authorized users for this app. This wasn't going to be using the Google API, so I had to decide if I wanted to code it up on my own, or use one of the AJAX Frameworks. I looked at the code if I rolled it myself, and decided that it was far easier if I did it myself - considering that I did not have to support IE, so I did.

The result was amazingly simple:

  var username = document.bridgeApplet.getUsername();
  var xhr = new XMLHttpRequest();
  xhr.open("GET", "validate?" + escape(username) + "&page=PnLTool");
  xhr.onreadystatechange = function() {
    // if we're not yet done, skip doing anything
    if (xhr.readyState != 4) {
      return;
    }
    // ...otherwise, look at the response for what I need
    if (xhr.responseText != 'YES') {
      // we can't allow unauthorized access
      var tag = document.getElementById('chart_div');
      tag.innerHTML = '<br/><br/><br/><p class="header">'
            + 'Unknown User</p><br/>'
            + '<p class="reason">The user "' + username + '" is not registered '
            + 'on this application. Please contact the Risk Analytics Team '
            + 'about adding your username to the list of known users.</p>'
            + '<p class="reason">Response: ' + xhr.responseText + '</p>';
    } else {
      // this user was valid, so finish the initialization
      initialize();
    }
  }
  xhr.send(null);

in this little bit, I can issue the URL, track it's progress, and then decode the answer. It's absolutely the most elegant solution I've seen in ages. I'm getting hooked on the AJAX way of doing things and while I wasn't a big fan of servlets, I'm getting there as they are a wonderful way to get into the back-end without having an enormous overhead, and subclassing really works there. Have a nice servlet that does all the database work, and subclass a bunch of servlets off that.

I have to admit, this is changing the way I look at web site building. It's also a lot more fun than the old way.

Hotmail Access from Mail.app Finally Works

Friday, April 17th, 2009

pirate.jpg

I was a huge fan of Hotmail when it was first introduced. I loved that they started with their entire infrastructure being linux boxes - when the easy path was to choose Windows. I used it, told everyone about it, and loved the independence of it. This was years before Google was even a search engine - let alone "gmail". So the idea of a free web-based email was new. There was Yahoo, but that was limited unless you were a paid subscriber, and there was Hotmail.

Then they got bought up by Microsoft, and the slow dive began. It was clear that they wanted to show that they could build the same great service on Windows, but in the end, it was a miserable failure in the first years. I had almost given up on it. Then it started to come back. MSN IM was the first real decent thing of that old system, and then things built on that and got better. Now, it's decent, but completely overshadowed by GMail.

However, they haven't really caught up to GMail because they haven't allowed generic POP/IMAP access to the mail system. Until now, that is. Sure, there was a plugin for Mail.app that would talk to Hotmail, but that was a bit of a hit-n-miss proposition, and I never really used it because I couldn't really trust it. Now, it seems, we have complete POP capability with SSL encryption to Hotmail.

This hint really goes through most of it, but the big points are these:

  • set up a POP source in Mail.app
  • the POP3 Server is: pop3.live.com
  • the SMTP Server is: smtp.live.com
  • your 'Username:' is the complete Hotmail address: you@hotmail.com

When you're done setting it up, Mail.app will recognize that this server allows SSL (excellent!) and it'll be ready to go. Very nice to not have to have Firefox up and running to see emails from Hotmail anymore.

Making Good Progress, but Slowing for Others

Tuesday, April 7th, 2009

cubeLifeView.gif

Today was a good day for my little project. I have been waiting for a few folks to do somethings for me - get data back to me, set up servers, install a little software - nothing that they can't do, but stuff that normally just takes time. It's a little frustrating, but that's just the way it is working with folks. Gotta take time for these things.

I will say that I'm glad to be working with a good QA Team. These folks are actually doing tests on my stuff that I hadn't thought of. Memory profiling as a function of time is a great little thing because my Google AnnotatedTimeLine is not very memory efficient and can crash IE 6 and 7 if you have it up for a while, and while Firefox 3 works, it's the exception on Windows. But these folks are willing (and interested) in doing the tests to make sure that it's reasonably stable. That's great news.

So today was time to put in new features and get things cleaned up while I wait.

Adding Polish to My Web App

Thursday, April 2nd, 2009

WebDevel.jpg

I have to admit that the process of adding polish to an AJAX web app is a lot like a regular app. Getting users to hammer on it - including yourself, and working to see what you can do to make it better, cleaner, smoother. The goal should be to have it work exactly like the user thinks it should act. Face it, it's a web page with a few widgets on it - it shouldn't require a manual to operate. If it does, then there are big problems.

So today I did a lot of little things - a few to the back-end, and a bunch to the front-end.

Probably one of the biggest things was the addition of the 'resolution' of the display. Face it, there may not bee the need to show all the data points, but maybe so. What I added was a very simple way of compressing the data (averaging points) so that the data looks 'smoother', but retains a lot of the shape of the original curve. It's going to make it more useful as it's footprint on the client will be smaller, and therefore faster to deal with on older machines.

It looks nice.

Holy Smoke! Building Web Sites is Fun Again!

Tuesday, March 31st, 2009

WebDevel.jpg

I've been fine-tuning my webapp this morning, and I have to say that it's a ton more fun to use servlets on the back-end and HTML and Javascript on the front, typical AJAX, than the other schemes I've used. Probably the second best is the Tapestry framework, and there's no reason you can't use AJAX on Tapestry, but the HTML in Tapestry is still going to have to be generated by the server, so it's not as lightweight as the system I'm using, but it's still not bad.

No, I have to say that this is a wonderful little way to put pages together. Certainly, a lot of the credit goes to Google's Visualization API. Without the widgets and the data standard, it would have been possible, but not nearly as powerful and therefore - fun.

Yeah, I think I'm going to have to do a lot more of this and see where it goes. Fun.

Awesome Day – Loads Accomplished

Monday, March 30th, 2009

cubeLifeView.gif

Today I leave feeling like I've really gotten the webapp into a good place. It's not all done, that's for sure, and I want to fix a lot of things, but it's working. It's got all the features it was supposed to have in it's first cut, and it's ready to show to the users.

It's nice to have a really great day. Get a lot done. Feel like you're a contributing part of the team. It's nice. While today isn't the first time this has happened, it's always nice to have it happen as often as possible.

The app is really close. I can see how it'll finally look.