Building a Veracity Module - Part 4
Finishing up our Veracity module overview, let’s look at a few “fitting in” considerations.
How’d We End Up in the Menu?
If your server_files/ui/modules/yourmodule
folder contains a menu.js
file, that file will be loaded via a <script>
tag in the footer of every Veracity web page.
Whatever you want to add/change in the Veracity menu, do it here. In our case (and most cases), we just append an item to the <ul>
named topmenu
, which is (surprise!) Veracity’s top-level menu:
var tm = $('#topmenu');
var mi = $("<li id='topmenuwiki'></li>");
var ln = $("<a class='menulink'>wiki</a>").
attr('href', sgCurrentRepoUrl + "/wiki.html").
appendTo(mi);
tm.append(mi);
Notice that you can count on jQuery being available to your code.
What About the Activity Stream?
Wiki page changes show up in Veracity’s activity stream, alongside commits, bug updates, etc. The activity stream interface is a simple one: you need to create an object supporting three methods:
name()
: returns a string describing this particular activity component, for debug logging. Totally up to you.dagsUsed()
: returns an array of database DAG IDs, for caching. Include any DAGs your activity stream might query. In our case, it’s[sg.dagnum.WIKI, sg.dagnum.USERS]
getActivity()
: where all of the work happens
getActivity()
returns an array of objects, with (at least) the following members:
what
: A short description of the object that changed, updated, etc.title
: Usually redundant to “what”. Used for Atom entry titles.action
: What happened to that thing (created, updated, deleted, fixed…)who
: The Veracity user ID to whom this activity should be attributed (a committer, the editor of this particular Wiki change, etc.)when
: The (Unix timestamp) time when this activity occurred.link
: Optional, a link to the object, its history, etc.
Bug updates, for example, contain (among other things):
{
"what": "Work items that reference missing changesets can not be viewed",
"title: "Work items that reference missing changesets can not be viewed",
"action": "Fixed X1384",
"who":"g02d63075631e47bc8a29dad7027f59d382cff0ac413311e0838c60fb42f09aca",
"when":1313620280696.000000,
"link":"/workitem.html?recid=gdbb98600a5114533a0a936226f4b2efb8e381b80c91811e0b40f1c6f65d71da9"
}
You should return the most recent N items. The activity stream wrappers will sort them in with other activity sources before returning the JSON or Atom stream.
In the wiki’s case, we build records like so:
var record = {
what: thispage.title,
title: thispage.title,
who: thispage.userid,
when: thispage.timestamp
};
if (first)
record.action = "Created Wiki page";
else
record.action = "Edited Wiki page";
if (lastpage)
{
if (lastpage.title != thispage.title)
{
record.action = "Renamed Wiki page";
record.what += " (was " + lastpage.title + ")";
}
}
record.link = '/wiki.html?page=' + encodeURIComponent(title);
The first time a page is seen, we report it as “created”; thereafter, as “edited”. If the title changes along the way, we note that instead.
That’s about it, as module high points go. Further questions are very much welcome at the Veracity Q/A site.