groundwork for pivot tracker integration

This commit is contained in:
Bengt Brodersen 2015-05-12 11:35:23 +02:00
parent 05992ab72e
commit 5c5272087b

View File

@ -2,17 +2,14 @@
var version = "3.2.3"; var version = "3.2.3";
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
if (/.*projectKey=ANERDS.*/g.test(document.URL)) { || /.*pivotaltracker.com\/n\/projects\/510733.*/g.test(document.URL); // PivotTracker
isDev = true;
}
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");
@ -24,6 +21,8 @@
ga('create', 'UA-50840116-3', {'alwaysSendReferrer': true}); ga('create', 'UA-50840116-3', {'alwaysSendReferrer': true});
ga('set', 'page', '/cardprinter'); ga('set', 'page', '/cardprinter');
}
try { try {
@ -49,6 +48,7 @@
console.logLevel = console.INFO; console.logLevel = console.INFO;
resourceOrigin = hostOrigin+ "resources/"; resourceOrigin = hostOrigin+ "resources/";
} }
function main(){ function main(){
@ -76,9 +76,7 @@
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();
}); });
setColumnCount(1);
} }
function print(){ function print(){
@ -117,25 +115,6 @@
} }
} }
function setColumnCount(columnCount){
var printFrame = jQuery("#card-print-dialog-content-iframe");
var printWindow = printFrame[0].contentWindow;
var printDocument = printWindow.document;
jQuery(".column > .page",printDocument).unwrap();
jQuery(".page",printDocument).sort(function(a, b) {
return parseInt(jQuery(a).attr("index")) > parseInt(jQuery(b).attr("index")) ? 1 : -1;
}).appendTo(jQuery("body",printDocument));
var columns = []
for(var columnIndex = 0; columnIndex < columnCount; columnIndex+=1) {
columns[columnIndex] = jQuery(".page:nth-child("+columnCount+"n+"+columnIndex+")", printDocument);
}
for(var columnIndex = 0; columnIndex < columnCount; columnIndex+=1) {
columns[columnIndex].wrapAll("<div class='column' style='width: calc(100% / "+columnCount+" - "+((columnCount-1)/columnCount)+"cm)'></div>");
}
}
function renderCards(issueKeyList, callback) { function renderCards(issueKeyList, callback) {
var printFrame = jQuery("#card-print-dialog-content-iframe"); var printFrame = jQuery("#card-print-dialog-content-iframe");
@ -159,8 +138,12 @@
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();
@ -184,8 +167,14 @@
jQuery("#card-print-overlay-style").remove(); jQuery("#card-print-overlay-style").remove();
} }
function getSelectedIssueKeyList() { function getSelectedIssueKeyList() {
// jira
if( true){
return getSelectedJiraIssueKeyList();
}
}
function getSelectedJiraIssueKeyList() {
//JIRA //JIRA
if (jQuery("meta[name='application-name'][ content='JIRA']").length > 0) { if (jQuery("meta[name='application-name'][ content='JIRA']").length > 0) {
@ -207,152 +196,153 @@
return []; return [];
} }
function fillCardWithJSONData(card, data) { function getCardData(issueKey, callback){
//Jira
if(true){
getJiraCardData(issueKey, callback);
}
}
function getJiraCardData(issueKey, callback) {
getJiraIssueData(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;
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 ) {
getJiraIssueData(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 getJiraIssueData(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: " + window.location.hostname + 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 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: {},
});
}
//############################################################################################################################ //############################################################################################################################
//############################################################################################################################ //############################################################################################################################
@ -384,7 +374,6 @@
<label style="margin-right:10px"><input id="card-scale-range" type="range" min="0.4" max="1.4" step="0.05" value="1.0" />Scale</label> <label style="margin-right:10px"><input id="card-scale-range" type="range" min="0.4" max="1.4" step="0.05" value="1.0" />Scale</label>
<label style="margin-right:10px"><input id="hide-description-checkbox" type="checkbox"/>Hide Description</label> <label style="margin-right:10px"><input id="hide-description-checkbox" type="checkbox"/>Hide Description</label>
<label style="margin-right:10px"><input id="multi-card-page-checkbox" type="checkbox"/>Multi Card Page</label> <label style="margin-right:10px"><input id="multi-card-page-checkbox" type="checkbox"/>Multi Card Page</label>
<label style="margin-right:10px"><input id="two-column-page-checkbox" type="checkbox"/>Two Column Page</label>
<input id="card-print-dialog-print" type="button" class="aui-button aui-button-primary" value="Print" /> <input id="card-print-dialog-print" type="button" class="aui-button aui-button-primary" value="Print" />
<a id="card-print-dialog-cancel" title="Cancel" class="cancel">Cancel</a> <a id="card-print-dialog-cancel" title="Cancel" class="cancel">Cancel</a>
</div> </div>
@ -414,14 +403,6 @@
return true; return true;
}); });
// enable two column page
result.find("#two-column-page-checkbox")
.click(function() {
setColumnCount(this.checked ? 2 : 1);
return true;
});
// hide description // hide description
result.find("#hide-description-checkbox") result.find("#hide-description-checkbox")
@ -606,22 +587,6 @@
padding: 0.5cm; padding: 0.5cm;
} }
.column{
display:inline-block;
float: left;
padding: 0.0cm;
margin: 0.0cm;
margin-right: 0.5cm;
margin-left: 0.5cm;
}
.column:first-of-type{
margin-left: 0.0cm;
}
.column:last-of-type {
margin-right: 0.0cm;
}
.page { .page {
position: relative; position: relative;
overflow: auto; overflow: auto;