Tag Archives: HTML

Instant HTML/CSS Updating

Want instant updating to HTML / CSS pages you’re editing?

See it in action

You can now have it. I’ve tried it on both IntelliJ IDEA and WebStorm successfully. It should most likely work on our other IDE’s too (PhpStorm, PyCharm).

To install:

1. Download Web Browser Connector plugin for JetBrains plugin repo. This is needed for the actual Instant HTML editing plugin.

2. Download Instant HTML editing plugin.

3. Open up WebStorm (or IDEA) and click on Preferences. Search for ‘plugin’

4. Install the plugins previously downloaded from disk. First install the Web Browser Connector*

5. Restart WebStorm (or IntelliJ)

6. Open up your Web Project. Under the Run menu select Instant HTML editing

7. Launch Chrome**. If all has gone well you should now see this below the URL bar

As you make changes (to both HTML and CSS) you should now be able to see them updating live in Chrome.

It’s still early days of the plugin so there might be quirks with it, but I’m sure Vladmir will appreciate any and all feedback.

* You could in principle just install this directly from WebStorm by clicking on Browse Repositories without having to download. However for some reason, Web Browser Connector is not listed.

** Currently only works in Chrome.

Generating Graphs for YouTrack with HTML 5 and jQuery

A few days ago, a customer of ours asked me if it would be possible to visualize statistics in graphs in our Bug Tracker YouTrack. Answer is Yes. Since YouTrack offers a “ReSTful” API, you can obtain pretty much any kind of information you want from it and once you have this information, you can then display it however you wish, be it a table or a graph.

Let’s see how.

What we’ll be using…

One of the great benefits of jQuery is the rich ecosystem it offers. There’s a plug-in for pretty much everything you need, even for displaying graphs. In fact there are quite a few. We’ll be using jQuery Visualize. We’ll also be using jQuery (I’m using 1.4.4 but should work with older version) and jQueryUI, which is needed by jQuery Visualize. Finally we’ll also need jQuery Templates (I’ll explain why later on).

Don’t worry about downloading each individual file. Everything you’ll need is included in the demo code attached to this post.

Getting the information from YouTrack

For this demo, what we want to do is create a chart containing Issue counts for different projects. In particular, we are interested in Open, Fixed and Duplicate issues for ReSharper, dotCover and dotTrace:

image

In order to get this information from YouTrack we have to make a request to count the number of issues based on filters, i.e  ReSharper + Open, ReSharper + Fixed, etc.*. The URL for this would be:

http://youtrack.host.com/rest/issue/count?filter=project:ReSharper%20state:Fixed

which is nothing other than a URL encoded version of a search expression we can enter directly into YouTrack’s web interface,but to the rest API. We therefore need to send requests from our web page to YouTrack to obtain this information. The way we can do this is with Ajax and JSONP which YouTrack supports. Using jQuery.ajax, our code would look like this:

image

Problem is, this wouldn’t work, or at least, not always. When requesting a count of issues by YouTrack, the response is not immediate. YouTrack will free the request and will spin off to calculate the count. Once it’s complete it will then store the information in the cache. Next time a request is made, the value from the cache will be returned. What this means to us is that if we fire off a request, if it’s a cache miss, then we will get back a –1 instead of the actual count. We would therefore need to send a new request, until we get a value greater or equal to 0. This is not complicated to do with JavaScript and in particular with jQuery. It merely consists of polling for a result. But like all things jQuery, before you re-invent the wheel, check to see if there’s already a wheel and it turns to your liking, something which in this case does. This alternative to $.ajax allows us to poll servers and only process the result if a condition is met. As such, our previous code would now look like this:

 image

(the polling interval can be set for the calls. Here we’re using the default value).

In terms of requesting information from YouTrack, that’s all there is to it. What we need to do now is repeat the process for each project and status type and store the value.

[* Currently YouTrack does not support grouping so multiple requests will have to be made. This feature is planned however]

Representing the information as a table using jQuery Templates

We want to do two things with the results, represent them as an HTML table and display them as a graph. The data retrieved from the server is given to us as an array of objects (something we did in the code ourselves), where each object has a one property indicating the Project and three additional properties with the values of each status:

image 

We would now need to iterate through this array and generate a table from it. Instead of doing this in an ugly way by mixing tags with data, we can take advantage of jQuery templates (if you are not familiar with templates, you can think of them as a view engine for jQuery). What we do is define a template and then make a call to a function that replaces placeholders with our data. If the data we provide this function is an array, it will repeat it for each entry.

image

