Skip to content

Instantly share code, notes, and snippets.

@andyed
Created August 19, 2009 19:09
Show Gist options
  • Save andyed/170593 to your computer and use it in GitHub Desktop.
Save andyed/170593 to your computer and use it in GitHub Desktop.
VersionOne Ubiquity Commands for v0.5
var v1 = {
"path" : Application.prefs.getValue("extensions.ubiquity.v1instance",""),
"debugMode" : true,
"commandVersion": "0.3.3"
}
const V1MAXRESULTS = 20;
const V1NOPATH = 'Please run v1setinstance to set the path to your server.<br/><em>v1setinstance http://localhost/versionone/</em>';
const V1BRANDBAR = '<center><img src="http://udpates.versionone.com/ubiquity/images/versionone_logo_onblack_30.gif"/></center><br/>';
const V1BSDSTYLELICENSE = 'Copyright (c) 2008, VersionOne, Inc. All rights reserved.'+
'Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:'+
'* Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.'+
'* Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.'+
'*Neither the name of VersionOne, Inc. nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission of VersionOne, Inc.'+
'THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.';
var noun_type_creatable_asset = new CmdUtils.NounType( "CreatableAsset",
["Story", "Issue", "Defect","Requirement", "BacklogItem", "Request"]
);
var noun_type_asset = new CmdUtils.NounType( "Asset",
["Story", "Issue", "Defect", "Iteration", "Sprint", "Task", "Test", "Requirement", "Workitem", "Epic", "BacklogItem", "Message", "Request"]
);
var noun_type_assets = new CmdUtils.NounType( "Assets",
["Stories", "Issues", "Defects", "Iterations", "Sprints", "Tasks", "Tests", "Requirements", "Workitems", "Epics", "BacklogItems", "Messages", "Requests"]
);
var noun_type_pages = {
_name: "Pages",
_expectedWords: ["PrimaryBacklog","BuildReport","CategoryVelocity", "CloseIteration", "DetailPlanning", "DetailRoadmap","DetailTracking","DefectList","DefectPriorityTrend","DefectResolutionTrend","DefectStatusTrend","Epics","EstimateBurndown","EstimateTrend","ExternalTestTrend","Goals","GoalAssignment","Import","IssueActivity","IssueList","IssuesProductPlanning","IssuesIterationPlanning","IterationScheduling","IterationCapacityByMemberByTeam","IterationCapacityByMember","IterationDashboard","IterationEstimate", "IterationLoad","IterationTrackingIssues","MemberGroupDashboard", "MemberList","MemberPlanning","MemberTracking","MyHomeSummary", "MyHomeProjectScorecard", "MyInbox", "PriorityVelocity", "ProgramScopeChange", "ProjectDashboard", "ProjectList", "ProjectRoadmap","ProjectScopeChangePage", "ProjectVelocity","ReleaseScheduling","ReleaseForecasting","RequestsPlanning", "RequestStatusTrend","Retrospectives", "RetrospectiveList","RiskVelocity", "StandupDashboardPopup", "StoryList","StatusVelocity","TaskList", "Taskboard", "Testboard","Templates","TeamAssignment","TeamEstimateTrend","TeamTestTrend","TeamBurndown","TestList","TestTrend","ThemeAssignment","ThemeDashboard","ThemeList", "TimeboxList", "TotalVelocity"],
suggest: function( text, html, callback ) {
var cmd = text.toLowerCase();
var suggests = [];
for(var i=0;i<this._expectedWords.length;i++) {
if(this._expectedWords[i].toLowerCase().indexOf(cmd) > -1 ) {
suggests.push(CmdUtils.makeSugg(this._expectedWords[i]));
}
}
return suggests;
}
};
var noun_type_sortby = {
_name: "Sort Orders",
_expectedWords: ["ChangeDate", "-ChangeDate","Order","-Order", "Priority", "-Priority", "Estimate", "-Estimate", "ToDo", "-ToDo"],
suggest: function( text, html, data ) {
var cmd = text.toLowerCase();
var suggests = [];
for(var i=0;i<this._expectedWords.length;i++) {
if(this._expectedWords[i].toLowerCase().indexOf(cmd) > -1 ) {
suggests.push(CmdUtils.makeSugg(this._expectedWords[i]));
}
}
return suggests;
}
};
var noun_type_v1project_topic = {
_name: "V1 Project",
// "https://www7.v1host.com/V1Production/rest-1.v1/Data/Scope?where=AssetState!=%27Closed%27"
suggest: function suggest( text, html, callback ) {
jQuery.ajax( {
url:v1.path + "rest-1.v1/Data/Scope?sel=Name&where=AssetState!=%27Closed%27" + "&Accept=application/json",
dataType: "json",
data: { prefix: text, limit: V1MAXRESULTS },
success: function suggestTopics( response ) {
var i, results, result;
results = response.Assets;
//if(v1.debugMode) CmdUtils.log(results.length);
for ( i = 0; i < results.length; i++ ) {
result = results[ i ];
// if(v1.debugMode) CmdUtils.log(result.Attributes["Name"].value);
//if(v1.debugMode) CmdUtils.log(result.Attributes["Name"].value.toUpperCase().indexOf(text.toUpperCase()));
if(result.Attributes["Name"].value.toUpperCase().indexOf(text.toUpperCase()) > -1) callback( CmdUtils.makeSugg( result.Attributes["Name"].value, result.id, result ));
}
}
} );
return ["","",""];
}
}
CmdUtils.CreateCommand({
names: "v1setinstance",
author: {name: "Andy Edmonds", homepage: "http://udpates.versionone.com/ubiquity/"},
icon: "http://www.versionone.com/favicon.ico",
license: V1BSDSTYLELICENSE,
arguments: [{ role: 'object', nountype: noun_arb_text, label:'URL Prefix'}],
preview: function( previewBlock, args ) {
var current = args.object;
var curInstance = Application.prefs.getValue("extensions.ubiquity.v1instance", false);
if(v1.debugMode) CmdUtils.log(curInstance);
var msg = 'Set server instance to path ... ' + '<br/>';
if(curInstance) msg += "Current instance is " + curInstance + '<br/>';
previewBlock.innerHTML = msg + V1BRANDBAR ; // + term.text;
},
execute: function( args ) {
Application.prefs.setValue("extensions.ubiquity.v1instance",args.object.text);
v1.path = args.object.text;
}
}
)
CmdUtils.CreateCommand({
names: "v1find",
author: {name: "Andy Edmonds", homepage: "http://udpates.versionone.com/ubiquity/"},
icon: "http://www.versionone.com/favicon.ico",
license: V1BSDSTYLELICENSE,
arguments:[ {role:"object", nountype:noun_arb_text, label:"keyword:"}, {role:"location", nountype:noun_type_assets, label:"AssetType"}, {role:"goal", nountype:noun_type_sortby, label:"sortby"},
{role: "source", nountype: noun_type_v1project_topic, label:"in project" }],
preview: function( previewBlock, mods ) {
const openClause = "Workitem.AssetState!='Closed'";
const mineClause = "Owners.IsSelf='TRUE'";
const closedClause = "Workitem.AssetState='Closed'";
const currentClause = "Timebox.State.Code='ACTV'";
var query = 'rest-1.v1/Data/';
var attribute, relation, attributeValue, theTerm, keyword;
var whereClause = '';
var findClause = '';
var searchText = jQuery.trim(mods.object.text);S
if(!v1.path.length) { previewBlock.innerHTML = V1NOPATH;return;}
if(mods == 'undefined' || !mods) {
if(v1.debugMode) CmdUtils.log("Punting");
return;
}
//Sif(!mods.object.text.length && !mods.goal.text.length && !mods.format.text.length) return;
if(v1.debugMode) CmdUtils.log(mods);
var dtype;
var dsort = '';
var fields = 'Name,Description,AssetState,Number';
if(!mods.location || !mods.location.text || !mods.location.text.length ) mods.location.text = "WorkItems";
switch ( mods.location.text.toLowerCase()) {
// Notes disabled due to variation in summary fields, name/content
case 'notes':
dtype = 'Note';
dsort = '-ChangeDate';
icon = 'note';
break;
case 'baseasset':
dtype = 'BaseAsset';
dsort = ''
break;
case 'stories':
dtype = 'Story';
icon = 'Feature';
dsort = 'Order';
break;
case 'messages':
dtype = 'Message';
icon = 'Message';
dsort = '-ChangeDate';
break;
case 'issues':
dtype = 'Issue';
icon = 'Issue';
break;
case 'defects':
dtype = 'Defect';
break;
case 'tasks':
dtype = 'Task';
icon = 'Task';
break;
case 'requests':
dtype = 'Request';
icon = 'Request';
break;
case 'tests':
dtype = 'Test';
icon = 'Test';
break;
case 'sprints':
dtype = 'Timebox';
icon = 'Iteration';
break;
case 'iterations':
dtype = 'Timebox';
break;
case 'themes':
dtype = 'Theme';
break;
case 'featuregroups':
dtype = 'Theme';
break;
case 'usecases':
dtype = 'Theme';
break;
case 'projects':
dtype = 'Scope';
break;
case 'scopes':
dtype = 'Scope';
break;
case 'workitems':
dtype = 'Workitem';
dsort='';
break;
case 'epic':
whereOverride = "AssetState='208'";
dtype = 'Story';
break;
}
query += '' + dtype + '?page=' + V1MAXRESULTS + ',0&findin=Name,Description,Number';
query += '&sel=' + fields;
var terms = mods.object.text.split(" ");
for(var termIndex=0;termIndex < terms.length;termIndex++) {
theTerm=terms[termIndex];
var bits = /([^!]*)(\!\=|\=|<|>)(.*)/.exec(theTerm);
if(bits) {
if(whereClause.length) whereClause+= ';';
if(!whereClause.length) whereClause = '&where=';
attribute = bits[1];
attributeValue = bits[3];
relation = bits[2];
whereClause += attribute + relation + "'" + attributeValue + "'";
} else {
keyword = false;
if(theTerm == '@current') {
!whereClause.length ? whereClause += '&where=' : whereClause += ';';
whereClause += currentClause;
keyword = true
}
if(theTerm == '@mine' ) {
if(dtype == 'BaseAssets') dtype = 'Workitems';
!whereClause.length ? whereClause += '&where=' : whereClause += ';';
whereClause +=mineClause;
keyword = true
}
if(theTerm == '@open') {
!whereClause.length ? whereClause += '&where=' : whereClause += ';';
whereClause += openClause;
keyword = true
}
if(theTerm == '@closed') {
!whereClause.length ? whereClause += '&where=' : whereClause += ';';
whereClause += closedClause;
keyword = true
}
if(!keyword) query += '&find=' + theTerm;
}
}
if(mods.sortby && mods.sortby.text && mods.sortby.text.length) {
var sortby =dsort;
switch (mods.sortby.text.toLowerCase()) {
case "order":
if(dtype != 'BaseAsset') sortby = "Order";
break;
case "-order":
if(dtype != 'BaseAsset') sortby = "-Order";
break;
case "changedate":
sortby = "ChangeDate";
break;
case "-changedate":
sortby = "-ChangeDate";
break;
case "priority":
sortby = "Priority";
break;
case "-priority":
sortby = "-Priority";
break;
case "estimate":
sortby = "PrimaryWorkitem.Estimate";
break;
case "-estimate":
sortby = "-PrimaryWorkitem.Estimate";
break;
case "todo":
sortby = "ToDo";
break;
case "-Todo":
sortby = "-ToDo";
break;
}
query += '&sort=' + sortby;
} else {
query += '&sort=-ChangeDate';
}
if(mods.source.text.length && mods.source.text.length) {
!whereClause.length ? whereClause += '&where=' : whereClause += ';';
whereClause += "Scope.Name='" + mods.source .text + "'";
}
urlString = v1.path + query;
if(v1.debugMode) CmdUtils.log(urlString);
if(whereClause.length) urlString += whereClause;
previewBlock.innerHTML = "Please wait<blink>...</blink> Searching for: " + query ;
if(v1.debugMode) CmdUtils.log(urlString);
jQuery.ajax({
type: "GET",
url: urlString,
dataType: "xml",
error: function() {
previewBlock.innerHTML = "Error searching... at " + urlString + ". Check your instance and make sure the sort & operators apply to the asset type (hint: try adding 'in stories')";
},
success: function(responseData) {
var items = [];
xmlDoc = jQuery(responseData);
var resultCount = xmlDoc.find("Assets").attr("total");
previewBlock.innerHTML = resultCount + " results.";
xmlDoc.find("Assets").children("Asset").slice(0, V1MAXRESULTS).each(
function(itemIndex) {
var itemDetails = jQuery(this);
var href = itemDetails.attr("href");
var id = itemDetails.attr("id");
var type = '';
var idval = '';
var href='';
if(id != 'undefined') {
type = id.split(":")[0];
idval = id.split(":")[1];
icon = type;
href = v1.path + 'assetdetail.v1?oid=' + id;
if(type == 'Message') href= v1.path + 'Default.aspx?menu=MyInboxPage';
if(icon == 'Story') icon = 'Feature';
if(icon == 'Timebox') icon = 'Iteration';
items.push({
icontype: icon,
title: itemDetails.find("[name='Number']").text() + "&nbsp;&nbsp;" + itemDetails.find("[name='Name']").text(),
//id + "::" + itemDetails.find("[name='Name']").text(),
description: itemDetails.find("[name='Description']").text(),
url:href,
});
}
});
var previewTemplate =
"{for item in items}" +
"<div style=\"clear: both; padding: 1px 0px; 0px; 0px;\">" +
"<a href=\"${item.url}\">" +
"<img src='" + v1.path + "images/Clifton/icons/${item.icontype}-Icon.gif' border='0' vspace='2' style='border:none' align='left'/>" +
"<u>${item.title}</u></a> " +
"<div style='max-height:120px;overflow:hidden;border-top:0px;padding-top:0px;padding-left:14px;size:10px;' hspace=1>${item.description}</div>" +
"</div>" +
"{/for}";
var previewData = {
items: items
};
if(parseInt(resultCount)) {
previewBlock.innerHTML = V1BRANDBAR + 'Preview of ' + resultCount + ' Assets. <br/><br/>' + CmdUtils.renderTemplate(previewTemplate, previewData);
} else {
previewBlock.innerHTML = V1BRANDBAR + 'No Results Found';
}
}
})
},
execute: function( term, mods ) {
var loadpath = 'Search.aspx?';
if(term.text.length && term.text.indexOf("=") == -1) {
loadpath+= 'q=' + term.text;
if(mods.in.text.length) {
var typeval='';
switch ( mods.in.text) {
case "Tasks":
typeval="Task";
break;
case "Stories":
typeval = "Story";
break;
case "Defects":
typeval = "Defect";
break;
case "Requests":
typeval = "Request";
break;
case "Issues":
typeval = "Issue";
break;
default:
typeval ="AllItems";
}
loadpath += '&type=' + typeval;
} else {
loadpath += '&type=AllItems'
}
Utils.openUrlInBrowser(v1.path + loadpath );
}
}
})
CmdUtils.CreateCommand({
names: "v1goto",
author: {name: "Andy Edmonds", homepage: "http://udpates.versionone.com/ubiquity/"},
icon: "http://www.versionone.com/favicon.ico",
license: V1BSDSTYLELICENSE,
arguments: [{role: 'object', nountype: noun_type_pages, label:'page'}, {role: 'location', nountype: noun_type_v1project_topic, label: 'project'} ],
preview: function( previewBlock, args ) {
if(v1.debugMode) CmdUtils.log(args);
if(!v1.path.length) { previewBlock.innerHTML = V1NOPATH;return;}
previewBlock.innerHTML = 'Jump to Page ... <br/>'+ V1BRANDBAR; // + term.text;
},
execute: function( args ) {
if(v1.debugMode) CmdUtils.log(args);
if(args) {
Utils.openUrlInBrowser(v1.path + 'Default.aspx?menu=' + args.object.text + 'Page&PrimaryScopeContext=' + args.location.html.split(":")[0] + '%3a' + args.location.html.split(":")[1] );
} else {
Utils.openUrlInBrowser(v1.path + 'Default.aspx?menu=' + args.object.text + 'Page' );
}
}
})
CmdUtils.CreateCommand({
names: "v1new",
author: {name: "Andy Edmonds", homepage: "http://udpates.versionone.com/ubiquity/"},
arguments: [ { role: 'object', nountype: noun_type_creatable_asset, label: 'asset'},
{role: 'location', nountype: noun_type_v1project_topic, label: 'project'} ],
icon: "http://www.versionone.com/favicon.ico",
license: V1BSDSTYLELICENSE,
preview: function( previewBlock, term ) {
if(!v1.path.length) { previewBlock.innerHTML = V1NOPATH;return;}
previewBlock.innerHTML = 'Create a new VersionOne Asset: Story, Request, Issue ... in [Project Name]<br/><br/>' + V1BRANDBAR; // + term.text;
},
execute: function( mods ) {
var dtype;
switch ( mods.object.text.toLowerCase()) {
case 'story':
dtype = 'Story';
break;
case 'requirement':
dbtype = 'Story';
case 'issue':
dtype = 'Issue';
break;
case 'defect':
dtype = 'Defect';
break;
case 'request':
dtype = 'Request';
break;
case 'task':
dtype = 'Task';
break;
case 'sprint':
dtype = 'Timebox';
break;
case 'iteration':
dtype = 'Timebox';
break;
case 'theme':
dtype = 'Theme';
break;
case 'featuregroup':
dtype = 'Theme';
break;
case 'usecase':
dtype = 'Theme';
break;
case 'project':
dtype = 'Scope';
break;
case 'scope':
dtype = 'Scope';
break;
}
if(mods.location) {
Utils.openUrlInBrowser( v1.path + 'Default.aspx?Page=Gadgets%2fAddNewAsset%2fDropDown%2fControls%2fAdd' +dtype + '&W=1' + 'Page&PrimaryScopeContext=' + mods.location.html.split(":")[0] + '%3a' + mods.location.html.split(":")[1] );
} else {
Utils.openUrlInBrowser(v1.path + 'Default.aspx?Page=Gadgets%2fAddNewAsset%2fDropDown%2fControls%2fAdd' +dtype + '&W=1' );
}
}
})
CmdUtils.CreateCommand({
names: "v1community",
author: {name: "Andy Edmonds", homepage: "http://udpates.versionone.com/ubiquity/"},
icon: "http://www.versionone.com/favicon.ico",
license: V1BSDSTYLELICENSE,
arguments: [{ role:'object', nountype: noun_arb_text, label:'keyword'}],
preview: function( previewBlock, term ) {
previewBlock.innerHTML = 'Search the VersionOne community site or go straight there. <br/>'+ V1BRANDBAR;
},
execute: function( args ) {
if(args.object.text.length) {
Utils.openUrlInBrowser('http://community.versionone.com/_layouts/searchresults.aspx?u=http://community.versionone.com&k=' + encodeURIComponent(args.object.text) );
} else {
Utils.openUrlInBrowser('http://community.versionone.com/' );
}
}
})
CmdUtils.CreateCommand({
names: "v1faqs",
author: {name: "Andy Edmonds", homepage: "http://udpates.versionone.com/ubiquity/"},
icon: "http://www.versionone.com/favicon.ico",
license: V1BSDSTYLELICENSE,
arguments: [{ role:'object', nountype: noun_arb_text, label:'keyword'}],
preview: function( previewBlock, term ) {
previewBlock.innerHTML = 'Search the FAQs with Google or jump straight to the KnowledgeBase <br/>'+ V1BRANDBAR;
},
execute: function( args ) {
if(args.object.text.length) {
Utils.openUrlInBrowser('http://www.google.com/search?hl=en&q=site:community.versionone.com/KnowledgeBase+' + encodeURIComponent(args.object.text) );
} else {
Utils.openUrlInBrowser('http://community.versionone.com/KnowledgeBase/default.aspx' );
}
}
})
CmdUtils.CreateCommand({
names: "v1mail",
author: {name: "Andy Edmonds", homepage: "http://udpates.versionone.com/ubiquity/"},
icon: "http://www.versionone.com/favicon.ico",
license: V1BSDSTYLELICENSE,
//takes: {keyword: noun_arb_text},
//modifiers: {to: noun_type_teamMember},
preview: function( previewBlock) {
var urlString= v1.path + 'rest-1.v1/Data/Message?page=' + V1MAXRESULTS + ',0&sort=-ChangeDate';
if(v1.debugMode) CmdUtils.log(urlString);
// CmdUtils.log(urlString);
jQuery.ajax({
type: "GET",
url: urlString,
dataType: "xml",
error: function() {
//previewBlock.innerHTML = "Error searching...";
},
success: function(responseData) {
var items = [];
xmlDoc = jQuery(responseData);
var resultCount = xmlDoc.find("Assets").attr("total");
previewBlock.innerHTML = resultCount + " results.";
xmlDoc.find("Assets").children("Asset").slice(0, V1MAXRESULTS).each(
function(itemIndex) {
var itemDetails = jQuery(this);
//var href = itemDetails.attr("href");
var id = itemDetails.find("Relation[name='Asset']").find("Asset[idref]")[0].attributes[1].nodeValue;
var type = '';
var idval = '';
var href='';
if(id != 'undefined') {
type = id.split(":")[0];
idval = id.split(":")[1];
icon = type;
if(icon == 'Story') icon = 'Feature';
items.push({
icontype: icon,
title: itemDetails.find("[name='Number']").text() + "&nbsp;&nbsp;" + itemDetails.find("[name='Name']").text(),
//id + "::" + itemDetails.find("[name ='Name']").text(),
description: itemDetails.find("[name='Description']").text(),
url: v1.path + 'assetdetail.v1?oid=' + type + ':' + idval,
});
}
});
var previewTemplate =
"{for item in items}" +
"<div style=\"clear: both; padding: 1px 0px; 0px; 0px;\">" +
"<a href=\"${item.url}\">" +
"<img src='" + v1.path + "images/Clifton/icons/${item.icontype}-Icon.gif' border='0' vspace='2' style='border:none' align='left'/>" +
"<u>${item.title}</u></a> " +
"<div style='max-height:320px;overflow:hidden;border-top:0px;padding-top:0px;padding-left:14px;size:10px;' hspace=1>${item.description}</div>" +
"</div>" +
"{/for}";
var previewData = {
items: items
};
if(parseInt(resultCount)) {
previewBlock.innerHTML = V1BRANDBAR + 'Preview of ' + resultCount + ' Assets. <br/><br/>' + CmdUtils.renderTemplate(previewTemplate, previewData);
} else {
previewBlock.innerHTML = V1BRANDBAR + 'No Results Found';
}
}
})
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment