Showing posts with label javascript. Show all posts
Showing posts with label javascript. Show all posts

Wednesday, October 17, 2012

Trello Bugzilla Integration

Here is a GreaseMonkey script that provides simplistic integration of Bugzilla into Trello.com.


So far it supports:
  • Decorating cards that have 'Bug \d+' in their card title with a badge that is a hyper link to Bugzilla.

  • Auto-completion of new card titles starting with 'Bug \d+' 

The script also works in Chrome with the Tampermonkey extension installed.

You can get the code on GitHub


// ==UserScript==
// @name Trello Bugzilla Integration
// @namespace http://www.navicon.dk/
// @version 0.1
// @require http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js
// @description Looks for card titles with 'Bug \d+' and adds badge/links to bugzilla. Also autocompletes new card titles that starts with 'Bug \d+' from bugzilla. Autocomplete is actived when pressing spacebar after 'Bug \d+'.
// @match https://trello.com/board/*
// @copyright 2012+, Carsten Madsen
// ==/UserScript==

// grey bugz icon
var bugzillaImg = '';

// edit me to point somewhere else
var bugzillaLink = 'http://bugzilla.mozilla.com/show_bug.cgi?id=';

var addBugzillaBadge = function() {
    $(".list-card-title").each(function(i,val){
    if ($(this).html().match(/Bug \d+/)) {
        var regExpMatch = $(this).html().match(/Bug (\d+)/);
        if ($(this).parent().find(".bugz").length < 1){
        $(this).parent().children('.badges').append(''+bugzillaImg+'');}
    }
    });
};

// intercept spacebar press when creating new cards and look in
// bugzilla to do possible autocomplete

unsafeWindow.$("body").delegate(".js-card-title", "keypress", function(e){
    var code = (e.keyCode ? e.keyCode : e.which);
    if(code == 32) { //Space keycode
    var text = $(this).val();
    var regExpMatch = text.match(/Bug (\d+)/);
    var textarea = $(this);
    if (regExpMatch) {
        // see http://stackoverflow.com/questions/11007605/gm-xmlhttprequest-why-is-it-never-firing-the-onload-in-firefox
        setTimeout(function() {GM_xmlhttpRequest({
        method: "GET",
        url: bugzillaLink+regExpMatch[1],
        onload: function(response) {
            var jq = $(response.responseText);
            textarea.val(jq.find(".bz_alias_short_desc_container b").text().replace(String.fromCharCode(160)," ")+ " - " + jq.find("#short_desc_nonedit_display").text());
        }
        })}, 0);
    }   
    }
});

setInterval(addBugzillaBadge, 5000);

Wednesday, August 3, 2011

CouchBoard - Porting a ROR/JQuery application to CouchDB/JQuery


Looking for a replacement for our small company Scrummy taskboard I stumbled over CognifidesLabs Taskboard Ruby On Rails (ROR) application. It looked useful but it seemed stale and being a complete ROR imbecile and a JavaScript novice I initially gave up as the entry threshold just seemed to big.




But after fooling around with CouchDB in another context I realized that maybe I could scrap the entire ROR backend as the data exchange format was JSON and just port the http requests to the ROR backend to CouchDB JavaScript.

At first this seemed as a daunting task as most tutorials etc. for doing CouchDB application development uses couchapp so even a simple task as figuring out how to port the login logic was hard. Eventually I found couchdb-login-jquery and from there on the porting job was as easy a calling the CouchDB JavaScript CRUD functions.

The ROR back end is approximately 1700 lines of Ruby code this was exchanged for an additional 200 lines of JavaScript. For somebody used to setting up Eclipse, Maven, Tomcat, Spring, Spring Security, PostgreSQL just to get started it seems unreal to just use a text editor, reupholster and Firefox/Firebug for the entire developmet process.

On top of this all that is needed to host the application is a free account at cloudant where you get a scalable, fault-tolerant, distributed database to host your applications in.

In summary porting the ROR backend to pure CouchDB/JavaScript was surprisingly easy. The most diffuclt part was acctual to understand the CouchDB security model and then learn that the cloudant (BigCouch) model was incompatible.

In case you need a small and simple to manage scrum/kanban board you can get the code from here and you can test the application here

Live Traffic Map