The code first creates the template for the markup we want to generate, which are rows of a table. It then calls the template function to create a compiled version of the template which will then be passed in to the tmpl function along with the data (the series variable). The call to appendTo is a jQuery method which adds the contents of the object it’s called on to the item passed in to the selector (in this case #rows). 

In the body section of our page, we can then define the rest of the table, which includes the header and the tag for the table body:

image

Creating the Graph

So far we have retrieved the information from YouTrack and created an HTML table to display it. Our main objective however was to also display this information graphically. That in fact is the easiest part. One reason we are using jQuery Visualize is because it can easily convert a table into a graph (it supports different types of graphs, including lines, pies, etc.). All we need to do is call visualize on a table.

image

That’s all there is to it. Once we put all the pieces together, we will end up with the following page:

image

This chart works in all browsers I’ve tested (IE 9, Opera, Firefox and Chrome)

Summary

The complete code for requesting information from YouTrack and generating the Graphs is available on my GitHub Blog repository. Once you examine it, you’ll see that it’s very few lines of code, thanks to the rich ecosystem around jQuery. I’m sure it can even be improved further, since I am by far a jQuery expert and can also be made a bit more generic to allow for different statistics to be obtained without change to the source.

I’m currently working on YouTrackSharp which is a wrapper for YouTrack requests in C#. So if you’re interested in doing the same thing from C#, you will soon be able to do.

As always, if you have any questions please leave a comment.

Enjoy!

It’s not about a specific technology dying…

Déjà Vu

History repeats itself, over and over again. ASP.NET MVC came out. WebForms was dead. Entity Framework came out, Linq2Sql was dead. Now the same thing is happening with Silverlight*.

Of course, every time this happens, we’ll immediately see reactions from those that have very high interests vested into the technology. It would be silly to think otherwise. If I’m a company or individual that has been promoting a technology for years, what else am I going to say?

Tomorrow some other technology will be deprecated and again we’ll see the same thing happen.

[Edited to add clarifcation] *When I talk about Silverlight in this context, I'm referring to it's use for Web Development

 

What does dead mean?

 

When it comes to technology, I think there’s an overall consensus that dead means there will be little to no significant improvements in the technology. This means there will probably be only a few more bug fixes coming out and some minor feature here and there.

Taking this into account, what does dead mean to you?

Need the competitive edge: Building software that your business relies on to be competitive? Technology can play an important part in this.

Need to hire people: People hear about a technology dying, there’s less incentive in learning it. This means less offers on the market. Harder to find people.

Need training: Less demand. Less offers for training.

Need to find a new job: Less demand for a dying technology.

 

It’s all a chain reaction. But every cloud has a silver lining, The market now becomes a niche. Do you know how well some Delphi and Cobol consultants are paid? If all you care about is the money, this could be a good thing too. This also doesn't necessarily imply that you need to stop what you're doing or port applications to the *next best thing*. Evaluate the situation. What are you advantages/disadvantages?

 

Lessons to learn…

We’re in a profession where things move fast. Technologies, languages, frameworks come and go. If you’ve been around long enough, you’ll soon realize that it doesn’t matter what language, framework or technology you use, everything has it’s place and time.

Lessons to learn here:

- Don’t jump on board the next hype immediately, no matter who tells you it’s great. Nowadays people get fired even if they pick IBM.

- Don’t limit yourself to learning just one technology or putting all your eggs in one basket. Whether you’re a consultant, trainer or a developer or company writing software, it’s too risky.

- Don’t blindly follow.Open up your mind.

 

And remember, it will happen again.

WTF you got against Silverlight?!

Nothing.

Friend of mine, and Silverlight MVP, asks me why I’ve become The Anti-Silverlight. I’m actually not on a crusade to bash Silverlight. My “issue” per se is not so much the technology but how it’s being sold.

Despite the recent outburst of Global amnesia, some of us recall how Silverlight, which originated from WPF/E, a subset of WPF, was about bringing rich user interfaces to the web. It was about, and I quote “lighting up the web”. Rich User Interface? Silverlight. Vivid user experiences? Silverlight. Video? Silverlight. And might I add, there was a lot of emphasis placed on video…

Of course, fast-forward to today, and things haven’t gone so much according to plan. And with recent changes, it looks less promising.

Now, some of us that have been doing web development for some time, and have suffered the pains of cross-browser compatibility, JavaScript (the copy/paste snippet joke language), CSS (the “crap, I moved a DIV and all hell’s broken loose” language), have also seen the advances in these fields. Not to sound repetitive, but jQuery for example has not not only made JavaScript fun, but opened our eyes in seeing how powerful this so called “joke” language actually is. CSS has become easy. I actually really dug into CSS after learning jQuery and realized how stupid I was to ignore it for so long.

Frameworks such as ASP.NET MVC (for context, I’m sticking to .NET), MonoRail and others are proving that the whole abstraction that WebForms provided didn’t work that well, and have made web development in .NET more productive, maintainable, testable, and consequently fun. 

There are many web sites now being developed using nothing more than HTML4, JavaScript and CSS and being done so very productively, and providing a very rich user experience. We have applications that work “offline”. We have applications that are keyboard centric. Cross-platform? If by platform we mean not only browsers but operating systems, yep, we have that too! Easy deployment? Yes sir! That one is actually inherent to the whole “web thingy”.

So we’ve managed to successfully create Consumer and Line of Business Applications. And now, with HTML5 coming, we’re also going to get video and more!

Yet despite all this, recent posts about what Silverlight is most suited for, are selling these same points as benefits of Silverlight, as if somehow implying that none of this can be accomplished with existing technology.

Some say “Sure, I can also program in Assembly and not use C#”, to which I reply "Open your eyes". Using HTML, jQuery and CSS is by no means less productive or harder to do than learning XAML, MVVM and asynchronous programming.

Now, having said that, if you prefer Silverlight, whether or not you’ve even tried alternatives, that’s great. I have absolutely no issue with people choosing to use Silverlight or any other technology for that matter. What I don’t agree with however is promoting technologies in the wrong way.

Of course, some now say that Silverlight was never about taking over the web, or lighting it up for that matter. It has always been about Windows Phone and Desktop applications. Wait?! Wasn’t this a subset of WPF?