Latest Entries »

Ever have those days that just seem to be working against you? Yeah, today was that day for me. Ultimately though, I was the victor (at least in this instance) against my Javascript model that said NO NO NO, I kept trying and succeeded where I wondered if I should even continue trying or move a separate way.

After a bit of playing I figured it out… essentially, when binding to a select list, you have two forms of output that can be obtained… an output of an individual property on your model, or the complete model itself. Below is my example and the solution I found, for those of you looking to do a similar thing.

 http://jsfiddle.net/eEGxV/36/

That’s one thing I love about KO, always a way to make my job easier (once i figure it out! lol)
Anyways, in this example, I have an item that contains 3 properties (obviously there can be more), but only a single one is bound to the "text" attribute via "optionsText"… if you don’t specify a property to be returned for a value,( e.g. I could have made id, or quantityAvail the return type here), but this limits the return value to a single parameter. If you do not specify the optionsValue attribute for your select, it returns the entire object, meaning, you get everything.
Ultimately it depends what you are trying to accomplish, but I found this method very helpful for my complex and I figured I would share!

-Haddy
Keep Moving Forward

Advertisements

So, I took some time today to ponder ways of allowing TBody elements to be scrollable, and came up with a solution in jQuery, that is compatible with pretty much any browser that supports jQuery. One of the biggest desires for DOM developers using tables, is to have a scrollable tbody, to allow table headers to be visible no matter where in the table you scroll to…

The idea I had was, getting widths of columns, saving this data into an array, and then passing back this data as css widths onload and then moving the header row to a separate table.

After some messing around, I was able to come up with a solution to the issue, and am proud to offer a working example!

http://jsfiddle.net/pe295/

Although it does add an additional table to the page, at the end of the day, I’m okay with a greater interaction for the user, over a few lines of code…

So, I’ve been working on a new multi-tier cloud project for a while, and ran into a major issue regarding date/times, specific to a time-sensitive date/time that must be configurable in different timezones, for a specific timezone. Of course, this is a very specific scenario, but the fact is, managing date/times on the client side can be a real pain in the… knees? I mean truly, if you can’t walk that sucks, almost as bad as not being able to sit.

One big thing to note here… this is not a matter of converting UTC time to local time, that is actually very easy to do.

Anyways, There’s a lot to deal with when you are working with the Date object in Javascript, not only are dates returned arbitrarily from JSon as a crazily formatted digit, but next, browsers start to mess with the display of dates. There’s also a lot of questions that can come up during this timeframe…

  • How should I store the dates?
  • How do I convert the dates?
  • Do I convert the dates back before reaching the client?
  • If I do convert dates back, and the browser changes it further, then I have to write a library to change it back….
  • Do I need to make the dates into a string and parse it manually?
  • What do I want for lunch?
  • What is the real meaning of life?

I went through a painstaking process of first determining where the date/time changes were coming from (SQL=> WCF),(WCF=>WebClient),(WebClient=>Json), (Json=>localclient)… and it turns out, this happens when the date/time is being rendered to the client. I won’t go into all the different tests/steps and frameworks I tried to use for fixing the issue, but I will go into how I fixed the issue and how to deploy such a solution in MVC.

First, you have get timezone data that you would like to use, and create a action method (more on this later) for returning this data… this timezone data is available for free here: http://www.iana.org/time-zones, you will want to select “Time Zone Data” not “Time Zone Code”… this will contain timezone data for areas in the world.

Next you want to pick up two different JavaScript libraries, TimezoneJS and jsTimezoneDetect which will help determine and convert the local timezone into the timezone of your target (mine specifically is PST).

public ActionResult GetTz(string id)
        {
            string file = Server.MapPath("~/Content/tz/" + id);
            if (System.IO.File.Exists(file))
                return File(file, "application/java-archive");
            else
                return RedirectToAction("Index2");

        }

Now, as far as DT storage on the server side… for cloud/major internet apps, UTC is the way to go, but if you have a specific timezone you need to target, this will create issues when creating, updating and displaying these dates through javascript/json async post-backs. So in my case, the user is entering dates in a PST format (the start and end time of a specific item), which is then saved in a UTC format using .NET:

TimeZoneInfo.ConvertTimeToUtc(newItem.StartDate, TimeZoneInfo.FindSystemTimeZoneById("Pacific Standard Time"))

Now that the DT is stored in a UTC format, you can return the DT to the client unchanged, in UTC format and the libraries will do the rest…. kind-of… there’s still some configuration needed if you are deploying a solution similar to mine, where I’m loading the data on pageload, that needs the DT’s formatted. First we determine which timezone the person loading the browser is, and saving this into a variable to be used later:

var timezone = jstz.determine();

Next, we write an MVC method that allows us to utilize the library(s) you downloaded earlier for timezone data, and returns this data to the client.

 

Note, I placed the files that were returned from the library into a /tz folder in the Content directory, and set all files that would need to be transferred on publish, Build Action = “Content”, so when you deploy the MVC project, it will deploy these files as well.

Now that we have our files, and a method to retrieve them, we can move ahead and get our timezones… We need to set our zoneFileBasePath:

timezoneJS.timezone.zoneFileBasePath = '/YourController/GetTz';

Setting async here is important if you are loading data that requires the formatting initially. within the brackets we write all our JS to work with the timezone data… to get the date from a json return properly, we will now create a new date using the timezoneJS library, set it to the current timezone name, and then change the timezone. This converts from UTC to local, and then local to another timezone:

