Aimless noise and insights into my little world

Monday, July 13, 2009

New CouchApp feature

Since playing with CouchApp I noticed a missing feature and provided a patch. It allows you to upload a set of documents associated with your aplication, e.g. demo docs, configuration files etc. You can try it out here (I'm not sure how all the cool kids share code on github...)

Saturday, July 11, 2009

Writing kanbancouch

First up I installed the couchapp program. I'd installed it a few months back but had since upgraded my default python to 2.6. Install is nice and easy:

sudo easy_install couchapp


(I already had CouchDB 090 installed and running as CouchDBX)
I then generated and initialised the kanbancouch application:

metson$ couchapp generate kanbancouch
[INFO] Generating a new CouchApp in /Users/metson/workspace/KanbanCouch/src/kanbancouch
metson$ couchapp init --db=http://localhost:5984/kanbancouch
[INFO] Initializing a new CouchApp in .


So far so good. I then did a test push, and low the app appears in Futon.

metson$ couchapp push
[INFO] Pushing CouchApp in /Users/metson/workspace/KanbanCouch/src to design doc:
http://localhost:5984/kanbancouch/_design/src


Which hasn't worked. I realised this is because I was pushing the parent directory (src) and not the kanbancouch application. Moving the .couchapprc file into kanbancouch and running push from inside there worked fine:

metson$ couchapp push
[INFO] Pushing CouchApp in /Users/metson/workspace/KanbanCouch/src/kanbancouch to design doc:
http://localhost:5984/kanbancouch/_design/kanbancouch
[INFO] Visit your CouchApp here:
http://localhost:5984/kanbancouch/_design/kanbancouch/index.html


Lesson 1: push from the right directory!


Next I pulled in the Simple Kanban empty html file and used this as the index.html for the application. Pushing this up to the server gives me the Simple Kanban interface but being served from my CouchDB instance - nice!

metson$ cd _attachments/
metson$ wget http://www.simple-kanban.com/download/Simple_Kanban_App_1.0RC1_Empty.html
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 73011 100 73011 0 0 95224 0 --:--:-- --:--:-- --:--:-- 130k
metson$ ls
Simple_Kanban_App_1.0RC1_Empty.html index.html style
metson$ mv index.html placeholder.html
metson$ mv Simple_Kanban_App_1.0RC1_Empty.html index.html
metson$ cd ..
metson$ couchapp push
[INFO] Pushing CouchApp in /Users/metson/workspace/KanbanCouch/src/kanbancouch to design doc:
http://localhost:5984/kanbancouch/_design/kanbancouch
[INFO] Visit your CouchApp here:
http://localhost:5984/kanbancouch/_design/kanbancouch/index.html


Next I needed to decide on how to store data, and what their associated views would be. I figured I'd have two types of document:


Stories

The Kanban "story" that represented some work you needed to do

States

The different states a story could be in



The state documents would be simple, just their name and shortcut identifier. There would be one view which would list all the state documents.


{
"_id": "d5164b50205561f45f9b4dbb7b69607b",
"_rev": "2-1724121541",
"state_shortcut": "D",
"state_name": "Design"
"state_position": 0
}


This made me think it'd be kind of neat to be able to push data up into the CouchApp. Looking through the code quickly I think that's not possible - feature request/patch for the future...

So I have a bunch of states, now I need a view to spit out the states, sorted by their position, in a format ready for the kanban script to consume. And here it is:


function(doc) {
if (doc.state_name){
emit(doc.state_position, doc.state_shortcut + ',' + doc.state_name);
}
}


This goes in a file called views/states/map.js. Pushing that to the server I can now see the json data from the resulting view. (This was sort of non-obvious from the docs/examples - I think something has changed in CouchApp that's not been reflected elsewhere, though I did see mention of it in one GitHub commit)

Next I'm going to need a few example stories and associated views. The stories need to have a syntax appropriate to the Simple Kanban code:

There are three columns for stories. The first column contains the state the story is in, the second contains an identifier for your story and the last column the name of the story. You can edit the columns, change states, change names, remove and add stories.


The state will be the state_shortcut and the story id will be the document id (I'm in two minds about whether to let couchdb auto-generate this or allow it to be a user filled field, if couch generates it then I'll need to shorten it in the view). I thought I'd go a bit further than this and add a tag to a story and associated tag cloud. So a story document looks like:


{
"_id": "work123",
"_rev": "2-3372157482",
"story_state": "D",
"story_tags": [
"kanban",
"couchapp",
"blog"
],
"story_name": "kanbancouch",
"story_description": "A port of the Simple Kanban web page to a CouchApp, and associated blog post"
}


Now I need a view to generate the data for the stories and another one for the tag cloud.

Stories data (views/story-data/map.js):
function(doc) {
if (doc.story_state){
emit(null, doc.story_state + ',' + doc._id + ',' + doc.story_name);
}
}


Tag cloud map (views/story-tags/map.js):
function(doc) {
if (doc.story_tags){
for (t in doc.story_tags){
emit(doc.story_tags[t], 1);
}
}
};


Tag cloud reduce (views/story-tags/reduce.js):
function(keys, values, rereduce) {
return sum(values);
};


So that's all the CouchDB internals done. Now I need to hook it into the Simple Kanban code.

"References"


Pages I read while writing this
  • Couchdb and Couchapp
  • CouchDB Relax
  • Thursday, February 26, 2009

    Good Week At FNAL

    It's been a good week at FNAL, I think we've got a lot done despite some bad news re effort available for our group. Got some cool t shirts too.



    FNAL at sunset, originally uploaded by simonroadkill.


    But now I'm tired and feeling a bit fluey, very glad to be heading home tomorrow afternoon, despite Sarah and Daves awesome hospitality!


    Posted with LifeCast - Geolocate this post

    Friday, February 13, 2009

    Thursday, February 12, 2009