Merge branch 'develop' into gh-pages

* develop:
  implement pivotal tracker
  groundwork for pivot tracker integration
  add column view known bug: page-break-after not working
This commit is contained in:
Bengt Brodersen 2015-05-12 13:20:00 +02:00
commit f3c04efd8e

View File

@ -1,15 +1,15 @@
(function () { (function () {
var version = "3.2.3"; var version = "3.4.0";
console.log("Version: " + version); console.log("Version: " + version);
var isDev = typeof isDev !== 'undefined' && isDev ; var isDev = /.*jira.atlassian.com\/secure\/RapidBoard.jspa\?.*projectKey=ANERDS.*/g.test(document.URL) // Jira
|| /.*pivotaltracker.com\/n\/projects\/510733.*/g.test(document.URL); // PivotTracker
var hostOrigin = "https://qoomon.github.io/Jira-Issue-Card-Printer/"; var hostOrigin = "https://qoomon.github.io/Jira-Issue-Card-Printer/";
if(isDev){ if(isDev){
console.log("DEVELOPMENT"); console.log("DEVELOPMENT");
hostOrigin = "https://rawgit.com/qoomon/Jira-Issue-Card-Printer/develop/"; hostOrigin = "https://rawgit.com/qoomon/Jira-Issue-Card-Printer/develop/";
} } else {
//cors = "https://cors-anywhere.herokuapp.com/"; //cors = "https://cors-anywhere.herokuapp.com/";
//$("#card").load("https://cors-anywhere.herokuapp.com/"+"https://qoomon.github.io/Jira-Issue-Card-Printer/card.html"); //$("#card").load("https://cors-anywhere.herokuapp.com/"+"https://qoomon.github.io/Jira-Issue-Card-Printer/card.html");
@ -21,9 +21,9 @@
ga('create', 'UA-50840116-3', {'alwaysSendReferrer': true}); ga('create', 'UA-50840116-3', {'alwaysSendReferrer': true});
ga('set', 'page', '/cardprinter'); ga('set', 'page', '/cardprinter');
}
try { try {
// load jQuery // load jQuery
if (window.jQuery === undefined) { if (window.jQuery === undefined) {
appendScript('//ajax.googleapis.com/ajax/libs/jquery/1.7.0/jquery.min.js'); appendScript('//ajax.googleapis.com/ajax/libs/jquery/1.7.0/jquery.min.js');
@ -34,9 +34,17 @@
init(); init();
main(); main();
}); });
} catch (err) {
console.log(err.message);
if(!isDev){
ga('send', 'exception', {
'exDescription': err.message,
'exFatal': true
});
}
}
function init(){ function init(){
addJQueryFunctions(); addJQueryFunctions();
addConsoleFunctions(); addConsoleFunctions();
addStringFunctions(); addStringFunctions();
@ -47,6 +55,15 @@
console.logLevel = console.INFO; console.logLevel = console.INFO;
resourceOrigin = hostOrigin+ "resources/"; resourceOrigin = hostOrigin+ "resources/";
JIRA='JIRA'
PIVOTAL_TRACKER='PIVOTAL_TRACKER'
issueTracker = 'UNKNOWN'
if( jQuery("meta[name='application-name'][ content='JIRA']").length > 0){
issueTracker = JIRA
} else if( /.*\pivotaltracker.com\/.*/g.test(document.URL)){
issueTracker = PIVOTAL_TRACKER
}
} }
function main(){ function main(){
@ -74,7 +91,6 @@
jQuery("#card-print-dialog-title").text("Card Print - Loading " + issueKeyList.length + " issues..."); jQuery("#card-print-dialog-title").text("Card Print - Loading " + issueKeyList.length + " issues...");
renderCards(issueKeyList, function(){ renderCards(issueKeyList, function(){
jQuery("#card-print-dialog-title").text("Card Print"); jQuery("#card-print-dialog-title").text("Card Print");
//print();
}); });
} }
@ -98,6 +114,7 @@
var lineClamp = Math.floor(height / lineHeight); var lineClamp = Math.floor(height / lineHeight);
jQuery(page).find(".description").css("-webkit-line-clamp", lineClamp+""); jQuery(page).find(".description").css("-webkit-line-clamp", lineClamp+"");
//jQuery(page).scc("float","left");
}); });
}); });
printWindow.print(); printWindow.print();
@ -143,14 +160,19 @@
var deferredList = []; var deferredList = [];
issueKeyList.each(function(position, issueKey) { issueKeyList.each(function(index, issueKey) {
var page = newPage(issueKey); var page = newPage(issueKey);
page.attr("index",index);
page.hide(); page.hide();
page.find('.key').text(issueKey); page.find('.key').text(issueKey);
jQuery("body", printDocument).append(page); jQuery("body", printDocument).append(page);
var deferred = addDeferred(deferredList); var deferred = addDeferred(deferredList);
loadCardDataJSON(issueKey, function(responseData) { getCardData(issueKey, function(cardData) {
fillCardWithJSONData(page, responseData); console.logDebug("cardData: " + cardData);
if(!isDev){
ga('send', 'event', 'task', 'generate', 'card', cardData.type );
}
fillCard(page, cardData);
page.show(); page.show();
resizeIframe(printFrame); resizeIframe(printFrame);
deferred.resolve(); deferred.resolve();
@ -174,11 +196,17 @@
jQuery("#card-print-overlay-style").remove(); jQuery("#card-print-overlay-style").remove();
} }
function getSelectedIssueKeyList() { function getSelectedIssueKeyList() {
switch(issueTracker) {
case JIRA:
return getSelectedIssueKeyListJira();
case PIVOTAL_TRACKER:
return getSelectedIssueKeyListPivotalTracker();
}
}
function getSelectedIssueKeyListJira() {
//JIRA
if (jQuery("meta[name='application-name'][ content='JIRA']").length > 0) {
//Browse //Browse
if (/.*\/browse\/.*/g.test(document.URL)) { if (/.*\/browse\/.*/g.test(document.URL)) {
return jQuery("a[data-issue-key][id='key-val']").map(function() { return jQuery("a[data-issue-key][id='key-val']").map(function() {
@ -192,159 +220,249 @@
return jQuery(this).attr('data-issue-key'); return jQuery(this).attr('data-issue-key');
}); });
} }
return [];
}
function getSelectedIssueKeyListPivotalTracker() {
//Single Story
if (/.*\/n\/projects\/.*\/stories\/.*/g.test(document.URL)) {
return jQuery('.story[data-id]').map(function() {
return jQuery(this).attr('data-id');
});
}
// Board
if (/.*\/n\/projects\/.*/g.test(document.URL)) {
return jQuery('.story[data-id]:has(.selected)').map(function() {
return jQuery(this).attr('data-id');
});
} }
return []; return [];
} }
function fillCardWithJSONData(card, data) { function getCardData(issueKey, callback){
switch(issueTracker) {
case JIRA:
return getCardDataJira(issueKey, callback);
case PIVOTAL_TRACKER:
return getCardDataPivotalTracker(issueKey, callback);
}
}
function getCardDataJira(issueKey, callback) {
getIssueDataJira(issueKey,function(data){
var issueData = {};
issueData.key = data.key;
issueData.type = data.fields.issuetype.name.toLowerCase();
issueData.summary = data.fields.summary;
issueData.description = data.renderedFields.description;
if ( data.fields.assignee ) {
issueData.assignee = data.fields.assignee.displayName;
var avatarUrl = data.fields.assignee.avatarUrls['48x48'];
if(avatarUrl.indexOf("ownerId=") >= 0){
issueData.avatarUrl = avatarUrl;
}
}
if ( data.fields.duedate ) {
issueData.dueDate = new Date(data.fields.duedate).format('D d.m.');
}
issueData.hasAttachment = data.fields.attachment.length > 0;
if(issueData.description){
var printScope = issueData.description.indexOf(printScopeDeviderToken);
if (printScope >= 0) {
issueData.description = issueData.description.substring(0, printScope);
issueData.hasAttachment = true;
}
}
issueData.storyPoints = data.fields.storyPoints;
issueData.epicKey = data.fields.epicLink;
if ( issueData.epicKey ) {
getIssueDataJira(issueData.epicKey , function(data) {
issueData.epicName = data.fields.epicName;
}, false);
}
issueData.url = window.location.origin + "/browse/" + key;
//check for lrs
if(true){
console.logInfo("Apply LRS Specifics");
//Desired-Date
if ( data.fields.desiredDate ) {
issueData.dueDate = new Date(data.fields.desiredDate).format('D d.m.');
}
}
callback(issueData);
});
}
function getCardDataPivotalTracker(issueKey, callback) {
getIssueDataPivotalTracker(issueKey,function(data){
var issueData = {};
issueData.key = data.id;
issueData.type = data.kind.toLowerCase();
issueData.summary = data.name;
issueData.description = data.description;
if(issueData.description){
issueData.description = "<p>"+issueData.description
}
if ( data.owned_by && data.owned_by.length > 0 ) {
issueData.assignee = data.owner_ids[0].name;
}
if ( data.deadline ) {
issueData.dueDate = new Date(data.deadline).format('D d.m.');
}
issueData.hasAttachment = false;
if(issueData.description){
var printScope = issueData.description.indexOf(printScopeDeviderToken);
if (printScope >= 0) {
issueData.description = issueData.description.substring(0, printScope);
issueData.hasAttachment = true;
}
}
issueData.storyPoints = data.estimate;
// TODO
// issueData.epicKey = data.fields.epicLink;
// if ( issueData.epicKey ) {
// getIssueDataPivotalTracker(issueData.epicKey , function(data) {
// issueData.epicName = data.fields.epicName;
// }, false);
// }
issueData.url = data.url;
callback(issueData);
});
}
function getIssueDataJira(issueKey, callback, async) {
async = typeof async !== 'undefined' ? async : true;
//https://docs.atlassian.com/jira/REST/latest/
var url = '/rest/api/2/issue/' + issueKey + '?expand=renderedFields,names';
console.logDebug("IssueUrl: " + url);
console.logDebug("Issue: " + issueKey + " Loading...");
jQuery.ajax({
type: 'GET',
url: url,
data: {},
dataType: 'json',
async: async,
success: function(responseData){
console.logDebug("Issue: " + issueKey + " Loaded!");
// add custom fields with field names
jQuery.each(responseData.names, function(key, value) {
if(key.startsWith("customfield_")){
var newFieldId = value.toCamelCase();
console.logTrace("add new field: " + newFieldId +" with value from "+ key);
responseData.fields[value.toCamelCase()] = responseData.fields[key];
}
});
callback(responseData);
},
});
}
function getIssueDataPivotalTracker(issueKey, callback, async) {
async = typeof async !== 'undefined' ? async : true;
//http://www.pivotaltracker.com/help/api
var url = 'https://www.pivotaltracker.com/services/v5/stories/' + issueKey + "?fields=name,kind,description,story_type,owned_by(name),comments(file_attachments(kind)),estimate,deadline";
console.logDebug("IssueUrl: " + url);
console.logDebug("Issue: " + issueKey + " Loading...");
jQuery.ajax({
type: 'GET',
url: url,
data: {},
dataType: 'json',
async: async,
success: function(responseData){
console.logDebug("Issue: " + issueKey + " Loaded!");
callback(responseData);
},
});
}
function fillCard(card, data) {
//Key //Key
var key = data.key; card.find('.key').text(data.key);
console.logDebug("key: " + key);
card.find('.key').text(key);
//Type //Type
var type = data.fields.issuetype.name.toLowerCase(); card.find(".card").attr("type", data.type);
console.logDebug("type: " + type);
card.find(".card").attr("type", type);
if(!isDev){
ga('send', 'event', 'task', 'generate', 'card', type );
}
//Summary //Summary
var summary = data.fields.summary; card.find('.summary').text(data.summary);
console.logDebug("summary: " + summary);
card.find('.summary').text(summary);
//Description //Description
var description = data.renderedFields.description; card.find('.description').html(data.description);
console.logDebug("description: " + description);
card.find('.description').html(description);
//Assignee //Assignee
var assignee = data.fields.assignee; if ( data.assignee ) {
console.logDebug("assignee: " + assignee); if(data.avatarUrl){
if ( assignee ) { card.find(".assignee").css("background-image", "url('" + data.avatarUrl + "')");
var avatarUrl = assignee.avatarUrls['48x48']; } else {
if(avatarUrl.indexOf("ownerId=") < 0){ card.find(".assignee").text(data.assignee[0].toUpperCase());
var displayName = assignee.displayName;
card.find(".assignee").text(displayName[0].toUpperCase());
}
else {
card.find(".assignee").css("background-image", "url('" + avatarUrl + "')");
} }
} else { } else {
card.find(".assignee").addClass("hidden"); card.find(".assignee").addClass("hidden");
} }
//Due-Date //Due-Date
var duedate = data.fields.duedate; if ( data.dueDate ) {
console.logDebug("duedate: " + duedate); card.find(".due-date").text(data.dueDate);
if ( duedate ) {
var renderedDuedate = new Date(duedate).format('D d.m.');
card.find(".due-date").text(renderedDuedate);
} else { } else {
card.find(".due").addClass("hidden"); card.find(".due").addClass("hidden");
} }
//Attachment //Attachment
var hasAttachment = false; if ( data.hasAttachment ) {
var indexOfPrintScopeDeviderToken = description.indexOf(printScopeDeviderToken);
if (indexOfPrintScopeDeviderToken >= 0) {
var descriptionWithoutAttachment = description.substring(0, indexOfPrintScopeDeviderToken);
card.find('.description').html(descriptionWithoutAttachment);
hasAttachment = true;
} else if (data.fields.attachment.length > 0) {
hasAttachment = true;
}
console.logDebug("hasAttachment: " + hasAttachment);
if ( hasAttachment ) {
} else{ } else{
card.find('.attachment').addClass('hidden'); card.find('.attachment').addClass('hidden');
} }
//Story Points //Story Points
var storyPoints = data.fields.storyPoints; if (data.storyPoints) {
console.logDebug("storyPoints: " + storyPoints); card.find(".estimate").text(data.storyPoints);
if (storyPoints) {
card.find(".estimate").text(storyPoints);
} else { } else {
card.find(".estimate").addClass("hidden"); card.find(".estimate").addClass("hidden");
} }
//Epic //Epic
var epicKey = data.fields.epicLink; if ( data.epicKey ) {
console.logDebug("epicKey: " + epicKey); card.find(".epic-key").text(data.epicKey);
if ( epicKey ) { card.find(".epic-name").text(data.epicName);
card.find(".epic-key").text(epicKey);
loadCardDataJSON(epicKey, function(responseData) {
var epicName = responseData.fields.epicName;
console.logTrace("epicName: " + epicName);
card.find(".epic-name").text(epicName);
}, false);
} else { } else {
card.find(".epic").addClass("hidden"); card.find(".epic").addClass("hidden");
} }
//QR-Code //QR-Code
var qrCodeImageUrl = 'https://chart.googleapis.com/chart?cht=qr&chs=256x256&chld=L|1&chl=' + window.location.origin + "/browse/" + key; var qrCodeUrl = 'https://chart.googleapis.com/chart?cht=qr&chs=256x256&chld=L|1&chl=' + data.url;
console.logTrace("qrCodeImageUrl: " + qrCodeImageUrl); card.find(".qr-code").css("background-image", "url('" + qrCodeUrl + "')");
card.find(".qr-code").css("background-image", "url('" + qrCodeImageUrl + "')");
//handle Site specifics
switch (window.location.hostname) {
case "lrs-support.com": fillCardWithJSONDataLRS(card, data);
break;
default:
} }
}
function fillCardWithJSONDataLRS(card, data) {
console.logInfo("Apply LRS Specifics");
//Desired-Date
var desiredDate = data.fields.desiredDate;
console.logDebug("desiredDate: " + desiredDate);
if ( desiredDate ) {
var renderedDesiredDate = new Date(desiredDate).format('D d.m.');
card.find(".due-date").text(renderedDesiredDate);
card.find(".due").removeClass("hidden");
} else {
card.find(".due").addClass("hidden");
}
}
function loadCardDataJSON(issueKey, callback) {
//https://docs.atlassian.com/jira/REST/latest/
var url = '/rest/api/2/issue/' + issueKey + '?expand=renderedFields,names';
console.logDebug("IssueUrl: " + window.location.hostname + url);
console.logDebug("Issue: " + issueKey + " Loading...");
return jQuery.ajax({
type: 'GET',
url: url,
dataType: 'json',
success: function(responseData){
fields = responseData.fields;
// add custom fields with field names
jQuery.each(responseData.names, function(key, value) {
if(key.startsWith("customfield_")){
var newFieldId = value.toCamelCase();
console.logTrace("add new field: " + newFieldId +" with value from "+ key);
fields[value.toCamelCase()] = fields[key];
}
});
console.logDebug("Issue: " + issueKey + " Loaded!");
callback(responseData);
},
data: {},
});
}
//############################################################################################################################ //############################################################################################################################
//############################################################################################################################ //############################################################################################################################
//############################################################################################################################ //############################################################################################################################
@ -1178,13 +1296,4 @@
iframe.height(iframe[0].contentWindow.document.body.scrollHeight); iframe.height(iframe[0].contentWindow.document.body.scrollHeight);
} }
} catch (err) {
console.logError(err.message);
if(!isDev){
ga('send', 'exception', {
'exDescription': err.message,
'exFatal': true
});
}
};
})(); })();