var dt = new timezoneJS.Date(parseInt(jsonDate.substr(6), timezone.name()));
dt.setTimezone('America/Los_Angeles');

 

The idea is to make sure that all admins who configure something (that needs to be PST), no matter where they login, they will see accurate PST DT’s.

There’s a lot more to these libraries than I’ve included above, but wanted to share the joy that is, having DT’s to serve up specific timezone data globally through the cloud.

*DT = DateTime

I’ve seen many posts online regarding this issue, and there are many suggestions offered. From increasing the default limit size, to ensuring your properly disposing these documents. Fortunately, there’s a quick fix for this issue, that will allow you to get up and running immediately, which is recycling the App Pool for your application. Your app pool maintains the temporary document space for these documents, and if there is a memory management issue, it will be here.

This was the best case scenario for getting Crystal working immediately on my end, and I will probably deploy an update to an app in requirements of this document format to ensure proper document disposal. I don’t see a huge necessity in doing so, since the application has been in full swing for over a year, and has only ran into this error once, but it’s always best to write for all case scenarios.

I ran into this error today when I added some transformations to my web.config to allow for different versions of the config to exist (I’m using one for different nodes on Azure, and local debugging). The problem is, after I did this and redeployed, I received the above error.

Turns out, it has to do with a processor setting that gets populated when adding transformations, and is easily fixed. You’ll need to go into the project file for each of your webroles, edit it with a text editor, and remove all platformtarget entries.

Easiest way to do this is to do a replace the following: “<PlatformTarget>AnyCPU</PlatformTarget>” with nothing. I ended up having to remove four total. Once I redeployed after this change, the project worked appropriately

Recently I needed to add a datacontract to a service of mine, that didn’t have a method associated. It seemed pretty straight forward, but ended up being very simple, but I could find little to no documentation about adding an additional data contract with no dependencies. Why would you want to do this? Well, I was in need for sharing the logical structure of the object down to code that would end up pushing out xml objects in the required format for my wcf service.

Seems you cannot just add a datacontract, you actually have to have some method that utilizes the datacontract for your wcf service to see it as a required dependency, and therefore include it at runtime. I went ahead and just created a simple method that would return a list of the specified type, and presto, we have a datacontract.

It seems there’s quite a few people who’ve run into a similar situation, but I couldn’t find much information regarding this in all the threads I searched, so I figured I’d share it here.

More recently, I’ve been writing a lot of client side code for some interfaces on a new platform I’ve been designing. I have discovered a new toolkit that allows data binding of elements and providing a more rich user interaction through observable objects. One issue I ran into was the ability to to bind element id’s on a foreach loop of data elements. I looked around and didn’t see much about the issue, but thought others may run into the desire to add this element data to lists as well.

After you data-bind your particular array of items, or whatever element you want to use, the easiest way to get this data onto your DOM is to use the attr selector within your internal data.

For example:

   1: <tbody data-bind="foreach: items">

   2:             <tr data-bind="attr: {id: ItemId}" >

   3:                 <!-- item template goes here -->

   4:             </tr>

   5:         </tbody>

 

As you can see, through this binding attribute, you can bind almost any element to values within the DOM, which can be very helpful in the development process of advanced client interfaces.

I’ve been working with JSon services quite a bit these days, and one of the big issues with JSon to Javascript translation is the Date element from server side. Since JSon doesn’t return a valid Javascript date object (which in my mind, was a very poor design at the implementation of the JSon form factor), it is up to the developer to make this happen. I have written a simple Javascript function that translates from the JSon format to a user-friendly format here:

 

Code Snippet
  1. function formatDate(dateToFormat){
  2.     var d = new Date(parseInt(dateToFormat.substr(6)));
  3.     var day = d.getDay();
  4.     var m = d.getMonth() + 1;
  5.     var month = (m < 10) ? '0' + m : m;
  6.     var yy = d.getYear();
  7.     var year = (yy < 1000) ? yy + 1900 : yy;
  8.     var hour = d.getHours();
  9.     var min = d.getMinutes();
  10.  
  11.     return (day + "/" + month + "/" + year + " " + hour + ":" + min);
  12. }

 

Javascript usage is as follows:

formatDate(JsonReturnedDate);

 

This function can be modified to fulfill pretty much any date requirement you have, and can also just return a dynamic JS Date object if you would like.

Recently, when I was working on a project that contained a WCF service that I was having problems with. i deleted the service, but forgot the delete the reference to the service within my web.config file. Funny thing though, Visual Studio will let this compile (if you have two independent references to the same service, for configuration) The thing is, though, when you try to consume the service, you will come upon errors included the that of which you can see at the top of this article.

The solution to this was easy, just delete the old reference, and ensure there is only a single reference to the service in question. A simple solution to a problem that could have easily been avoided when I replaced my service.

Just something to watch out for, if you come upon it, you may want to check your service declarations within your web.config and make sure you’re declaring the reference, only once.

I am working on troubleshooting an aspect of one program, and had a situation where I wanted to remove all text in between parenthesis (from an output block), and leave the text within the parenthesis intact, and each on it’s own line. Obviously, this can be done manually, but I had a ton of records, and prefer finding find/replace solutions for situations like this. I ended up creating a wildcard: \)*\(*\(

The replace keyword I used was ^p, which inserts a new line in place of the text it replaces.

The first and last record must be manually removed, but this did the majority of the work for me, and I’m happy. I don’t claim to be a regular expression expert in any way, so I’m sure there may be a better way about this, but I figured I would share anyways.